pub struct Monitor<Source, SourceTime, Verdict = Incremental, VerdictTime = RelativeFloat>where
    Source: Input,
    SourceTime: TimeRepresentation,
    Verdict: VerdictRepresentation,
    VerdictTime: OutputTimeRepresentation + 'static,
{ /* private fields */ }
Expand description

The Monitor is the central object exposed by the API.

The Monitor accepts new events and computes streams. It can compute event-based streams based on new events through accept_event. It can also simply advance periodic streams up to a given timestamp through accept_time. The generic argument Source implements the Input trait describing the input source of the API. The generic argument SourceTime implements the TimeRepresentation trait defining the input time format. The generic argument Verdict implements the VerdictRepresentation trait describing the output format of the API that is by default Incremental. The generic argument VerdictTime implements the TimeRepresentation trait defining the output time format. It defaults to RelativeFloat

Implementations§

Crate-public interface

setup

Examples found in repository?
src/configuration/config.rs (line 74)
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
    pub fn monitor_with_data(
        self,
        data: Source::CreationData,
    ) -> Result<Monitor<Source, SourceTime, Verdict, VerdictTime>, Source::Error> {
        Monitor::setup(self.config, data)
    }

    /// Transforms the configuration into a [Monitor]
    pub fn monitor(self) -> Result<Monitor<Source, SourceTime, Verdict, VerdictTime>, Source::Error>
    where
        Source: Input<CreationData = ()>,
    {
        Monitor::setup(self.config, ())
    }

    #[cfg(feature = "queued-api")]
    /// Transforms the configuration into a [QueuedMonitor] using the provided data to setup the input source.
    pub fn queued_monitor_with_data(
        self,
        data: Source::CreationData,
    ) -> QueuedMonitor<Source, SourceTime, Verdict, VerdictTime> {
        QueuedMonitor::setup(self.config, data)
    }

    #[cfg(feature = "queued-api")]
    /// Transforms the configuration into a [QueuedMonitor]
    pub fn queued_monitor(self) -> QueuedMonitor<Source, SourceTime, Verdict, VerdictTime>
    where
        Source: Input<CreationData = ()>,
    {
        QueuedMonitor::setup(self.config, ())
    }
}

/// The execution mode of the interpreter. See the `README` for more details.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum ExecutionMode {
    /// Time provided by input source
    Offline,
    /// Time taken by evaluator
    Online,
}

impl Config<RelativeFloat, RelativeFloat> {
    /// Creates a new Debug config.
    pub fn debug(ir: RtLolaMir) -> Self {
        Config {
            ir,
            mode: ExecutionMode::Offline,
            input_time_representation: RelativeFloat::default(),
            output_time_representation: PhantomData::<RelativeFloat>::default(),
            start_time: None,
        }
    }
}

impl<InputTime: TimeRepresentation, OutputTime: OutputTimeRepresentation> Config<InputTime, OutputTime> {
    /// Creates a new API config
    pub fn api(ir: RtLolaMir) -> Self {
        Config {
            ir,
            mode: ExecutionMode::Offline,
            input_time_representation: InputTime::default(),
            output_time_representation: PhantomData::default(),
            start_time: None,
        }
    }

