Pools#

constellation::pools Namespace#

template<typename MESSAGE, chirp::ServiceIdentifier SERVICE, zmq::socket_type SOCKET_TYPE>
class BasePool#
#include <constellation/core/pools/BasePool.hpp>

Abstract Base pool class.

This class registers a CHIRP callback for the services defined via the template parameter, listens to incoming messages and forwards them to a callback registered upon creation of the socket.

Template Parameters:
  • MESSAGE – Constellation Message class to be decoded

  • SERVICE – CHIRP service to connect to

  • SOCKET_TYPE – ZeroMQ socket type of connection

Subclassed by constellation::pools::SubscriberPool< message::CHP1Message, chirp::HEARTBEAT >

Public Functions

BasePool(std::string_view log_topic, std::function<void(MESSAGE&&)> callback)#

Construct BasePool.

Parameters:
  • log_topic – Logger topic to be used for this component

  • callback – Callback function pointer for received messages

virtual ~BasePool()#

Destruct BasePool.

This closes all connections and unregisters the CHIRP service discovery callback

void checkPoolException()#

Check if pool thread has thrown an exception.

Throws:

Exception – thrown by pool thread, if any

void startPool()#

Start the pool thread and send the CHIRP requests.

void stopPool()#

Stop the pool thread.

inline std::size_t pollerEvents()#

Return number of events returned by poller_.wait()

Protected Functions

virtual bool should_connect(const chirp::DiscoveredService &service)#

Method to select which services to connect to. By default this pool connects to all discovered services, derived pools may implement selection criteria.

Parameters:

service – The discovered service

Returns:

Boolean indicating whether a connection should be opened

virtual void socket_connected(zmq::socket_t &socket)#

Method for derived classes to act on newly connected sockets.

Parameters:

socket – The newly connected socket

virtual void socket_disconnected(zmq::socket_t &socket)#

Method for derived classes to act on sockets before disconnecting.

Parameters:

socket – The socket to be disconnected

inline const std::map<chirp::DiscoveredService, zmq::socket_t> &get_sockets() const#

Return all connected sockets.

Warning

Read access to the sockets needs to be protected with sockets_mutex_

Returns:

Maps that maps the discovered service to the corresponding ZeroMQ sockets

Protected Attributes

std::mutex sockets_mutex_#
log::Logger pool_logger_#
template<typename MESSAGE, chirp::ServiceIdentifier SERVICE>
class SubscriberPool : public constellation::pools::BasePool<MESSAGE, SERVICE, zmq::socket_type::sub>#
#include <constellation/core/pools/SubscriberPool.hpp>

Abstract Subscriber pool class

This class registers a CHIRP callback for the services defined via the template parameter, listens to incoming messages and forwards them to a callback registered upon creation of the subscriber socket

Public Types

using BasePoolT = BasePool<MESSAGE, SERVICE, zmq::socket_type::sub>#

Public Functions

SubscriberPool(std::string_view log_topic, std::function<void(MESSAGE&&)> callback, std::initializer_list<std::string> default_topics = {})#

Construct SubscriberPool.

Parameters:
  • log_topic – Logger topic to be used for this component

  • callback – Callback function pointer for received messages

  • default_topics – List of default subscription topics to which this component subscribes directly upon opening the socket

void subscribe(std::string_view host, std::string_view topic)#

Subscribe to a given topic of a specific host.

Parameters:
  • host – Canonical name of the host to subscribe to

  • topic – Topic to subscribe to

void unsubscribe(std::string_view host, std::string_view topic)#

Unsubscribe from a given topic of a specific host.

Parameters:
  • host – Canonical name of the host to unsubscribe from

  • topic – Topic to unsubscribe