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
-
MessagingChannelsStruct: A simple container struct that aggregates all theAquaSenderandAquaReceiverendpoints required by theMessagingthread. -
send_command_to_domain()Method: The core logic of this module. It takes anInternalCommandand aMessagingDomainand uses amatchstatement 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
Messagingthread’s communication dependencies. This makes the overall architecture easier to reason about. -
Decoupling: The
Messagingthread 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
Feedthread’s logic without needing to run the entire application.
Structs§
- Messaging
Channels - Collects all channels used by the
Messagingmodule for IPC.