Struct Messaging

Source
pub struct Messaging {
    config: MessagingConfig,
    mq: PosixMq,
    mq_max_msg_len: usize,
    pub lock_warn_inapplicable_command_signal_handler: bool,
    pub lock_error_channel_receive_termination: bool,
    execution_config: ExecutionConfig,
}
Expand description

Struct provides data structure and implementation for IPC message queue communication. Thread communication of this component is as follows:

graph LR signal_handler[Signal handler] --> messaging[Messaging] messaging --> refill[Refill control] messaging --> ventilation[Ventilation control] messaging --> heating[Heating control] messaging --> feed[Feed control] messaging --> balling[Balling dosing control] messaging --> monitors[Monitors] messaging --> watchdog[Watchdog]

Fields§

§config: MessagingConfig§mq: PosixMq§mq_max_msg_len: usize§lock_warn_inapplicable_command_signal_handler: bool

an inhibition flag to avoid flooding the log file with repeated messages about having received an inapplicable command

§lock_error_channel_receive_termination: bool

an inhibition flag to avoid flooding the log file with repeated messages about failure to receive termination signal via the channel

§execution_config: ExecutionConfig

configuration data indicating which threads are started

Implementations§

Source§

impl Messaging

Source

pub fn new( config: MessagingConfig, execution_config: ExecutionConfig, ) -> Result<Messaging, MessagingError>

Opens and initializes the POSIX message queue for inter-process communication.

This constructor attempts to open the message queue specified in the configuration. It then retrieves the maximum message length supported by this queue. This function is specifically enabled for Linux operating systems because the messaging subsystem is only supported by this operating system and not by other operating systems (e.g., macOS).

§Arguments
  • config - Configuration data for the messaging module, primarily containing the mq_filename (the name of the POSIX message queue).
  • execution_config - Configuration data indicating which threads are started.
§Returns

A Result containing a new, initialized Messaging struct on success.

§Errors

This function will return an error if:

  • It fails to open the message queue with the specified mq_filename. This will be a MessagingError::PosixMessageQueueOpeningError.
  • It fails to retrieve the attributes (like max message length) of the opened message queue. This will be a MessagingError::PosixMessageQueueAttributesError.
Source

pub fn execute(&mut self, messaging_channels: &mut MessagingChannels)

Continuously monitors the POSIX message queue for incoming commands and forwards them to the relevant modules.

This function serves as the central message dispatching unit for the application on Linux systems. It operates in a loop, attempting to receive messages from a configured POSIX message queue (mq_filename). Upon receiving a message, it parses the message’s content (domain, command, parameters) and dispatches it as an InternalCommand to the appropriate module’s channel.

It also periodically checks for a Quit command from the signal handler to initiate a graceful shutdown and then waits for a Terminate command before exiting.

§Arguments
  • messaging_channels - A mutable reference to a struct containing all channels for communication to other threads.
§Panics

This function will panic if:

  • It encounters a fatal error while receiving from the POSIX message queue (other than a timeout).
  • It fails to receive the Terminate command from the signal handler during shutdown.

Trait Implementations§

Source§

impl ProcessExternalRequestTrait for Messaging

Source§

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

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

This is the specialized implementation of ProcessExternalRequestTrait for Messaging. It delegates directly to process_external_request_without_messaging, indicating that the Messaging module only processes commands from the signal handler and ignores any input from a separate messaging channel.

§Arguments
  • rx_from_signal_handler - A reference to the receiver end of the channel for commands originating from the signal handler.
  • _ - This parameter is ignored, as the Messaging module does not process messages from a secondary messaging channel.
§Returns

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

  • The first bool is true if a Quit command was received; otherwise false.
  • The second bool is always false (no “Start” commands processed).
  • The third bool is always false (no “Stop” commands processed).

This code is specific for a Linux operating system because the messaging system is only implemented for that platform.

Source§

impl WaitForTerminationTrait for Messaging

Source§

fn get_warn_lock_mut(&mut self) -> &mut bool

Method connects the default trait implementation with the specific implementation accessing the warn-lock.

Source§

fn get_error_lock_mut(&mut self) -> &mut bool

Method connects the default trait implementation with the specific implementation for accessing the error-lock.

Source§

fn wait_for_termination( &mut self, rx_waiting_thread_from_signal_handler: &mut AquaReceiver<InternalCommand>, sleep_duration: Duration, origin: &str, )

Implements the graceful shutdown wait loop for several threads (default implementation). Read more

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