Skip to main content

drasi_core/evaluation/functions/future/
mod.rs

1// Copyright 2024 The Drasi Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::sync::{Arc, Weak};
16
17use crate::{
18    evaluation::ExpressionEvaluator,
19    interface::{FutureQueue, ResultIndex},
20};
21
22use self::{future_element::FutureElement, true_for::TrueFor, true_until::TrueUntil};
23
24use super::{Function, FunctionRegistry};
25
26mod awaiting;
27mod future_element;
28mod previous_distinct_value;
29mod previous_value;
30mod sliding_window;
31mod true_for;
32mod true_later;
33mod true_now_or_later;
34mod true_until;
35
36#[cfg(test)]
37mod tests;
38
39pub trait RegisterFutureFunctions {
40    fn register_future_functions(
41        &self,
42        future_queue: Arc<dyn FutureQueue>,
43        result_index: Arc<dyn ResultIndex>,
44        expression_evaluator: Weak<ExpressionEvaluator>,
45    );
46}
47
48impl RegisterFutureFunctions for FunctionRegistry {
49    fn register_future_functions(
50        &self,
51        future_queue: Arc<dyn FutureQueue>,
52        result_index: Arc<dyn ResultIndex>,
53        expression_evaluator: Weak<ExpressionEvaluator>,
54    ) {
55        self.register_function(
56            "drasi.awaiting",
57            Function::Scalar(Arc::new(awaiting::Awaiting::new())),
58        );
59
60        self.register_function(
61            "drasi.future",
62            Function::Scalar(Arc::new(FutureElement::new(future_queue.clone()))),
63        );
64
65        self.register_function(
66            "drasi.trueUntil",
67            Function::Scalar(Arc::new(TrueUntil::new(future_queue.clone()))),
68        );
69
70        self.register_function(
71            "drasi.trueFor",
72            Function::Scalar(Arc::new(TrueFor::new(
73                future_queue.clone(),
74                result_index.clone(),
75                expression_evaluator.clone(),
76            ))),
77        );
78
79        self.register_function(
80            "drasi.trueLater",
81            Function::Scalar(Arc::new(true_later::TrueLater::new(future_queue.clone()))),
82        );
83
84        self.register_function(
85            "drasi.trueNowOrLater",
86            Function::Scalar(Arc::new(true_now_or_later::TrueNowOrLater::new(
87                future_queue.clone(),
88            ))),
89        );
90
91        self.register_function(
92            "drasi.previousValue",
93            Function::Scalar(Arc::new(previous_value::PreviousValue::new(
94                result_index.clone(),
95                expression_evaluator.clone(),
96            ))),
97        );
98
99        self.register_function(
100            "drasi.previousDistinctValue",
101            Function::Scalar(Arc::new(
102                previous_distinct_value::PreviousDistinctValue::new(
103                    result_index.clone(),
104                    expression_evaluator.clone(),
105                ),
106            )),
107        );
108
109        self.register_function(
110            "drasi.slidingWindow",
111            Function::LazyScalar(Arc::new(sliding_window::SlidingWindow::new(
112                future_queue.clone(),
113                result_index.clone(),
114                expression_evaluator.clone(),
115            ))),
116        );
117    }
118}