All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Attributes | List of all members
ignition::transport::Discovery< Pub > Class Template Reference

A discovery class that implements a distributed topic discovery protocol. More...

#include <ignition/transport/Discovery.hh>

Public Member Functions

 Discovery (const std::string &_pUuid, const int _port, const bool _verbose=false)
 Constructor. More...
 
virtual ~Discovery ()
 Destructor. More...
 
unsigned int ActivityInterval () const
 The discovery checks the validity of the topic information every 'activity interval' milliseconds. More...
 
bool Advertise (const Pub &_publisher)
 Advertise a new message. More...
 
void ConnectionsCb (const DiscoveryCallback< Pub > &_cb)
 Register a callback to receive discovery connection events. More...
 
void DisconnectionsCb (const DiscoveryCallback< Pub > &_cb)
 Register a callback to receive discovery disconnection events. More...
 
bool Discover (const std::string &_topic) const
 Request discovery information about a topic. More...
 
unsigned int HeartbeatInterval () const
 Each node broadcasts periodic heartbeats to keep its topic information alive in other nodes. More...
 
std::string HostAddr () const
 Get the IP address of this host. More...
 
const TopicStorage< Pub > & Info () const
 Get the discovery information. More...
 
void PrintCurrentState () const
 Print the current discovery state. More...
 
bool Publishers (const std::string &_topic, Addresses_M< Pub > &_publishers) const
 Get all the publishers' information known for a given topic. More...
 
void SetActivityInterval (const unsigned int _ms)
 Set the activity interval. More...
 
void SetHeartbeatInterval (const unsigned int _ms)
 Set the heartbeat interval. More...
 
void SetSilenceInterval (const unsigned int _ms)
 Set the maximum silence interval. More...
 
unsigned int SilenceInterval () const
 Get the maximum time allowed without receiving any discovery information from a node before canceling its entries. More...
 
void Start ()
 Start the discovery service. More...
 
void TopicList (std::vector< std::string > &_topics) const
 Get the list of topics currently advertised in the network. More...
 
bool Unadvertise (const std::string &_topic, const std::string &_nUuid)
 Unadvertise a new message. More...
 
void WaitForInit () const
 Check if ready/initialized. More...
 

Protected Attributes

std::map< std::string, Timestampactivity
 Activity information. More...
 

Detailed Description

template<typename Pub>
class ignition::transport::Discovery< Pub >

A discovery class that implements a distributed topic discovery protocol.

It uses UDP broadcast for sending/receiving messages and stores updated topic information. The discovery clients can request the discovery of a topic or the advertisement of a local topic. The discovery uses heartbeats to track the state of other peers in the network. The discovery clients can register callbacks to detect when new topics are discovered or topics are no longer available.

Constructor & Destructor Documentation

template<typename Pub >
ignition::transport::Discovery< Pub >::Discovery ( const std::string &  _pUuid,
const int  _port,
const bool  _verbose = false 
)
inline

Constructor.

Parameters
[in]_pUuidThis discovery instance will run inside a transport process. This parameter is the transport process' UUID.
[in]_portUDP port used for discovery traffic.
[in]_verbosetrue for enabling verbose mode.

References ignition::transport::determineInterfaces(), and ignition::transport::env().

template<typename Pub >
virtual ignition::transport::Discovery< Pub >::~Discovery ( )
inlinevirtual

Destructor.

References ignition::transport::ByeType.

Member Function Documentation

template<typename Pub >
unsigned int ignition::transport::Discovery< Pub >::ActivityInterval ( ) const
inline

The discovery checks the validity of the topic information every 'activity interval' milliseconds.

See Also
SetActivityInterval.
Returns
The value in milliseconds.
template<typename Pub >
bool ignition::transport::Discovery< Pub >::Advertise ( const Pub &  _publisher)
inline

Advertise a new message.

Parameters
[in]_publisherPublisher's information to advertise.
Returns
True if the method succeed or false otherwise (e.g. if the discovery has not been started).

References ignition::transport::AdvType, and ignition::transport::PROCESS.

template<typename Pub >
void ignition::transport::Discovery< Pub >::ConnectionsCb ( const DiscoveryCallback< Pub > &  _cb)
inline

Register a callback to receive discovery connection events.

Each time a new topic is connected, the callback will be executed. This version uses a free function as callback.

Parameters
[in]_cbFunction callback.
template<typename Pub >
void ignition::transport::Discovery< Pub >::DisconnectionsCb ( const DiscoveryCallback< Pub > &  _cb)
inline

