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 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... | |
unsigned int | AdvertiseInterval () const |
While a topic is being advertised by a node, a beacon is sent periodically every 'advertise interval' milliseconds. More... | |
bool | AdvertiseMsg (const MessagePublisher &_publisher) |
Advertise a new message. More... | |
bool | AdvertiseSrv (const ServicePublisher &_publisher) |
Advertise a new service. More... | |
void | ConnectionsCb (const MsgDiscoveryCallback &_cb) |
Register a callback to receive discovery connection events. More... | |
template<typename C > | |
void | ConnectionsCb (void(C::*_cb)(const MessagePublisher &_pub), C *_obj) |
Register a callback to receive discovery connection events. More... | |
void | ConnectionsSrvCb (const SrvDiscoveryCallback &_cb) |
Register a callback to receive discovery connection events for services. More... | |
template<typename C > | |
void | ConnectionsSrvCb (void(C::*_cb)(const ServicePublisher &_pub), C *_obj) |
Register a callback to receive discovery connection events for services. More... | |
void | DisconnectionsCb (const transport::MsgDiscoveryCallback &_cb) |
Register a callback to receive discovery disconnection events. More... | |
template<typename C > | |
void | DisconnectionsCb (void(C::*_cb)(const MessagePublisher &_pub), C *_obj) |
Register a callback to receive discovery disconnection events. More... | |
void | DisconnectionsSrvCb (const transport::SrvDiscoveryCallback &_cb) |
Register a callback to receive discovery disconnection events for services. More... | |
template<typename C > | |
void | DisconnectionsSrvCb (void(C::*_cb)(const ServicePublisher &_pub), C *_obj) |
Register a callback to receive discovery disconnection events. More... | |
bool | DiscoverMsg (const std::string &_topic) |
Request discovery information about a topic. More... | |
bool | DiscoverSrv (const std::string &_topic) |
Request discovery information about a service. More... | |
const TopicStorage< MessagePublisher > & | DiscoveryMsgInfo () const |
Get the discovery information object (messages). More... | |
const TopicStorage< ServicePublisher > & | DiscoverySrvInfo () const |
Get the discovery information object (services). 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... | |
bool | MsgPublishers (const std::string &_topic, MsgAddresses_M &_publishers) |
Get all the publishers' information known for a given topic. More... | |
std::recursive_mutex & | Mutex () const |
Get mutex used in the Discovery class. More... | |
void | PrintCurrentState () const |
Print the current discovery state (info, activity, unknown). More... | |
void | ServiceList (std::vector< std::string > &_services) const |
Get the list of services currently advertised in the network. More... | |
void | SetActivityInterval (const unsigned int _ms) |
Set the activity interval. More... | |
void | SetAdvertiseInterval (const unsigned int _ms) |
Set the advertise 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... | |
bool | SrvPublishers (const std::string &_topic, SrvAddresses_M &_publishers) |
Get all the publishers' information known for a given service. 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 | UnadvertiseMsg (const std::string &_topic, const std::string &_nUuid) |
Unadvertise a new message. More... | |
bool | UnadvertiseSrv (const std::string &_topic, const std::string &_nUuid) |
Unadvertise a new message service. More... | |
void | WaitForInit () const |
Check if ready/initialized. More... | |
Protected Attributes | |
std::unique_ptr< DiscoveryPrivate > | dataPtr |
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.
ignition::transport::Discovery::Discovery | ( | const std::string & | _pUuid, |
const bool | _verbose = false |
||
) |
Constructor.
[in] | _pUuid | This discovery instance will run inside a transport process. This parameter is the transport process' UUID. |
[in] | _verbose | true for enabling verbose mode. |
|
virtual |
Destructor.
unsigned int ignition::transport::Discovery::ActivityInterval | ( | ) | const |
The discovery checks the validity of the topic information every 'activity interval' milliseconds.
unsigned int ignition::transport::Discovery::AdvertiseInterval | ( | ) | const |
While a topic is being advertised by a node, a beacon is sent periodically every 'advertise interval' milliseconds.
bool ignition::transport::Discovery::AdvertiseMsg | ( | const MessagePublisher & | _publisher | ) |
Advertise a new message.
[in] | _publisher | Publisher's information to advertise. |
bool ignition::transport::Discovery::AdvertiseSrv | ( | const ServicePublisher & | _publisher | ) |
Advertise a new service.
[in] | _publisher | Publisher's information to advertise. |
void ignition::transport::Discovery::ConnectionsCb | ( | const MsgDiscoveryCallback & | _cb | ) |
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.
[in] | _cb | Function callback. |
|
inline |
Register a callback to receive discovery connection events.
Each time a new topic is discovered, the callback will be executed. This version uses a member functions as callback.
[in] | _cb | Function callback with the following parameters. _pub Publisher's information. |
[in] | _obj | Object instance where the member function belongs. |
void ignition::transport::Discovery::ConnectionsSrvCb | ( | const SrvDiscoveryCallback & | _cb | ) |
Register a callback to receive discovery connection events for services.
Each time a new service is available, the callback will be executed. This version uses a free function as callback.
[in] | _cb | Function callback. |
|
inline |
Register a callback to receive discovery connection events for services.
Each time a new service is available, the callback will be executed. This version uses a member functions as callback.
[in] | _cb | Function callback with the following parameters. _pub Publisher's information. |
[in] | _obj | Object instance where the member function belongs. |
void ignition::transport::Discovery::DisconnectionsCb | ( | const transport::MsgDiscoveryCallback & | _cb | ) |
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.
[in] | _cb | Function callback. |
|
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 member function as callback.
[in] | _cb | Function callback with the following parameters. _pub Publisher's information. |
[in] | _obj | Object instance where the member function belongs. |
void ignition::transport::Discovery::DisconnectionsSrvCb | ( | const transport::SrvDiscoveryCallback & | _cb | ) |
Register a callback to receive discovery disconnection events for services.
Each time a service is no longer available, the callback will be executed. This version uses a free function as callback.
[in] | _cb | Function callback. |
|
inline |
Register a callback to receive discovery disconnection events.
Each time a service is no longer available, the callback will be executed. This version uses a member function as callback.
[in] | _cb | Function callback with the following parameters. _pub Publisher's information. |
[in] | _obj | Object instance where the member function belongs. |
References ignition::transport::AdvSrvType, ignition::transport::AdvType, ignition::transport::ByeType, ignition::transport::HeartbeatType, ignition::transport::SubscriptionMsg::MsgLength(), ignition::transport::AdvertiseMessage< T >::MsgLength(), ignition::transport::MsgTypesStr, ignition::transport::SubscriptionMsg::Pack(), ignition::transport::AdvertiseMessage< T >::Pack(), ignition::transport::SubSrvType, ignition::transport::SubType, ignition::transport::UnadvSrvType, and ignition::transport::UnadvType.
bool ignition::transport::Discovery::DiscoverMsg | ( | const std::string & | _topic | ) |
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.
[in] | _topic | Topic name requested. |
bool ignition::transport::Discovery::DiscoverSrv | ( | const std::string & | _topic | ) |
Request discovery information about a service.
The user might want to use SetConnectionsSrvCb() and SetDisconnectionSrvCb(), that registers callbacks that will be executed when the service address is discovered or when the node providing the service is disconnected.
[in] | _topic | Topic name requested. |
const TopicStorage<MessagePublisher>& ignition::transport::Discovery::DiscoveryMsgInfo | ( | ) | const |
Get the discovery information object (messages).
const TopicStorage<ServicePublisher>& ignition::transport::Discovery::DiscoverySrvInfo | ( | ) | const |
Get the discovery information object (services).
unsigned int ignition::transport::Discovery::HeartbeatInterval | ( | ) | const |
Each node broadcasts periodic heartbeats to keep its topic information alive in other nodes.
A heartbeat message is sent after 'heartbeat interval' milliseconds.
std::string ignition::transport::Discovery::HostAddr | ( | ) | const |
Get the IP address of this host.
bool ignition::transport::Discovery::MsgPublishers | ( | const std::string & | _topic, |
MsgAddresses_M & | _publishers | ||
) |
Get all the publishers' information known for a given topic.
[in] | _topic | Topic name. |
[out] | _publishers | Publishers requested. |
std::recursive_mutex& ignition::transport::Discovery::Mutex | ( | ) | const |
Get mutex used in the Discovery class.
void ignition::transport::Discovery::PrintCurrentState | ( | ) | const |
Print the current discovery state (info, activity, unknown).
void ignition::transport::Discovery::ServiceList | ( | std::vector< std::string > & | _services | ) | const |
Get the list of services currently advertised in the network.
[out] | _topics | List of advertised services. |
void ignition::transport::Discovery::SetActivityInterval | ( | const unsigned int | _ms | ) |
void ignition::transport::Discovery::SetAdvertiseInterval | ( | const unsigned int | _ms | ) |
void ignition::transport::Discovery::SetHeartbeatInterval | ( | const unsigned int | _ms | ) |
void ignition::transport::Discovery::SetSilenceInterval | ( | const unsigned int | _ms | ) |
Set the maximum silence interval.
[in] | _ms | New value in milliseconds. |
unsigned int ignition::transport::Discovery::SilenceInterval | ( | ) | const |
Get the maximum time allowed without receiving any discovery information from a node before canceling its entries.
bool ignition::transport::Discovery::SrvPublishers | ( | const std::string & | _topic, |
SrvAddresses_M & | _publishers | ||
) |
Get all the publishers' information known for a given service.
[in] | _topic | Service name. |
[out] | _publishers | Publishers requested. |
void ignition::transport::Discovery::Start | ( | ) |
Start the discovery service.
You probably want to register the callbacks for receiving discovery notifications before starting the service.
void ignition::transport::Discovery::TopicList | ( | std::vector< std::string > & | _topics | ) | const |
Get the list of topics currently advertised in the network.
[out] | _topics | List of advertised topics. |
bool ignition::transport::Discovery::UnadvertiseMsg | ( | const std::string & | _topic, |
const std::string & | _nUuid | ||
) |
Unadvertise a new message.
Broadcast a discovery message that will cancel all the discovery information for the topic advertised by a specific node.
[in] | _topic | Topic name to be unadvertised. |
[in] | _nUuid | Node UUID. |
bool ignition::transport::Discovery::UnadvertiseSrv | ( | const std::string & | _topic, |
const std::string & | _nUuid | ||
) |
Unadvertise a new message service.
Broadcast a discovery message that will cancel all the discovery information for the service advertised by a specific node.
[in] | _topic | Service name to be unadvertised. |
[in] | _nUuid | Node UUID. |
void ignition::transport::Discovery::WaitForInit | ( | ) | const |
Check if ready/initialized.
If not, then wait on the initializedCv condition variable.
|
protected |