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