Expand description
Generates all channels used by the application. Defines and constructs the entire inter-thread communication infrastructure for the application.
This module serves as the central nervous system of the aquarium controller. It is responsible for two primary tasks:
-
Defining Channel Wrappers: It provides
AquaSenderandAquaReceiver, which are custom wrappers aroundstd::sync::mpscchannels. These wrappers add optional debugging capabilities. -
Constructing the Communication Graph: The
Channels::buildmethod instantiates every single channel required for the application’s threads to communicate. It then bundles them into the mainChannelsstruct.
§Key Components
-
AquaSender/AquaReceiver: These wrappers provide a consistent channel interface. When thedebug_channelsfeature is enabled, they use boundedsync_channels and count the number of messages sent and received. In release builds, they compile down to lightweight wrappers around standard, unbounded channels. -
ChannelsStruct: A struct that aggregates all the individual...Channelsstructs (e.g.,FeedChannels,RelayManagerChannels). This provides a single, clean object that can be used to distribute the correct channel endpoints to each thread at startup. -
Channels::build(): This is the most critical function in the module. It contains the complete “wiring diagram” of the application. It creates all bidirectional and unidirectional channels, carefully handling conditional compilation for features like the IPCmessagingsystem (on Linux) and various simulators used during testing.
§Design and Architecture
-
Centralized Construction: By creating every channel in one place, this module acts as a single source of truth for the application’s communication topology. Any change to inter-thread communication can be understood by looking at this file.
-
Decoupling via Aggregation: Modules like
feedorrefilldon’t need to know about the entire system’s channel graph. They are simply given their own smallFeedChannelsorRefillChannelsstruct, which contains only the endpoints they care about. This dramatically reduces coupling between modules. -
Compile-Time Flexibility: The extensive use of
#[cfg]attributes allows the communication graph to be adapted at compile time. For example, channels to theTcpCommunicationsimulator are only created and wired up if a simulator is enabled, and IPC channels are only created on Linux.
Macros§
- create_
bidirectional_ 🔒channel - Creates a pair of bidirectional channels for request/response communication.
- create_
unidirectional_ 🔒channel - Creates a channel for one-way communication.