Module messaging_channels

Source
Expand description

Container for channels A central container for all inter-thread communication channels used by the Messaging module.

This module defines the MessagingChannels struct, which acts as a “switchboard” or router for commands received from an external source. Its primary purpose is to hold all the mpsc::channel senders that the main Messaging thread needs to dispatch commands to the various application domains (e.g., Refill, Heating, Feed).

This entire module is conditionally compiled and is only available on target_os = "linux" (or during tests), as it is a core part of the POSIX message queue IPC mechanism.

§Key Components

  • MessagingChannels Struct: A simple container struct that aggregates all the AquaSender and AquaReceiver endpoints required by the Messaging thread.

  • send_command_to_domain() Method: The core logic of this module. It takes an InternalCommand and a MessagingDomain and uses a match statement to select the correct channel sender, effectively routing the command to the intended thread.

§Design and Architecture

The MessagingChannels struct is a key part of the application’s inter-thread communication strategy, promoting clean and decoupled code.

  • Centralization: By gathering all necessary channels into a single struct, it provides a clear and explicit declaration of the Messaging thread’s communication dependencies. This makes the overall architecture easier to reason about.

  • Decoupling: The Messaging thread itself doesn’t need to know about every channel. It just needs this struct, which it can use to dispatch commands. This separates the dispatch logic from the communication infrastructure.

  • Testability: The struct’s channels can be used by mock implementation during unit testing, allowing for isolated testing of the Feed thread’s logic without needing to run the entire application.

Structs§

MessagingChannels
Collects all channels used by the Messaging module for IPC.