DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
WIBCommon.hpp
Go to the documentation of this file.
1
11#ifndef WIBMOD_INCLUDE_WIBMOD_WIBCOMMON_HPP_
12#define WIBMOD_INCLUDE_WIBMOD_WIBCOMMON_HPP_
13
14#include "logging/Logging.hpp"
15
16#include "zmq.hpp"
17#include "wib.pb.h"
18
19#include <string>
20
21namespace dunedaq {
22namespace wibmod {
23
29{
30public:
31
32 WIBCommon(const std::string &wib_addr);
33
34 ~WIBCommon();
35
36 template <class R, class C>
37 void send_command(const C &msg, R &repl);
38
39private:
40
41 zmq::context_t context;
42
43 zmq::socket_t socket;
44
45};
46
47template <class R, class C>
48void
49WIBCommon::send_command(const C &msg, R &repl)
50{
51 wib::Command command;
52 command.mutable_cmd()->PackFrom(msg);
53
54 std::string cmd_str;
55 command.SerializeToString(&cmd_str);
56
57 zmq::message_t request(cmd_str.size());
58 memcpy(static_cast<void*>(request.data()), cmd_str.c_str(), cmd_str.size());
59 socket.send(request);
60
61 zmq::message_t reply;
62 socket.recv(&reply);
63
64 std::string reply_str(static_cast<char*>(reply.data()), reply.size());
65 repl.ParseFromString(reply_str);
66}
67
68} // namespace wibmod
69} // namespace dunedaq
70
71#endif // WIBMOD_INCLUDE_WIBMOD_WIBCOMMON_HPP_
The WIBCommon class defines convenience methods for using the ZeroMQ and protobuf communication proto...
Definition WIBCommon.hpp:29
WIBCommon(const std::string &wib_addr)
Definition WIBCommon.cpp:20
void send_command(const C &msg, R &repl)
Definition WIBCommon.hpp:49
::google::protobuf::Any * mutable_cmd()
Definition wib.pb.h:7195
Including Qt Headers.