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