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