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