coral
A C++ library for distributed co-simulation
|
A class for detecting services on a network. More...
#include "coral/net/service.hpp"
Public Types | |
using | NotificationHandler = std::function< void(const ip::Address &, const std::string &, const std::string &, const char *, std::size_t)> |
The type for functions that handle incoming service notifications. More... | |
Public Member Functions | |
Listener (coral::net::Reactor &reactor, std::uint32_t partitionID, const ip::Endpoint &endpoint, NotificationHandler onNotification) | |
Constructor. More... | |
~Listener () CORAL_NOEXCEPT | |
Destructor. | |
Listener (Listener &&) CORAL_NOEXCEPT | |
Move constructor. | |
Listener & | operator= (Listener &&) CORAL_NOEXCEPT |
Move assignment operator. | |
A class for detecting services on a network.
An object of this class can be used to listen for service announcements broadcast by one or more Beacon instances. (It is recommended to read the documentation for that class too.)
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::Listener::NotificationHandler = std::function<void ( const ip::Address&, const std::string&, const std::string&, const char*, std::size_t)> |
The type for functions that handle incoming service notifications.
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::Listener::Listener | ( | coral::net::Reactor & | reactor, |
std::uint32_t | partitionID, | ||
const ip::Endpoint & | endpoint, | ||
NotificationHandler | onNotification | ||
) |
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. |
[in] | onNotification | A function which will be called whenever a service notification is received. |
std::runtime_error | on network error. |