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