rogue
Loading...
Searching...
No Matches
ZmqClient.h
Go to the documentation of this file.
1
17#ifndef __ROGUE_ZMQ_CLIENT_H__
18#define __ROGUE_ZMQ_CLIENT_H__
19#include "rogue/Directives.h"
20
21#include <memory>
22#include <string>
23#include <thread>
24
25#include "rogue/Logging.h"
26
27#ifndef NO_PYTHON
28 #include <boost/python.hpp>
29#endif
30
31namespace rogue {
32namespace interfaces {
33
48class ZmqClient {
49 // ZeroMQ context.
50 void* zmqCtx_;
51
52 // ZeroMQ subscriber socket for async updates.
53 void* zmqSub_;
54
55 // ZeroMQ request socket for RPC.
56 void* zmqReq_;
57
58 // Logger instance.
59 std::shared_ptr<rogue::Logging> log_;
60
61 // Request timeout in milliseconds.
62 uint32_t timeout_;
63
64 // Continue retrying after timeout when true.
65 bool waitRetry_;
66
67 // Background update thread (binary mode).
68 std::thread* thread_;
69 bool threadEn_;
70 bool running_;
71
72 // True when operating in string request mode.
73 bool doString_;
74
75 void runThread();
76
77 public:
93 static std::shared_ptr<rogue::interfaces::ZmqClient> create(const std::string& addr, uint16_t port, bool doString);
94
96 static void setup_python();
97
109 ZmqClient(const std::string& addr, uint16_t port, bool doString);
110
112 virtual ~ZmqClient();
113
119 void setTimeout(uint32_t msecs, bool waitRetry);
120
128 std::string sendString(const std::string& path, const std::string& attr, const std::string& arg);
129
135 std::string getDisp(const std::string& path);
136
142 void setDisp(const std::string& path, const std::string& value);
143
150 std::string exec(const std::string& path, const std::string& arg = "");
151
157 std::string valueDisp(const std::string& path);
158
159#ifndef NO_PYTHON
165 boost::python::object send(boost::python::object data);
166
171 virtual void doUpdate(boost::python::object data);
172#endif
173
175 void stop();
176};
177typedef std::shared_ptr<rogue::interfaces::ZmqClient> ZmqClientPtr;
178
179#ifndef NO_PYTHON
180
184class ZmqClientWrap : public rogue::interfaces::ZmqClient, public boost::python::wrapper<rogue::interfaces::ZmqClient> {
185 public:
192 ZmqClientWrap(const std::string& addr, uint16_t port, bool doString);
193
201 void doUpdate(boost::python::object data);
202
210 void defDoUpdate(boost::python::object data);
211};
212
213typedef std::shared_ptr<rogue::interfaces::ZmqClientWrap> ZmqClientWrapPtr;
214#endif
215} // namespace interfaces
216} // namespace rogue
217
218#endif
Python-overridable wrapper for ZmqClient.
Definition ZmqClient.h:184
void defDoUpdate(boost::python::object data)
Calls base-class doUpdate() implementation.
void doUpdate(boost::python::object data)
Handles an update message from the subscription path.
ZeroMQ client for Rogue control and update messaging.
Definition ZmqClient.h:48
std::string sendString(const std::string &path, const std::string &attr, const std::string &arg)
Sends a string-mode request.
void stop()
Stops client sockets and background thread.
std::string getDisp(const std::string &path)
Reads display-formatted value at a path (string mode).
virtual void doUpdate(boost::python::object data)
Handles async update payloads received on subscriber socket.
std::string exec(const std::string &path, const std::string &arg="")
Executes callable node at path (string mode).
boost::python::object send(boost::python::object data)
Sends binary request payload and receives binary response.
static void setup_python()
Registers Python bindings for this class.
Definition ZmqClient.cpp:44
std::string valueDisp(const std::string &path)
Reads compact value display at a path (string mode).
static std::shared_ptr< rogue::interfaces::ZmqClient > create(const std::string &addr, uint16_t port, bool doString)
Creates a ZeroMQ client.
Definition ZmqClient.cpp:38
void setTimeout(uint32_t msecs, bool waitRetry)
Sets request timeout behavior.
virtual ~ZmqClient()
Destroys client and stops background activity.
void setDisp(const std::string &path, const std::string &value)
Writes display-formatted value at a path (string mode).
std::shared_ptr< rogue::interfaces::ZmqClient > ZmqClientPtr
Definition ZmqClient.h:177
std::shared_ptr< rogue::interfaces::ZmqClientWrap > ZmqClientWrapPtr
Definition ZmqClient.h:213