DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
wibmod
src
wibmod
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
21
namespace
dunedaq
{
22
namespace
wibmod
{
23
28
class
WIBCommon
29
{
30
public
:
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
38
private
:
39
zmq::context_t
context
;
40
41
zmq::socket_t
socket
;
42
};
43
44
template
<
class
R,
class
C>
45
void
46
WIBCommon::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_
dunedaq::wibmod::WIBCommon::context
zmq::context_t context
Definition
WIBCommon.hpp:39
dunedaq::wibmod::WIBCommon::socket
zmq::socket_t socket
Definition
WIBCommon.hpp:41
dunedaq::wibmod::WIBCommon::WIBCommon
WIBCommon(const std::string &wib_addr)
Definition
WIBCommon.cpp:20
dunedaq::wibmod::WIBCommon::send_command
void send_command(const C &msg, R &repl)
Definition
WIBCommon.hpp:46
wib::Command
Definition
wib.pb.h:184
wib::Command::mutable_cmd
::google::protobuf::Any * mutable_cmd()
Definition
wib.pb.h:7195
Logging.hpp
TLOG_DEBUG
#define TLOG_DEBUG(lvl,...)
Definition
Logging.hpp:116
dunedaq::wibmod
Definition
WIBCommon.cpp:18
dunedaq
The DUNE-DAQ namespace.
Definition
cib_utilities.cpp:5
wib.pb.h
Generated on
for DUNE-DAQ by
1.18.0