BlueZero (BØ)
Middleware for distributed applications
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
b0::Subscriber Class Reference

The subscriber class. More...

#include <b0/subscriber.h>

Inheritance diagram for b0::Subscriber:
b0::Socket b0::logger::LogInterface

Public Member Functions

 Subscriber (Node *node, std::string topic_name, boost::function< void(const std::string &)> callback=0, bool managed=true, bool notify_graph=true)
 Construct an Subscriber child of the specified Node, optionally using a boost::function as callback.
 
template<class TNode >
 Subscriber (TNode *node, std::string topic_name, void(TNode::*callbackMethod)(const std::string &), bool managed=true, bool notify_graph=true)
 Construct a Subscriber child of a specified Node, with a method (of the Node subclass) as a callback.
 
template<class T >
 Subscriber (Node *node, std::string topic_name, void(T::*callbackMethod)(const std::string &), T *callbackObject, bool managed=true, bool notify_graph=true)
 Construct a Subscriber child of a specified Node, with a method as a callback.
 
virtual ~Subscriber ()
 Subscriber destructor.
 
void log (LogLevel level, std::string message) const override
 Log a message using node's logger, prepending this subscriber informations.
 
virtual void init () override
 Perform initialization and optionally send graph notify.
 
virtual void cleanup () override
 Perform cleanup and optionally send graph notify.
 
virtual void spinOnce () override
 Process incoming messages and call callbacks.
 
std::string getTopicName ()
 Return the name of this subscriber's topic.
 
- Public Member Functions inherited from b0::Socket
 Socket (Node *node, int type, std::string name, bool managed=true)
 Construct a Socket.
 
virtual ~Socket ()
 Socket destructor.
 
void setHasHeader (bool has_header)
 Set the has_header_ flag which specifies if this socket require a message part with the address (usually for publish/subscribe pattern).
 
void setRemoteAddress (std::string addr)
 Set the remote address the socket will connect to.
 
std::string getName () const
 Return the name of the socket bus.
 
NodegetNode () const
 Return the node owning this socket.
 
bool matchesPattern (const std::string &pattern) const
 Check if this socket name matches the specified pattern. More...
 
virtual void readRaw (std::string &msg)
 Read a raw payload from the underlying ZeroMQ socket.
 
virtual void readRaw (std::string &msg, std::string &type)
 Read a raw payload with type from the underlying ZeroMQ socket.
 
virtual bool poll (long timeout=0)
 Poll for messages. If timeout is 0 return immediately, otherwise wait for the specified amount of milliseconds.
 
virtual void writeRaw (const std::string &msg, const std::string &type="")
 Write a raw payload.
 
void setCompression (std::string algorithm, int level=-1)
 Set compression algorithm and level. More...
 
int getReadTimeout () const
 (low-level socket option) Get read timeout (in milliseconds, -1 for no timeout)
 
void setReadTimeout (int timeout)
 (low-level socket option) Set read timeout (in milliseconds, -1 for no timeout)
 
int getWriteTimeout () const
 (low-level socket option) Get write timeout (in milliseconds, -1 for no timeout)
 
void setWriteTimeout (int timeout)
 (low-level socket option) Set write timeout (in milliseconds, -1 for no timeout)
 
int getLingerPeriod () const
 (low-level socket option) Get linger period (in milliseconds, -1 for no timeout)
 
void setLingerPeriod (int period)
 (low-level socket option) Set linger period (in milliseconds, -1 for no timeout)
 
int getBacklog () const
 (low-level socket option) Get backlog
 
void setBacklog (int backlog)
 (low-level socket option) Set backlog
 
bool getImmediate () const
 (low-level socket option) Get immediate flag
 
void setImmediate (bool immediate)
 (low-level socket option) Set immediate flag
 
bool getConflate () const
 (low-level socket option) Get conflate flag
 
void setConflate (bool conflate)
 (low-level socket option) Set conflate flag
 
int getReadHWM () const
 (low-level socket option) Get read high-water-mark
 
void setReadHWM (int n)
 (low-level socket option) Set read high-water-mark
 
int getWriteHWM () const
 (low-level socket option) Get write high-water-mark
 
void setWriteHWM (int n)
 (low-level socket option) Set write high-water-mark
 
- Public Member Functions inherited from b0::logger::LogInterface
template<typename... Arguments>
void log (LogLevel level, std::string const &fmt, Arguments &&... args) const
 Log a message using a format string.
 

Protected Member Functions

virtual void connect ()
 Connect to the remote address.
 
virtual void disconnect ()
 Disconnect from the remote address.
 
- Protected Member Functions inherited from b0::Socket
void connect (std::string const &addr)
 Wrapper to zmq::socket_t::connect.
 
void disconnect (std::string const &addr)
 Wrapper to zmq::socket_t::disconnect.
 
void bind (std::string const &addr)
 Wrapper to zmq::socket_t::bind.
 
void unbind (std::string const &addr)
 Wrapper to zmq::socket_t::unbind.
 
void setsockopt (int option, const void *optval, size_t optvallen)
 Wrapper to zmq::socket_t::setsockopt.
 
void getsockopt (int option, void *optval, size_t *optvallen) const
 Wrapper to zmq::socket_t::getsockopt.
 
void setIntOption (int option, int value)
 High level wrapper for setsockopt.
 
int getIntOption (int option) const
 High level wrapper for getsockopt.
 

Protected Attributes

const bool notify_graph_
 If false this socket will not send announcement to resolv (i.e. it will be "invisible")
 
boost::function< void(std::string &)> callback_
 Callback which will be called when a new message is read from the socket.
 
- Protected Attributes inherited from b0::Socket
Nodenode_
 The Node owning this Socket.
 
std::string name_
 This socket bus name.
 
bool has_header_
 True if the payload has a header part (i.e. More...
 
const bool managed_
 True if this socket is managed (init(), cleanup() are called by the owner Node)
 
std::string remote_addr_
 The address of the ZeroMQ socket to connect to (will skip name resolution if given)
 

Additional Inherited Members

- Public Types inherited from b0::logger::LogInterface
enum  LogLevel {
  trace = 0, debug = 10, info = 20, warn = 30,
  error = 40, fatal = 50
}
 

Detailed Description

The subscriber class.

This class wraps a SUB socket. It will automatically connect to the XPUB socket of the proxy (note: the proxy is started by the resolver node).

In order to receive some message, you must set a topic subscription with Subscriber::subscribe. You can set multiple subscription, and the incoming messages will match any of those.

The subscription topics are strings and are matched on a prefix basis. (i.e. if the topic of the incoming message is "AAA", a subscription for "A" will match it)

See also
b0::Publisher, b0::Subscriber
Examples:
multi_subscriber.cpp, subscriber_node.cpp, subscriber_node_object.cpp, and subscriber_node_object_manual.cpp.

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