aquarium_control/recorder/
data_logger_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, AquaSender};
10use crate::utilities::channel_content::InternalCommand;
11use std::fmt;
12
13/// Struct acts as a central hub for communication channels used by the DataLogger.
14/// It's a way to bundle together all the necessary mpsc (Multi-Producer, Single-Consumer) channel
15/// endpoints that the data logger needs to interact with other parts of your application.
16pub struct DataLoggerChannels {
17    /// Sender part of the channel for communication to the signal handler
18    pub tx_data_logger_to_signal_handler: AquaSender<bool>,
19    /// Receiver part of the channel for communication from the signal handler                
20    pub rx_data_logger_from_signal_handler: AquaReceiver<InternalCommand>,
21}
22
23impl DataLoggerChannels {
24    /// Sends an acknowledgment to the signal handler.
25    ///
26    /// This wrapper function sends a boolean acknowledgment and increments the
27    /// associated debug counter if the `debug_channels` feature is enabled.
28    pub fn send_to_signal_handler(&mut self, ack: bool) -> Result<(), AquaChannelError> {
29        self.tx_data_logger_to_signal_handler.send(ack)
30    }
31}
32
33#[cfg(feature = "debug_channels")]
34impl fmt::Display for DataLoggerChannels {
35    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36        writeln!(f, "=== DataLoggerChannels ===")?;
37        writeln!(
38            f,
39            "tx_data_logger_to_signal_handler: {}",
40            self.tx_data_logger_to_signal_handler.count
41        )?;
42        write!(
43            f,
44            "rx_data_logger_from_signal_handler: {}",
45            self.rx_data_logger_from_signal_handler.count
46        )
47    }
48}
49
50#[cfg(not(feature = "debug_channels"))]
51impl fmt::Display for DataLoggerChannels {
52    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53        write!(
54            f,
55            "Channel counters are not active. Use --features \"debug_channels\" to enable them."
56        )
57    }
58}