salsa 0.7.1
Loading...
Searching...
No Matches
SocketZyre.cc
1#include "SocketZyre.hh"
2#include "MessageZyre.hh"
3
4namespace Salsa {
5SocketZyre::SocketZyre(std::string name, std::map<std::string, std::string> headers)
6 : Socket(), mpSocket(zyre_new(name.c_str()))
7{
13
14 SPD_TRACE("Creating zyre socket name [{}]", name);
15
16 for (auto const & header : headers) {
17 SPD_DEBUG("[{}] header : [{}] [{}]", name, header.first, header.second);
18 zyre_set_header(mpSocket, header.first.c_str(), "%s", header.second.c_str());
19 }
20 mHeaders = headers;
21}
23{
27
28 disconnect();
29
30 zyre_destroy(&mpSocket);
31}
32
34{
38
39 SPD_TRACE("Starting zyre socket name [{}]", zyre_name(mpSocket));
40 return zyre_start(mpSocket);
41}
42
44{
48
49 if (mpSocket) {
50 SPD_TRACE("Stopping zyre socket name [{}]", zyre_name(mpSocket));
51 zyre_stop(mpSocket);
52 }
53 return 0;
54}
55
57{
61
62 zyre_event_t * pEvent = zyre_event_new(mpSocket);
63 return new MessageZyre(pEvent);
64}
65
67{
71
72 SPD_WARN("SocketZyre::push(Message *) not supported!");
73 if (!pMsg) {
74 return 1;
75 }
76 return 0;
77}
78
79int SocketZyre::push(std::string targetUUID, std::string payload)
80{
81 if (targetUUID.empty()) {
82 SPD_ERROR("Target UUID is empty!");
83 }
84
85 if (payload.empty()) {
86 SPD_ERROR("Payload is empty!");
87 }
88
89 return zyre_whispers(mpSocket, targetUUID.c_str(), "%s", payload.c_str());
90}
91
92} // namespace Salsa
Salsa zyre message class.
Base Message class.
Definition Message.hh:15
zyre_t * mpSocket
Zyre instance.
Definition SocketZyre.hh:50
virtual int push(Message *)
Push message.
Definition SocketZyre.cc:66
SocketZyre(std::string name="no_name", std::map< std::string, std::string > headers={})
Definition SocketZyre.cc:5
virtual Message * pull()
Pull message.
Definition SocketZyre.cc:56
virtual int disconnect() final
Disconnect function.
Definition SocketZyre.cc:43
virtual int connect() final
Connect function.
Definition SocketZyre.cc:33
std::string header(const char *pKey) const
Returns value for key from header.
Definition SocketZyre.hh:47
std::map< std::string, std::string > mHeaders
List of headers.
Definition SocketZyre.hh:52
virtual ~SocketZyre()
Definition SocketZyre.cc:22
Base Socket class.
Definition Socket.hh:15