9c312311 |
1 | /* This file is part of the Linux Trace Toolkit viewer |
852f16bb |
2 | * Copyright (C) 2003-2005 Michel Dagenais and Simon Bouvier-Zappa |
9c312311 |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License Version 2 as |
6 | * published by the Free Software Foundation; |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program; if not, write to the Free Software |
15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
16 | * MA 02111-1307, USA. |
17 | */ |
18 | |
7e7af7f2 |
19 | /*! \file lttv/lttv/filter.c |
20 | * \brief Defines the core filter of application |
21 | * |
22 | * consist in AND, OR and NOT nested expressions, forming a tree with |
23 | * simple relations as leaves. The simple relations test if a field |
24 | * in an event is equal, not equal, smaller, smaller or equal, larger, or |
25 | * larger or equal to a specified value. |
26 | * |
27 | * Fields specified in a simple expression can take following |
28 | * values |
29 | * |
da2e1bfb |
30 | * \verbatim |
31 | * LttvTracefileContext{} |
7e7af7f2 |
32 | * |->event\ |
33 | * | |->name (String, converted to GQuark) |
34 | * | |->category (String, not yet implemented) |
35 | * | |->time (LttTime) |
bbd9d557 |
36 | * | |->tsc (LttCycleCount --> uint64) |
7e7af7f2 |
37 | * | |->fields |
38 | * | |->"event name" |
39 | * | |->"field name" |
40 | * | |->"sub-field name" |
41 | * | |->... |
42 | * | |->"leaf-field name" (field type) |
43 | * |->tracefile |
44 | * | |->name (String, converted to GQuark) |
45 | * |->trace |
46 | * | |->name (String, converted to GQuark) |
47 | * |->state |
48 | * |->pid (uint64) |
49 | * |->ppid (uint64) |
50 | * |->creation_time (LttTime) |
51 | * |->insertion_time (LttTime) |
52 | * |->process_name (String, converted to GQuark) |
53 | * |->execution_mode (LttvExecutionMode) |
54 | * |->execution_submode (LttvExecutionSubmode) |
55 | * |->process_status (LttvProcessStatus) |
da2e1bfb |
56 | * |->cpu (GQuark) |
57 | * \endverbatim |
150f0d33 |
58 | */ |
59 | |
60 | /* |
bbd9d557 |
61 | * \todo |
150f0d33 |
62 | * - refine switch of expression in multiple uses functions |
be66ef34 |
63 | * - remove the idle expressions in the tree |
64 | * - replace string for enum value for corresponding value |
150f0d33 |
65 | */ |
66 | |
be66ef34 |
67 | #define TEST |
68 | #ifdef TEST |
69 | #include <time.h> |
70 | #include <sys/time.h> |
71 | #endif |
72 | |
150f0d33 |
73 | #include <lttv/filter.h> |
80f9611a |
74 | |
75 | /** |
56e29124 |
76 | * @fn LttvSimpleExpression* lttv_simple_expression_new() |
77 | * |
80f9611a |
78 | * Constructor for LttvSimpleExpression |
79 | * @return pointer to new LttvSimpleExpression |
80 | */ |
81 | LttvSimpleExpression* |
82 | lttv_simple_expression_new() { |
83 | |
84 | LttvSimpleExpression* se = g_new(LttvSimpleExpression,1); |
85 | |
86 | se->field = LTTV_FILTER_UNDEFINED; |
87 | se->op = NULL; |
88 | se->offset = 0; |
80f9611a |
89 | |
90 | return se; |
91 | } |
92 | |
0769c82f |
93 | /** |
7e7af7f2 |
94 | * @fn gboolean lttv_simple_expression_assign_field(GPtrArray*,LttvSimpleExpression*) |
56e29124 |
95 | * |
0769c82f |
96 | * Parse through filtering field hierarchy as specified |
97 | * by user. This function compares each value to |
98 | * predetermined quarks |
99 | * @param fp The field path list |
bb87caa7 |
100 | * @param se current simple expression |
0769c82f |
101 | * @return success/failure of operation |
102 | */ |
103 | gboolean |
9ab5ebd7 |
104 | lttv_simple_expression_assign_field(GPtrArray* fp, LttvSimpleExpression* se) { |
0769c82f |
105 | |
f4e9dd16 |
106 | GString* f = NULL; |
73050a5f |
107 | |
2b99ec10 |
108 | if(fp->len < 2) return FALSE; |
56e29124 |
109 | g_assert(f=g_ptr_array_remove_index(fp,0)); |
73050a5f |
110 | |
47aa6e58 |
111 | /* |
112 | * Parse through the specified |
113 | * hardcoded fields. |
114 | * |
115 | * Take note however that the |
116 | * 'event' subfields might change |
117 | * depending on values specified |
118 | * in core.xml file. Hence, if |
119 | * none of the subfields in the |
120 | * array match the hardcoded |
121 | * subfields, it will be considered |
122 | * as a dynamic field |
123 | */ |
80f9611a |
124 | if(!g_strcasecmp(f->str,"trace") ) { |
47aa6e58 |
125 | /* |
126 | * Possible values: |
127 | * trace.name |
128 | */ |
73050a5f |
129 | g_string_free(f,TRUE); |
130 | f=g_ptr_array_remove_index(fp,0); |
80f9611a |
131 | if(!g_strcasecmp(f->str,"name")) { |
389ba50e |
132 | se->field = LTTV_FILTER_TRACE_NAME; |
133 | } |
80f9611a |
134 | } else if(!g_strcasecmp(f->str,"traceset") ) { |
47aa6e58 |
135 | /* |
136 | * FIXME: not yet implemented ! |
137 | */ |
80f9611a |
138 | } else if(!g_strcasecmp(f->str,"tracefile") ) { |
47aa6e58 |
139 | /* |
140 | * Possible values: |
141 | * tracefile.name |
142 | */ |
73050a5f |
143 | g_string_free(f,TRUE); |
144 | f=g_ptr_array_remove_index(fp,0); |
80f9611a |
145 | if(!g_strcasecmp(f->str,"name")) { |
389ba50e |
146 | se->field = LTTV_FILTER_TRACEFILE_NAME; |
147 | } |
80f9611a |
148 | } else if(!g_strcasecmp(f->str,"state") ) { |
47aa6e58 |
149 | /* |
150 | * Possible values: |
151 | * state.pid |
152 | * state.ppid |
153 | * state.creation_time |
154 | * state.insertion_time |
155 | * state.process_name |
156 | * state.execution_mode |
157 | * state.execution_submode |
158 | * state.process_status |
159 | * state.cpu |
160 | */ |
73050a5f |
161 | g_string_free(f,TRUE); |
162 | f=g_ptr_array_remove_index(fp,0); |
80f9611a |
163 | if(!g_strcasecmp(f->str,"pid") ) { |
389ba50e |
164 | se->field = LTTV_FILTER_STATE_PID; |
165 | } |
80f9611a |
166 | else if(!g_strcasecmp(f->str,"ppid") ) { |
389ba50e |
167 | se->field = LTTV_FILTER_STATE_PPID; |
168 | } |
80f9611a |
169 | else if(!g_strcasecmp(f->str,"creation_time") ) { |
389ba50e |
170 | se->field = LTTV_FILTER_STATE_CT; |
171 | } |
80f9611a |
172 | else if(!g_strcasecmp(f->str,"insertion_time") ) { |
389ba50e |
173 | se->field = LTTV_FILTER_STATE_IT; |
174 | } |
80f9611a |
175 | else if(!g_strcasecmp(f->str,"process_name") ) { |
389ba50e |
176 | se->field = LTTV_FILTER_STATE_P_NAME; |
177 | } |
80f9611a |
178 | else if(!g_strcasecmp(f->str,"execution_mode") ) { |
389ba50e |
179 | se->field = LTTV_FILTER_STATE_EX_MODE; |
180 | } |
80f9611a |
181 | else if(!g_strcasecmp(f->str,"execution_submode") ) { |
389ba50e |
182 | se->field = LTTV_FILTER_STATE_EX_SUBMODE; |
183 | } |
80f9611a |
184 | else if(!g_strcasecmp(f->str,"process_status") ) { |
389ba50e |
185 | se->field = LTTV_FILTER_STATE_P_STATUS; |
186 | } |
80f9611a |
187 | else if(!g_strcasecmp(f->str,"cpu") ) { |
389ba50e |
188 | se->field = LTTV_FILTER_STATE_CPU; |
189 | } |
80f9611a |
190 | } else if(!g_strcasecmp(f->str,"event") ) { |
389ba50e |
191 | /* |
192 | * Possible values: |
193 | * event.name |
194 | * event.category |
195 | * event.time |
196 | * event.tsc |
197 | */ |
73050a5f |
198 | g_string_free(f,TRUE); |
199 | f=g_ptr_array_remove_index(fp,0); |
80f9611a |
200 | if(!g_strcasecmp(f->str,"name") ) { |
389ba50e |
201 | se->field = LTTV_FILTER_EVENT_NAME; |
202 | } |
80f9611a |
203 | else if(!g_strcasecmp(f->str,"category") ) { |
389ba50e |
204 | /* |
205 | * FIXME: Category not yet functional in lttv |
206 | */ |
207 | se->field = LTTV_FILTER_EVENT_CATEGORY; |
208 | } |
80f9611a |
209 | else if(!g_strcasecmp(f->str,"time") ) { |
389ba50e |
210 | se->field = LTTV_FILTER_EVENT_TIME; |
2b99ec10 |
211 | } |
80f9611a |
212 | else if(!g_strcasecmp(f->str,"tsc") ) { |
389ba50e |
213 | se->field = LTTV_FILTER_EVENT_TSC; |
2b99ec10 |
214 | } |
215 | else { /* core.xml specified options */ |
389ba50e |
216 | se->field = LTTV_FILTER_EVENT_FIELD; |
2b99ec10 |
217 | } |
91ad3f0a |
218 | } else { |
219 | g_warning("Unrecognized field in filter string"); |
0769c82f |
220 | } |
47aa6e58 |
221 | |
56e29124 |
222 | /* free memory for last string */ |
73050a5f |
223 | g_string_free(f,TRUE); |
56e29124 |
224 | |
225 | /* array should be empty */ |
73050a5f |
226 | g_assert(fp->len == 0); |
56e29124 |
227 | |
56e29124 |
228 | if(se->field == LTTV_FILTER_UNDEFINED) { |
229 | g_warning("The specified field was not recognized !"); |
230 | return FALSE; |
231 | } |
91ad3f0a |
232 | return TRUE; |
0769c82f |
233 | } |
234 | |
bb87caa7 |
235 | /** |
56e29124 |
236 | * @fn gboolean lttv_simple_expression_assign_operator(LttvSimpleExpression*,LttvExpressionOp) |
237 | * |
bb87caa7 |
238 | * Sets the function pointer for the current |
239 | * Simple Expression |
240 | * @param se current simple expression |
7e7af7f2 |
241 | * @param op current operator |
bb87caa7 |
242 | * @return success/failure of operation |
243 | */ |
be66ef34 |
244 | gboolean |
245 | lttv_simple_expression_assign_operator(LttvSimpleExpression* se, LttvExpressionOp op) { |
aa4600f3 |
246 | |
bb87caa7 |
247 | switch(se->field) { |
56e29124 |
248 | /* |
249 | * string |
250 | */ |
bb87caa7 |
251 | case LTTV_FILTER_TRACE_NAME: |
252 | case LTTV_FILTER_TRACEFILE_NAME: |
253 | case LTTV_FILTER_STATE_P_NAME: |
254 | case LTTV_FILTER_EVENT_NAME: |
bbd9d557 |
255 | case LTTV_FILTER_STATE_CPU: |
be66ef34 |
256 | case LTTV_FILTER_STATE_EX_MODE: |
257 | case LTTV_FILTER_STATE_EX_SUBMODE: |
258 | case LTTV_FILTER_STATE_P_STATUS: |
bb87caa7 |
259 | switch(op) { |
260 | case LTTV_FIELD_EQ: |
c6832b57 |
261 | se->op = lttv_apply_op_eq_quark; |
bb87caa7 |
262 | break; |
263 | case LTTV_FIELD_NE: |
c6832b57 |
264 | se->op = lttv_apply_op_ne_quark; |
bb87caa7 |
265 | break; |
266 | default: |
73050a5f |
267 | g_warning("Error encountered in operator assignment = or != expected"); |
bb87caa7 |
268 | return FALSE; |
269 | } |
270 | break; |
56e29124 |
271 | /* |
272 | * integer |
273 | */ |
bb87caa7 |
274 | case LTTV_FILTER_STATE_PID: |
275 | case LTTV_FILTER_STATE_PPID: |
bbd9d557 |
276 | case LTTV_FILTER_EVENT_TSC: |
bb87caa7 |
277 | switch(op) { |
278 | case LTTV_FIELD_EQ: |
279 | se->op = lttv_apply_op_eq_uint64; |
280 | break; |
281 | case LTTV_FIELD_NE: |
282 | se->op = lttv_apply_op_ne_uint64; |
283 | break; |
284 | case LTTV_FIELD_LT: |
285 | se->op = lttv_apply_op_lt_uint64; |
286 | break; |
287 | case LTTV_FIELD_LE: |
288 | se->op = lttv_apply_op_le_uint64; |
289 | break; |
290 | case LTTV_FIELD_GT: |
291 | se->op = lttv_apply_op_gt_uint64; |
292 | break; |
293 | case LTTV_FIELD_GE: |
294 | se->op = lttv_apply_op_ge_uint64; |
295 | break; |
296 | default: |
297 | g_warning("Error encountered in operator assignment"); |
298 | return FALSE; |
299 | } |
300 | break; |
f017db44 |
301 | /* |
302 | * Enums |
be66ef34 |
303 | * Entered as string, converted to enum |
304 | * |
f017db44 |
305 | * can only be compared with 'equal' or 'not equal' operators |
306 | * |
307 | * unsigned int of 16 bits are used here since enums |
be66ef34 |
308 | * should not go over 2^16-1 values |
f017db44 |
309 | */ |
be66ef34 |
310 | // case /*NOTHING*/: |
311 | // switch(op) { |
312 | // case LTTV_FIELD_EQ: |
313 | // se->op = lttv_apply_op_eq_uint16; |
314 | // break; |
315 | // case LTTV_FIELD_NE: |
316 | // se->op = lttv_apply_op_ne_uint16; |
317 | // break; |
318 | // default: |
319 | // g_warning("Error encountered in operator assignment = or != expected"); |
320 | // return FALSE; |
321 | // } |
322 | // break; |
56e29124 |
323 | /* |
7145a073 |
324 | * Ltttime |
56e29124 |
325 | */ |
bb87caa7 |
326 | case LTTV_FILTER_STATE_CT: |
327 | case LTTV_FILTER_STATE_IT: |
328 | case LTTV_FILTER_EVENT_TIME: |
bb87caa7 |
329 | switch(op) { |
330 | case LTTV_FIELD_EQ: |
7145a073 |
331 | se->op = lttv_apply_op_eq_ltttime; |
bb87caa7 |
332 | break; |
333 | case LTTV_FIELD_NE: |
7145a073 |
334 | se->op = lttv_apply_op_ne_ltttime; |
bb87caa7 |
335 | break; |
336 | case LTTV_FIELD_LT: |
7145a073 |
337 | se->op = lttv_apply_op_lt_ltttime; |
bb87caa7 |
338 | break; |
339 | case LTTV_FIELD_LE: |
7145a073 |
340 | se->op = lttv_apply_op_le_ltttime; |
bb87caa7 |
341 | break; |
342 | case LTTV_FIELD_GT: |
7145a073 |
343 | se->op = lttv_apply_op_gt_ltttime; |
bb87caa7 |
344 | break; |
345 | case LTTV_FIELD_GE: |
7145a073 |
346 | se->op = lttv_apply_op_ge_ltttime; |
bb87caa7 |
347 | break; |
348 | default: |
349 | g_warning("Error encountered in operator assignment"); |
350 | return FALSE; |
351 | } |
352 | break; |
353 | default: |
9ab5ebd7 |
354 | g_warning("Error encountered in operator assignation ! Field type:%i",se->field); |
bb87caa7 |
355 | return FALSE; |
356 | } |
aa4600f3 |
357 | |
358 | return TRUE; |
bb87caa7 |
359 | |
360 | } |
361 | |
9ab5ebd7 |
362 | /** |
7e7af7f2 |
363 | * @fn gboolean lttv_simple_expression_assign_value(LttvSimpleExpression*,char*) |
9ab5ebd7 |
364 | * |
365 | * Assign the value field to the current LttvSimpleExpression |
366 | * @param se pointer to the current LttvSimpleExpression |
367 | * @param value string value for simple expression |
368 | */ |
be66ef34 |
369 | gboolean |
370 | lttv_simple_expression_assign_value(LttvSimpleExpression* se, char* value) { |
9ab5ebd7 |
371 | |
46c40a93 |
372 | unsigned i; |
373 | gboolean is_double = FALSE; |
c6832b57 |
374 | LttTime t = ltt_time_zero; |
375 | GString* v; |
376 | GQuark quark; |
9ab5ebd7 |
377 | |
378 | switch(se->field) { |
379 | /* |
be66ef34 |
380 | * Strings |
381 | * entered as strings, converted to Quarks |
9ab5ebd7 |
382 | */ |
383 | case LTTV_FILTER_TRACE_NAME: |
384 | case LTTV_FILTER_TRACEFILE_NAME: |
385 | case LTTV_FILTER_STATE_P_NAME: |
386 | case LTTV_FILTER_EVENT_NAME: |
bbd9d557 |
387 | case LTTV_FILTER_STATE_CPU: |
be66ef34 |
388 | case LTTV_FILTER_STATE_EX_MODE: |
389 | case LTTV_FILTER_STATE_EX_SUBMODE: |
390 | case LTTV_FILTER_STATE_P_STATUS: |
391 | // se->value.v_string = value; |
bbd9d557 |
392 | se->value.v_uint32 = g_quark_from_string(value); |
c6832b57 |
393 | g_free(value); |
9ab5ebd7 |
394 | break; |
395 | /* |
be66ef34 |
396 | * integer -- supposed to be uint64 |
9ab5ebd7 |
397 | */ |
398 | case LTTV_FILTER_STATE_PID: |
399 | case LTTV_FILTER_STATE_PPID: |
bbd9d557 |
400 | case LTTV_FILTER_EVENT_TSC: |
9ab5ebd7 |
401 | se->value.v_uint64 = atoi(value); |
402 | g_free(value); |
403 | break; |
404 | /* |
7145a073 |
405 | * LttTime |
9ab5ebd7 |
406 | */ |
407 | case LTTV_FILTER_STATE_CT: |
408 | case LTTV_FILTER_STATE_IT: |
409 | case LTTV_FILTER_EVENT_TIME: |
7145a073 |
410 | //se->value.v_double = atof(value); |
46c40a93 |
411 | /* |
412 | * parsing logic could be optimised, |
413 | * but as for now, simpler this way |
414 | */ |
415 | v = g_string_new(""); |
416 | for(i=0;i<strlen(value);i++) { |
417 | if(value[i] == '.') { |
418 | /* cannot specify number with more than one '.' */ |
419 | if(is_double) return FALSE; |
420 | else is_double = TRUE; |
421 | t.tv_sec = atoi(v); |
422 | g_string_free(v,TRUE); |
423 | v = g_string_new(""); |
424 | } else g_string_append_c(v,value[i]); |
425 | } |
426 | /* number can be integer or double */ |
427 | if(is_double) t.tv_nsec = atoi(v); |
c6832b57 |
428 | else t.tv_sec = atoi(v); |
429 | |
46c40a93 |
430 | g_string_free(v,TRUE); |
431 | |
432 | se->value.v_ltttime = t; |
9ab5ebd7 |
433 | g_free(value); |
434 | break; |
435 | default: |
436 | g_warning("Error encountered in value assignation ! Field type = %i",se->field); |
c6832b57 |
437 | g_free(value); |
9ab5ebd7 |
438 | return FALSE; |
439 | } |
440 | |
441 | return TRUE; |
442 | |
443 | } |
444 | |
31452f49 |
445 | /** |
56e29124 |
446 | * @fn void lttv_simple_expression_destroy(LttvSimpleExpression*) |
447 | * |
9ab5ebd7 |
448 | * Disallocate memory for the current |
56e29124 |
449 | * simple expression |
450 | * @param se pointer to the current LttvSimpleExpression |
451 | */ |
452 | void |
453 | lttv_simple_expression_destroy(LttvSimpleExpression* se) { |
454 | |
9ab5ebd7 |
455 | // g_free(se->value); |
786c5c3b |
456 | // switch(se->field) { |
457 | // case LTTV_FILTER_TRACE_NAME: |
458 | // case LTTV_FILTER_TRACEFILE_NAME: |
459 | // case LTTV_FILTER_STATE_P_NAME: |
460 | // case LTTV_FILTER_EVENT_NAME: |
461 | // g_free(se->value.v_string); |
462 | // break; |
463 | // } |
56e29124 |
464 | g_free(se); |
465 | |
466 | } |
467 | |
468 | /** |
469 | * @fn gint lttv_struct_type(gint) |
470 | * |
80f9611a |
471 | * Finds the structure type depending |
472 | * on the fields in parameters |
473 | * @params ft Field of the current structure |
474 | * @return LttvStructType enum or -1 for error |
84a333d6 |
475 | */ |
80f9611a |
476 | gint |
477 | lttv_struct_type(gint ft) { |
5f185a2b |
478 | |
80f9611a |
479 | switch(ft) { |
480 | case LTTV_FILTER_TRACE_NAME: |
481 | return LTTV_FILTER_TRACE; |
482 | break; |
483 | case LTTV_FILTER_TRACEFILE_NAME: |
484 | return LTTV_FILTER_TRACEFILE; |
485 | break; |
486 | case LTTV_FILTER_STATE_PID: |
487 | case LTTV_FILTER_STATE_PPID: |
488 | case LTTV_FILTER_STATE_CT: |
489 | case LTTV_FILTER_STATE_IT: |
490 | case LTTV_FILTER_STATE_P_NAME: |
491 | case LTTV_FILTER_STATE_EX_MODE: |
492 | case LTTV_FILTER_STATE_EX_SUBMODE: |
493 | case LTTV_FILTER_STATE_P_STATUS: |
494 | case LTTV_FILTER_STATE_CPU: |
495 | return LTTV_FILTER_STATE; |
496 | break; |
497 | case LTTV_FILTER_EVENT_NAME: |
498 | case LTTV_FILTER_EVENT_CATEGORY: |
499 | case LTTV_FILTER_EVENT_TIME: |
500 | case LTTV_FILTER_EVENT_TSC: |
501 | case LTTV_FILTER_EVENT_FIELD: |
502 | return LTTV_FILTER_EVENT; |
503 | break; |
504 | default: |
505 | return -1; |
506 | } |
84a333d6 |
507 | } |
508 | |
150f0d33 |
509 | /** |
7e7af7f2 |
510 | * @fn gboolean lttv_apply_op_eq_uint64(gpointer,LttvFieldValue) |
56e29124 |
511 | * |
150f0d33 |
512 | * Applies the 'equal' operator to the |
47aa6e58 |
513 | * specified structure and value |
514 | * @param v1 left member of comparison |
515 | * @param v2 right member of comparison |
150f0d33 |
516 | * @return success/failure of operation |
517 | */ |
4d9ff942 |
518 | gboolean lttv_apply_op_eq_uint64(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
519 | |
520 | guint64* r = (guint64*) v1; |
9ab5ebd7 |
521 | return (*r == v2.v_uint64); |
83aa92fc |
522 | |
523 | } |
150f0d33 |
524 | |
5b729fcf |
525 | /** |
7e7af7f2 |
526 | * @fn gboolean lttv_apply_op_eq_uint32(gpointer,LttvFieldValue) |
56e29124 |
527 | * |
5b729fcf |
528 | * Applies the 'equal' operator to the |
47aa6e58 |
529 | * specified structure and value |
530 | * @param v1 left member of comparison |
531 | * @param v2 right member of comparison |
5b729fcf |
532 | * @return success/failure of operation |
533 | */ |
4d9ff942 |
534 | gboolean lttv_apply_op_eq_uint32(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
535 | guint32* r = (guint32*) v1; |
9ab5ebd7 |
536 | return (*r == v2.v_uint32); |
83aa92fc |
537 | } |
5b729fcf |
538 | |
539 | /** |
7e7af7f2 |
540 | * @fn gboolean lttv_apply_op_eq_uint16(gpointer,LttvFieldValue) |
56e29124 |
541 | * |
5b729fcf |
542 | * Applies the 'equal' operator to the |
47aa6e58 |
543 | * specified structure and value |
544 | * @param v1 left member of comparison |
545 | * @param v2 right member of comparison |
5b729fcf |
546 | * @return success/failure of operation |
547 | */ |
4d9ff942 |
548 | gboolean lttv_apply_op_eq_uint16(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
549 | guint16* r = (guint16*) v1; |
9ab5ebd7 |
550 | return (*r == v2.v_uint16); |
83aa92fc |
551 | } |
5b729fcf |
552 | |
553 | /** |
7e7af7f2 |
554 | * @fn gboolean lttv_apply_op_eq_double(gpointer,LttvFieldValue) |
56e29124 |
555 | * |
5b729fcf |
556 | * Applies the 'equal' operator to the |
47aa6e58 |
557 | * specified structure and value |
558 | * @param v1 left member of comparison |
559 | * @param v2 right member of comparison |
5b729fcf |
560 | * @return success/failure of operation |
561 | */ |
4d9ff942 |
562 | gboolean lttv_apply_op_eq_double(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
563 | double* r = (double*) v1; |
9ab5ebd7 |
564 | return (*r == v2.v_double); |
83aa92fc |
565 | } |
5b729fcf |
566 | |
567 | /** |
7e7af7f2 |
568 | * @fn gboolean lttv_apply_op_eq_string(gpointer,LttvFieldValue) |
56e29124 |
569 | * |
5b729fcf |
570 | * Applies the 'equal' operator to the |
47aa6e58 |
571 | * specified structure and value |
572 | * @param v1 left member of comparison |
573 | * @param v2 right member of comparison |
5b729fcf |
574 | * @return success/failure of operation |
575 | */ |
4d9ff942 |
576 | gboolean lttv_apply_op_eq_string(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
577 | char* r = (char*) v1; |
9ab5ebd7 |
578 | return (!g_strcasecmp(r,v2.v_string)); |
83aa92fc |
579 | } |
150f0d33 |
580 | |
c6832b57 |
581 | /** |
7e7af7f2 |
582 | * @fn gboolean lttv_apply_op_eq_quark(gpointer,LttvFieldValue) |
c6832b57 |
583 | * |
584 | * Applies the 'equal' operator to the |
585 | * specified structure and value |
586 | * @param v1 left member of comparison |
587 | * @param v2 right member of comparison |
588 | * @return success/failure of operation |
589 | */ |
590 | gboolean lttv_apply_op_eq_quark(const gpointer v1, LttvFieldValue v2) { |
591 | GQuark* r = (GQuark*) v1; |
592 | g_print("v1:%i v2:%i\n",*r,v2.v_uint32); |
593 | return (*r == v2.v_uint32); |
594 | } |
595 | |
7145a073 |
596 | /** |
7e7af7f2 |
597 | * @fn gboolean lttv_apply_op_eq_ltttime(gpointer,LttvFieldValue) |
7145a073 |
598 | * |
599 | * Applies the 'equal' operator to the |
600 | * specified structure and value |
601 | * @param v1 left member of comparison |
602 | * @param v2 right member of comparison |
603 | * @return success/failure of operation |
604 | */ |
4d9ff942 |
605 | gboolean lttv_apply_op_eq_ltttime(const gpointer v1, LttvFieldValue v2) { |
7145a073 |
606 | LttTime* r = (LttTime*) v1; |
c6832b57 |
607 | return ltt_time_compare(*r, v2.v_ltttime)==0?1:0; |
7145a073 |
608 | } |
609 | |
610 | |
150f0d33 |
611 | /** |
7e7af7f2 |
612 | * @fn gboolean lttv_apply_op_ne_uint64(gpointer,LttvFieldValue) |
56e29124 |
613 | * |
150f0d33 |
614 | * Applies the 'not equal' operator to the |
47aa6e58 |
615 | * specified structure and value |
616 | * @param v1 left member of comparison |
617 | * @param v2 right member of comparison |
150f0d33 |
618 | * @return success/failure of operation |
619 | */ |
4d9ff942 |
620 | gboolean lttv_apply_op_ne_uint64(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
621 | guint64* r = (guint64*) v1; |
9ab5ebd7 |
622 | return (*r != v2.v_uint64); |
83aa92fc |
623 | } |
150f0d33 |
624 | |
5b729fcf |
625 | /** |
7e7af7f2 |
626 | * @fn gboolean lttv_apply_op_ne_uint32(gpointer,LttvFieldValue) |
56e29124 |
627 | * |
5b729fcf |
628 | * Applies the 'not equal' operator to the |
47aa6e58 |
629 | * specified structure and value |
630 | * @param v1 left member of comparison |
631 | * @param v2 right member of comparison |
5b729fcf |
632 | * @return success/failure of operation |
633 | */ |
4d9ff942 |
634 | gboolean lttv_apply_op_ne_uint32(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
635 | guint32* r = (guint32*) v1; |
9ab5ebd7 |
636 | return (*r != v2.v_uint32); |
83aa92fc |
637 | } |
5b729fcf |
638 | |
639 | /** |
7e7af7f2 |
640 | * @fn gboolean lttv_apply_op_ne_uint16(gpointer,LttvFieldValue) |
56e29124 |
641 | * |
5b729fcf |
642 | * Applies the 'not equal' operator to the |
47aa6e58 |
643 | * specified structure and value |
644 | * @param v1 left member of comparison |
645 | * @param v2 right member of comparison |
5b729fcf |
646 | * @return success/failure of operation |
647 | */ |
4d9ff942 |
648 | gboolean lttv_apply_op_ne_uint16(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
649 | guint16* r = (guint16*) v1; |
9ab5ebd7 |
650 | return (*r != v2.v_uint16); |
83aa92fc |
651 | } |
5b729fcf |
652 | |
653 | /** |
7e7af7f2 |
654 | * @fn gboolean lttv_apply_op_ne_double(gpointer,LttvFieldValue) |
56e29124 |
655 | * |
5b729fcf |
656 | * Applies the 'not equal' operator to the |
47aa6e58 |
657 | * specified structure and value |
658 | * @param v1 left member of comparison |
659 | * @param v2 right member of comparison |
5b729fcf |
660 | * @return success/failure of operation |
661 | */ |
4d9ff942 |
662 | gboolean lttv_apply_op_ne_double(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
663 | double* r = (double*) v1; |
9ab5ebd7 |
664 | return (*r != v2.v_double); |
83aa92fc |
665 | } |
5b729fcf |
666 | |
667 | /** |
7e7af7f2 |
668 | * @fn gboolean lttv_apply_op_ne_string(gpointer,LttvFieldValue) |
56e29124 |
669 | * |
5b729fcf |
670 | * Applies the 'not equal' operator to the |
47aa6e58 |
671 | * specified structure and value |
672 | * @param v1 left member of comparison |
673 | * @param v2 right member of comparison |
5b729fcf |
674 | * @return success/failure of operation |
675 | */ |
4d9ff942 |
676 | gboolean lttv_apply_op_ne_string(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
677 | char* r = (char*) v1; |
9ab5ebd7 |
678 | return (g_strcasecmp(r,v2.v_string)); |
83aa92fc |
679 | } |
150f0d33 |
680 | |
c6832b57 |
681 | /** |
7e7af7f2 |
682 | * @fn gboolean lttv_apply_op_ne_quark(gpointer,LttvFieldValue) |
c6832b57 |
683 | * |
684 | * Applies the 'not equal' operator to the |
685 | * specified structure and value |
686 | * @param v1 left member of comparison |
687 | * @param v2 right member of comparison |
688 | * @return success/failure of operation |
689 | */ |
690 | gboolean lttv_apply_op_ne_quark(const gpointer v1, LttvFieldValue v2) { |
691 | GQuark* r = (GQuark*) v1; |
692 | return (*r != v2.v_uint32); |
693 | } |
694 | |
695 | |
7145a073 |
696 | /** |
7e7af7f2 |
697 | * @fn gboolean lttv_apply_op_ne_ltttime(gpointer,LttvFieldValue) |
7145a073 |
698 | * |
699 | * Applies the 'not equal' operator to the |
700 | * specified structure and value |
701 | * @param v1 left member of comparison |
702 | * @param v2 right member of comparison |
703 | * @return success/failure of operation |
704 | */ |
4d9ff942 |
705 | gboolean lttv_apply_op_ne_ltttime(const gpointer v1, LttvFieldValue v2) { |
7145a073 |
706 | LttTime* r = (LttTime*) v1; |
46c40a93 |
707 | return ltt_time_compare(*r, v2.v_ltttime)!=0?1:0; |
7145a073 |
708 | } |
709 | |
710 | |
150f0d33 |
711 | /** |
7e7af7f2 |
712 | * @fn gboolean lttv_apply_op_lt_uint64(gpointer,LttvFieldValue) |
56e29124 |
713 | * |
150f0d33 |
714 | * Applies the 'lower than' operator to the |
47aa6e58 |
715 | * specified structure and value |
716 | * @param v1 left member of comparison |
717 | * @param v2 right member of comparison |
150f0d33 |
718 | * @return success/failure of operation |
719 | */ |
4d9ff942 |
720 | gboolean lttv_apply_op_lt_uint64(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
721 | guint64* r = (guint64*) v1; |
9ab5ebd7 |
722 | return (*r < v2.v_uint64); |
83aa92fc |
723 | } |
150f0d33 |
724 | |
5b729fcf |
725 | /** |
7e7af7f2 |
726 | * @fn gboolean lttv_apply_op_lt_uint32(gpointer,LttvFieldValue) |
56e29124 |
727 | * |
5b729fcf |
728 | * Applies the 'lower than' operator to the |
47aa6e58 |
729 | * specified structure and value |
730 | * @param v1 left member of comparison |
731 | * @param v2 right member of comparison |
5b729fcf |
732 | * @return success/failure of operation |
733 | */ |
4d9ff942 |
734 | gboolean lttv_apply_op_lt_uint32(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
735 | guint32* r = (guint32*) v1; |
9ab5ebd7 |
736 | return (*r < v2.v_uint32); |
83aa92fc |
737 | } |
5b729fcf |
738 | |
739 | /** |
7e7af7f2 |
740 | * @fn gboolean lttv_apply_op_lt_uint16(gpointer,LttvFieldValue) |
56e29124 |
741 | * |
5b729fcf |
742 | * Applies the 'lower than' operator to the |
47aa6e58 |
743 | * specified structure and value |
744 | * @param v1 left member of comparison |
745 | * @param v2 right member of comparison |
5b729fcf |
746 | * @return success/failure of operation |
747 | */ |
4d9ff942 |
748 | gboolean lttv_apply_op_lt_uint16(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
749 | guint16* r = (guint16*) v1; |
9ab5ebd7 |
750 | return (*r < v2.v_uint16); |
83aa92fc |
751 | } |
5b729fcf |
752 | |
753 | /** |
7e7af7f2 |
754 | * @fn gboolean lttv_apply_op_lt_double(gpointer,LttvFieldValue) |
56e29124 |
755 | * |
5b729fcf |
756 | * Applies the 'lower than' operator to the |
47aa6e58 |
757 | * specified structure and value |
758 | * @param v1 left member of comparison |
759 | * @param v2 right member of comparison |
5b729fcf |
760 | * @return success/failure of operation |
761 | */ |
4d9ff942 |
762 | gboolean lttv_apply_op_lt_double(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
763 | double* r = (double*) v1; |
9ab5ebd7 |
764 | return (*r < v2.v_double); |
83aa92fc |
765 | } |
5b729fcf |
766 | |
7145a073 |
767 | /** |
7e7af7f2 |
768 | * @fn gboolean lttv_apply_op_lt_ltttime(gpointer,LttvFieldValue) |
7145a073 |
769 | * |
770 | * Applies the 'lower than' operator to the |
771 | * specified structure and value |
772 | * @param v1 left member of comparison |
773 | * @param v2 right member of comparison |
774 | * @return success/failure of operation |
775 | */ |
4d9ff942 |
776 | gboolean lttv_apply_op_lt_ltttime(const gpointer v1, LttvFieldValue v2) { |
7145a073 |
777 | LttTime* r = (LttTime*) v1; |
c6832b57 |
778 | // return ((r->tv_sec < v2.v_ltttime.tv_sec) || ((r->tv_sec == v2.v_ltttime.tv_sec) && (r->tv_nsec < v2.v_ltttime.tv_nsec))); |
779 | return ltt_time_compare(*r, v2.v_ltttime)==-1?1:0; |
7145a073 |
780 | } |
781 | |
782 | |
5b729fcf |
783 | /** |
7e7af7f2 |
784 | * @fn gboolean lttv_apply_op_le_uint64(gpointer,LttvFieldValue) |
56e29124 |
785 | * |
786 | * Applies the 'lower or equal' operator to the |
47aa6e58 |
787 | * specified structure and value |
788 | * @param v1 left member of comparison |
789 | * @param v2 right member of comparison |
5b729fcf |
790 | * @return success/failure of operation |
791 | */ |
4d9ff942 |
792 | gboolean lttv_apply_op_le_uint64(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
793 | guint64* r = (guint64*) v1; |
9ab5ebd7 |
794 | return (*r <= v2.v_uint64); |
83aa92fc |
795 | } |
150f0d33 |
796 | |
797 | /** |
7e7af7f2 |
798 | * @fn gboolean lttv_apply_op_le_uint32(gpointer,LttvFieldValue) |
56e29124 |
799 | * |
150f0d33 |
800 | * Applies the 'lower or equal' operator to the |
47aa6e58 |
801 | * specified structure and value |
802 | * @param v1 left member of comparison |
803 | * @param v2 right member of comparison |
150f0d33 |
804 | * @return success/failure of operation |
805 | */ |
4d9ff942 |
806 | gboolean lttv_apply_op_le_uint32(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
807 | guint32* r = (guint32*) v1; |
9ab5ebd7 |
808 | return (*r <= v2.v_uint32); |
83aa92fc |
809 | } |
150f0d33 |
810 | |
5b729fcf |
811 | /** |
7e7af7f2 |
812 | * @fn gboolean lttv_apply_op_le_uint16(gpointer,LttvFieldValue) |
56e29124 |
813 | * |
5b729fcf |
814 | * Applies the 'lower or equal' operator to the |
47aa6e58 |
815 | * specified structure and value |
816 | * @param v1 left member of comparison |
817 | * @param v2 right member of comparison |
5b729fcf |
818 | * @return success/failure of operation |
819 | */ |
4d9ff942 |
820 | gboolean lttv_apply_op_le_uint16(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
821 | guint16* r = (guint16*) v1; |
9ab5ebd7 |
822 | return (*r <= v2.v_uint16); |
83aa92fc |
823 | } |
5b729fcf |
824 | |
825 | /** |
7e7af7f2 |
826 | * @fn gboolean lttv_apply_op_le_double(gpointer,LttvFieldValue) |
56e29124 |
827 | * |
5b729fcf |
828 | * Applies the 'lower or equal' operator to the |
47aa6e58 |
829 | * specified structure and value |
830 | * @param v1 left member of comparison |
831 | * @param v2 right member of comparison |
5b729fcf |
832 | * @return success/failure of operation |
833 | */ |
4d9ff942 |
834 | gboolean lttv_apply_op_le_double(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
835 | double* r = (double*) v1; |
9ab5ebd7 |
836 | return (*r <= v2.v_double); |
83aa92fc |
837 | } |
5b729fcf |
838 | |
7145a073 |
839 | /** |
7e7af7f2 |
840 | * @fn gboolean lttv_apply_op_le_ltttime(gpointer,LttvFieldValue) |
7145a073 |
841 | * |
842 | * Applies the 'lower or equal' operator to the |
843 | * specified structure and value |
844 | * @param v1 left member of comparison |
845 | * @param v2 right member of comparison |
846 | * @return success/failure of operation |
847 | */ |
4d9ff942 |
848 | gboolean lttv_apply_op_le_ltttime(const gpointer v1, LttvFieldValue v2) { |
7145a073 |
849 | LttTime* r = (LttTime*) v1; |
c6832b57 |
850 | // return ((r->tv_sec < v2.v_ltttime.tv_sec) || ((r->tv_sec == v2.v_ltttime.tv_sec) && (r->tv_nsec <= v2.v_ltttime.tv_nsec))); |
851 | return ltt_time_compare(*r, v2.v_ltttime)<1?1:0; |
7145a073 |
852 | } |
853 | |
854 | |
5b729fcf |
855 | /** |
7e7af7f2 |
856 | * @fn gboolean lttv_apply_op_gt_uint64(gpointer,LttvFieldValue) |
56e29124 |
857 | * |
83aa92fc |
858 | * Applies the 'greater than' operator to the |
47aa6e58 |
859 | * specified structure and value |
860 | * @param v1 left member of comparison |
861 | * @param v2 right member of comparison |
5b729fcf |
862 | * @return success/failure of operation |
863 | */ |
4d9ff942 |
864 | gboolean lttv_apply_op_gt_uint64(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
865 | guint64* r = (guint64*) v1; |
9ab5ebd7 |
866 | return (*r > v2.v_uint64); |
83aa92fc |
867 | } |
150f0d33 |
868 | |
869 | /** |
7e7af7f2 |
870 | * @fn gboolean lttv_apply_op_gt_uint32(gpointer,LttvFieldValue) |
56e29124 |
871 | * |
150f0d33 |
872 | * Applies the 'greater than' operator to the |
47aa6e58 |
873 | * specified structure and value |
874 | * @param v1 left member of comparison |
875 | * @param v2 right member of comparison |
150f0d33 |
876 | * @return success/failure of operation |
877 | */ |
4d9ff942 |
878 | gboolean lttv_apply_op_gt_uint32(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
879 | guint32* r = (guint32*) v1; |
9ab5ebd7 |
880 | return (*r > v2.v_uint32); |
83aa92fc |
881 | } |
150f0d33 |
882 | |
5b729fcf |
883 | /** |
7e7af7f2 |
884 | * @fn gboolean lttv_apply_op_gt_uint16(gpointer,LttvFieldValue) |
56e29124 |
885 | * |
5b729fcf |
886 | * Applies the 'greater than' operator to the |
47aa6e58 |
887 | * specified structure and value |
888 | * @param v1 left member of comparison |
889 | * @param v2 right member of comparison |
5b729fcf |
890 | * @return success/failure of operation |
891 | */ |
4d9ff942 |
892 | gboolean lttv_apply_op_gt_uint16(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
893 | guint16* r = (guint16*) v1; |
9ab5ebd7 |
894 | return (*r > v2.v_uint16); |
83aa92fc |
895 | } |
5b729fcf |
896 | |
897 | /** |
7e7af7f2 |
898 | * @fn gboolean lttv_apply_op_gt_double(gpointer,LttvFieldValue) |
56e29124 |
899 | * |
5b729fcf |
900 | * Applies the 'greater than' operator to the |
47aa6e58 |
901 | * specified structure and value |
902 | * @param v1 left member of comparison |
903 | * @param v2 right member of comparison |
5b729fcf |
904 | * @return success/failure of operation |
905 | */ |
4d9ff942 |
906 | gboolean lttv_apply_op_gt_double(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
907 | double* r = (double*) v1; |
9ab5ebd7 |
908 | return (*r > v2.v_double); |
83aa92fc |
909 | } |
5b729fcf |
910 | |
7145a073 |
911 | /** |
7e7af7f2 |
912 | * @fn gboolean lttv_apply_op_gt_ltttime(gpointer,LttvFieldValue) |
7145a073 |
913 | * |
914 | * Applies the 'greater than' operator to the |
915 | * specified structure and value |
916 | * @param v1 left member of comparison |
917 | * @param v2 right member of comparison |
918 | * @return success/failure of operation |
919 | */ |
4d9ff942 |
920 | gboolean lttv_apply_op_gt_ltttime(const gpointer v1, LttvFieldValue v2) { |
7145a073 |
921 | LttTime* r = (LttTime*) v1; |
c6832b57 |
922 | // return ((r->tv_sec > v2.v_ltttime.tv_sec) || ((r->tv_sec == v2.v_ltttime.tv_sec) && (r->tv_nsec > v2.v_ltttime.tv_nsec))); |
923 | return ltt_time_compare(*r, v2.v_ltttime)==1?1:0; |
7145a073 |
924 | } |
925 | |
926 | |
5b729fcf |
927 | /** |
7e7af7f2 |
928 | * @fn gboolean lttv_apply_op_ge_uint64(gpointer,LttvFieldValue) |
56e29124 |
929 | * |
83aa92fc |
930 | * Applies the 'greater or equal' operator to the |
47aa6e58 |
931 | * specified structure and value |
932 | * @param v1 left member of comparison |
933 | * @param v2 right member of comparison |
5b729fcf |
934 | * @return success/failure of operation |
935 | */ |
4d9ff942 |
936 | gboolean lttv_apply_op_ge_uint64(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
937 | guint64* r = (guint64*) v1; |
9ab5ebd7 |
938 | return (*r >= v2.v_uint64); |
83aa92fc |
939 | } |
150f0d33 |
940 | |
941 | /** |
7e7af7f2 |
942 | * @fn gboolean lttv_apply_op_ge_uint32(gpointer,LttvFieldValue) |
56e29124 |
943 | * |
150f0d33 |
944 | * Applies the 'greater or equal' operator to the |
47aa6e58 |
945 | * specified structure and value |
946 | * @param v1 left member of comparison |
947 | * @param v2 right member of comparison |
150f0d33 |
948 | * @return success/failure of operation |
949 | */ |
4d9ff942 |
950 | gboolean lttv_apply_op_ge_uint32(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
951 | guint32* r = (guint32*) v1; |
9ab5ebd7 |
952 | return (*r >= v2.v_uint32); |
83aa92fc |
953 | } |
150f0d33 |
954 | |
5b729fcf |
955 | /** |
7e7af7f2 |
956 | * @fn gboolean lttv_apply_op_ge_uint16(gpointer,LttvFieldValue) |
56e29124 |
957 | * |
5b729fcf |
958 | * Applies the 'greater or equal' operator to the |
47aa6e58 |
959 | * specified structure and value |
960 | * @param v1 left member of comparison |
961 | * @param v2 right member of comparison |
5b729fcf |
962 | * @return success/failure of operation |
963 | */ |
4d9ff942 |
964 | gboolean lttv_apply_op_ge_uint16(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
965 | guint16* r = (guint16*) v1; |
9ab5ebd7 |
966 | return (*r >= v2.v_uint16); |
83aa92fc |
967 | } |
150f0d33 |
968 | |
5b729fcf |
969 | /** |
7e7af7f2 |
970 | * @fn gboolean lttv_apply_op_ge_double(gpointer,LttvFieldValue) |
56e29124 |
971 | * |
5b729fcf |
972 | * Applies the 'greater or equal' operator to the |
47aa6e58 |
973 | * specified structure and value |
974 | * @param v1 left member of comparison |
975 | * @param v2 right member of comparison |
5b729fcf |
976 | * @return success/failure of operation |
977 | */ |
4d9ff942 |
978 | gboolean lttv_apply_op_ge_double(const gpointer v1, LttvFieldValue v2) { |
83aa92fc |
979 | double* r = (double*) v1; |
9ab5ebd7 |
980 | return (*r >= v2.v_double); |
83aa92fc |
981 | } |
150f0d33 |
982 | |
7145a073 |
983 | /** |
7e7af7f2 |
984 | * @fn gboolean lttv_apply_op_ge_ltttime(gpointer,LttvFieldValue) |
7145a073 |
985 | * |
986 | * Applies the 'greater or equal' operator to the |
987 | * specified structure and value |
988 | * @param v1 left member of comparison |
989 | * @param v2 right member of comparison |
990 | * @return success/failure of operation |
991 | */ |
4d9ff942 |
992 | gboolean lttv_apply_op_ge_ltttime(const gpointer v1, LttvFieldValue v2) { |
7145a073 |
993 | LttTime* r = (LttTime*) v1; |
c6832b57 |
994 | // return ((r->tv_sec > v2.v_ltttime.tv_sec) || ((r->tv_sec == v2.v_ltttime.tv_sec) && (r->tv_nsec >= v2.v_ltttime.tv_nsec))); |
995 | return ltt_time_compare(*r, v2.v_ltttime)>-1?1:0; |
7145a073 |
996 | } |
997 | |
998 | |
150f0d33 |
999 | |
1000 | /** |
56e29124 |
1001 | * Makes a copy of the current filter tree |
1002 | * @param tree pointer to the current tree |
1003 | * @return new copy of the filter tree |
150f0d33 |
1004 | */ |
1005 | LttvFilterTree* |
4d9ff942 |
1006 | lttv_filter_tree_clone(const LttvFilterTree* tree) { |
150f0d33 |
1007 | |
8c89f5a8 |
1008 | LttvFilterTree* newtree = lttv_filter_tree_new(); |
150f0d33 |
1009 | |
8c89f5a8 |
1010 | newtree->node = tree->node; |
1011 | |
1012 | newtree->left = tree->left; |
1013 | if(newtree->left == LTTV_TREE_NODE) { |
1014 | newtree->l_child.t = lttv_filter_tree_clone(tree->l_child.t); |
1015 | } else if(newtree->left == LTTV_TREE_LEAF) { |
1016 | newtree->l_child.leaf = lttv_simple_expression_new(); |
1017 | newtree->l_child.leaf->field = tree->l_child.leaf->field; |
1018 | newtree->l_child.leaf->offset = tree->l_child.leaf->offset; |
1019 | newtree->l_child.leaf->op = tree->l_child.leaf->op; |
9ab5ebd7 |
1020 | /* FIXME: special case for string copy ! */ |
1021 | newtree->l_child.leaf->value = tree->l_child.leaf->value; |
8c89f5a8 |
1022 | } |
1023 | |
1024 | newtree->right = tree->right; |
1025 | if(newtree->right == LTTV_TREE_NODE) { |
1026 | newtree->r_child.t = lttv_filter_tree_clone(tree->r_child.t); |
1027 | } else if(newtree->right == LTTV_TREE_LEAF) { |
1028 | newtree->r_child.leaf = lttv_simple_expression_new(); |
1029 | newtree->r_child.leaf->field = tree->r_child.leaf->field; |
1030 | newtree->r_child.leaf->offset = tree->r_child.leaf->offset; |
1031 | newtree->r_child.leaf->op = tree->r_child.leaf->op; |
9ab5ebd7 |
1032 | newtree->r_child.leaf->value = tree->r_child.leaf->value; |
8c89f5a8 |
1033 | } |
1034 | |
1035 | return newtree; |
1036 | |
150f0d33 |
1037 | } |
1038 | |
1039 | /** |
56e29124 |
1040 | * Makes a copy of the current filter |
1041 | * @param filter pointer to the current filter |
1042 | * @return new copy of the filter |
150f0d33 |
1043 | */ |
1044 | LttvFilter* |
4d9ff942 |
1045 | lttv_filter_clone(const LttvFilter* filter) { |
150f0d33 |
1046 | |
1047 | LttvFilter* newfilter = g_new(LttvFilter,1); |
1048 | |
150f0d33 |
1049 | strcpy(newfilter->expression,filter->expression); |
1050 | |
1051 | newfilter->head = lttv_filter_tree_clone(filter->head); |
1052 | |
1053 | return newfilter; |
1054 | |
1055 | } |
1056 | |
1057 | |
84a333d6 |
1058 | /** |
56e29124 |
1059 | * @fn LttvFilter* lttv_filter_new() |
1060 | * |
7e7af7f2 |
1061 | * Creates a new LttvFilter |
1062 | * @return the current LttvFilter or NULL if error |
31452f49 |
1063 | */ |
2ea36caf |
1064 | LttvFilter* |
5f185a2b |
1065 | lttv_filter_new() { |
a4c292d4 |
1066 | |
5f185a2b |
1067 | LttvFilter* filter = g_new(LttvFilter,1); |
1068 | filter->expression = NULL; |
1069 | filter->head = NULL; |
7e7af7f2 |
1070 | |
1071 | return filter; |
5f185a2b |
1072 | |
1073 | } |
a4c292d4 |
1074 | |
8c89f5a8 |
1075 | /** |
56e29124 |
1076 | * @fn gboolean lttv_filter_update(LttvFilter*) |
1077 | * |
8c89f5a8 |
1078 | * Updates the current LttvFilter by building |
1079 | * its tree based upon the expression string |
1080 | * @param filter pointer to the current LttvFilter |
1081 | * @return Failure/Success of operation |
1082 | */ |
5f185a2b |
1083 | gboolean |
1084 | lttv_filter_update(LttvFilter* filter) { |
1085 | |
4d9ff942 |
1086 | // g_print("filter::lttv_filter_new()\n"); /* debug */ |
5f185a2b |
1087 | |
1088 | if(filter->expression == NULL) return FALSE; |
1089 | |
f3020899 |
1090 | int |
a4c292d4 |
1091 | i, |
56e29124 |
1092 | p_nesting=0; /* parenthesis nesting value */ |
1601b365 |
1093 | |
1094 | /* trees */ |
5b729fcf |
1095 | LttvFilterTree |
1601b365 |
1096 | *tree = lttv_filter_tree_new(), /* main tree */ |
1097 | *subtree = NULL, /* buffer for subtrees */ |
1098 | *t1, /* buffer #1 */ |
1099 | *t2; /* buffer #2 */ |
1100 | |
5f185a2b |
1101 | /* |
1102 | * the filter |
1103 | * If the tree already exists, |
1104 | * destroy it and build a new one |
1105 | */ |
1106 | if(filter->head != NULL) lttv_filter_tree_destroy(filter->head); |
f3020899 |
1107 | filter->head = NULL; /* will be assigned at the end */ |
5f185a2b |
1108 | |
1601b365 |
1109 | /* |
1110 | * Tree Stack |
f4e9dd16 |
1111 | * each element of the list |
1112 | * is a sub tree created |
1113 | * by the use of parenthesis in the |
1114 | * global expression. The final tree |
1601b365 |
1115 | * will be the one left at the root of |
f4e9dd16 |
1116 | * the list |
1117 | */ |
18d1226f |
1118 | GPtrArray *tree_stack = g_ptr_array_new(); |
1119 | g_ptr_array_add( tree_stack,(gpointer) tree ); |
f4e9dd16 |
1120 | |
a4c292d4 |
1121 | /* temporary values */ |
0769c82f |
1122 | GString *a_field_component = g_string_new(""); |
56e29124 |
1123 | GPtrArray *a_field_path = g_ptr_array_new(); |
1124 | |
1125 | /* simple expression buffer */ |
389ba50e |
1126 | LttvSimpleExpression* a_simple_expression = lttv_simple_expression_new(); |
0769c82f |
1127 | |
a4c292d4 |
1128 | /* |
1129 | * Parse entire expression and construct |
1130 | * the binary tree. There are two steps |
1131 | * in browsing that string |
f4e9dd16 |
1132 | * 1. finding boolean ops " &,|,^,! " and parenthesis " {,(,[,],),} " |
a4c292d4 |
1133 | * 2. finding simple expressions |
0769c82f |
1134 | * - field path ( separated by dots ) |
a4c292d4 |
1135 | * - op ( >, <, =, >=, <=, !=) |
0769c82f |
1136 | * - value ( integer, string ... ) |
1137 | * To spare computing time, the whole |
1138 | * string is parsed in this loop for a |
1139 | * O(n) complexity order. |
1601b365 |
1140 | * |
18d1226f |
1141 | * When encountering logical op &,|,^ |
1142 | * 1. parse the last value if any |
1143 | * 2. create a new tree |
1144 | * 3. add the expression (simple exp, or exp (subtree)) to the tree |
1145 | * 4. concatenate this tree with the current tree on top of the stack |
1146 | * When encountering math ops >,>=,<,<=,=,!= |
1147 | * 1. add to op to the simple expression |
1148 | * 2. concatenate last field component to field path |
1149 | * When encountering concatening ops . |
1150 | * 1. concatenate last field component to field path |
1151 | * When encountering opening parenthesis (,{,[ |
1152 | * 1. create a new subtree on top of tree stack |
1153 | * When encountering closing parenthesis ),},] |
1154 | * 1. add the expression on right child of the current tree |
1155 | * 2. the subtree is completed, allocate a new subtree |
1156 | * 3. pop the tree value from the tree stack |
1157 | */ |
be66ef34 |
1158 | |
1159 | #ifdef TEST |
1160 | struct timeval starttime; |
1161 | struct timeval endtime; |
1162 | gettimeofday(&starttime, NULL); |
1163 | #endif |
18d1226f |
1164 | |
5f185a2b |
1165 | for(i=0;i<strlen(filter->expression);i++) { |
1166 | // debug |
4d9ff942 |
1167 | //g_print("%c ",filter->expression[i]); |
1168 | |
5f185a2b |
1169 | switch(filter->expression[i]) { |
a4c292d4 |
1170 | /* |
1171 | * logical operators |
1172 | */ |
1173 | case '&': /* and */ |
aa4600f3 |
1174 | |
5b729fcf |
1175 | t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1); |
9ab5ebd7 |
1176 | while(t1->right != LTTV_TREE_IDLE) { |
1177 | g_assert(t1->right == LTTV_TREE_NODE); |
1178 | t1 = t1->r_child.t; |
1179 | } |
18d1226f |
1180 | t2 = lttv_filter_tree_new(); |
0cdc2470 |
1181 | t2->node = LTTV_LOGICAL_AND; |
bb87caa7 |
1182 | if(subtree != NULL) { /* append subtree to current tree */ |
18d1226f |
1183 | t2->left = LTTV_TREE_NODE; |
1184 | t2->l_child.t = subtree; |
f4e9dd16 |
1185 | subtree = NULL; |
18d1226f |
1186 | t1->right = LTTV_TREE_NODE; |
410c83da |
1187 | t1->r_child.t = t2; |
bb87caa7 |
1188 | } else { /* append a simple expression */ |
9ab5ebd7 |
1189 | lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE)); |
18d1226f |
1190 | a_field_component = g_string_new(""); |
1191 | t2->left = LTTV_TREE_LEAF; |
0cdc2470 |
1192 | t2->l_child.leaf = a_simple_expression; |
389ba50e |
1193 | a_simple_expression = lttv_simple_expression_new(); |
18d1226f |
1194 | t1->right = LTTV_TREE_NODE; |
9ab5ebd7 |
1195 | t1->r_child.t = t2; |
f4e9dd16 |
1196 | } |
f4e9dd16 |
1197 | break; |
aa4600f3 |
1198 | |
a4c292d4 |
1199 | case '|': /* or */ |
aa4600f3 |
1200 | |
e00d6a24 |
1201 | t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1); |
9ab5ebd7 |
1202 | while(t1->right != LTTV_TREE_IDLE) { |
1203 | g_assert(t1->right == LTTV_TREE_NODE); |
1204 | t1 = t1->r_child.t; |
1205 | } |
1601b365 |
1206 | t2 = lttv_filter_tree_new(); |
0cdc2470 |
1207 | t2->node = LTTV_LOGICAL_OR; |
bb87caa7 |
1208 | if(subtree != NULL) { /* append subtree to current tree */ |
1601b365 |
1209 | t2->left = LTTV_TREE_NODE; |
1210 | t2->l_child.t = subtree; |
1211 | subtree = NULL; |
1212 | t1->right = LTTV_TREE_NODE; |
1213 | t1->r_child.t = t2; |
bb87caa7 |
1214 | } else { /* append a simple expression */ |
9ab5ebd7 |
1215 | lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE)); |
1601b365 |
1216 | a_field_component = g_string_new(""); |
1217 | t2->left = LTTV_TREE_LEAF; |
0cdc2470 |
1218 | t2->l_child.leaf = a_simple_expression; |
389ba50e |
1219 | a_simple_expression = lttv_simple_expression_new(); |
1601b365 |
1220 | t1->right = LTTV_TREE_NODE; |
1221 | t1->r_child.t = t2; |
1222 | } |
f4e9dd16 |
1223 | break; |
aa4600f3 |
1224 | |
a4c292d4 |
1225 | case '^': /* xor */ |
aa4600f3 |
1226 | |
e00d6a24 |
1227 | t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1); |
9ab5ebd7 |
1228 | while(t1->right != LTTV_TREE_IDLE) { |
1229 | g_assert(t1->right == LTTV_TREE_NODE); |
1230 | t1 = t1->r_child.t; |
1231 | } |
1601b365 |
1232 | t2 = lttv_filter_tree_new(); |
0cdc2470 |
1233 | t2->node = LTTV_LOGICAL_XOR; |
bb87caa7 |
1234 | if(subtree != NULL) { /* append subtree to current tree */ |
1601b365 |
1235 | t2->left = LTTV_TREE_NODE; |
1236 | t2->l_child.t = subtree; |
1237 | subtree = NULL; |
1238 | t1->right = LTTV_TREE_NODE; |
1239 | t1->r_child.t = t2; |
bb87caa7 |
1240 | } else { /* append a simple expression */ |
9ab5ebd7 |
1241 | lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE)); |
1601b365 |
1242 | a_field_component = g_string_new(""); |
1243 | t2->left = LTTV_TREE_LEAF; |
0cdc2470 |
1244 | t2->l_child.leaf = a_simple_expression; |
389ba50e |
1245 | a_simple_expression = lttv_simple_expression_new(); |
1601b365 |
1246 | t1->right = LTTV_TREE_NODE; |
1247 | t1->r_child.t = t2; |
1248 | } |
a4c292d4 |
1249 | break; |
aa4600f3 |
1250 | |
a4c292d4 |
1251 | case '!': /* not, or not equal (math op) */ |
aa4600f3 |
1252 | |
5f185a2b |
1253 | if(filter->expression[i+1] == '=') { /* != */ |
0cdc2470 |
1254 | g_ptr_array_add( a_field_path,(gpointer) a_field_component ); |
9ab5ebd7 |
1255 | lttv_simple_expression_assign_field(a_field_path,a_simple_expression); |
0cdc2470 |
1256 | a_field_component = g_string_new(""); |
56e29124 |
1257 | lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_NE); |
aa4600f3 |
1258 | i++; |
a4c292d4 |
1259 | } else { /* ! */ |
e00d6a24 |
1260 | t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1); |
9ab5ebd7 |
1261 | while(t1->right != LTTV_TREE_IDLE) { |
1262 | g_assert(t1->right == LTTV_TREE_NODE); |
1263 | t1 = t1->r_child.t; |
1264 | } |
1601b365 |
1265 | t2 = lttv_filter_tree_new(); |
0cdc2470 |
1266 | t2->node = LTTV_LOGICAL_NOT; |
1601b365 |
1267 | t1->right = LTTV_TREE_NODE; |
1268 | t1->r_child.t = t2; |
a4c292d4 |
1269 | } |
1270 | break; |
aa4600f3 |
1271 | |
a4c292d4 |
1272 | case '(': /* start of parenthesis */ |
91ad3f0a |
1273 | case '[': |
1274 | case '{': |
aa4600f3 |
1275 | |
91ad3f0a |
1276 | p_nesting++; /* incrementing parenthesis nesting value */ |
1601b365 |
1277 | t1 = lttv_filter_tree_new(); |
1278 | g_ptr_array_add( tree_stack,(gpointer) t1 ); |
a4c292d4 |
1279 | break; |
aa4600f3 |
1280 | |
a4c292d4 |
1281 | case ')': /* end of parenthesis */ |
91ad3f0a |
1282 | case ']': |
1283 | case '}': |
aa4600f3 |
1284 | |
91ad3f0a |
1285 | p_nesting--; /* decrementing parenthesis nesting value */ |
18d1226f |
1286 | if(p_nesting<0 || tree_stack->len<2) { |
f4e9dd16 |
1287 | g_warning("Wrong filtering options, the string\n\"%s\"\n\ |
5f185a2b |
1288 | is not valid due to parenthesis incorrect use",filter->expression); |
1289 | return FALSE; |
f4e9dd16 |
1290 | } |
56e29124 |
1291 | |
1292 | /* there must at least be the root tree left in the array */ |
18d1226f |
1293 | g_assert(tree_stack->len>0); |
56e29124 |
1294 | |
bb87caa7 |
1295 | if(subtree != NULL) { /* append subtree to current tree */ |
18d1226f |
1296 | t1 = g_ptr_array_index(tree_stack,tree_stack->len-1); |
9ab5ebd7 |
1297 | while(t1->right != LTTV_TREE_IDLE) { |
1298 | g_assert(t1->right == LTTV_TREE_NODE); |
1299 | t1 = t1->r_child.t; |
18d1226f |
1300 | } |
1301 | t1->right = LTTV_TREE_NODE; |
1302 | t1->r_child.t = subtree; |
1303 | subtree = g_ptr_array_index(tree_stack,tree_stack->len-1); |
1304 | g_ptr_array_remove_index(tree_stack,tree_stack->len-1); |
bb87caa7 |
1305 | } else { /* assign subtree as current tree */ |
9ab5ebd7 |
1306 | lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE)); |
18d1226f |
1307 | a_field_component = g_string_new(""); |
1308 | t1 = g_ptr_array_index(tree_stack,tree_stack->len-1); |
9ab5ebd7 |
1309 | while(t1->right != LTTV_TREE_IDLE) { |
9ab5ebd7 |
1310 | g_assert(t1->right == LTTV_TREE_NODE); |
1311 | g_assert(t1->r_child.t != NULL); |
1312 | t1 = t1->r_child.t; |
1313 | } |
18d1226f |
1314 | t1->right = LTTV_TREE_LEAF; |
0cdc2470 |
1315 | t1->r_child.leaf = a_simple_expression; |
389ba50e |
1316 | a_simple_expression = lttv_simple_expression_new(); |
9ab5ebd7 |
1317 | subtree = g_ptr_array_remove_index(tree_stack,tree_stack->len-1); |
18d1226f |
1318 | } |
a4c292d4 |
1319 | break; |
1320 | |
1321 | /* |
1322 | * mathematic operators |
1323 | */ |
1324 | case '<': /* lower, lower or equal */ |
aa4600f3 |
1325 | |
1326 | g_ptr_array_add( a_field_path,(gpointer) a_field_component ); |
9ab5ebd7 |
1327 | lttv_simple_expression_assign_field(a_field_path,a_simple_expression); |
aa4600f3 |
1328 | a_field_component = g_string_new(""); |
5f185a2b |
1329 | if(filter->expression[i+1] == '=') { /* <= */ |
a4c292d4 |
1330 | i++; |
56e29124 |
1331 | lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_LE); |
1332 | } else lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_LT); |
aa4600f3 |
1333 | break; |
1334 | |
1335 | case '>': /* higher, higher or equal */ |
1336 | |
1337 | g_ptr_array_add( a_field_path,(gpointer) a_field_component ); |
9ab5ebd7 |
1338 | lttv_simple_expression_assign_field(a_field_path,a_simple_expression); |
f4e9dd16 |
1339 | a_field_component = g_string_new(""); |
5f185a2b |
1340 | if(filter->expression[i+1] == '=') { /* >= */ |
a4c292d4 |
1341 | i++; |
56e29124 |
1342 | lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_GE); |
1343 | } else lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_GT); |
aa4600f3 |
1344 | break; |
1345 | |
a4c292d4 |
1346 | case '=': /* equal */ |
aa4600f3 |
1347 | |
f4e9dd16 |
1348 | g_ptr_array_add( a_field_path,(gpointer) a_field_component ); |
9ab5ebd7 |
1349 | lttv_simple_expression_assign_field(a_field_path,a_simple_expression); |
f4e9dd16 |
1350 | a_field_component = g_string_new(""); |
56e29124 |
1351 | lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_EQ); |
a4c292d4 |
1352 | break; |
aa4600f3 |
1353 | |
0769c82f |
1354 | /* |
1355 | * Field concatening caracter |
1356 | */ |
1357 | case '.': /* dot */ |
aa4600f3 |
1358 | |
bb87caa7 |
1359 | /* |
1360 | * divide field expression into elements |
1361 | * in a_field_path array. |
4d9ff942 |
1362 | * |
1363 | * A dot can also be present in double values |
bb87caa7 |
1364 | */ |
8ff6243c |
1365 | if(a_simple_expression->field == LTTV_FILTER_UNDEFINED) { |
bb87caa7 |
1366 | g_ptr_array_add( a_field_path,(gpointer) a_field_component ); |
1367 | a_field_component = g_string_new(""); |
8ff6243c |
1368 | } |
1369 | break; |
4d9ff942 |
1370 | case ' ': /* ignore */ |
1371 | case '\n': /* ignore */ |
0769c82f |
1372 | break; |
a4c292d4 |
1373 | default: /* concatening current string */ |
73050a5f |
1374 | g_string_append_c(a_field_component,filter->expression[i]); |
a4c292d4 |
1375 | } |
1376 | } |
1601b365 |
1377 | |
0cdc2470 |
1378 | /* |
1379 | * Preliminary check to see |
1380 | * if tree was constructed correctly |
1381 | */ |
1382 | if( p_nesting>0 ) { |
1383 | g_warning("Wrong filtering options, the string\n\"%s\"\n\ |
5f185a2b |
1384 | is not valid due to parenthesis incorrect use",filter->expression); |
1385 | return FALSE; |
0cdc2470 |
1386 | } |
1387 | |
1388 | if(tree_stack->len != 1) /* only root tree should remain */ |
5f185a2b |
1389 | return FALSE; |
1601b365 |
1390 | |
410c83da |
1391 | /* processing last element of expression */ |
410c83da |
1392 | t1 = g_ptr_array_index(tree_stack,tree_stack->len-1); |
9ab5ebd7 |
1393 | while(t1->right != LTTV_TREE_IDLE) { |
1394 | g_assert(t1->right == LTTV_TREE_NODE); |
1395 | t1 = t1->r_child.t; |
1396 | } |
410c83da |
1397 | if(subtree != NULL) { /* add the subtree */ |
1398 | t1->right = LTTV_TREE_NODE; |
0cdc2470 |
1399 | t1->r_child.t = subtree; |
410c83da |
1400 | subtree = NULL; |
1401 | } else { /* add a leaf */ |
9ab5ebd7 |
1402 | lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE)); |
56e29124 |
1403 | a_field_component = NULL; |
410c83da |
1404 | t1->right = LTTV_TREE_LEAF; |
0cdc2470 |
1405 | t1->r_child.leaf = a_simple_expression; |
56e29124 |
1406 | a_simple_expression = NULL; |
410c83da |
1407 | } |
1408 | |
56e29124 |
1409 | |
73050a5f |
1410 | /* free the pointer array */ |
1411 | g_assert(a_field_path->len == 0); |
1412 | g_ptr_array_free(a_field_path,TRUE); |
56e29124 |
1413 | |
1414 | /* free the tree stack -- but keep the root tree */ |
f3020899 |
1415 | filter->head = g_ptr_array_remove_index(tree_stack,0); |
1416 | g_ptr_array_free(tree_stack,TRUE); |
1417 | |
56e29124 |
1418 | /* free the field buffer if allocated */ |
1419 | if(a_field_component != NULL) g_string_free(a_field_component,TRUE); |
1420 | |
1421 | /* free the simple expression buffer if allocated */ |
1422 | if(a_simple_expression != NULL) lttv_simple_expression_destroy(a_simple_expression); |
73050a5f |
1423 | |
f3020899 |
1424 | g_assert(filter->head != NULL); /* tree should exist */ |
56e29124 |
1425 | g_assert(subtree == NULL); /* remaining subtree should be included in main tree */ |
be66ef34 |
1426 | |
1427 | #ifdef TEST |
1428 | gettimeofday(&endtime, NULL); |
1429 | |
1430 | /* Calcul du temps de l'algorithme */ |
1431 | double time1 = starttime.tv_sec + (starttime.tv_usec/1000000.0); |
1432 | double time2 = endtime.tv_sec + (endtime.tv_usec/1000000.0); |
1433 | // g_print("Tree build took %.10f ms for strlen of %i\n",(time2-time1)*1000,strlen(filter->expression)); |
1434 | g_print("%.10f %i\n",(time2-time1)*1000,strlen(filter->expression)); |
1435 | #endif |
a4c292d4 |
1436 | |
56e29124 |
1437 | /* debug */ |
1438 | g_print("+++++++++++++++ BEGIN PRINT ++++++++++++++++\n"); |
1439 | lttv_print_tree(filter->head) ; |
1440 | g_print("+++++++++++++++ END PRINT ++++++++++++++++++\n"); |
1441 | |
1442 | /* success */ |
5f185a2b |
1443 | return TRUE; |
80f9611a |
1444 | |
31452f49 |
1445 | } |
1446 | |
8c89f5a8 |
1447 | /** |
56e29124 |
1448 | * @fn void lttv_filter_destroy(LttvFilter*) |
1449 | * |
8c89f5a8 |
1450 | * Destroy the current LttvFilter |
1451 | * @param filter pointer to the current LttvFilter |
1452 | */ |
1da1525d |
1453 | void |
2ea36caf |
1454 | lttv_filter_destroy(LttvFilter* filter) { |
5f185a2b |
1455 | |
1456 | g_free(filter->expression); |
1457 | lttv_filter_tree_destroy(filter->head); |
1458 | g_free(filter); |
1459 | |
1da1525d |
1460 | } |
1461 | |
150f0d33 |
1462 | /** |
8ff6243c |
1463 | * @fn LttvFilterTree* lttv_filter_tree_new() |
56e29124 |
1464 | * |
150f0d33 |
1465 | * Assign a new tree for the current expression |
1466 | * or sub expression |
1467 | * @return pointer of LttvFilterTree |
1468 | */ |
5f185a2b |
1469 | LttvFilterTree* |
1470 | lttv_filter_tree_new() { |
150f0d33 |
1471 | LttvFilterTree* tree; |
1472 | |
e00d6a24 |
1473 | tree = g_new(LttvFilterTree,1); |
150f0d33 |
1474 | tree->node = 0; //g_new(lttv_expression,1); |
150f0d33 |
1475 | tree->left = LTTV_TREE_IDLE; |
1476 | tree->right = LTTV_TREE_IDLE; |
f3020899 |
1477 | tree->r_child.t = NULL; |
1478 | tree->l_child.t = NULL; |
1479 | |
150f0d33 |
1480 | return tree; |
1481 | } |
1482 | |
80f9611a |
1483 | /** |
56e29124 |
1484 | * @fn void lttv_filter_append_expression(LttvFilter*,char*) |
1485 | * |
80f9611a |
1486 | * Append a new expression to the expression |
1487 | * defined in the current filter |
1488 | * @param filter pointer to the current LttvFilter |
1489 | * @param expression string that must be appended |
56e29124 |
1490 | * @return Success/Failure of operation |
80f9611a |
1491 | */ |
be66ef34 |
1492 | gboolean |
1493 | lttv_filter_append_expression(LttvFilter* filter, const char *expression) { |
80f9611a |
1494 | |
56e29124 |
1495 | if(expression == NULL) return FALSE; |
da2e1bfb |
1496 | if(filter == NULL) return FALSE; |
80f9611a |
1497 | |
da2e1bfb |
1498 | GString* s = g_string_new(""); |
1499 | if(filter->expression != NULL) { |
1500 | g_string_append(s,filter->expression); |
1501 | g_string_append_c(s,'&'); |
1502 | } |
1503 | g_string_append(s,expression); |
786c5c3b |
1504 | |
1505 | g_free(filter->expression); |
da2e1bfb |
1506 | filter->expression = g_string_free(s,FALSE); |
1507 | |
1508 | /* TRUE if construction of tree proceeded without errors */ |
56e29124 |
1509 | return lttv_filter_update(filter); |
80f9611a |
1510 | |
1511 | } |
1512 | |
1513 | /** |
56e29124 |
1514 | * @fn void lttv_filter_clear_expression(LttvFilter*) |
1515 | * |
80f9611a |
1516 | * Clear the filter expression from the |
1517 | * current filter and sets its pointer to NULL |
1518 | * @param filter pointer to the current LttvFilter |
1519 | */ |
be66ef34 |
1520 | void |
1521 | lttv_filter_clear_expression(LttvFilter* filter) { |
80f9611a |
1522 | |
1523 | if(filter->expression != NULL) { |
1524 | g_free(filter->expression); |
1525 | filter->expression = NULL; |
1526 | } |
1527 | |
1528 | } |
1529 | |
150f0d33 |
1530 | /** |
56e29124 |
1531 | * @fn void lttv_filter_tree_destroy(LttvFilterTree*) |
1532 | * |
150f0d33 |
1533 | * Destroys the tree and his sub-trees |
1534 | * @param tree Tree which must be destroyed |
1535 | */ |
5f185a2b |
1536 | void |
1537 | lttv_filter_tree_destroy(LttvFilterTree* tree) { |
56e29124 |
1538 | |
150f0d33 |
1539 | if(tree == NULL) return; |
1540 | |
56e29124 |
1541 | if(tree->left == LTTV_TREE_LEAF) lttv_simple_expression_destroy(tree->l_child.leaf); |
150f0d33 |
1542 | else if(tree->left == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->l_child.t); |
1543 | |
56e29124 |
1544 | if(tree->right == LTTV_TREE_LEAF) lttv_simple_expression_destroy(tree->r_child.leaf); |
150f0d33 |
1545 | else if(tree->right == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->r_child.t); |
1546 | |
e00d6a24 |
1547 | // g_free(tree->node); |
150f0d33 |
1548 | g_free(tree); |
1549 | } |
1550 | |
84a333d6 |
1551 | /** |
80f9611a |
1552 | * Global parsing function for the current |
1553 | * LttvFilterTree |
7e7af7f2 |
1554 | * @param t pointer to the current LttvFilterTree |
80f9611a |
1555 | * @param event current LttEvent, NULL if not used |
1556 | * @param tracefile current LttTracefile, NULL if not used |
1557 | * @param trace current LttTrace, NULL if not used |
1558 | * @param state current LttvProcessState, NULL if not used |
4d9ff942 |
1559 | * @param context current LttvTracefileContext, NULL if not used |
1560 | * @return response of filter |
84a333d6 |
1561 | */ |
31452f49 |
1562 | gboolean |
80f9611a |
1563 | lttv_filter_tree_parse( |
4d9ff942 |
1564 | const LttvFilterTree* t, |
1565 | const LttEvent* event, |
1566 | const LttTracefile* tracefile, |
1567 | const LttTrace* trace, |
1568 | const LttvProcessState* state, |
1569 | const LttvTracefileContext* context |
80f9611a |
1570 | /*,...*/) |
1571 | { |
0769c82f |
1572 | |
80f9611a |
1573 | /* |
1601b365 |
1574 | * Each tree is parsed in inorder. |
1575 | * This way, it's possible to apply the left filter of the |
1576 | * tree, then decide whether or not the right branch should |
1577 | * be parsed depending on the linking logical operator |
1578 | * |
80f9611a |
1579 | * Each node consists in a |
1580 | * 1. logical operator |
1581 | * 2. left child ( node or simple expression ) |
1582 | * 3. right child ( node or simple expression ) |
1583 | * |
1584 | * When the child is a simple expression, we must |
1585 | * before all determine if the expression refers to |
1586 | * a structure which is whithin observation ( not NULL ). |
1587 | * -If so, the expression is evaluated. |
1588 | * -If not, the result is set to TRUE since this particular |
1589 | * operation does not interfere with the lttv structure |
1590 | * |
1591 | * The result of each simple expression will directly |
1592 | * affect the next branch. This way, depending on |
1593 | * the linking logical operator, the parser will decide |
1594 | * to explore or not the next branch. |
1595 | * 1. AND OPERATOR |
1596 | * -If result of left branch is 0 / FALSE |
1597 | * then don't explore right branch and return 0; |
1598 | * -If result of left branch is 1 / TRUE then explore |
1599 | * 2. OR OPERATOR |
1600 | * -If result of left branch is 1 / TRUE |
1601 | * then don't explore right branch and return 1; |
1602 | * -If result of left branch is 0 / FALSE then explore |
1603 | * 3. XOR OPERATOR |
56e29124 |
1604 | * -Result of left branch will not affect exploration of |
80f9611a |
1605 | * right branch |
1601b365 |
1606 | */ |
73050a5f |
1607 | |
80f9611a |
1608 | gboolean lresult = FALSE, rresult = FALSE; |
0769c82f |
1609 | |
80f9611a |
1610 | /* |
1611 | * Parse left branch |
1612 | */ |
4d9ff942 |
1613 | if(t->left == LTTV_TREE_NODE) { |
1614 | lresult = lttv_filter_tree_parse(t->l_child.t,event,tracefile,trace,state,context); |
1615 | } |
5b729fcf |
1616 | else if(t->left == LTTV_TREE_LEAF) { |
4d9ff942 |
1617 | lresult = lttv_filter_tree_parse_branch(t->l_child.leaf,event,tracefile,trace,state,context); |
0cdc2470 |
1618 | } |
4d9ff942 |
1619 | |
80f9611a |
1620 | /* |
1621 | * Parse linking operator |
1622 | * make a cutoff if possible |
1623 | */ |
1624 | if((t->node & LTTV_LOGICAL_OR) && lresult == TRUE) return TRUE; |
1625 | if((t->node & LTTV_LOGICAL_AND) && lresult == FALSE) return FALSE; |
1626 | |
1627 | /* |
1628 | * Parse right branch |
1629 | */ |
4d9ff942 |
1630 | if(t->right == LTTV_TREE_NODE) { |
1631 | rresult = lttv_filter_tree_parse(t->r_child.t,event,tracefile,trace,state,context); |
1632 | } |
5b729fcf |
1633 | else if(t->right == LTTV_TREE_LEAF) { |
4d9ff942 |
1634 | rresult = lttv_filter_tree_parse_branch(t->r_child.leaf,event,tracefile,trace,state,context); |
1635 | } |
1636 | |
1637 | /* |
1638 | * Apply and return the |
1639 | * logical link between the |
1640 | * two operation |
1641 | */ |
1642 | switch(t->node) { |
1643 | case LTTV_LOGICAL_OR: return (lresult | rresult); |
1644 | case LTTV_LOGICAL_AND: return (lresult & rresult); |
1645 | case LTTV_LOGICAL_NOT: return (!rresult); |
1646 | case LTTV_LOGICAL_XOR: return (lresult ^ rresult); |
1647 | case 0: return (rresult); |
1648 | default: |
1649 | /* |
1650 | * This case should never be |
1651 | * parsed, if so, this subtree |
1652 | * is cancelled ! |
1653 | */ |
1654 | return TRUE; |
1655 | } |
1656 | |
1657 | } |
1658 | |
1659 | /** |
4d9ff942 |
1660 | * This function parses a particular branch of the tree |
7e7af7f2 |
1661 | * @param se pointer to the current LttvSimpleExpression |
4d9ff942 |
1662 | * @param event current LttEvent, NULL if not used |
1663 | * @param tracefile current LttTracefile, NULL if not used |
1664 | * @param trace current LttTrace, NULL if not used |
1665 | * @param state current LttvProcessState, NULL if not used |
1666 | * @param context current LttvTracefileContext, NULL if not used |
1667 | * @return response of filter |
1668 | */ |
be66ef34 |
1669 | gboolean |
1670 | lttv_filter_tree_parse_branch( |
4d9ff942 |
1671 | const LttvSimpleExpression* se, |
1672 | const LttEvent* event, |
1673 | const LttTracefile* tracefile, |
1674 | const LttTrace* trace, |
1675 | const LttvProcessState* state, |
1676 | const LttvTracefileContext* context) { |
1677 | |
9ab5ebd7 |
1678 | LttvFieldValue v; |
4d9ff942 |
1679 | v = se->value; |
1680 | switch(se->field) { |
80f9611a |
1681 | case LTTV_FILTER_TRACE_NAME: |
4d9ff942 |
1682 | if(trace == NULL) return TRUE; |
c6832b57 |
1683 | else { |
bbd9d557 |
1684 | char* trace_name = ltt_trace_name(trace); |
1685 | GQuark quark = g_quark_from_string(trace_name); |
c6832b57 |
1686 | return se->op((gpointer)&quark,v); |
1687 | } |
80f9611a |
1688 | break; |
1689 | case LTTV_FILTER_TRACEFILE_NAME: |
4d9ff942 |
1690 | if(tracefile == NULL) return TRUE; |
c6832b57 |
1691 | else { |
bbd9d557 |
1692 | char* tracefile_name = ltt_tracefile_name(tracefile); |
1693 | GQuark quark = g_quark_from_string(tracefile_name); |
c6832b57 |
1694 | return se->op((gpointer)&quark,v); |
1695 | } |
80f9611a |
1696 | break; |
1697 | case LTTV_FILTER_STATE_PID: |
4d9ff942 |
1698 | if(state == NULL) return TRUE; |
1699 | else return se->op((gpointer)&state->pid,v); |
80f9611a |
1700 | break; |
1701 | case LTTV_FILTER_STATE_PPID: |
4d9ff942 |
1702 | if(state == NULL) return TRUE; |
1703 | else return se->op((gpointer)&state->ppid,v); |
80f9611a |
1704 | break; |
1705 | case LTTV_FILTER_STATE_CT: |
4d9ff942 |
1706 | if(state == NULL) return TRUE; |
80f9611a |
1707 | else { |
4d9ff942 |
1708 | return se->op((gpointer)&state->creation_time,v); |
80f9611a |
1709 | } |
1710 | break; |
1711 | case LTTV_FILTER_STATE_IT: |
4d9ff942 |
1712 | if(state == NULL) return TRUE; |
80f9611a |
1713 | else { |
4d9ff942 |
1714 | return se->op((gpointer)&state->insertion_time,v); |
80f9611a |
1715 | } |
1716 | break; |
1717 | case LTTV_FILTER_STATE_P_NAME: |
1718 | /* |
4d9ff942 |
1719 | * All 'unnamed' for the moment |
80f9611a |
1720 | */ |
4d9ff942 |
1721 | if(state == NULL) return TRUE; |
46c40a93 |
1722 | else { |
bbd9d557 |
1723 | GQuark quark = state->name; |
c6832b57 |
1724 | return se->op((gpointer)&quark,v); |
46c40a93 |
1725 | } |
80f9611a |
1726 | break; |
1727 | case LTTV_FILTER_STATE_EX_MODE: |
4d9ff942 |
1728 | if(state == NULL) return TRUE; |
1729 | else return se->op((gpointer)&state->state->t,v); |
80f9611a |
1730 | break; |
1731 | case LTTV_FILTER_STATE_EX_SUBMODE: |
4d9ff942 |
1732 | if(state == NULL) return TRUE; |
1733 | else return se->op((gpointer)&state->state->n,v); |
80f9611a |
1734 | break; |
1735 | case LTTV_FILTER_STATE_P_STATUS: |
4d9ff942 |
1736 | if(state == NULL) return TRUE; |
1737 | else return se->op((gpointer)&state->state->s,v); |
80f9611a |
1738 | break; |
1739 | case LTTV_FILTER_STATE_CPU: |
4d9ff942 |
1740 | if(context == NULL) return TRUE; |
46c40a93 |
1741 | else { |
bbd9d557 |
1742 | /* FIXME: not sure of that one */ |
1743 | GQuark quark = ((LttvTracefileState*)context)->cpu_name; |
1744 | return se->op((gpointer)&quark,v); |
46c40a93 |
1745 | } |
80f9611a |
1746 | break; |
1747 | case LTTV_FILTER_EVENT_NAME: |
4d9ff942 |
1748 | if(event == NULL) return TRUE; |
1749 | else { |
46c40a93 |
1750 | LttEventType* et; |
1751 | et = ltt_event_eventtype(event); |
bbd9d557 |
1752 | char* event_name = ltt_eventtype_name(et); |
1753 | GQuark quark = g_quark_from_string(event_name); |
c6832b57 |
1754 | return se->op((gpointer)&quark,v); |
4d9ff942 |
1755 | } |
1756 | break; |
1757 | |
80f9611a |
1758 | case LTTV_FILTER_EVENT_CATEGORY: |
1759 | /* |
c6832b57 |
1760 | * TODO: Not yet implemented |
80f9611a |
1761 | */ |
4d9ff942 |
1762 | return TRUE; |
80f9611a |
1763 | break; |
1764 | case LTTV_FILTER_EVENT_TIME: |
4d9ff942 |
1765 | if(event == NULL) return TRUE; |
46c40a93 |
1766 | else { |
1767 | LttTime time = ltt_event_time(event); |
4d9ff942 |
1768 | return se->op((gpointer)&time,v); |
46c40a93 |
1769 | } |
80f9611a |
1770 | break; |
1771 | case LTTV_FILTER_EVENT_TSC: |
bbd9d557 |
1772 | if(event == NULL) return TRUE; |
1773 | else { |
1774 | LttCycleCount count = ltt_event_cycle_count(event); |
1775 | return se->op((gpointer)&count,v); |
1776 | } |
80f9611a |
1777 | break; |
1778 | case LTTV_FILTER_EVENT_FIELD: |
1779 | /* |
1780 | * TODO: Use the offset to |
1781 | * find the dynamic field |
1782 | * in the event struct |
1783 | */ |
4d9ff942 |
1784 | return TRUE; |
80f9611a |
1785 | default: |
1786 | /* |
1787 | * This case should never be |
4d9ff942 |
1788 | * parsed, if so, the whole |
1789 | * filtering is cancelled |
80f9611a |
1790 | */ |
1791 | g_warning("Error while parsing the filter tree"); |
1792 | return TRUE; |
1793 | } |
4d9ff942 |
1794 | |
1795 | /* should never get here */ |
1796 | return TRUE; |
1797 | |
80f9611a |
1798 | } |
0769c82f |
1799 | |
4d9ff942 |
1800 | |
1801 | |
80f9611a |
1802 | /** |
7e7af7f2 |
1803 | * Debug function. Prints tree memory allocation. |
56e29124 |
1804 | * @param t the pointer to the current LttvFilterTree |
80f9611a |
1805 | */ |
1806 | void |
4d9ff942 |
1807 | lttv_print_tree(const LttvFilterTree* t) { |
0769c82f |
1808 | |
73050a5f |
1809 | g_print("node:%p lchild:%p rchild:%p\n",t, //t->l_child.t,t->r_child.t); |
80f9611a |
1810 | (t->left==LTTV_TREE_NODE)?t->l_child.t:NULL, |
1811 | (t->right==LTTV_TREE_NODE)?t->r_child.t:NULL); |
1812 | g_print("node type: %i / [left] %i / [right] %i\n",t->node,t->left,t->right); |
1813 | if(t->left == LTTV_TREE_NODE) lttv_print_tree(t->l_child.t); |
1814 | else if(t->left == LTTV_TREE_LEAF) { |
9ab5ebd7 |
1815 | g_print("%p: left is %i %p value\n",t,t->l_child.leaf->field,t->l_child.leaf->op); |
0769c82f |
1816 | } |
80f9611a |
1817 | if(t->right == LTTV_TREE_NODE) lttv_print_tree(t->r_child.t); |
1818 | else if(t->right == LTTV_TREE_LEAF) { |
9ab5ebd7 |
1819 | g_print("%p: right is %i %p value\n",t,t->r_child.leaf->field,t->r_child.leaf->op); |
80f9611a |
1820 | } |
80f9611a |
1821 | |
1822 | } |
1823 | |
91ad3f0a |
1824 | /** |
56e29124 |
1825 | * @fn static void module_init() |
1826 | * |
91ad3f0a |
1827 | * Initializes the filter module and specific values |
1828 | */ |
1a7fa682 |
1829 | static void module_init() |
1830 | { |
91ad3f0a |
1831 | |
1a7fa682 |
1832 | } |
1833 | |
91ad3f0a |
1834 | /** |
7e7af7f2 |
1835 | * Destroys the filter module and specific values |
91ad3f0a |
1836 | */ |
1a7fa682 |
1837 | static void module_destroy() |
1838 | { |
56e29124 |
1839 | |
1a7fa682 |
1840 | } |
1841 | |
1842 | |
91ad3f0a |
1843 | LTTV_MODULE("filter", "Filters traceset and events", \ |
1844 | "Filters traceset and events specifically to user input", \ |
1a7fa682 |
1845 | module_init, module_destroy) |
1846 | |
1847 | |
1848 | |