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