coral
A C++ library for distributed co-simulation
|
A class for keeping track of services on a network. More...
#include "coral/net/service.hpp"
Public Types | |
using | AppearedHandler = std::function< void(const ip::Address &, const std::string &, const std::string &, const char *, std::size_t)> |
The type for functions that are called when a service is discovered. More... | |
using | PayloadChangedHandler = AppearedHandler |
The type for functions that are called when a service changes its data payload. More... | |
using | DisappearedHandler = std::function< void(const std::string &, const std::string &)> |
The type for functions that are called when a service disappears. More... | |
Public Member Functions | |
Tracker (coral::net::Reactor &reactor, std::uint32_t partitionID, const ip::Endpoint &endpoint) | |
Constructor. More... | |
~Tracker () CORAL_NOEXCEPT | |
Destructor. | |
Tracker (Tracker &&) CORAL_NOEXCEPT | |
Move constructor. | |
Tracker & | operator= (Tracker &&) CORAL_NOEXCEPT |
Move assignment operator. | |
void | AddTrackedServiceType (const std::string &serviceType, std::chrono::milliseconds expiryTime, AppearedHandler onAppearance, PayloadChangedHandler onPayloadChange, DisappearedHandler onDisappearance) |
Adds (or updates the settings for) a tracked service type. More... | |
A class for keeping track of services on a network.
An object of this class can be used to keep track of services that announce their presence using Beacon. It is built on top of Listener, but rather than forwarding "raw" beacon pings, it translates these into events that indicate whether a new service has appeared on the network, whether one has disappeared, or whether one has changed its data payload.
Unlike Beacon, this class does not create a background thread; rather it uses the reactor pattern (specifically, coral::net::Reactor) to deal with incoming data in the current thread.
using coral::net::service::Tracker::AppearedHandler = std::function<void ( const ip::Address&, const std::string&, const std::string&, const char*, std::size_t)> |
The type for functions that are called when a service is discovered.
Such a function must have the following signature:
The payload
array is not guaranteed to exist beyond this function call, so a copy must be made if the data is to be kept around.
using coral::net::service::Tracker::DisappearedHandler = std::function<void(const std::string&, const std::string&)> |
The type for functions that are called when a service disappears.
Such a function must have the following signature:
The type for functions that are called when a service changes its data payload.
Such a function must have the following signature:
The payload
array is not guaranteed to exist beyond this function call, so a copy must be made if the data is to be kept around.
coral::net::service::Tracker::Tracker | ( | coral::net::Reactor & | reactor, |
std::uint32_t | partitionID, | ||
const ip::Endpoint & | endpoint | ||
) |
Constructor.
[in] | reactor | Used to listen for incoming data. |
[in] | partitionID | This must match the partition ID of any Beacon one wishes to detect. |
[in] | endpoint | The name or IP address of the network interface, together with the UDP port, to listen on. The name may be "*" to listen on all interfaces. The port number must match the port used in the Beacon. |
std::runtime_error | on network error. |
void coral::net::service::Tracker::AddTrackedServiceType | ( | const std::string & | serviceType, |
std::chrono::milliseconds | expiryTime, | ||
AppearedHandler | onAppearance, | ||
PayloadChangedHandler | onPayloadChange, | ||
DisappearedHandler | onDisappearance | ||
) |
Adds (or updates the settings for) a tracked service type.
[in] | serviceType | The service type to listen for. |
[in] | expiryTime | How long a period of silence from a particular service of this type must pass before it is considered to have disappeared. This should be at least a few times larger than the services' beacon period. |
[in] | onAppearance | A function that should be called when a new service of this type is discovered, or nullptr if this event is not to be handled. |
[in] | onPayloadChange | A function that should be called when a previously discoverd service of this type changes its data "payload", or nullptr if this event is not to be handled. |
[in] | onDisappearance | A function that should be called when a previously discovered service of this type disappears again (i.e. a period of timeout has passed without any pings having been received from it), or nullptr if this event is not to be handled. |