Controller#

constellation::controller Namespace#

inline QDateTime constellation::controller::from_timepoint(const std::chrono::system_clock::time_point &time_point)#
inline QString constellation::controller::duration_string(std::chrono::seconds duration)#
class ConfigFileNotFoundError : public constellation::controller::ControllerError#
#include <constellation/controller/exceptions.hpp>

Notifies of a missing configuration file.

Public Functions

inline explicit ConfigFileNotFoundError(const std::filesystem::path &file_name)#

Construct an error for a configuration that is not found.

Parameters:

file_name – Name of the configuration file

class ConfigFileParseError : public constellation::controller::ControllerError#
#include <constellation/controller/exceptions.hpp>

Error with parsing the file content to TOML.

Public Functions

inline explicit ConfigFileParseError(std::string_view error)#

Construct an error for a configuration file that cannot correctly be parsed as TOML.

Parameters:

error – Error message returned by the TOML parser

class ConfigFileTypeError : public constellation::controller::ControllerError#
#include <constellation/controller/exceptions.hpp>

Error with the type of a key in the configuration file.

Public Functions

inline explicit ConfigFileTypeError(std::string_view key, std::string_view error)#

Construct an error for a configuration key that has an invalid type.

Parameters:
  • key – The offending configuration key

  • error – Error message

class Controller#
#include <constellation/controller/Controller.hpp>

Controller base class which handles satellite connections, command distribution and heartbeating

Subclassed by DummyController, QController

Public Types

using CommandPayload = std::variant<std::monostate, config::Dictionary, config::List, std::string>#

Payload of a command function: variant with (configuration) dictionary, (argument) list or (run id) string

Public Functions

Controller(std::string controller_name)#

Construct a controller base object.

Parameters:

controller_name – Name of the controller

virtual ~Controller() = default#

Destruct controller.

Warning

stop() has to be called before the pool can be safely destructed

void start()#
void stop()#

Destruct the controller base class object.

This deregisters the CHIRP service discovery callback and closes all open connections to satellites

message::CSCP1Message sendCommand(std::string_view satellite_name, message::CSCP1Message &cmd)#

Send a command to a single satellite.

This method allows to send an already prepared command message to a connected satellite, identified via its canonical name. Returns a message with verb ERROR if the satellite is not connected or the message is not a request. If the command was successfully transmitted to the satellite, the response message of the command is returned.

Parameters:
  • satellite_name – Canonical name of the target satellite

  • cmd – Command message

Returns:

CSCP response message

message::CSCP1Message sendCommand(std::string_view satellite_name, std::string verb, const CommandPayload &payload = {})#

Send a command to a single satellite.

This method allows to send a command to a connected satellite, identified via its canonical name. Returns a message with verb ERROR if the satellite is not connected. If the command was successfully transmitted to the satellite, the response message of the command is returned.

Parameters:
  • satellite_name – Canonical name of the target satellite

  • verb – Command

  • payload – Optional payload for this command message

Returns:

CSCP response message

std::map<std::string, message::CSCP1Message> sendCommands(message::CSCP1Message &cmd)#

Send a command to all connected satellites.

This method allows to send an already prepared command message to all connected satellites. The response from all satellites is returned as a map.

Parameters:

cmd – Command message

Returns:

Map of satellite canonical names and their CSCP response messages

std::map<std::string, message::CSCP1Message> sendCommands(std::string verb, const CommandPayload &payload = {})#

Send a command to all connected satellites.

This method allows to send command message to all connected satellites. The message is formed from the provided verb and optional payload. The payload is the same for all satellites. The response from all satellites is returned as a map.

Parameters:
  • verb – Command

  • payload – Optional payload for this command message

Returns:

Map of satellite canonical names and their CSCP response messages

std::map<std::string, message::CSCP1Message> sendCommands(const std::string &verb, const std::map<std::string, CommandPayload> &payloads)#

Send a command to all connected satellites.

This method allows to send command message to all connected satellites. The message is formed individually for each satellite from the provided verb and the payload entry in the map for the given satellite. Missing entries in the payload table will receive an empty payload. The response from all satellites is returned as a map.

Parameters:
  • verb – Command

  • payloads – Map of payloads for each target satellite.

Returns:

Map of satellite canonical names and their CSCP response messages

bool isInState(protocol::CSCP::State state) const#

Helper to check if all connected satellites are in a given state.

Parameters:

state – State to be checked for

Returns:

True if all connected satellites are in the given state, false otherwise

bool isInGlobalState() const#

Helper to check if the constellation is in a coherent global state of if states are mixed.

Returns:

True if all connected satellites are in the same state, false if states are mixed

protocol::CSCP::State getLowestState() const#

Get lowest state of any satellite connected.

This returns the lowest state of any of the satellites. Here, “lowest” refers to the state code, i.e. the underlying value of the protocol::CSCP::State enum.

Returns:

Lowest state currently held

std::set<std::string> getConnections() const#

Get set of currently active connected satellites.

Returns:

Set of fully-qualified canonical names of currently connected satellites

inline std::size_t getConnectionCount() const#

