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