rtmlib
macros.h
Go to the documentation of this file.
1 /*
2  * rtmlib is a Real-Time Monitoring Library.
3  *
4  * Copyright (C) 2018-2020 AndrĂ© Pedro
5  *
6  * This file is part of rtmlib.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
30 template <typename T>
31 three_valued_type prop(T &trace, proposition &p, timespan &t) {
32 
33  typename T::buffer_t::event_t e;
34  typename T::buffer_t::event_t e_next;
35 
36  typename T::error_t status = trace.read(e);
37 
38  if (status == trace.AVAILABLE && trace.read_next(e_next) == trace.AVAILABLE &&
39  e.getTime() <= t && t < e_next.getTime()) {
40  DEBUGV_RMTLD3("eval: t=%lu prop=%d - (%d %d) next-> (%d %d)\n", t, p,
41  e.getData(), e.getTime(), e_next.getData(), e_next.getTime());
42  return e.getData() == p ? T_TRUE : T_FALSE;
43  } else {
44  DEBUGV_RMTLD3("eval: t=%lu prop=%d - (%d %d) nobound\n", t, p, e.getData(),
45  e.getTime());
46  return T_UNKNOWN;
47  }
48 }
49 
53 template <typename T, typename E, timespan b>
54 three_valued_type until_less(T &trace, timespan &t) {
55  auto eval_fold = [](T &trace,
56  timespan &t) -> std::pair<four_valued_type, timespan> {
57  // eval_b lambda function
58  auto eval_b = [](T &trace, timespan &t,
60  // eval_i lambda function
61  auto eval_i = [](three_valued_type &b1,
63  return (b2 != T_FALSE) ? b3_to_b4(b2)
64  : ((b1 != T_TRUE) ? b3_to_b4(b1) : FV_SYMBOL);
65  };
66 
67  DEBUGV_RMTLD3("$compute phi1\n");
68  // compute phi1
69  three_valued_type cmpphi1 = E::eval_phi1(trace, t);
70  trace.set(t); // reset all reads of the subformula
71  DEBUGV_RMTLD3("@compute phi1.\n");
72 
73  DEBUGV_RMTLD3("$compute phi2\n");
74  // compute phi2
75  three_valued_type cmpphi2 = E::eval_phi2(trace, t);
76  trace.set(t); // reset all reads of the subformula
77  DEBUGV_RMTLD3("@compute phi2.\n");
78 
79  four_valued_type rs = eval_i(cmpphi1, cmpphi2);
80 
81  DEBUGV_RMTLD3("eval_b: phi1=%s phi2=%s\n", out_p(cmpphi1),
82  out_p(cmpphi2));
83 
84  if (v == FV_SYMBOL) {
85  return rs;
86  } else {
87  return v;
88  }
89  };
90 
91  trace.set(t); // force start at t
92 
93  timespan c_time = t;
94 
95  four_valued_type symbol = FV_SYMBOL;
96 
97  typename T::buffer_t::event_t event;
98 
99  symbol = eval_b(trace, c_time, symbol);
100 
101  trace.debug();
102 
103  while (trace.pull(event) == trace.AVAILABLE) {
104 
105  DEBUGV_RMTLD3("t=%d c_time=%d len=%d\n", t, c_time, trace.length());
106 
107  trace.read(event);
108  c_time = event.getTime();
109 
110  if (c_time > b + t)
111  break;
112 
113  symbol = eval_b(trace, c_time, symbol);
114 
115  trace.debug();
116  }
117 
118  return std::make_pair(symbol, c_time);
119  };
120 
121  DEBUGV_RMTLD3("$(+++) until_op_less\n");
122 
123  std::pair<four_valued_type, timespan> eval_c = eval_fold(trace, t);
124 
125  DEBUGV_RMTLD3("@(---) until_op (%s) enough(%d)=%d.\n", out_fv(eval_c.first),
126  eval_c.second, eval_c.second < t + b);
127 
128  return (eval_c.first == FV_SYMBOL)
129  ? ((eval_c.second < t + b) ? T_UNKNOWN : T_FALSE)
130  : b4_to_b3(eval_c.first);
131 }
132 
141 template <typename T, typename E, timespan b>
142 three_valued_type eventually_equal(T &trace, timespan &t) {
143 
144  three_valued_type v_phi = E::eval_phi(trace, t + b);
145  trace.set(t);
146 
147  return v_phi;
148 }
149 
153 template <typename T, typename E, timespan b>
154 three_valued_type eventually_less(T &trace, timespan &t) {
155  // [TODO]
156  return T_TRUE;
157 }
158 
168 template <typename T, typename E, timespan b>
169 three_valued_type always_less(T &trace, timespan &t) {
170  // [TODO]
171  return T_TRUE;
172 }
#define out_p(res)
Definition: rmtld3.h:100
Definition: rmtld3.h:10
#define out_fv(fv)
Definition: rmtld3.h:103
four_valued_type
Definition: rmtld3.h:11
three_valued_type eventually_less(T &trace, timespan &t)
Definition: macros.h:154
#define b4_to_b3(b4)
Definition: rmtld3.h:28
#define b3_to_b4(b3)
Definition: rmtld3.h:24
status
Definition: task_compat.h:59
Definition: rmtld3.h:11
three_valued_type
Definition: rmtld3.h:10
Definition: rmtld3.h:10
Definition: rmtld3.h:10
#define DEBUGV_RMTLD3(...)
Definition: rmtld3.h:50
three_valued_type until_less(T &trace, timespan &t)
Definition: macros.h:54
three_valued_type prop(T &trace, proposition &p, timespan &t)
Definition: macros.h:31
three_valued_type eventually_equal(T &trace, timespan &t)
Definition: macros.h:142
three_valued_type always_less(T &trace, timespan &t)
Definition: macros.h:169
unsigned int proposition
Definition: rmtld3.h:6