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:
Fields§
§config: MessagingConfig§mq: PosixMq§mq_max_msg_len: usize§lock_warn_inapplicable_command_signal_handler: boolan inhibition flag to avoid flooding the log file with repeated messages about having received an inapplicable command
lock_error_channel_receive_termination: boolan inhibition flag to avoid flooding the log file with repeated messages about failure to receive termination signal via the channel
execution_config: ExecutionConfigconfiguration data indicating which threads are started
Implementations§
Source§impl Messaging
impl Messaging
Sourcepub fn new(
config: MessagingConfig,
execution_config: ExecutionConfig,
) -> Result<Messaging, MessagingError>
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 themq_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 aMessagingError::PosixMessageQueueOpeningError. - It fails to retrieve the attributes (like max message length) of the opened
message queue. This will be a
MessagingError::PosixMessageQueueAttributesError.
Sourcepub fn execute(&mut self, messaging_channels: &mut MessagingChannels)
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
Terminatecommand from the signal handler during shutdown.
Trait Implementations§
Source§impl ProcessExternalRequestTrait for Messaging
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)
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 theMessagingmodule does not process messages from a secondary messaging channel.
§Returns
A tuple (bool, bool, bool) indicating the status of commands received:
- The first
boolistrueif aQuitcommand was received; otherwisefalse. - The second
boolis alwaysfalse(no “Start” commands processed). - The third
boolis alwaysfalse(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
impl WaitForTerminationTrait for Messaging
Source§fn get_warn_lock_mut(&mut self) -> &mut bool
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
fn get_error_lock_mut(&mut self) -> &mut bool
Method connects the default trait implementation with the specific implementation for accessing the error-lock.