Back to Site
Loading...
Searching...
No Matches
librats::MessageJson Class Referencefinal

#include <message_json.h>

Inheritance diagram for librats::MessageJson:
[legend]
Collaboration diagram for librats::MessageJson:
[legend]

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

Detailed Description

Definition at line 45 of file message_json.h.

Member Typedef Documentation

◆ Handler

using librats::MessageJson::Handler = std::function<void(const PeerId& from, const librats::Json& data)>

Definition at line 47 of file message_json.h.

◆ SendCallback

using librats::MessageJson::SendCallback = std::function<void(bool ok, const std::string& error)>

Definition at line 48 of file message_json.h.

Member Function Documentation

◆ attach()

void librats::MessageJson::attach ( NodeContext & ctx)
overridevirtual

Implements librats::Subsystem.

◆ off()

void librats::MessageJson::off ( const std::string & type)

Remove every handler registered for type.

◆ on()

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.

◆ once()

void librats::MessageJson::once ( const std::string & type,
Handler handler )

Like on(), but the handler is removed right after it fires once.

◆ send() [1/2]

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).

◆ send() [2/2]

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.

◆ start()

void librats::MessageJson::start ( )
inlineoverridevirtual

Implements librats::Subsystem.

Definition at line 71 of file message_json.h.

◆ stop()

void librats::MessageJson::stop ( )
inlineoverridevirtual

Implements librats::Subsystem.

Definition at line 72 of file message_json.h.


The documentation for this class was generated from the following file: