#include <message_json.h>
Public Types | |
| using | Handler = std::function< void(const PeerId &from, const librats::Json &data)> |
| using | SendCallback = std::function< void(bool ok, const std::string &error)> |
Public Member Functions | |
| void | on (const std::string &type, Handler handler) |
Register a handler for type. | |
| void | once (const std::string &type, Handler handler) |
| Like on(), but the handler is removed right after it fires once. | |
| void | off (const std::string &type) |
Remove every handler registered for type. | |
| void | send (const std::string &type, const librats::Json &data, SendCallback cb=nullptr) |
Broadcast data of type to all connected peers. | |
| void | send (const PeerId &to, const std::string &type, const librats::Json &data, SendCallback cb=nullptr) |
Send data of type to one peer. | |
| void | attach (NodeContext &ctx) override |
| void | start () override |
| void | stop () override |
Public Member Functions inherited from librats::Subsystem | |
| virtual | ~Subsystem ()=default |
Definition at line 44 of file message_json.h.
| using librats::MessageJson::Handler = std::function<void(const PeerId& from, const librats::Json& data)> |
Definition at line 46 of file message_json.h.
| using librats::MessageJson::SendCallback = std::function<void(bool ok, const std::string& error)> |
Definition at line 47 of file message_json.h.
|
overridevirtual |
Implements librats::Subsystem.
| void librats::MessageJson::off | ( | const std::string & | type | ) |
Remove every handler registered for type.
| void librats::MessageJson::on | ( | const std::string & | type, |
| Handler | handler | ||
| ) |
Register a handler for type.
Additive: multiple handlers may coexist and all fire (in registration order) for each received message of that type.
| void librats::MessageJson::once | ( | const std::string & | type, |
| Handler | handler | ||
| ) |
Like on(), but the handler is removed right after it fires once.
| void librats::MessageJson::send | ( | const PeerId & | to, |
| const std::string & | type, | ||
| const librats::Json & | data, | ||
| SendCallback | cb = nullptr |
||
| ) |
Send data of type to one peer.
cb, if given, reports success or the reason it could not be sent (e.g. the peer is not connected).
| void librats::MessageJson::send | ( | const std::string & | type, |
| const librats::Json & | data, | ||
| SendCallback | cb = nullptr |
||
| ) |
Broadcast data of type to all connected peers.
cb, if given, reports whether there was at least one peer to send to.
|
inlineoverridevirtual |
Implements librats::Subsystem.
Definition at line 70 of file message_json.h.
|
inlineoverridevirtual |
Implements librats::Subsystem.
Definition at line 71 of file message_json.h.