Struct Watchdog

Source
pub struct Watchdog {
    config: WatchdogConfig,
}
Expand description

Represents the Watchdog responsible for activating and petting the watchdog.

This struct encapsulates the configuration, interface details, and internal state required to communicate with the operating system.

Thread Communication: This module is designed to run in its own dedicated thread. It reads commands provided by the messaging system and acts accordingly. It responds to Quit commands for graceful shutdown.

Platform-Specific Behavior: The watchdog logic will only work on Linux systems but compile for any other system as well.

Thread communication of this component is as follows:

graph LR
    messaging[Messaging] --> ds18b20[Ds18b20]
    signal_handler[SignalHandler] --> ds18b20

Fields§

§config: WatchdogConfig

Implementations§

Source§

impl Watchdog

Source

pub fn new(config: WatchdogConfig) -> Result<Watchdog, WatchdogError>

Creates a new Watchdog instance.

This constructor initializes the watchdog communication module with its specified configuration. It performs critical validation checks on the configuration parameters to ensure the watchdog can operate correctly and safely.

**Validation checks performed: **

  • heartbeat_duration_millis must be greater than zero.
  • watchdog_filename cannot be an empty string.
  • watchdog_heartbeat message cannot be an empty string.
  • watchdog_deactivation message cannot be an empty string.
  • watchdog_heartbeat and watchdog_deactivation messages must be different.
§Arguments
  • config - Configuration data for the watchdog communication, loaded from a TOML file. This includes filename, heartbeat messages, and timing parameters.
§Returns

A new Watchdog struct, ready for sending heartbeats or respond to termination requests.

§Panics

This function will panic if any of the configuration validation checks fail, as an incorrectly configured watchdog can lead to system instability or unintended resets.

Source

pub fn execute( &mut self, watchdog_channels: &mut WatchDogChannels, petting: &mut impl PettingTrait, )

Executes the main control loop for the watchdog communication module.

This function runs continuously, managing the periodic sending of heartbeats to a system watchdog. It ensures the application’s liveness is maintained and handles various external commands for controlling its operation.

Key Operations:

  • Heartbeat Sending: If active and not inhibited, it calls the petting.pet() method to send a heartbeat message to the configured watchdog_filename.
  • Cycle Management: It sleeps for the configured heartbeat_duration_millis between each heartbeat.
  • External Control: It processes Start and Stop commands received from messaging or the signal handler to inhibit or re-enable watchdog activity.
  • Graceful Deactivation: Upon receiving a Quit command, it sends a final watchdog_deactivation message before exiting the loop.
  • Shutdown Confirmation: After exiting the loop, it sends a confirmation back to the signal handler.
§Arguments
  • watchdog_channels - A mutable reference to the struct containing the channels.
  • petting - A mutable reference to an object implementing the PettingTrait, responsible for the actual writing of heartbeat/deactivation messages to the watchdog file.

Trait Implementations§

Source§

impl ProcessExternalRequestTrait for Watchdog

Source§

fn process_external_request( &mut self, rx_from_signal_handler: &mut AquaReceiver<InternalCommand>, rx_from_messaging_opt: Option<&mut AquaReceiver<InternalCommand>>, ) -> (bool, bool, bool)

Checks for and processes new commands relevant to the Watchdog module from external channels.

This is the specialized implementation of ProcessExternalRequestTrait for the Watchdog. It handles standard “Terminate” or “Quit” commands from the signal handler. From the messaging channel, it specifically processes “Start” and “Stop” commands, ignoring other inapplicable commands with warnings.

§Arguments
  • rx_from_signal_handler - A reference to the receiver end of the channel for commands originating from the signal handler.
  • rx_from_messaging_opt - An Option containing a reference to the receiver end of the channel for commands from the messaging system. This channel is optional.
§Returns

A tuple (bool, bool, bool) indicating the status of specific commands received:

  • The first bool is true if a Quit or Terminate command was received from the signal handler; otherwise false.
  • The second bool is true if a Start command was received from messaging; otherwise false.
  • The third bool is true if a Stop command was received from messaging; otherwise false.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T