Register a callback to receive discovery disconnection events.

Each time a topic is no longer active, the callback will be executed. This version uses a free function as callback.

Parameters
[in]_cbFunction callback.
template<typename Pub >
bool ignition::transport::Discovery< Pub >::Discover ( const std::string &  _topic) const
inline

Request discovery information about a topic.

When using this method, the user might want to use SetConnectionsCb() and SetDisconnectionCb(), that registers callbacks that will be executed when the topic address is discovered or when the node providing the topic is disconnected.

See Also
SetConnectionsCb.
SetDisconnectionsCb.
Parameters
[in]_topicTopic name requested.
Returns
True if the method succeeded or false otherwise (e.g. if the discovery has not been started).

References ignition::transport::SubType.

template<typename Pub >
unsigned int ignition::transport::Discovery< Pub >::HeartbeatInterval ( ) const
inline

Each node broadcasts periodic heartbeats to keep its topic information alive in other nodes.

A heartbeat message is sent after 'heartbeat interval' milliseconds.

See Also
SetHeartbeatInterval.
Returns
The value in milliseconds.
template<typename Pub >
std::string ignition::transport::Discovery< Pub >::HostAddr ( ) const
inline

Get the IP address of this host.

Returns
A string with this host's IP address.
template<typename Pub >
const TopicStorage<Pub>& ignition::transport::Discovery< Pub >::Info ( ) const
inline

Get the discovery information.

Returns
Reference to the discovery information object.
template<typename Pub >
void ignition::transport::Discovery< Pub >::PrintCurrentState ( ) const
inline

Print the current discovery state.

template<typename Pub >
bool ignition::transport::Discovery< Pub >::Publishers ( const std::string &  _topic,
Addresses_M< Pub > &  _publishers 
) const
inline

Get all the publishers' information known for a given topic.

Parameters
[in]_topicTopic name.
[out]_publishersPublishers requested.
Returns
True if the topic is found and there is at least one publisher
template<typename Pub >
void ignition::transport::Discovery< Pub >::SetActivityInterval ( const unsigned int  _ms)
inline

Set the activity interval.

See Also
ActivityInterval.
Parameters
[in]_msNew value in milliseconds.
template<typename Pub >
void ignition::transport::Discovery< Pub >::SetHeartbeatInterval ( const unsigned int  _ms)
inline

Set the heartbeat interval.

See Also
HeartbeatInterval.
Parameters
[in]_msNew value in milliseconds.
template<typename Pub >
void ignition::transport::Discovery< Pub >::SetSilenceInterval ( const unsigned int  _ms)
inline

Set the maximum silence interval.

See Also
SilenceInterval.
Parameters
[in]_msNew value in milliseconds.
template<typename Pub >
unsigned int ignition::transport::Discovery< Pub >::SilenceInterval ( ) const
inline

Get the maximum time allowed without receiving any discovery information from a node before canceling its entries.

See Also
SetSilenceInterval.
Returns
The value in milliseconds.
template<typename Pub >
void ignition::transport::Discovery< Pub >::Start ( )
inline

Start the discovery service.

You probably want to register the callbacks for receiving discovery notifications before starting the service.

template<typename Pub >
void ignition::transport::Discovery< Pub >::TopicList ( std::vector< std::string > &  _topics) const
inline

Get the list of topics currently advertised in the network.

Parameters
[out]_topicsList of advertised topics.
template<typename Pub >
bool ignition::transport::Discovery< Pub >::Unadvertise ( const std::string &  _topic,
const std::string &  _nUuid 
)
inline

Unadvertise a new message.

Broadcast a discovery message that will cancel all the discovery information for the topic advertised by a specific node.

Parameters
[in]_topicTopic name to be unadvertised.
[in]_nUuidNode UUID.
Returns
True if the method succeeded or false otherwise (e.g. if the discovery has not been started).

References ignition::transport::PROCESS, and ignition::transport::UnadvType.

template<typename Pub >
void ignition::transport::Discovery< Pub >::WaitForInit ( ) const
inline

Check if ready/initialized.

If not, then wait on the initializedCv condition variable.

Member Data Documentation

template<typename Pub >
std::map<std::string, Timestamp> ignition::transport::Discovery< Pub >::activity
protected

Activity information.

Every time there is a message from a remote node, its activity information is updated. If we do not hear from a node in a while, its entries in 'info' will be invalided. The key is the process uuid.


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