aquarium_control/permission/
schedule_check_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 collects all channels for communication between ScheduleCheck and other components.
14pub struct ScheduleCheckChannels {
15    /// Sender part of the channel for communication to ventilation
16    pub tx_schedule_check_to_ventilation: AquaSender<bool>,
17
18    /// Receiver part of the channel for communication from ventilation
19    pub rx_schedule_check_from_ventilation: AquaReceiver<InternalCommand>,
20
21    /// Sender part of the channel for communication to heating
22    pub tx_schedule_check_to_heating: AquaSender<bool>,
23
24    /// Receiver part of the channel for communication from heating
25    pub rx_schedule_check_from_heating: AquaReceiver<InternalCommand>,
26
27    /// Sender part of the channel for communication to refill
28    pub tx_schedule_check_to_refill: AquaSender<bool>,
29
30    /// Receiver part of the channel for communication from refill
31    pub rx_schedule_check_from_refill: AquaReceiver<InternalCommand>,
32
33    /// Sender part of the channel for communication to the Balling dosing control
34    pub tx_schedule_check_to_balling: AquaSender<bool>,
35
36    /// Receiver part of the channel for communication from the Balling dosing control
37    pub rx_schedule_check_from_balling: AquaReceiver<InternalCommand>,
38
39    /// Sender part of the channel for communication to the signal handler
40    pub tx_schedule_check_to_signal_handler: AquaSender<bool>,
41
42    /// Receiver part of the channel for communication from the signal handler
43    pub rx_schedule_check_from_signal_handler: AquaReceiver<InternalCommand>,
44}
45
46impl ScheduleCheckChannels {
47    /// Sends an acknowledgment to the signal handler.
48    pub fn send_to_signal_handler(&mut self, ack: bool) -> Result<(), AquaChannelError> {
49        self.tx_schedule_check_to_signal_handler.send(ack)
50    }
51}
52
53#[cfg(feature = "debug_channels")]
54impl fmt::Display for ScheduleCheckChannels {
55    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56        writeln!(f, "=== ScheduleCheckChannels ===")?;
57        writeln!(
58            f,
59            "tx_schedule_check_to_ventilation: {}",
60            self.tx_schedule_check_to_ventilation.count
61        )?;
62        writeln!(
63            f,
64            "rx_schedule_check_from_ventilation: {}",
65            self.rx_schedule_check_from_ventilation.count
66        )?;
67        writeln!(
68            f,
69            "tx_schedule_check_to_heating: {}",
70            self.tx_schedule_check_to_heating.count
71        )?;
72        writeln!(
73            f,
74            "rx_schedule_check_from_heating: {}",
75            self.rx_schedule_check_from_heating.count
76        )?;
77        writeln!(
78            f,
79            "tx_schedule_check_to_refill: {}",
80            self.tx_schedule_check_to_refill.count
81        )?;
82        writeln!(
83            f,
84            "rx_schedule_check_from_refill: {}",
85            self.rx_schedule_check_from_refill.count
86        )?;
87        writeln!(
88            f,
89            "tx_schedule_check_to_balling: {}",
90            self.tx_schedule_check_to_balling.count
91        )?;
92        writeln!(
93            f,
94            "rx_schedule_check_from_balling: {}",
95            self.rx_schedule_check_from_balling.count
96        )?;
97        writeln!(
98            f,
99            "tx_schedule_check_to_signal_handler: {}",
100            self.tx_schedule_check_to_signal_handler.count
101        )?;
102        write!(
103            f,
104            "rx_schedule_check_from_signal_handler: {}",
105            self.rx_schedule_check_from_signal_handler.count
106        )
107    }
108}
109
110#[cfg(not(feature = "debug_channels"))]
111impl fmt::Display for ScheduleCheckChannels {
112    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
113        write!(
114            f,
115            "Channel counters are not active. Use --features \"debug_channels\" to enable them."
116        )
117    }
118}