coral
A C++ library for distributed co-simulation
Public Types | Public Member Functions | List of all members
coral::net::service::Listener Class Reference

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.
 
Listeneroperator= (Listener &&) CORAL_NOEXCEPT
 Move assignment operator.
 

Detailed Description

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.

Member Typedef Documentation

The type for functions that handle incoming service notifications.

Such a function must have the following signature:

void handler(
const coral::net::ip::Address& address, // the service's IP address
const std::string& serviceType, // the service type (see Beacon)
const std::string& serviceID, // the service name (see Beacon)
const char* payload, // data payload (or null if none)
std::size_t payloadSize); // data payload size

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.

Constructor & Destructor Documentation

coral::net::service::Listener::Listener ( coral::net::Reactor reactor,
std::uint32_t  partitionID,
const ip::Endpoint endpoint,
NotificationHandler  onNotification 
)

Constructor.

Parameters
[in]reactorUsed to listen for incoming data.
[in]partitionIDThis must match the partition ID of any Beacon one wishes to detect.
[in]endpointThe 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]onNotificationA function which will be called whenever a service notification is received.
Exceptions
std::runtime_erroron network error.

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