aquarium_control/relays/
actuate_simulator_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, AquaSender};
10use crate::utilities::channel_content::InternalCommand;
11use std::fmt;
12
13pub struct ActuateSimulatorChannels {
14    pub tx_actuate_simulator_to_tcp_opt: Option<AquaSender<InternalCommand>>,
15}
16
17impl ActuateSimulatorChannels {
18    /// Sends a command to the TCP simulator if the channel exists.
19    ///
20    /// This wrapper function sends a command and increments the associated debug
21    /// counter if the `debug_channels` feature is enabled.
22    #[allow(unused)]
23    pub fn send_to_tcp(
24        &mut self,
25        command: InternalCommand,
26    ) -> Option<Result<(), AquaChannelError>> {
27        self.tx_actuate_simulator_to_tcp_opt
28            .as_mut()
29            .map(|tx| tx.send(command))
30    }
31}
32
33#[cfg(feature = "debug_channels")]
34impl fmt::Display for ActuateSimulatorChannels {
35    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36        writeln!(f, "=== ActuateSimulatorChannels ===")?;
37        write!(
38            f,
39            "tx_actuate_simulator_to_tcp_opt: {}",
40            self.tx_actuate_simulator_to_tcp_opt.as_ref().unwrap().count
41        )
42    }
43}
44
45#[cfg(not(feature = "debug_channels"))]
46impl fmt::Display for ActuateSimulatorChannels {
47    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48        write!(
49            f,
50            "Channel counters are not active. Use --features \"debug_channels\" to enable them."
51        )
52    }
53}