Get total number of currently active connected satellites.

Returns:

Number of currently connected satellites

std::string getRunIdentifier()#

Return the current or last run identifier of the constellation.

This function will search through all connected satellites and returns the first valid run identifier found. The value will be empty if the satellites have just started or no satellite is connected.

Returns:

Run identifier

std::optional<std::chrono::system_clock::time_point> getRunStartTime()#

Return the starting time of the current or last run of the constellation.

This function will go through all connected satellites and returns the latest run starting time found. The optional will not hold a value if the satellites have just started or no satellite is connected.

Returns:

Optional with the run starting time

Protected Types

enum class UpdateType : std::uint8_t#

Update identifier

Values:

enumerator UPDATED#

Connection data has been updated

enumerator ADDED#

A connection has been added

enumerator REMOVED#

A connection has been removed

Protected Functions

virtual void reached_state(protocol::CSCP::State state, bool global)#

Method called whenever a new global or lowest state has been reached.

A global state is a situation when all connected satellites share a common state. The lowest state is often used to convey the state of a Constellation when its constituents are in different states, i.e. the Constellation is not in a global state. Whenever a new state of the Constellation is reached, e.g. by a state update of a satellite or the joining or departing of a satellite, this method is called. This can e.g. be used to emit signals for user interfaces or to trigger further actions.

Parameters:
  • state – The new global state of the constellation

  • global – Flag indicating whether the new state is global or lowest

virtual void propagate_update(UpdateType type, std::size_t position, std::size_t total)#

Method to propagate updates of connection data.

This virtual method can be overridden by derived controller classes in order to be informed about data updates of the attached connections such as state changes and additions or deletions of connections. The parameter position holds the position of the updated data row.

Parameters:
  • type – Type of the connection update performed

  • position – Index of the connection which has received an update

  • total – Total number of current connections

Protected Attributes

log::Logger logger_#

Logger to use

std::map<std::string, Connection, std::less<>> connections_#

Map of open connections

mutable std::mutex connection_mutex_#

Mutex for accessing the connection map

Note

: This is marked mutable since some derived controllers may need to lock this for read access to the connection list in functions marked as const.

struct Connection#
#include <constellation/controller/Controller.hpp>

Local representation of a remote connection and state.

Remote connection, comprising the socket and host ID and URI of a remote satellite as well as its last known state, the last command response and verb. Furthermore, the current heartbeat interval, heartbeat check time points and lives are kept.

Public Members

zmq::socket_t req#

Connection

message::MD5Hash host_id#
std::string uri#
protocol::CSCP::State state = {protocol::CSCP::State::NEW}#

State and last response

message::CSCP1Message::Type last_cmd_type = {}#
std::string last_cmd_verb = {}#
config::Dictionary commands = {}#
std::chrono::milliseconds interval = {10000}#

Heartbeat status

std::chrono::system_clock::time_point last_heartbeat = {std::chrono::system_clock::now()}#
std::chrono::system_clock::time_point last_checked = {std::chrono::system_clock::now()}#
std::uint8_t lives = {protocol::CHP::Lives}#
class ControllerConfiguration#
#include <constellation/controller/ControllerConfiguration.hpp>

Configuration parser to read TOML files and emit dictionaries for individual satellites.

The configuration file holds a hierarchy of tables which contain the configuration keys for all satellites of the Constellation. The dictionaries for the individual satellites need to be assembled from keys specific to the respective satellite, keys valid for the relevant satellite type and keys intended for all satellites.

Public Functions

virtual ~ControllerConfiguration() = default#
ControllerConfiguration() = default#

Default constructor with empty configuration dictionaries.

ControllerConfiguration(std::string_view toml)#

Construct a controller configuration and parse dictionaries from a string.

Parameters:

toml – TOML data as string

Throws:
explicit ControllerConfiguration(const std::filesystem::path &path)#

Construct a controller configuration and parse dictionaries from a configuration file.

Parameters:

path – File path to the TOML configuration file

Throws:
bool hasSatelliteConfiguration(std::string_view canonical_name) const#

Check if a configuration exists for a given satellite.

This only checks the specific (named) satellite sections of the configuration file, not any type-bound or global configuration key-value-pairs.

Returns:

True if a configuration is available for the satellite with the given name, false otherwise

config::Dictionary getSatelliteConfiguration(std::string_view canonical_name) const#

Prepare and return configuration dictionary for a given satellite.

The cached dictionaries from parsed from the input TOML are searched for the given satellite, and keys from the type section matching this satellite as well as global keys to all satellites are added. Name and type are matched case-insensitively.

Returns:

Configuration dictionary, possibly empty if the satellite was not found in the cached configuration

void addSatelliteConfiguration(std::string_view canonical_name, config::Dictionary config)#
std::string getAsTOML() const#
class ControllerError : public constellation::utils::RuntimeError#
#include <constellation/controller/exceptions.hpp>

Base class for all controller exceptions.

Subclassed by constellation::controller::ConfigFileNotFoundError, constellation::controller::ConfigFileParseError, constellation::controller::ConfigFileTypeError