| helics 3.6.1

ZmqRequestSets.h
1 /*
2 Copyright (c) 2017-2025,
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 {
24 class WaitingResponse {
25 public:
26 int route = 0;
27 std::uint16_t loops = 0;
28 bool waiting = false;
29 ActionMessage txmsg;
30 };
31
38 class ZmqRequestSets {
39 public:
41 ZmqRequestSets();
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
helics::ActionMessage
Definition: ActionMessage.hpp:30
helics::zeromq::WaitingResponse
Definition: ZmqRequestSets.h:24
helics::zeromq::WaitingResponse::txmsg
ActionMessage txmsg
the most recently sent message
Definition: ZmqRequestSets.h:29
helics::zeromq::WaitingResponse::loops
std::uint16_t loops
the number of loops
Definition: ZmqRequestSets.h:27
helics::zeromq::WaitingResponse::route
int route
the route identifier for the socket
Definition: ZmqRequestSets.h:26
helics::zeromq::WaitingResponse::waiting
bool waiting
whether the response is waiting
Definition: ZmqRequestSets.h:28
helics::zeromq::ZmqRequestSets
Definition: ZmqRequestSets.h:38
helics::zeromq::ZmqRequestSets::close
void close()
Definition: ZmqRequestSets.cpp:138
helics::zeromq::ZmqRequestSets::checkForMessages
int checkForMessages()
Definition: ZmqRequestSets.cpp:69
helics::zeromq::ZmqRequestSets::transmit
bool transmit(int routeNumber, const ActionMessage &command)
Definition: ZmqRequestSets.cpp:39
helics::zeromq::ZmqRequestSets::hasMessages
bool hasMessages() const
Definition: ZmqRequestSets.cpp:64
helics::zeromq::ZmqRequestSets::ZmqRequestSets
ZmqRequestSets()
Definition: ZmqRequestSets.cpp:17
helics::zeromq::ZmqRequestSets::addRoutes
void addRoutes(int routeNumber, const std::string &routeInfo)
Definition: ZmqRequestSets.cpp:18
helics::zeromq::ZmqRequestSets::waiting
bool waiting() const
Definition: ZmqRequestSets.cpp:59
helics::zeromq::ZmqRequestSets::getMessage
std::optional< ActionMessage > getMessage()
Definition: ZmqRequestSets.cpp:149
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14