Heartbeat Protocol Implementation#
constellation::heartbeat
Namespace#
-
class HeartbeatManager : public constellation::heartbeat::HeartbeatRecv#
- #include <constellation/core/heartbeat/HeartbeatManager.hpp>
Manager for CHP publishing and receiving.
This manager holds a heartbeat sender and receiver as well as the logic for calling FSM interrupts based on received heartbeats. It keeps track of received heartbeats from remote heartbeat senders, counts their lives and takes action either upon missing heartbeats or a remote ERROR state of the FSM.
Public Functions
-
HeartbeatManager(std::string sender, std::function<protocol::CSCP::State()> state_callback, std::function<void(std::string_view)> interrupt_callback, std::function<void()> degradation_callback)#
Construct a heartbeat manager.
The constructor directly starts sender and receiver as well as the managerβs watchdog thread which keeps track of remote heartbeat rates and states
- Parameters:
sender β Canonical name of the heartbeat sender
state_callback β Function that return the current state
interrupt_callback β Interrupt callback which is invoked when a remote heartbeat sender reports an ERROR state or stopped sending heartbeats
degradation_callback β Callback to mark a run as degraded when the constituents of the constellation changed
-
virtual ~HeartbeatManager()#
Destructor which terminates the heartbeat manager
-
void terminate()#
Terminate the heartbeat manager.
This stops the heartbeat manager pool and watchdog thread and terminate the heartbeat sender.
-
void sendExtrasystole(std::string_view status)#
Send an extrasystole.
- Parameters:
status β Latest status message of the satellite
-
std::optional<protocol::CSCP::State> getRemoteState(std::string_view remote)#
Obtain the current state registered from a given remote.
Note
Remote canonical names are matched case-insensitive
- Parameters:
remote β Canonical name of the remote in question
- Returns:
Currently registered state of the remote if remote is present, empty optional otherwise
-
void setRole(protocol::CHP::Role role)#
Set the sender role.
- Parameters:
role β Role of the heartbeat sender
-
inline protocol::CHP::Role getRole() const#
Get the sender role.
- Returns:
Role of the heartbeat sender
-
inline void setMaximumInterval(std::chrono::milliseconds interval)#
Update the maximum heartbeat interval to a new value.
Note
Heartbeats are send roughly twice as often as the maximum heartbeat interval
- Parameters:
interval β New maximum heartbeat interval
-
HeartbeatManager(std::string sender, std::function<protocol::CSCP::State()> state_callback, std::function<void(std::string_view)> interrupt_callback, std::function<void()> degradation_callback)#
-
class HeartbeatRecv : public constellation::pools::SubscriberPool<message::CHP1Message, protocol::CHIRP::HEARTBEAT>#
- #include <constellation/core/heartbeat/HeartbeatRecv.hpp>
Receiver class for distributed heartbeats in a constellation.
This class registers a CHIRP callback for heartbeat services, subscribes automatically to all available and appearing services in the constellation and listens for heartbeat and extrasystole messages from remote satellites and forwards them to a callback registered upon creation of the receiver.
Note
Needs to be started with
start()
and stopped withstop()
Subclassed by constellation::heartbeat::HeartbeatManager
Public Functions
-
inline HeartbeatRecv(std::function<void(message::CHP1Message&&)> callback)#
Construct heartbeat receiver.
- Parameters:
callback β Callback function pointer for received heartbeat messages
-
inline HeartbeatRecv(std::function<void(message::CHP1Message&&)> callback)#
-
class HeartbeatSend#
- #include <constellation/core/heartbeat/HeartbeatSend.hpp>
Sender class which emits heartbeat messages in regular intervals as well as extrasystoles at state changes
Public Functions
-
HeartbeatSend(std::string sender, std::function<protocol::CSCP::State()> state_callback, std::chrono::milliseconds interval)#
Construct a heartbeat sender.
This directly opens a socket, binds to an ephemeral port and starts emission of heartbeats. It also registers a CHIRP heartbeat service.
- Parameters:
sender β Canonical name of the sender
state_callback β Function that return the current state
interval β Interval at which the heartbeats are sent
-
~HeartbeatSend()#
Destructor which terminates the heartbeat sender
-
void terminate()#
Terminate the heartbeat sender.
This unregisters the CHIRP heartbeat service and stops the heartbeat thread.
-
inline networking::Port getPort() const#
Get ephemeral port to which the CHP socket is bound.
- Returns:
Port number
-
inline void setFlags(protocol::CHP::MessageFlags flags)#
Set the message flags this sender is emitting.
- Parameters:
flags β Message flags for this sender
-
inline void setMaximumInterval(std::chrono::milliseconds interval)#
Update the maximum heartbeat interval to a new value.
Note
Heartbeats are send roughly twice as often as the maximum heartbeat interval
- Parameters:
interval β New maximum heartbeat interval
-
inline std::chrono::milliseconds getCurrentInterval() const#
Obtain the currently used heartbeat interval.
- Returns:
Current heartbeat interval
-
inline std::size_t getSubscriberCount() const#
Obtain the current number of subscribers.
- Returns:
Current number of heartbeat subscribers
-
void sendExtrasystole(std::string_view status)#
Send an extrasystole.
- Parameters:
status β message to be attached
-
HeartbeatSend(std::string sender, std::function<protocol::CSCP::State()> state_callback, std::chrono::milliseconds interval)#