1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! Flow Reservation Function Set
//!
//! This module contains an unimplemented interface for a Flow Reversation schedule, that takes in `FlowReservationResponse`.
//!
//! Unfortunately, it's very unclear how this schedule should operate based off the specification alone, and as such a generic implementation for this client library would be difficult to build.
//! Specifically, it is unclear when `FlowReservationResponseResponses` should be sent to the server, and with what `ResponseStatus` they should contain, as for whatever reason Flow Reservation is not included in Table 27.
//!
//! Regardless, end users of this library could easily implement a version of this scheduler for their specific use case, using the implemented schedulers as a reference.

use sep2_common::packages::flow_reservation::FlowReservationResponse;

use crate::event::{EventCallback, Schedule};

use std::{
    sync::{atomic::AtomicI64, Arc},
    time::Duration,
};

use tokio::sync::RwLock;

use crate::{
    client::Client,
    device::SEDevice,
    event::{Events, Scheduler},
};

// Flow Reservation Schedule
#[async_trait::async_trait]
impl Scheduler<FlowReservationResponse> for Schedule<FlowReservationResponse> {
    type Program = ();

    #[allow(unused_variables)]
    fn new(
        client: Client,
        device: Arc<RwLock<SEDevice>>,
        handler: impl EventCallback<FlowReservationResponse>,
        tickrate: Duration,
    ) -> Self {
        let (tx, rx) = tokio::sync::broadcast::channel::<()>(1);
        Schedule {
            client,
            device,
            events: Arc::new(RwLock::new(Events::new())),
            handler: Arc::new(move |ei| {
                let handler = handler.clone();
                Box::pin(async move { handler.event_update(ei).await })
            }),
            bc_sd: tx.clone(),
            tickrate,
            time_offset: Arc::new(AtomicI64::new(0)),
        }
    }

    #[allow(unused_variables)]
    async fn add_event(
        &mut self,
        event: FlowReservationResponse,
        program: &Self::Program,
        server_id: u8,
    ) {
    }
}