aquarium_control/watchmen/
memory_channels.rs

1/* Copyright 2025 Uwe Martin
2
3Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
5The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
7THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8*/
9use crate::launch::channels::{AquaChannelError, AquaReceiver};
10use crate::utilities::channel_content::InternalCommand;
11use std::fmt;
12
13/// Struct collects the channels for communication with other threads.
14pub struct MemoryChannels {
15    /// Receiver part of the channel for communication from the signal handler
16    pub rx_memory_from_signal_handler: AquaReceiver<InternalCommand>,
17}
18
19impl MemoryChannels {
20    /// Receives a command from the signal handler.
21    #[allow(unused)]
22    pub fn receive_from_signal_handler(&mut self) -> Result<InternalCommand, AquaChannelError> {
23        self.rx_memory_from_signal_handler.try_recv()
24    }
25}
26
27#[cfg(feature = "debug_channels")]
28impl fmt::Display for MemoryChannels {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        writeln!(f, "=== MemoryChannels ===")?;
31        write!(
32            f,
33            "rx_memory_from_signal_handler: {}",
34            self.rx_memory_from_signal_handler.count
35        )
36    }
37}
38
39#[cfg(not(feature = "debug_channels"))]
40impl fmt::Display for MemoryChannels {
41    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42        write!(
43            f,
44            "Channel counters are not active. Use --features \"debug_channels\" to enable them."
45        )
46    }
47}