helics  3.5.2
ZmqRequestSets.h
1 /*
2 Copyright (c) 2017-2024,
3 Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable
4 Energy, LLC. See the top-level NOTICE for additional details. All rights reserved.
5 SPDX-License-Identifier: BSD-3-Clause
6 */
7 #pragma once
8 
9 #include "../../core/ActionMessage.hpp"
10 #include "ZmqContextManager.h"
11 #include "cppzmq/zmq.hpp"
12 
13 #include <deque>
14 #include <map>
15 #include <memory>
16 #include <optional>
17 #include <string>
18 #include <utility>
19 #include <vector>
20 
21 namespace helics {
22 namespace zeromq {
25  public:
26  int route = 0;
27  std::uint16_t loops = 0;
28  bool waiting = false;
30  };
31 
39  public:
43  void addRoutes(int routeNumber, const std::string& routeInfo);
45  bool transmit(int routeNumber, const ActionMessage& command);
47  bool waiting() const;
50  int checkForMessages();
53  int checkForMessages(std::chrono::milliseconds timeout);
55  bool hasMessages() const;
57  std::optional<ActionMessage> getMessage();
59  void close();
60 
61  private:
63  void SendDelayedMessages();
64 
65  private:
66  std::map<int, std::unique_ptr<zmq::socket_t>> routes;
67  std::map<int, bool> routes_waiting;
68  std::vector<zmq::pollitem_t> active_routes;
69  std::vector<WaitingResponse> active_messages;
70  std::vector<std::pair<int, ActionMessage>>
71  waiting_messages;
72  std::deque<ActionMessage> Responses;
74  std::shared_ptr<ZmqContextManager> ctx;
75  };
76 } // namespace zeromq
77 } // namespace helics
Definition: ActionMessage.hpp:30
Definition: ZmqRequestSets.h:24
ActionMessage txmsg
the most recently sent message
Definition: ZmqRequestSets.h:29
std::uint16_t loops
the number of loops
Definition: ZmqRequestSets.h:27
int route
the route identifier for the socket
Definition: ZmqRequestSets.h:26
bool waiting
whether the response is waiting
Definition: ZmqRequestSets.h:28
Definition: ZmqRequestSets.h:38
void close()
Definition: ZmqRequestSets.cpp:137
int checkForMessages()
Definition: ZmqRequestSets.cpp:68
bool transmit(int routeNumber, const ActionMessage &command)
Definition: ZmqRequestSets.cpp:38
bool hasMessages() const
Definition: ZmqRequestSets.cpp:63
ZmqRequestSets()
Definition: ZmqRequestSets.cpp:16
void addRoutes(int routeNumber, const std::string &routeInfo)
Definition: ZmqRequestSets.cpp:17
bool waiting() const
Definition: ZmqRequestSets.cpp:58
std::optional< ActionMessage > getMessage()
Definition: ZmqRequestSets.cpp:148
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14