    /// Turn the configuration into the [Monitor] API.
    pub fn monitor<Source: Input, Verdict: VerdictRepresentation>(
        self,
        data: Source::CreationData,
    ) -> Result<Monitor<Source, InputTime, Verdict, OutputTime>, Source::Error> {
        Monitor::setup(self, data)
    }
More examples
Hide additional examples
src/api/queued.rs (line 593)
590
591
592
593
594
595
596
597
    fn init(&mut self) -> Result<(), QueueError> {
        // Setup evaluator
        let monitor: Monitor<Source, SourceTime, Verdict, VerdictTime> =
            Monitor::setup(self.config.clone(), self.setup_data.clone())
                .map_err(|e| QueueError::SourceError(Box::new(e)))?;
        self.monitor.replace(monitor);
        Ok(())
    }

Public interface

Computes all periodic streams up through the new timestamp and then handles the input event.

The new event is therefore not seen by periodic streams up through a new timestamp.

Examples found in repository?
src/api/queued.rs (line 609)
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
    fn process(&mut self) -> Result<(), QueueError> {
        let monitor = self.monitor.as_mut().expect("Init to be called before process");
        let mut last_event = None;
        let mut done = false;
        while !done {
            let timed = match self.input.recv() {
                Ok(WorkItem::Event(e, ts)) => {
                    // Received Event
                    last_event.replace(ts.clone());
                    let Verdicts { timed, event, ts } = monitor
                        .accept_event(e, ts)
                        .map_err(|e| QueueError::SourceError(Box::new(e)))?;

                    if !event.is_empty() {
                        let verdict = QueuedVerdict {
                            kind: VerdictKind::Event,
                            ts: ts.clone(),
                            verdict: event,
                        };
                        Self::try_send(&self.output, Some(verdict))?;
                    }

                    timed
                },
                Err(_) => {
                    // Channel closed, we are done here
                    done = true;
                    if let Some(last_event) = last_event.as_ref() {
                        monitor.accept_time(last_event.clone())
                    } else {
                        return Ok(());
                    }
                },
                Ok(WorkItem::Start) => {
                    // Received second start command -> abort
                    return Err(QueueError::MultipleStart);
                },
            };

            for (ts, v) in timed {
                let verdict = QueuedVerdict {
                    kind: VerdictKind::Timed,
                    ts,
                    verdict: v,
                };
                Self::try_send(&self.output, Some(verdict))?;
            }
        }
        Ok(())
    }

Computes all periodic streams up through and including the timestamp.

Examples found in repository?
src/api/queued.rs (line 627)
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
    fn process(&mut self) -> Result<(), QueueError> {
        let monitor = self.monitor.as_mut().expect("Init to be called before process");
        let mut last_event = None;
        let mut done = false;
        while !done {
            let timed = match self.input.recv() {
                Ok(WorkItem::Event(e, ts)) => {
                    // Received Event
                    last_event.replace(ts.clone());
                    let Verdicts { timed, event, ts } = monitor
                        .accept_event(e, ts)
                        .map_err(|e| QueueError::SourceError(Box::new(e)))?;

                    if !event.is_empty() {
                        let verdict = QueuedVerdict {
                            kind: VerdictKind::Event,
                            ts: ts.clone(),
                            verdict: event,
                        };
                        Self::try_send(&self.output, Some(verdict))?;
                    }

                    timed
                },
                Err(_) => {
                    // Channel closed, we are done here
                    done = true;
                    if let Some(last_event) = last_event.as_ref() {
                        monitor.accept_time(last_event.clone())
                    } else {
                        return Ok(());
                    }
                },
                Ok(WorkItem::Start) => {
                    // Received second start command -> abort
                    return Err(QueueError::MultipleStart);
                },
            };

            for (ts, v) in timed {
                let verdict = QueuedVerdict {
                    kind: VerdictKind::Timed,
                    ts,
                    verdict: v,
                };
                Self::try_send(&self.output, Some(verdict))?;
            }
        }
        Ok(())
    }

Returns the underlying representation of the specification as an RtLolaMir

Get the name of an input stream based on its InputReference.

The reference is valid for the lifetime of the monitor.

Get the name of an output stream based on its OutputReference.

The reference is valid for the lifetime of the monitor.

Get the message of a trigger based on its index.

The reference is valid for the lifetime of the monitor.

Get the OutputReference of a trigger based on its index.

Get the number of input streams.

Get the number of output streams (this includes one output stream for each trigger).

Get the number of triggers.

Get the type of an input stream based on its InputReference.

The reference is valid for the lifetime of the monitor.

Get the type of an output stream based on its OutputReference.

The reference is valid for the lifetime of the monitor.

Get the extend rate of an output stream based on its OutputReference.

The reference is valid for the lifetime of the monitor.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.