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