VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
G::PublisherSubscription Class Reference

An easy-to-use combination of a G::PublisherChannel object and a single G::PublisherSubscriber. More...

#include <gpublisher.h>

Public Member Functions

 PublisherSubscription (const std::string &channel_name, bool lazy=false)
 Constructor. More...
 
bool open ()
 Tries to initialise the object after lazy construction or after close(). More...
 
int fd () const
 Returns the subscriber's file descriptor or minus one.
 
bool receive (std::vector< char > &buffer, std::string *type_p=nullptr, G::EpochTime *time_p=nullptr)
 Does a read for new publish()ed data. More...
 
bool peek (std::vector< char > &buffer, std::string *type_p=nullptr, G::EpochTime *time_p=nullptr)
 Does a receive() but without requiring a publication event.
 
std::string name () const
 Returns the channel name, as passed in to the constructor.
 
std::string info () const
 Returns some channel metadata as a short json string (see G::Item::str()). More...
 
unsigned int age () const
 Returns the age of the latest data in seconds, or zero. More...
 
void close ()
 Closes the channel subscription, releasing resources and becoming inactive. More...
 

Detailed Description

An easy-to-use combination of a G::PublisherChannel object and a single G::PublisherSubscriber.

Definition at line 229 of file gpublisher.h.

Constructor & Destructor Documentation

G::PublisherSubscription::PublisherSubscription ( const std::string &  channel_name,
bool  lazy = false 
)
explicit

Constructor.

The channel is normally subscribed to immediately, with errors resulting in exceptions; but if the lazy option is used then then initialisation happens in init() and the constructor will not throw.

Channel names are simple names (eg. "foo"), but at this interface they can be overloaded with the socket prefix, eg. "/var/tmp/foo.s/foo".

Definition at line 399 of file gpublisher.cpp.

Member Function Documentation

unsigned int G::PublisherSubscription::age ( ) const

Returns the age of the latest data in seconds, or zero.

The implementation uses peek().

Definition at line 479 of file gpublisher.cpp.

void G::PublisherSubscription::close ( )

Closes the channel subscription, releasing resources and becoming inactive.

The fd() method will return -1, although name() remains valid.

Definition at line 490 of file gpublisher.cpp.

std::string G::PublisherSubscription::info ( ) const

Returns some channel metadata as a short json string (see G::Item::str()).

This is the 'publisher' subset of Publisher::info(), so originally passed in to the Publisher constructor, plus some enrichment with "type" and "pid".

Definition at line 474 of file gpublisher.cpp.

bool G::PublisherSubscription::open ( )

Tries to initialise the object after lazy construction or after close().

Returns true when successfully initialised. Does not throw.

Definition at line 427 of file gpublisher.cpp.

bool G::PublisherSubscription::receive ( std::vector< char > &  buffer,
std::string *  type_p = nullptr,
G::EpochTime time_p = nullptr 
)

Does a read for new publish()ed data.

Blocks if there is nothing to read. Returns false if the publisher has gone away. Returns an empty buffer in the case of an ignorable event.

Definition at line 459 of file gpublisher.cpp.


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