filter fix style
[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;
571ef1ed 436 guint string_len;
9ab5ebd7 437
438 switch(se->field) {
439 /*
be66ef34 440 * Strings
441 * entered as strings, converted to Quarks
9ab5ebd7 442 */
443 case LTTV_FILTER_TRACE_NAME:
444 case LTTV_FILTER_TRACEFILE_NAME:
445 case LTTV_FILTER_STATE_P_NAME:
7b5f6cf1 446 case LTTV_FILTER_STATE_T_BRAND:
9ab5ebd7 447 case LTTV_FILTER_EVENT_NAME:
c7891f0b 448 case LTTV_FILTER_EVENT_FACILITY:
be66ef34 449 case LTTV_FILTER_STATE_EX_MODE:
450 case LTTV_FILTER_STATE_EX_SUBMODE:
451 case LTTV_FILTER_STATE_P_STATUS:
452 // se->value.v_string = value;
c56a714e 453 se->value.v_quark = g_quark_from_string(value);
c6832b57 454 g_free(value);
9ab5ebd7 455 break;
456 /*
be66ef34 457 * integer -- supposed to be uint64
9ab5ebd7 458 */
bbd9d557 459 case LTTV_FILTER_EVENT_TSC:
9ab5ebd7 460 se->value.v_uint64 = atoi(value);
461 g_free(value);
462 break;
6e0d58d6 463 /*
2ec11087 464 * unsigned integers
6e0d58d6 465 */
466 case LTTV_FILTER_STATE_PID:
467 case LTTV_FILTER_STATE_PPID:
468 case LTTV_FILTER_STATE_CPU:
2ec11087 469 se->value.v_uint = atoi(value);
6e0d58d6 470 g_free(value);
471 break;
9ab5ebd7 472 /*
7145a073 473 * LttTime
9ab5ebd7 474 */
475 case LTTV_FILTER_STATE_CT:
476 case LTTV_FILTER_STATE_IT:
477 case LTTV_FILTER_EVENT_TIME:
7145a073 478 //se->value.v_double = atof(value);
46c40a93 479 /*
480 * parsing logic could be optimised,
481 * but as for now, simpler this way
482 */
483 v = g_string_new("");
571ef1ed 484 string_len = strlen(value);
485 for(i=0;i<string_len;i++) {
46c40a93 486 if(value[i] == '.') {
487 /* cannot specify number with more than one '.' */
488 if(is_double) return FALSE;
489 else is_double = TRUE;
826f1ab2 490 t.tv_sec = atoi(v->str);
46c40a93 491 g_string_free(v,TRUE);
492 v = g_string_new("");
4ec0c904 493 } else v = g_string_append_c(v,value[i]);
46c40a93 494 }
495 /* number can be integer or double */
826f1ab2 496 if(is_double) t.tv_nsec = atoi(v->str);
571ef1ed 497 else {
498 t.tv_sec = atoi(v->str);
499 t.tv_nsec = 0;
500 }
c6832b57 501
46c40a93 502 g_string_free(v,TRUE);
503
504 se->value.v_ltttime = t;
571ef1ed 505 //g_error("Filter TEST ltttime : %u, %u.", t.tv_sec, t.tv_nsec);
9ab5ebd7 506 g_free(value);
507 break;
508 default:
509 g_warning("Error encountered in value assignation ! Field type = %i",se->field);
c6832b57 510 g_free(value);
9ab5ebd7 511 return FALSE;
512 }
513
514 return TRUE;
515
516}
517
31452f49 518/**
56e29124 519 * @fn void lttv_simple_expression_destroy(LttvSimpleExpression*)
520 *
9ab5ebd7 521 * Disallocate memory for the current
56e29124 522 * simple expression
523 * @param se pointer to the current LttvSimpleExpression
524 */
525void
526lttv_simple_expression_destroy(LttvSimpleExpression* se) {
527
9ab5ebd7 528 // g_free(se->value);
786c5c3b 529// switch(se->field) {
530// case LTTV_FILTER_TRACE_NAME:
531// case LTTV_FILTER_TRACEFILE_NAME:
532// case LTTV_FILTER_STATE_P_NAME:
533// case LTTV_FILTER_EVENT_NAME:
534// g_free(se->value.v_string);
535// break;
536// }
56e29124 537 g_free(se);
538
539}
540
541/**
542 * @fn gint lttv_struct_type(gint)
543 *
80f9611a 544 * Finds the structure type depending
545 * on the fields in parameters
546 * @params ft Field of the current structure
547 * @return LttvStructType enum or -1 for error
84a333d6 548 */
80f9611a 549gint
550lttv_struct_type(gint ft) {
5f185a2b 551
80f9611a 552 switch(ft) {
553 case LTTV_FILTER_TRACE_NAME:
554 return LTTV_FILTER_TRACE;
555 break;
556 case LTTV_FILTER_TRACEFILE_NAME:
557 return LTTV_FILTER_TRACEFILE;
558 break;
559 case LTTV_FILTER_STATE_PID:
560 case LTTV_FILTER_STATE_PPID:
561 case LTTV_FILTER_STATE_CT:
562 case LTTV_FILTER_STATE_IT:
563 case LTTV_FILTER_STATE_P_NAME:
571ef1ed 564 case LTTV_FILTER_STATE_T_BRAND:
80f9611a 565 case LTTV_FILTER_STATE_EX_MODE:
566 case LTTV_FILTER_STATE_EX_SUBMODE:
567 case LTTV_FILTER_STATE_P_STATUS:
568 case LTTV_FILTER_STATE_CPU:
569 return LTTV_FILTER_STATE;
570 break;
571 case LTTV_FILTER_EVENT_NAME:
ffd088ef 572 case LTTV_FILTER_EVENT_FACILITY:
80f9611a 573 case LTTV_FILTER_EVENT_CATEGORY:
574 case LTTV_FILTER_EVENT_TIME:
575 case LTTV_FILTER_EVENT_TSC:
576 case LTTV_FILTER_EVENT_FIELD:
577 return LTTV_FILTER_EVENT;
578 break;
579 default:
580 return -1;
581 }
84a333d6 582}
583
2ec11087 584/**
585 * @fn gboolean lttv_apply_op_eq_uint(gpointer,LttvFieldValue)
586 *
587 * Applies the 'equal' operator to the
588 * specified structure and value
589 * @param v1 left member of comparison
590 * @param v2 right member of comparison
591 * @return success/failure of operation
592 */
593gboolean lttv_apply_op_eq_uint(const gpointer v1, LttvFieldValue v2) {
594
595 guint* r = (guint*) v1;
596 return (*r == v2.v_uint);
597
598}
599
150f0d33 600/**
7e7af7f2 601 * @fn gboolean lttv_apply_op_eq_uint64(gpointer,LttvFieldValue)
56e29124 602 *
150f0d33 603 * Applies the 'equal' operator to the
47aa6e58 604 * specified structure and value
605 * @param v1 left member of comparison
606 * @param v2 right member of comparison
150f0d33 607 * @return success/failure of operation
608 */
4d9ff942 609gboolean lttv_apply_op_eq_uint64(const gpointer v1, LttvFieldValue v2) {
83aa92fc 610
611 guint64* r = (guint64*) v1;
9ab5ebd7 612 return (*r == v2.v_uint64);
83aa92fc 613
614}
150f0d33 615
5b729fcf 616/**
7e7af7f2 617 * @fn gboolean lttv_apply_op_eq_uint32(gpointer,LttvFieldValue)
56e29124 618 *
5b729fcf 619 * Applies the 'equal' operator to the
47aa6e58 620 * specified structure and value
621 * @param v1 left member of comparison
622 * @param v2 right member of comparison
5b729fcf 623 * @return success/failure of operation
624 */
4d9ff942 625gboolean lttv_apply_op_eq_uint32(const gpointer v1, LttvFieldValue v2) {
83aa92fc 626 guint32* r = (guint32*) v1;
9ab5ebd7 627 return (*r == v2.v_uint32);
83aa92fc 628}
5b729fcf 629
630/**
7e7af7f2 631 * @fn gboolean lttv_apply_op_eq_uint16(gpointer,LttvFieldValue)
56e29124 632 *
5b729fcf 633 * Applies the 'equal' operator to the
47aa6e58 634 * specified structure and value
635 * @param v1 left member of comparison
636 * @param v2 right member of comparison
5b729fcf 637 * @return success/failure of operation
638 */
4d9ff942 639gboolean lttv_apply_op_eq_uint16(const gpointer v1, LttvFieldValue v2) {
83aa92fc 640 guint16* r = (guint16*) v1;
9ab5ebd7 641 return (*r == v2.v_uint16);
83aa92fc 642}
5b729fcf 643
644/**
7e7af7f2 645 * @fn gboolean lttv_apply_op_eq_double(gpointer,LttvFieldValue)
56e29124 646 *
5b729fcf 647 * Applies the 'equal' operator to the
47aa6e58 648 * specified structure and value
649 * @param v1 left member of comparison
650 * @param v2 right member of comparison
5b729fcf 651 * @return success/failure of operation
652 */
4d9ff942 653gboolean lttv_apply_op_eq_double(const gpointer v1, LttvFieldValue v2) {
83aa92fc 654 double* r = (double*) v1;
9ab5ebd7 655 return (*r == v2.v_double);
83aa92fc 656}
5b729fcf 657
658/**
7e7af7f2 659 * @fn gboolean lttv_apply_op_eq_string(gpointer,LttvFieldValue)
56e29124 660 *
5b729fcf 661 * Applies the 'equal' operator to the
47aa6e58 662 * specified structure and value
663 * @param v1 left member of comparison
664 * @param v2 right member of comparison
5b729fcf 665 * @return success/failure of operation
666 */
4d9ff942 667gboolean lttv_apply_op_eq_string(const gpointer v1, LttvFieldValue v2) {
83aa92fc 668 char* r = (char*) v1;
9ab5ebd7 669 return (!g_strcasecmp(r,v2.v_string));
83aa92fc 670}
150f0d33 671
c6832b57 672/**
7e7af7f2 673 * @fn gboolean lttv_apply_op_eq_quark(gpointer,LttvFieldValue)
c6832b57 674 *
675 * Applies the 'equal' operator to the
676 * specified structure and value
677 * @param v1 left member of comparison
678 * @param v2 right member of comparison
679 * @return success/failure of operation
680 */
681gboolean lttv_apply_op_eq_quark(const gpointer v1, LttvFieldValue v2) {
682 GQuark* r = (GQuark*) v1;
c56a714e 683 return (*r == v2.v_quark);
c6832b57 684}
685
7145a073 686/**
7e7af7f2 687 * @fn gboolean lttv_apply_op_eq_ltttime(gpointer,LttvFieldValue)
7145a073 688 *
689 * Applies the 'equal' operator to the
690 * specified structure and value
691 * @param v1 left member of comparison
692 * @param v2 right member of comparison
693 * @return success/failure of operation
694 */
4d9ff942 695gboolean lttv_apply_op_eq_ltttime(const gpointer v1, LttvFieldValue v2) {
7145a073 696 LttTime* r = (LttTime*) v1;
c6832b57 697 return ltt_time_compare(*r, v2.v_ltttime)==0?1:0;
7145a073 698}
699
2ec11087 700/**
701 * @fn gboolean lttv_apply_op_ne_uint(gpointer,LttvFieldValue)
702 *
703 * Applies the 'not equal' operator to the
704 * specified structure and value
705 * @param v1 left member of comparison
706 * @param v2 right member of comparison
707 * @return success/failure of operation
708 */
709gboolean lttv_apply_op_ne_uint(const gpointer v1, LttvFieldValue v2) {
710 guint* r = (guint*) v1;
711 return (*r != v2.v_uint);
712}
7145a073 713
150f0d33 714/**
7e7af7f2 715 * @fn gboolean lttv_apply_op_ne_uint64(gpointer,LttvFieldValue)
56e29124 716 *
150f0d33 717 * Applies the 'not equal' operator to the
47aa6e58 718 * specified structure and value
719 * @param v1 left member of comparison
720 * @param v2 right member of comparison
150f0d33 721 * @return success/failure of operation
722 */
4d9ff942 723gboolean lttv_apply_op_ne_uint64(const gpointer v1, LttvFieldValue v2) {
83aa92fc 724 guint64* r = (guint64*) v1;
9ab5ebd7 725 return (*r != v2.v_uint64);
83aa92fc 726}
150f0d33 727
5b729fcf 728/**
7e7af7f2 729 * @fn gboolean lttv_apply_op_ne_uint32(gpointer,LttvFieldValue)
56e29124 730 *
5b729fcf 731 * Applies the 'not equal' operator to the
47aa6e58 732 * specified structure and value
733 * @param v1 left member of comparison
734 * @param v2 right member of comparison
5b729fcf 735 * @return success/failure of operation
736 */
4d9ff942 737gboolean lttv_apply_op_ne_uint32(const gpointer v1, LttvFieldValue v2) {
83aa92fc 738 guint32* r = (guint32*) v1;
9ab5ebd7 739 return (*r != v2.v_uint32);
83aa92fc 740}
5b729fcf 741
742/**
7e7af7f2 743 * @fn gboolean lttv_apply_op_ne_uint16(gpointer,LttvFieldValue)
56e29124 744 *
5b729fcf 745 * Applies the 'not equal' operator to the
47aa6e58 746 * specified structure and value
747 * @param v1 left member of comparison
748 * @param v2 right member of comparison
5b729fcf 749 * @return success/failure of operation
750 */
4d9ff942 751gboolean lttv_apply_op_ne_uint16(const gpointer v1, LttvFieldValue v2) {
83aa92fc 752 guint16* r = (guint16*) v1;
9ab5ebd7 753 return (*r != v2.v_uint16);
83aa92fc 754}
5b729fcf 755
756/**
7e7af7f2 757 * @fn gboolean lttv_apply_op_ne_double(gpointer,LttvFieldValue)
56e29124 758 *
5b729fcf 759 * Applies the 'not equal' operator to the
47aa6e58 760 * specified structure and value
761 * @param v1 left member of comparison
762 * @param v2 right member of comparison
5b729fcf 763 * @return success/failure of operation
764 */
4d9ff942 765gboolean lttv_apply_op_ne_double(const gpointer v1, LttvFieldValue v2) {
83aa92fc 766 double* r = (double*) v1;
9ab5ebd7 767 return (*r != v2.v_double);
83aa92fc 768}
5b729fcf 769
770/**
7e7af7f2 771 * @fn gboolean lttv_apply_op_ne_string(gpointer,LttvFieldValue)
56e29124 772 *
5b729fcf 773 * Applies the 'not equal' operator to the
47aa6e58 774 * specified structure and value
775 * @param v1 left member of comparison
776 * @param v2 right member of comparison
5b729fcf 777 * @return success/failure of operation
778 */
4d9ff942 779gboolean lttv_apply_op_ne_string(const gpointer v1, LttvFieldValue v2) {
83aa92fc 780 char* r = (char*) v1;
9ab5ebd7 781 return (g_strcasecmp(r,v2.v_string));
83aa92fc 782}
150f0d33 783
c6832b57 784/**
7e7af7f2 785 * @fn gboolean lttv_apply_op_ne_quark(gpointer,LttvFieldValue)
c6832b57 786 *
787 * Applies the 'not equal' operator to the
788 * specified structure and value
789 * @param v1 left member of comparison
790 * @param v2 right member of comparison
791 * @return success/failure of operation
792 */
793gboolean lttv_apply_op_ne_quark(const gpointer v1, LttvFieldValue v2) {
794 GQuark* r = (GQuark*) v1;
c56a714e 795 return (*r != v2.v_quark);
c6832b57 796}
797
798
7145a073 799/**
7e7af7f2 800 * @fn gboolean lttv_apply_op_ne_ltttime(gpointer,LttvFieldValue)
7145a073 801 *
802 * Applies the 'not equal' operator to the
803 * specified structure and value
804 * @param v1 left member of comparison
805 * @param v2 right member of comparison
806 * @return success/failure of operation
807 */
4d9ff942 808gboolean lttv_apply_op_ne_ltttime(const gpointer v1, LttvFieldValue v2) {
7145a073 809 LttTime* r = (LttTime*) v1;
46c40a93 810 return ltt_time_compare(*r, v2.v_ltttime)!=0?1:0;
7145a073 811}
812
2ec11087 813/**
814 * @fn gboolean lttv_apply_op_lt_uint(gpointer,LttvFieldValue)
815 *
816 * Applies the 'lower than' operator to the
817 * specified structure and value
818 * @param v1 left member of comparison
819 * @param v2 right member of comparison
820 * @return success/failure of operation
821 */
822gboolean lttv_apply_op_lt_uint(const gpointer v1, LttvFieldValue v2) {
823 guint* r = (guint*) v1;
824 return (*r < v2.v_uint);
825}
7145a073 826
150f0d33 827/**
7e7af7f2 828 * @fn gboolean lttv_apply_op_lt_uint64(gpointer,LttvFieldValue)
56e29124 829 *
150f0d33 830 * Applies the 'lower than' operator to the
47aa6e58 831 * specified structure and value
832 * @param v1 left member of comparison
833 * @param v2 right member of comparison
150f0d33 834 * @return success/failure of operation
835 */
4d9ff942 836gboolean lttv_apply_op_lt_uint64(const gpointer v1, LttvFieldValue v2) {
83aa92fc 837 guint64* r = (guint64*) v1;
9ab5ebd7 838 return (*r < v2.v_uint64);
83aa92fc 839}
150f0d33 840
5b729fcf 841/**
7e7af7f2 842 * @fn gboolean lttv_apply_op_lt_uint32(gpointer,LttvFieldValue)
56e29124 843 *
5b729fcf 844 * Applies the 'lower than' operator to the
47aa6e58 845 * specified structure and value
846 * @param v1 left member of comparison
847 * @param v2 right member of comparison
5b729fcf 848 * @return success/failure of operation
849 */
4d9ff942 850gboolean lttv_apply_op_lt_uint32(const gpointer v1, LttvFieldValue v2) {
83aa92fc 851 guint32* r = (guint32*) v1;
9ab5ebd7 852 return (*r < v2.v_uint32);
83aa92fc 853}
5b729fcf 854
855/**
7e7af7f2 856 * @fn gboolean lttv_apply_op_lt_uint16(gpointer,LttvFieldValue)
56e29124 857 *
5b729fcf 858 * Applies the 'lower than' operator to the
47aa6e58 859 * specified structure and value
860 * @param v1 left member of comparison
861 * @param v2 right member of comparison
5b729fcf 862 * @return success/failure of operation
863 */
4d9ff942 864gboolean lttv_apply_op_lt_uint16(const gpointer v1, LttvFieldValue v2) {
83aa92fc 865 guint16* r = (guint16*) v1;
9ab5ebd7 866 return (*r < v2.v_uint16);
83aa92fc 867}
5b729fcf 868
869/**
7e7af7f2 870 * @fn gboolean lttv_apply_op_lt_double(gpointer,LttvFieldValue)
56e29124 871 *
5b729fcf 872 * Applies the 'lower than' operator to the
47aa6e58 873 * specified structure and value
874 * @param v1 left member of comparison
875 * @param v2 right member of comparison
5b729fcf 876 * @return success/failure of operation
877 */
4d9ff942 878gboolean lttv_apply_op_lt_double(const gpointer v1, LttvFieldValue v2) {
83aa92fc 879 double* r = (double*) v1;
9ab5ebd7 880 return (*r < v2.v_double);
83aa92fc 881}
5b729fcf 882
7145a073 883/**
7e7af7f2 884 * @fn gboolean lttv_apply_op_lt_ltttime(gpointer,LttvFieldValue)
7145a073 885 *
886 * Applies the 'lower than' operator to the
887 * specified structure and value
888 * @param v1 left member of comparison
889 * @param v2 right member of comparison
890 * @return success/failure of operation
891 */
4d9ff942 892gboolean lttv_apply_op_lt_ltttime(const gpointer v1, LttvFieldValue v2) {
7145a073 893 LttTime* r = (LttTime*) v1;
c6832b57 894// 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)));
895 return ltt_time_compare(*r, v2.v_ltttime)==-1?1:0;
7145a073 896}
897
2ec11087 898/**
899 * @fn gboolean lttv_apply_op_le_uint(gpointer,LttvFieldValue)
900 *
901 * Applies the 'lower or equal' operator to the
902 * specified structure and value
903 * @param v1 left member of comparison
904 * @param v2 right member of comparison
905 * @return success/failure of operation
906 */
907gboolean lttv_apply_op_le_uint(const gpointer v1, LttvFieldValue v2) {
908 guint* r = (guint*) v1;
909 return (*r <= v2.v_uint);
910}
7145a073 911
5b729fcf 912/**
7e7af7f2 913 * @fn gboolean lttv_apply_op_le_uint64(gpointer,LttvFieldValue)
56e29124 914 *
915 * Applies the 'lower or equal' operator to the
47aa6e58 916 * specified structure and value
917 * @param v1 left member of comparison
918 * @param v2 right member of comparison
5b729fcf 919 * @return success/failure of operation
920 */
4d9ff942 921gboolean lttv_apply_op_le_uint64(const gpointer v1, LttvFieldValue v2) {
83aa92fc 922 guint64* r = (guint64*) v1;
9ab5ebd7 923 return (*r <= v2.v_uint64);
83aa92fc 924}
150f0d33 925
926/**
7e7af7f2 927 * @fn gboolean lttv_apply_op_le_uint32(gpointer,LttvFieldValue)
56e29124 928 *
150f0d33 929 * Applies the 'lower or equal' operator to the
47aa6e58 930 * specified structure and value
931 * @param v1 left member of comparison
932 * @param v2 right member of comparison
150f0d33 933 * @return success/failure of operation
934 */
4d9ff942 935gboolean lttv_apply_op_le_uint32(const gpointer v1, LttvFieldValue v2) {
83aa92fc 936 guint32* r = (guint32*) v1;
9ab5ebd7 937 return (*r <= v2.v_uint32);
83aa92fc 938}
150f0d33 939
5b729fcf 940/**
7e7af7f2 941 * @fn gboolean lttv_apply_op_le_uint16(gpointer,LttvFieldValue)
56e29124 942 *
5b729fcf 943 * Applies the 'lower or equal' operator to the
47aa6e58 944 * specified structure and value
945 * @param v1 left member of comparison
946 * @param v2 right member of comparison
5b729fcf 947 * @return success/failure of operation
948 */
4d9ff942 949gboolean lttv_apply_op_le_uint16(const gpointer v1, LttvFieldValue v2) {
83aa92fc 950 guint16* r = (guint16*) v1;
9ab5ebd7 951 return (*r <= v2.v_uint16);
83aa92fc 952}
5b729fcf 953
954/**
7e7af7f2 955 * @fn gboolean lttv_apply_op_le_double(gpointer,LttvFieldValue)
56e29124 956 *
5b729fcf 957 * Applies the 'lower or equal' operator to the
47aa6e58 958 * specified structure and value
959 * @param v1 left member of comparison
960 * @param v2 right member of comparison
5b729fcf 961 * @return success/failure of operation
962 */
4d9ff942 963gboolean lttv_apply_op_le_double(const gpointer v1, LttvFieldValue v2) {
83aa92fc 964 double* r = (double*) v1;
9ab5ebd7 965 return (*r <= v2.v_double);
83aa92fc 966}
5b729fcf 967
7145a073 968/**
7e7af7f2 969 * @fn gboolean lttv_apply_op_le_ltttime(gpointer,LttvFieldValue)
7145a073 970 *
971 * Applies the 'lower or equal' operator to the
972 * specified structure and value
973 * @param v1 left member of comparison
974 * @param v2 right member of comparison
975 * @return success/failure of operation
976 */
4d9ff942 977gboolean lttv_apply_op_le_ltttime(const gpointer v1, LttvFieldValue v2) {
7145a073 978 LttTime* r = (LttTime*) v1;
c6832b57 979// 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)));
980 return ltt_time_compare(*r, v2.v_ltttime)<1?1:0;
7145a073 981}
982
983
2ec11087 984/**
985 * @fn gboolean lttv_apply_op_gt_uint(gpointer,LttvFieldValue)
986 *
987 * Applies the 'greater than' operator to the
988 * specified structure and value
989 * @param v1 left member of comparison
990 * @param v2 right member of comparison
991 * @return success/failure of operation
992 */
993gboolean lttv_apply_op_gt_uint(const gpointer v1, LttvFieldValue v2) {
994 guint* r = (guint*) v1;
995 return (*r > v2.v_uint);
996}
997
5b729fcf 998/**
7e7af7f2 999 * @fn gboolean lttv_apply_op_gt_uint64(gpointer,LttvFieldValue)
56e29124 1000 *
83aa92fc 1001 * Applies the 'greater than' operator to the
47aa6e58 1002 * specified structure and value
1003 * @param v1 left member of comparison
1004 * @param v2 right member of comparison
5b729fcf 1005 * @return success/failure of operation
1006 */
4d9ff942 1007gboolean lttv_apply_op_gt_uint64(const gpointer v1, LttvFieldValue v2) {
83aa92fc 1008 guint64* r = (guint64*) v1;
9ab5ebd7 1009 return (*r > v2.v_uint64);
83aa92fc 1010}
150f0d33 1011
1012/**
7e7af7f2 1013 * @fn gboolean lttv_apply_op_gt_uint32(gpointer,LttvFieldValue)
56e29124 1014 *
150f0d33 1015 * Applies the 'greater than' operator to the
47aa6e58 1016 * specified structure and value
1017 * @param v1 left member of comparison
1018 * @param v2 right member of comparison
150f0d33 1019 * @return success/failure of operation
1020 */
4d9ff942 1021gboolean lttv_apply_op_gt_uint32(const gpointer v1, LttvFieldValue v2) {
83aa92fc 1022 guint32* r = (guint32*) v1;
9ab5ebd7 1023 return (*r > v2.v_uint32);
83aa92fc 1024}
150f0d33 1025
5b729fcf 1026/**
7e7af7f2 1027 * @fn gboolean lttv_apply_op_gt_uint16(gpointer,LttvFieldValue)
56e29124 1028 *
5b729fcf 1029 * Applies the 'greater than' operator to the
47aa6e58 1030 * specified structure and value
1031 * @param v1 left member of comparison
1032 * @param v2 right member of comparison
5b729fcf 1033 * @return success/failure of operation
1034 */
4d9ff942 1035gboolean lttv_apply_op_gt_uint16(const gpointer v1, LttvFieldValue v2) {
83aa92fc 1036 guint16* r = (guint16*) v1;
9ab5ebd7 1037 return (*r > v2.v_uint16);
83aa92fc 1038}
5b729fcf 1039
1040/**
7e7af7f2 1041 * @fn gboolean lttv_apply_op_gt_double(gpointer,LttvFieldValue)
56e29124 1042 *
5b729fcf 1043 * Applies the 'greater than' operator to the
47aa6e58 1044 * specified structure and value
1045 * @param v1 left member of comparison
1046 * @param v2 right member of comparison
5b729fcf 1047 * @return success/failure of operation
1048 */
4d9ff942 1049gboolean lttv_apply_op_gt_double(const gpointer v1, LttvFieldValue v2) {
83aa92fc 1050 double* r = (double*) v1;
9ab5ebd7 1051 return (*r > v2.v_double);
83aa92fc 1052}
5b729fcf 1053
7145a073 1054/**
7e7af7f2 1055 * @fn gboolean lttv_apply_op_gt_ltttime(gpointer,LttvFieldValue)
7145a073 1056 *
1057 * Applies the 'greater than' operator to the
1058 * specified structure and value
1059 * @param v1 left member of comparison
1060 * @param v2 right member of comparison
1061 * @return success/failure of operation
1062 */
4d9ff942 1063gboolean lttv_apply_op_gt_ltttime(const gpointer v1, LttvFieldValue v2) {
7145a073 1064 LttTime* r = (LttTime*) v1;
c6832b57 1065// 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)));
1066 return ltt_time_compare(*r, v2.v_ltttime)==1?1:0;
7145a073 1067}
1068
2ec11087 1069/**
1070 * @fn gboolean lttv_apply_op_ge_uint(gpointer,LttvFieldValue)
1071 *
1072 * Applies the 'greater or equal' operator to the
1073 * specified structure and value
1074 * @param v1 left member of comparison
1075 * @param v2 right member of comparison
1076 * @return success/failure of operation
1077 */
1078gboolean lttv_apply_op_ge_uint(const gpointer v1, LttvFieldValue v2) {
1079 guint* r = (guint*) v1;
1080 return (*r >= v2.v_uint);
1081}
7145a073 1082
5b729fcf 1083/**
7e7af7f2 1084 * @fn gboolean lttv_apply_op_ge_uint64(gpointer,LttvFieldValue)
56e29124 1085 *
83aa92fc 1086 * Applies the 'greater or equal' operator to the
47aa6e58 1087 * specified structure and value
1088 * @param v1 left member of comparison
1089 * @param v2 right member of comparison
5b729fcf 1090 * @return success/failure of operation
1091 */
4d9ff942 1092gboolean lttv_apply_op_ge_uint64(const gpointer v1, LttvFieldValue v2) {
83aa92fc 1093 guint64* r = (guint64*) v1;
9ab5ebd7 1094 return (*r >= v2.v_uint64);
83aa92fc 1095}
150f0d33 1096
1097/**
7e7af7f2 1098 * @fn gboolean lttv_apply_op_ge_uint32(gpointer,LttvFieldValue)
56e29124 1099 *
150f0d33 1100 * Applies the 'greater or equal' operator to the
47aa6e58 1101 * specified structure and value
1102 * @param v1 left member of comparison
1103 * @param v2 right member of comparison
150f0d33 1104 * @return success/failure of operation
1105 */
4d9ff942 1106gboolean lttv_apply_op_ge_uint32(const gpointer v1, LttvFieldValue v2) {
83aa92fc 1107 guint32* r = (guint32*) v1;
9ab5ebd7 1108 return (*r >= v2.v_uint32);
83aa92fc 1109}
150f0d33 1110
5b729fcf 1111/**
7e7af7f2 1112 * @fn gboolean lttv_apply_op_ge_uint16(gpointer,LttvFieldValue)
56e29124 1113 *
5b729fcf 1114 * Applies the 'greater or equal' operator to the
47aa6e58 1115 * specified structure and value
1116 * @param v1 left member of comparison
1117 * @param v2 right member of comparison
5b729fcf 1118 * @return success/failure of operation
1119 */
4d9ff942 1120gboolean lttv_apply_op_ge_uint16(const gpointer v1, LttvFieldValue v2) {
83aa92fc 1121 guint16* r = (guint16*) v1;
9ab5ebd7 1122 return (*r >= v2.v_uint16);
83aa92fc 1123}
150f0d33 1124
5b729fcf 1125/**
7e7af7f2 1126 * @fn gboolean lttv_apply_op_ge_double(gpointer,LttvFieldValue)
56e29124 1127 *
5b729fcf 1128 * Applies the 'greater or equal' operator to the
47aa6e58 1129 * specified structure and value
1130 * @param v1 left member of comparison
1131 * @param v2 right member of comparison
5b729fcf 1132 * @return success/failure of operation
1133 */
4d9ff942 1134gboolean lttv_apply_op_ge_double(const gpointer v1, LttvFieldValue v2) {
83aa92fc 1135 double* r = (double*) v1;
9ab5ebd7 1136 return (*r >= v2.v_double);
83aa92fc 1137}
150f0d33 1138
7145a073 1139/**
7e7af7f2 1140 * @fn gboolean lttv_apply_op_ge_ltttime(gpointer,LttvFieldValue)
7145a073 1141 *
1142 * Applies the 'greater or equal' operator to the
1143 * specified structure and value
1144 * @param v1 left member of comparison
1145 * @param v2 right member of comparison
1146 * @return success/failure of operation
1147 */
4d9ff942 1148gboolean lttv_apply_op_ge_ltttime(const gpointer v1, LttvFieldValue v2) {
7145a073 1149 LttTime* r = (LttTime*) v1;
c6832b57 1150// 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)));
1151 return ltt_time_compare(*r, v2.v_ltttime)>-1?1:0;
7145a073 1152}
1153
1154
150f0d33 1155
1156/**
56e29124 1157 * Makes a copy of the current filter tree
1158 * @param tree pointer to the current tree
1159 * @return new copy of the filter tree
150f0d33 1160 */
1161LttvFilterTree*
4d9ff942 1162lttv_filter_tree_clone(const LttvFilterTree* tree) {
150f0d33 1163
8c89f5a8 1164 LttvFilterTree* newtree = lttv_filter_tree_new();
150f0d33 1165
8c89f5a8 1166 newtree->node = tree->node;
1167
1168 newtree->left = tree->left;
1169 if(newtree->left == LTTV_TREE_NODE) {
1170 newtree->l_child.t = lttv_filter_tree_clone(tree->l_child.t);
1171 } else if(newtree->left == LTTV_TREE_LEAF) {
1172 newtree->l_child.leaf = lttv_simple_expression_new();
1173 newtree->l_child.leaf->field = tree->l_child.leaf->field;
1174 newtree->l_child.leaf->offset = tree->l_child.leaf->offset;
1175 newtree->l_child.leaf->op = tree->l_child.leaf->op;
9ab5ebd7 1176 /* FIXME: special case for string copy ! */
1177 newtree->l_child.leaf->value = tree->l_child.leaf->value;
8c89f5a8 1178 }
1179
1180 newtree->right = tree->right;
1181 if(newtree->right == LTTV_TREE_NODE) {
1182 newtree->r_child.t = lttv_filter_tree_clone(tree->r_child.t);
1183 } else if(newtree->right == LTTV_TREE_LEAF) {
1184 newtree->r_child.leaf = lttv_simple_expression_new();
1185 newtree->r_child.leaf->field = tree->r_child.leaf->field;
1186 newtree->r_child.leaf->offset = tree->r_child.leaf->offset;
1187 newtree->r_child.leaf->op = tree->r_child.leaf->op;
9ab5ebd7 1188 newtree->r_child.leaf->value = tree->r_child.leaf->value;
8c89f5a8 1189 }
1190
1191 return newtree;
1192
150f0d33 1193}
1194
1195/**
56e29124 1196 * Makes a copy of the current filter
1197 * @param filter pointer to the current filter
1198 * @return new copy of the filter
150f0d33 1199 */
1200LttvFilter*
4d9ff942 1201lttv_filter_clone(const LttvFilter* filter) {
ebcead4a 1202
571ef1ed 1203 if(!filter) return NULL;
ebcead4a 1204
150f0d33 1205 LttvFilter* newfilter = g_new(LttvFilter,1);
1206
150f0d33 1207 strcpy(newfilter->expression,filter->expression);
1208
1209 newfilter->head = lttv_filter_tree_clone(filter->head);
1210
1211 return newfilter;
1212
1213}
1214
1215
84a333d6 1216/**
56e29124 1217 * @fn LttvFilter* lttv_filter_new()
1218 *
571ef1ed 1219 * Creates a new LttvFilter
1220 * @return the current LttvFilter or NULL if error
31452f49 1221 */
2ea36caf 1222LttvFilter*
5f185a2b 1223lttv_filter_new() {
a4c292d4 1224
5f185a2b 1225 LttvFilter* filter = g_new(LttvFilter,1);
1226 filter->expression = NULL;
1227 filter->head = NULL;
7e7af7f2 1228
1229 return filter;
5f185a2b 1230
1231}
a4c292d4 1232
8c89f5a8 1233/**
56e29124 1234 * @fn gboolean lttv_filter_update(LttvFilter*)
1235 *
8c89f5a8 1236 * Updates the current LttvFilter by building
1237 * its tree based upon the expression string
1238 * @param filter pointer to the current LttvFilter
1239 * @return Failure/Success of operation
1240 */
5f185a2b 1241gboolean
1242lttv_filter_update(LttvFilter* filter) {
1243
571ef1ed 1244// g_print("filter::lttv_filter_new()\n"); /* debug */
5f185a2b 1245
1246 if(filter->expression == NULL) return FALSE;
1247
571ef1ed 1248 int
a4c292d4 1249 i,
571ef1ed 1250 p_nesting=0, /* parenthesis nesting value */
72911c5d 1251 not=0;
571ef1ed 1252 guint expression_len;
72911c5d 1253
1601b365 1254 /* trees */
5b729fcf 1255 LttvFilterTree
1601b365 1256 *tree = lttv_filter_tree_new(), /* main tree */
1257 *subtree = NULL, /* buffer for subtrees */
1258 *t1, /* buffer #1 */
72911c5d 1259 *t2, /* buffer #2 */
1260 *t3; /* buffer #3 */
1601b365 1261
5f185a2b 1262 /*
1263 * the filter
1264 * If the tree already exists,
1265 * destroy it and build a new one
1266 */
1267 if(filter->head != NULL) lttv_filter_tree_destroy(filter->head);
f3020899 1268 filter->head = NULL; /* will be assigned at the end */
5f185a2b 1269
1601b365 1270 /*
1271 * Tree Stack
f4e9dd16 1272 * each element of the list
1273 * is a sub tree created
1274 * by the use of parenthesis in the
1275 * global expression. The final tree
1601b365 1276 * will be the one left at the root of
f4e9dd16 1277 * the list
1278 */
18d1226f 1279 GPtrArray *tree_stack = g_ptr_array_new();
1280 g_ptr_array_add( tree_stack,(gpointer) tree );
f4e9dd16 1281
a4c292d4 1282 /* temporary values */
0769c82f 1283 GString *a_field_component = g_string_new("");
ef2b07c1 1284 GString *a_string_spaces = g_string_new("");
56e29124 1285 GPtrArray *a_field_path = g_ptr_array_new();
1286
1287 /* simple expression buffer */
389ba50e 1288 LttvSimpleExpression* a_simple_expression = lttv_simple_expression_new();
d564d2ad 1289
1290 gint nest_quotes = 0;
0769c82f 1291
a4c292d4 1292 /*
571ef1ed 1293 * Parse entire expression and construct
1294 * the binary tree. There are two steps
1295 * in browsing that string
1296 * 1. finding boolean ops " &,|,^,! " and parenthesis " {,(,[,],),} "
1297 * 2. finding simple expressions
1298 * - field path ( separated by dots )
1299 * - op ( >, <, =, >=, <=, !=)
1300 * - value ( integer, string ... )
1301 * To spare computing time, the whole
1302 * string is parsed in this loop for a
1303 * O(n) complexity order.
1601b365 1304 *
18d1226f 1305 * When encountering logical op &,|,^
1306 * 1. parse the last value if any
1307 * 2. create a new tree
1308 * 3. add the expression (simple exp, or exp (subtree)) to the tree
1309 * 4. concatenate this tree with the current tree on top of the stack
1310 * When encountering math ops >,>=,<,<=,=,!=
1311 * 1. add to op to the simple expression
1312 * 2. concatenate last field component to field path
1313 * When encountering concatening ops .
1314 * 1. concatenate last field component to field path
1315 * When encountering opening parenthesis (,{,[
1316 * 1. create a new subtree on top of tree stack
1317 * When encountering closing parenthesis ),},]
1318 * 1. add the expression on right child of the current tree
1319 * 2. the subtree is completed, allocate a new subtree
1320 * 3. pop the tree value from the tree stack
1321 */
be66ef34 1322
1323#ifdef TEST
1324 struct timeval starttime;
1325 struct timeval endtime;
1326 gettimeofday(&starttime, NULL);
1327#endif
18d1226f 1328
571ef1ed 1329 expression_len = strlen(filter->expression);
1330 for(i=0;i<expression_len;i++) {
5f185a2b 1331 // debug
72911c5d 1332// g_print("%c\n ",filter->expression[i]);
d564d2ad 1333 if(nest_quotes) {
1334 switch(filter->expression[i]) {
571ef1ed 1335 case '\\' :
1336 if(filter->expression[i+1] == '\"') {
1337 i++;
1338 }
1339 break;
d564d2ad 1340 case '\"':
571ef1ed 1341 nest_quotes = 0;
1342 i++;
1343 break;
d564d2ad 1344 }
1345 if(a_string_spaces->len != 0) {
1346 a_field_component = g_string_append(
1347 a_field_component, a_string_spaces->str);
1348 a_string_spaces = g_string_set_size(a_string_spaces, 0);
1349 }
1350 a_field_component = g_string_append_c(a_field_component,
1351 filter->expression[i]);
1352 continue;
1353 }
1354
5f185a2b 1355 switch(filter->expression[i]) {
a4c292d4 1356 /*
1357 * logical operators
1358 */
1359 case '&': /* and */
72911c5d 1360
1361 /* get current tree in tree stack */
5b729fcf 1362 t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1);
72911c5d 1363
1364 /* get current node at absolute right */
9ab5ebd7 1365 while(t1->right != LTTV_TREE_IDLE) {
1366 g_assert(t1->right == LTTV_TREE_NODE);
1367 t1 = t1->r_child.t;
1368 }
18d1226f 1369 t2 = lttv_filter_tree_new();
0cdc2470 1370 t2->node = LTTV_LOGICAL_AND;
72911c5d 1371 t1->right = LTTV_TREE_NODE;
1372 t1->r_child.t = t2;
1373 if(not) { /* add not operator to tree */
1374 t3 = lttv_filter_tree_new();
1375 t3->node = LTTV_LOGICAL_NOT;
1376 t2->left = LTTV_TREE_NODE;
1377 t2->l_child.t = t3;
72911c5d 1378 t2 = t3;
1379 not = 0;
72911c5d 1380 }
bb87caa7 1381 if(subtree != NULL) { /* append subtree to current tree */
18d1226f 1382 t2->left = LTTV_TREE_NODE;
1383 t2->l_child.t = subtree;
f4e9dd16 1384 subtree = NULL;
bb87caa7 1385 } else { /* append a simple expression */
9ab5ebd7 1386 lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE));
18d1226f 1387 a_field_component = g_string_new("");
571ef1ed 1388 g_string_free(a_string_spaces, TRUE);
1389 a_string_spaces = g_string_new("");
18d1226f 1390 t2->left = LTTV_TREE_LEAF;
0cdc2470 1391 t2->l_child.leaf = a_simple_expression;
389ba50e 1392 a_simple_expression = lttv_simple_expression_new();
f4e9dd16 1393 }
f4e9dd16 1394 break;
aa4600f3 1395
a4c292d4 1396 case '|': /* or */
aa4600f3 1397
e00d6a24 1398 t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1);
9ab5ebd7 1399 while(t1->right != LTTV_TREE_IDLE) {
1400 g_assert(t1->right == LTTV_TREE_NODE);
1401 t1 = t1->r_child.t;
1402 }
1601b365 1403 t2 = lttv_filter_tree_new();
0cdc2470 1404 t2->node = LTTV_LOGICAL_OR;
72911c5d 1405 t1->right = LTTV_TREE_NODE;
1406 t1->r_child.t = t2;
1407 if(not) { // add not operator to tree
1408 t3 = lttv_filter_tree_new();
1409 t3->node = LTTV_LOGICAL_NOT;
1410 t2->left = LTTV_TREE_NODE;
1411 t2->l_child.t = t3;
1412 t2 = t3;
1413 not = 0;
1414 }
1415 if(subtree != NULL) { /* append subtree to current tree */
1601b365 1416 t2->left = LTTV_TREE_NODE;
1417 t2->l_child.t = subtree;
1418 subtree = NULL;
72911c5d 1419 } else { /* append a simple expression */
9ab5ebd7 1420 lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE));
1601b365 1421 a_field_component = g_string_new("");
571ef1ed 1422 g_string_free(a_string_spaces, TRUE);
1423 a_string_spaces = g_string_new("");
1601b365 1424 t2->left = LTTV_TREE_LEAF;
0cdc2470 1425 t2->l_child.leaf = a_simple_expression;
389ba50e 1426 a_simple_expression = lttv_simple_expression_new();
1601b365 1427 }
f4e9dd16 1428 break;
aa4600f3 1429
a4c292d4 1430 case '^': /* xor */
aa4600f3 1431
e00d6a24 1432 t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1);
9ab5ebd7 1433 while(t1->right != LTTV_TREE_IDLE) {
1434 g_assert(t1->right == LTTV_TREE_NODE);
1435 t1 = t1->r_child.t;
1436 }
1601b365 1437 t2 = lttv_filter_tree_new();
0cdc2470 1438 t2->node = LTTV_LOGICAL_XOR;
72911c5d 1439 t1->right = LTTV_TREE_NODE;
1440 t1->r_child.t = t2;
1441 if(not) { // add not operator to tree
1442 t3 = lttv_filter_tree_new();
1443 t3->node = LTTV_LOGICAL_NOT;
1444 t2->left = LTTV_TREE_NODE;
1445 t2->l_child.t = t3;
1446 t2 = t3;
1447 not = 0;
1448 }
bb87caa7 1449 if(subtree != NULL) { /* append subtree to current tree */
1601b365 1450 t2->left = LTTV_TREE_NODE;
1451 t2->l_child.t = subtree;
1452 subtree = NULL;
bb87caa7 1453 } else { /* append a simple expression */
9ab5ebd7 1454 lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE));
1601b365 1455 a_field_component = g_string_new("");
571ef1ed 1456 g_string_free(a_string_spaces, TRUE);
1457 a_string_spaces = g_string_new("");
1601b365 1458 t2->left = LTTV_TREE_LEAF;
0cdc2470 1459 t2->l_child.leaf = a_simple_expression;
389ba50e 1460 a_simple_expression = lttv_simple_expression_new();
1601b365 1461 }
a4c292d4 1462 break;
aa4600f3 1463
a4c292d4 1464 case '!': /* not, or not equal (math op) */
aa4600f3 1465
5f185a2b 1466 if(filter->expression[i+1] == '=') { /* != */
0cdc2470 1467 g_ptr_array_add( a_field_path,(gpointer) a_field_component );
9ab5ebd7 1468 lttv_simple_expression_assign_field(a_field_path,a_simple_expression);
0cdc2470 1469 a_field_component = g_string_new("");
571ef1ed 1470 g_string_free(a_string_spaces, TRUE);
1471 a_string_spaces = g_string_new("");
56e29124 1472 lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_NE);
aa4600f3 1473 i++;
a4c292d4 1474 } else { /* ! */
72911c5d 1475 not=1;
a4c292d4 1476 }
1477 break;
aa4600f3 1478
a4c292d4 1479 case '(': /* start of parenthesis */
91ad3f0a 1480 case '[':
1481 case '{':
aa4600f3 1482
91ad3f0a 1483 p_nesting++; /* incrementing parenthesis nesting value */
1601b365 1484 t1 = lttv_filter_tree_new();
72911c5d 1485 if(not) { /* add not operator to tree */
1486 t3 = lttv_filter_tree_new();
1487 t3->node = LTTV_LOGICAL_NOT;
1488 t1->right = LTTV_TREE_NODE;
1489 t1->r_child.t = t3;
1490 not = 0;
1491 }
1601b365 1492 g_ptr_array_add( tree_stack,(gpointer) t1 );
a4c292d4 1493 break;
aa4600f3 1494
a4c292d4 1495 case ')': /* end of parenthesis */
91ad3f0a 1496 case ']':
1497 case '}':
aa4600f3 1498
91ad3f0a 1499 p_nesting--; /* decrementing parenthesis nesting value */
18d1226f 1500 if(p_nesting<0 || tree_stack->len<2) {
f4e9dd16 1501 g_warning("Wrong filtering options, the string\n\"%s\"\n\
571ef1ed 1502 is not valid due to parenthesis incorrect use",filter->expression);
5f185a2b 1503 return FALSE;
f4e9dd16 1504 }
56e29124 1505
1506 /* there must at least be the root tree left in the array */
18d1226f 1507 g_assert(tree_stack->len>0);
72911c5d 1508
1509 t1 = g_ptr_array_index(tree_stack,tree_stack->len-1);
1510 while(t1->right != LTTV_TREE_IDLE) {
1511 t1 = t1->r_child.t;
1512 }
1513 if(not) { // add not operator to tree
1514 g_print("ici");
1515 t3 = lttv_filter_tree_new();
1516 t3->node = LTTV_LOGICAL_NOT;
1517 t1->right = LTTV_TREE_NODE;
1518 t1->r_child.t = t3;
1519 t1 = t3;
1520 not = 0;
1521 }
bb87caa7 1522 if(subtree != NULL) { /* append subtree to current tree */
18d1226f 1523 t1->right = LTTV_TREE_NODE;
1524 t1->r_child.t = subtree;
1525 subtree = g_ptr_array_index(tree_stack,tree_stack->len-1);
1526 g_ptr_array_remove_index(tree_stack,tree_stack->len-1);
bb87caa7 1527 } else { /* assign subtree as current tree */
9ab5ebd7 1528 lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE));
18d1226f 1529 a_field_component = g_string_new("");
571ef1ed 1530 g_string_free(a_string_spaces, TRUE);
1531 a_string_spaces = g_string_new("");
18d1226f 1532 t1->right = LTTV_TREE_LEAF;
0cdc2470 1533 t1->r_child.leaf = a_simple_expression;
389ba50e 1534 a_simple_expression = lttv_simple_expression_new();
9ab5ebd7 1535 subtree = g_ptr_array_remove_index(tree_stack,tree_stack->len-1);
18d1226f 1536 }
a4c292d4 1537 break;
1538
571ef1ed 1539 /*
1540 * mathematic operators
a4c292d4 1541 */
1542 case '<': /* lower, lower or equal */
aa4600f3 1543
1544 g_ptr_array_add( a_field_path,(gpointer) a_field_component );
9ab5ebd7 1545 lttv_simple_expression_assign_field(a_field_path,a_simple_expression);
aa4600f3 1546 a_field_component = g_string_new("");
571ef1ed 1547 g_string_free(a_string_spaces, TRUE);
1548 a_string_spaces = g_string_new("");
5f185a2b 1549 if(filter->expression[i+1] == '=') { /* <= */
a4c292d4 1550 i++;
56e29124 1551 lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_LE);
1552 } else lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_LT);
aa4600f3 1553 break;
1554
1555 case '>': /* higher, higher or equal */
1556
1557 g_ptr_array_add( a_field_path,(gpointer) a_field_component );
9ab5ebd7 1558 lttv_simple_expression_assign_field(a_field_path,a_simple_expression);
f4e9dd16 1559 a_field_component = g_string_new("");
571ef1ed 1560 g_string_free(a_string_spaces, TRUE);
1561 a_string_spaces = g_string_new("");
5f185a2b 1562 if(filter->expression[i+1] == '=') { /* >= */
a4c292d4 1563 i++;
56e29124 1564 lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_GE);
1565 } else lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_GT);
aa4600f3 1566 break;
1567
a4c292d4 1568 case '=': /* equal */
aa4600f3 1569
f4e9dd16 1570 g_ptr_array_add( a_field_path,(gpointer) a_field_component );
9ab5ebd7 1571 lttv_simple_expression_assign_field(a_field_path,a_simple_expression);
f4e9dd16 1572 a_field_component = g_string_new("");
571ef1ed 1573 g_string_free(a_string_spaces, TRUE);
1574 a_string_spaces = g_string_new("");
56e29124 1575 lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_EQ);
a4c292d4 1576 break;
aa4600f3 1577
0769c82f 1578 /*
1579 * Field concatening caracter
1580 */
1581 case '.': /* dot */
aa4600f3 1582
bb87caa7 1583 /*
1584 * divide field expression into elements
1585 * in a_field_path array.
4d9ff942 1586 *
1587 * A dot can also be present in double values
bb87caa7 1588 */
8ff6243c 1589 if(a_simple_expression->field == LTTV_FILTER_UNDEFINED) {
bb87caa7 1590 g_ptr_array_add( a_field_path,(gpointer) a_field_component );
1591 a_field_component = g_string_new("");
571ef1ed 1592 g_string_free(a_string_spaces, TRUE);
1593 a_string_spaces = g_string_new("");
8ff6243c 1594 }
1595 break;
ef2b07c1 1596 case ' ': /* keep spaces that are within a field component */
d564d2ad 1597 if(a_field_component->len == 0) break; /* ignore */
571ef1ed 1598 else
1599 a_string_spaces = g_string_append_c(a_string_spaces,
1600 filter->expression[i]);
ef2b07c1 1601
4d9ff942 1602 case '\n': /* ignore */
0769c82f 1603 break;
d564d2ad 1604 case '\"':
1605 nest_quotes?(nest_quotes=0):(nest_quotes=1);
1606 break;
a4c292d4 1607 default: /* concatening current string */
d564d2ad 1608 if(a_string_spaces->len != 0) {
571ef1ed 1609 a_field_component = g_string_append(
4ec0c904 1610 a_field_component, a_string_spaces->str);
1611 a_string_spaces = g_string_set_size(a_string_spaces, 0);
d564d2ad 1612 }
1613 a_field_component = g_string_append_c(a_field_component,
1614 filter->expression[i]);
a4c292d4 1615 }
1616 }
1601b365 1617
0cdc2470 1618 /*
1619 * Preliminary check to see
1620 * if tree was constructed correctly
1621 */
1622 if( p_nesting>0 ) {
1623 g_warning("Wrong filtering options, the string\n\"%s\"\n\
571ef1ed 1624 is not valid due to parenthesis incorrect use",filter->expression);
5f185a2b 1625 return FALSE;
0cdc2470 1626 }
1627
1628 if(tree_stack->len != 1) /* only root tree should remain */
5f185a2b 1629 return FALSE;
1601b365 1630
72911c5d 1631 /*
1632 * processing last element of expression
1633 */
410c83da 1634 t1 = g_ptr_array_index(tree_stack,tree_stack->len-1);
9ab5ebd7 1635 while(t1->right != LTTV_TREE_IDLE) {
1636 g_assert(t1->right == LTTV_TREE_NODE);
1637 t1 = t1->r_child.t;
1638 }
72911c5d 1639 if(not) { // add not operator to tree
1640 t3 = lttv_filter_tree_new();
1641 t3->node = LTTV_LOGICAL_NOT;
1642 t1->right = LTTV_TREE_NODE;
1643 t1->r_child.t = t3;
1644 t1 = t3;
1645 not = 0;
1646 }
410c83da 1647 if(subtree != NULL) { /* add the subtree */
1648 t1->right = LTTV_TREE_NODE;
0cdc2470 1649 t1->r_child.t = subtree;
410c83da 1650 subtree = NULL;
1651 } else { /* add a leaf */
9ab5ebd7 1652 lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE));
56e29124 1653 a_field_component = NULL;
571ef1ed 1654 g_string_free(a_string_spaces, TRUE);
1655 a_string_spaces = NULL;
410c83da 1656 t1->right = LTTV_TREE_LEAF;
0cdc2470 1657 t1->r_child.leaf = a_simple_expression;
56e29124 1658 a_simple_expression = NULL;
410c83da 1659 }
1660
56e29124 1661
73050a5f 1662 /* free the pointer array */
1663 g_assert(a_field_path->len == 0);
1664 g_ptr_array_free(a_field_path,TRUE);
56e29124 1665
1666 /* free the tree stack -- but keep the root tree */
f3020899 1667 filter->head = g_ptr_array_remove_index(tree_stack,0);
1668 g_ptr_array_free(tree_stack,TRUE);
1669
56e29124 1670 /* free the field buffer if allocated */
1671 if(a_field_component != NULL) g_string_free(a_field_component,TRUE);
571ef1ed 1672 if(a_string_spaces != NULL) g_string_free(a_string_spaces, TRUE);
ef2b07c1 1673
56e29124 1674 /* free the simple expression buffer if allocated */
1675 if(a_simple_expression != NULL) lttv_simple_expression_destroy(a_simple_expression);
73050a5f 1676
f3020899 1677 g_assert(filter->head != NULL); /* tree should exist */
56e29124 1678 g_assert(subtree == NULL); /* remaining subtree should be included in main tree */
be66ef34 1679
1680#ifdef TEST
1681 gettimeofday(&endtime, NULL);
1682
1683 /* Calcul du temps de l'algorithme */
1684 double time1 = starttime.tv_sec + (starttime.tv_usec/1000000.0);
1685 double time2 = endtime.tv_sec + (endtime.tv_usec/1000000.0);
1686// g_print("Tree build took %.10f ms for strlen of %i\n",(time2-time1)*1000,strlen(filter->expression));
1687 g_print("%.10f %i\n",(time2-time1)*1000,strlen(filter->expression));
1688#endif
a4c292d4 1689
56e29124 1690 /* debug */
c2a4581e 1691 g_debug("+++++++++++++++ BEGIN PRINT ++++++++++++++++\n");
72911c5d 1692 lttv_print_tree(filter->head,0) ;
c2a4581e 1693 g_debug("+++++++++++++++ END PRINT ++++++++++++++++++\n");
56e29124 1694
1695 /* success */
5f185a2b 1696 return TRUE;
80f9611a 1697
31452f49 1698}
1699
8c89f5a8 1700/**
56e29124 1701 * @fn void lttv_filter_destroy(LttvFilter*)
1702 *
8c89f5a8 1703 * Destroy the current LttvFilter
1704 * @param filter pointer to the current LttvFilter
1705 */
1da1525d 1706void
2ea36caf 1707lttv_filter_destroy(LttvFilter* filter) {
5f185a2b 1708
571ef1ed 1709 if(!filter) return;
ebcead4a 1710
571ef1ed 1711 if(filter->expression)
1712 g_free(filter->expression);
1713 if(filter->head)
1714 lttv_filter_tree_destroy(filter->head);
5f185a2b 1715 g_free(filter);
1716
1da1525d 1717}
1718
150f0d33 1719/**
8ff6243c 1720 * @fn LttvFilterTree* lttv_filter_tree_new()
56e29124 1721 *
150f0d33 1722 * Assign a new tree for the current expression
1723 * or sub expression
1724 * @return pointer of LttvFilterTree
1725 */
5f185a2b 1726LttvFilterTree*
1727lttv_filter_tree_new() {
150f0d33 1728 LttvFilterTree* tree;
1729
e00d6a24 1730 tree = g_new(LttvFilterTree,1);
150f0d33 1731 tree->node = 0; //g_new(lttv_expression,1);
150f0d33 1732 tree->left = LTTV_TREE_IDLE;
1733 tree->right = LTTV_TREE_IDLE;
f3020899 1734 tree->r_child.t = NULL;
1735 tree->l_child.t = NULL;
1736
150f0d33 1737 return tree;
1738}
1739
80f9611a 1740/**
56e29124 1741 * @fn void lttv_filter_append_expression(LttvFilter*,char*)
1742 *
80f9611a 1743 * Append a new expression to the expression
1744 * defined in the current filter
1745 * @param filter pointer to the current LttvFilter
1746 * @param expression string that must be appended
56e29124 1747 * @return Success/Failure of operation
80f9611a 1748 */
be66ef34 1749gboolean
1750lttv_filter_append_expression(LttvFilter* filter, const char *expression) {
80f9611a 1751
56e29124 1752 if(expression == NULL) return FALSE;
da2e1bfb 1753 if(filter == NULL) return FALSE;
0bc23ba9 1754 if(expression[0] == '\0') return FALSE; /* Empty expression */
80f9611a 1755
da2e1bfb 1756 GString* s = g_string_new("");
1757 if(filter->expression != NULL) {
4ec0c904 1758 s = g_string_append(s,filter->expression);
1759 s = g_string_append_c(s,'&');
da2e1bfb 1760 }
4ec0c904 1761 s = g_string_append(s,expression);
786c5c3b 1762
1763 g_free(filter->expression);
da2e1bfb 1764 filter->expression = g_string_free(s,FALSE);
1765
1766 /* TRUE if construction of tree proceeded without errors */
56e29124 1767 return lttv_filter_update(filter);
80f9611a 1768
1769}
1770
1771/**
56e29124 1772 * @fn void lttv_filter_clear_expression(LttvFilter*)
1773 *
80f9611a 1774 * Clear the filter expression from the
1775 * current filter and sets its pointer to NULL
1776 * @param filter pointer to the current LttvFilter
1777 */
be66ef34 1778void
1779lttv_filter_clear_expression(LttvFilter* filter) {
80f9611a 1780
1781 if(filter->expression != NULL) {
1782 g_free(filter->expression);
1783 filter->expression = NULL;
1784 }
1785
1786}
1787
150f0d33 1788/**
56e29124 1789 * @fn void lttv_filter_tree_destroy(LttvFilterTree*)
1790 *
150f0d33 1791 * Destroys the tree and his sub-trees
1792 * @param tree Tree which must be destroyed
1793 */
5f185a2b 1794void
1795lttv_filter_tree_destroy(LttvFilterTree* tree) {
56e29124 1796
150f0d33 1797 if(tree == NULL) return;
1798
56e29124 1799 if(tree->left == LTTV_TREE_LEAF) lttv_simple_expression_destroy(tree->l_child.leaf);
150f0d33 1800 else if(tree->left == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->l_child.t);
1801
56e29124 1802 if(tree->right == LTTV_TREE_LEAF) lttv_simple_expression_destroy(tree->r_child.leaf);
150f0d33 1803 else if(tree->right == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->r_child.t);
1804
e00d6a24 1805// g_free(tree->node);
150f0d33 1806 g_free(tree);
1807}
1808
84a333d6 1809/**
80f9611a 1810 * Global parsing function for the current
1811 * LttvFilterTree
7e7af7f2 1812 * @param t pointer to the current LttvFilterTree
80f9611a 1813 * @param event current LttEvent, NULL if not used
1814 * @param tracefile current LttTracefile, NULL if not used
1815 * @param trace current LttTrace, NULL if not used
1816 * @param state current LttvProcessState, NULL if not used
4d9ff942 1817 * @param context current LttvTracefileContext, NULL if not used
1818 * @return response of filter
84a333d6 1819 */
31452f49 1820gboolean
80f9611a 1821lttv_filter_tree_parse(
4d9ff942 1822 const LttvFilterTree* t,
1823 const LttEvent* event,
1824 const LttTracefile* tracefile,
1825 const LttTrace* trace,
4d9ff942 1826 const LttvTracefileContext* context
80f9611a 1827 /*,...*/)
1828{
0769c82f 1829
80f9611a 1830 /*
1601b365 1831 * Each tree is parsed in inorder.
1832 * This way, it's possible to apply the left filter of the
1833 * tree, then decide whether or not the right branch should
1834 * be parsed depending on the linking logical operator
1835 *
80f9611a 1836 * Each node consists in a
1837 * 1. logical operator
1838 * 2. left child ( node or simple expression )
1839 * 3. right child ( node or simple expression )
1840 *
1841 * When the child is a simple expression, we must
1842 * before all determine if the expression refers to
1843 * a structure which is whithin observation ( not NULL ).
1844 * -If so, the expression is evaluated.
1845 * -If not, the result is set to TRUE since this particular
1846 * operation does not interfere with the lttv structure
1847 *
1848 * The result of each simple expression will directly
1849 * affect the next branch. This way, depending on
1850 * the linking logical operator, the parser will decide
1851 * to explore or not the next branch.
1852 * 1. AND OPERATOR
1853 * -If result of left branch is 0 / FALSE
1854 * then don't explore right branch and return 0;
1855 * -If result of left branch is 1 / TRUE then explore
1856 * 2. OR OPERATOR
1857 * -If result of left branch is 1 / TRUE
1858 * then don't explore right branch and return 1;
1859 * -If result of left branch is 0 / FALSE then explore
1860 * 3. XOR OPERATOR
56e29124 1861 * -Result of left branch will not affect exploration of
80f9611a 1862 * right branch
1601b365 1863 */
73050a5f 1864
80f9611a 1865 gboolean lresult = FALSE, rresult = FALSE;
33e44b82 1866
1867 LttvProcessState* state;
1868
6e0d58d6 1869 LttvTraceState *ts = (LttvTraceState*)context->t_context;
ae3d0f50 1870 LttvTracefileState *tfs = (LttvTracefileState*)context;
1871 guint cpu = tfs->cpu;
6e0d58d6 1872 state = ts->running_process[cpu];
0769c82f 1873
80f9611a 1874 /*
1875 * Parse left branch
1876 */
4d9ff942 1877 if(t->left == LTTV_TREE_NODE) {
33e44b82 1878 lresult = lttv_filter_tree_parse(t->l_child.t,event,tracefile,trace,context);
4d9ff942 1879 }
5b729fcf 1880 else if(t->left == LTTV_TREE_LEAF) {
4d9ff942 1881 lresult = lttv_filter_tree_parse_branch(t->l_child.leaf,event,tracefile,trace,state,context);
0cdc2470 1882 }
4d9ff942 1883
80f9611a 1884 /*
1885 * Parse linking operator
1886 * make a cutoff if possible
1887 */
1888 if((t->node & LTTV_LOGICAL_OR) && lresult == TRUE) return TRUE;
1889 if((t->node & LTTV_LOGICAL_AND) && lresult == FALSE) return FALSE;
1890
1891 /*
1892 * Parse right branch
1893 */
4d9ff942 1894 if(t->right == LTTV_TREE_NODE) {
33e44b82 1895 rresult = lttv_filter_tree_parse(t->r_child.t,event,tracefile,trace,context);
4d9ff942 1896 }
5b729fcf 1897 else if(t->right == LTTV_TREE_LEAF) {
4d9ff942 1898 rresult = lttv_filter_tree_parse_branch(t->r_child.leaf,event,tracefile,trace,state,context);
1899 }
2bdb97c5 1900
2bdb97c5 1901
4d9ff942 1902 /*
1903 * Apply and return the
1904 * logical link between the
1905 * two operation
1906 */
1907 switch(t->node) {
1908 case LTTV_LOGICAL_OR: return (lresult | rresult);
1909 case LTTV_LOGICAL_AND: return (lresult & rresult);
72911c5d 1910 case LTTV_LOGICAL_NOT:
1911 return (t->left==LTTV_TREE_LEAF)?!lresult:((t->right==LTTV_TREE_LEAF)?!rresult:TRUE);
4d9ff942 1912 case LTTV_LOGICAL_XOR: return (lresult ^ rresult);
1913 case 0: return (rresult);
1914 default:
1915 /*
1916 * This case should never be
1917 * parsed, if so, this subtree
1918 * is cancelled !
1919 */
1920 return TRUE;
1921 }
1922
1923}
1924
1925/**
4d9ff942 1926 * This function parses a particular branch of the tree
7e7af7f2 1927 * @param se pointer to the current LttvSimpleExpression
4d9ff942 1928 * @param event current LttEvent, NULL if not used
1929 * @param tracefile current LttTracefile, NULL if not used
1930 * @param trace current LttTrace, NULL if not used
1931 * @param state current LttvProcessState, NULL if not used
1932 * @param context current LttvTracefileContext, NULL if not used
1933 * @return response of filter
1934 */
be66ef34 1935gboolean
1936lttv_filter_tree_parse_branch(
4d9ff942 1937 const LttvSimpleExpression* se,
1938 const LttEvent* event,
1939 const LttTracefile* tracefile,
1940 const LttTrace* trace,
1941 const LttvProcessState* state,
1942 const LttvTracefileContext* context) {
1943
9ab5ebd7 1944 LttvFieldValue v;
4d9ff942 1945 v = se->value;
1946 switch(se->field) {
80f9611a 1947 case LTTV_FILTER_TRACE_NAME:
4d9ff942 1948 if(trace == NULL) return TRUE;
c6832b57 1949 else {
eed2ef37 1950 GQuark quark = ltt_trace_name(trace);
c6832b57 1951 return se->op((gpointer)&quark,v);
1952 }
80f9611a 1953 break;
1954 case LTTV_FILTER_TRACEFILE_NAME:
4d9ff942 1955 if(tracefile == NULL) return TRUE;
c6832b57 1956 else {
eed2ef37 1957 GQuark quark = ltt_tracefile_name(tracefile);
c6832b57 1958 return se->op((gpointer)&quark,v);
1959 }
80f9611a 1960 break;
1961 case LTTV_FILTER_STATE_PID:
4d9ff942 1962 if(state == NULL) return TRUE;
1963 else return se->op((gpointer)&state->pid,v);
80f9611a 1964 break;
1965 case LTTV_FILTER_STATE_PPID:
4d9ff942 1966 if(state == NULL) return TRUE;
1967 else return se->op((gpointer)&state->ppid,v);
80f9611a 1968 break;
1969 case LTTV_FILTER_STATE_CT:
4d9ff942 1970 if(state == NULL) return TRUE;
80f9611a 1971 else {
4d9ff942 1972 return se->op((gpointer)&state->creation_time,v);
80f9611a 1973 }
1974 break;
1975 case LTTV_FILTER_STATE_IT:
4d9ff942 1976 if(state == NULL) return TRUE;
80f9611a 1977 else {
4d9ff942 1978 return se->op((gpointer)&state->insertion_time,v);
80f9611a 1979 }
1980 break;
1981 case LTTV_FILTER_STATE_P_NAME:
4d9ff942 1982 if(state == NULL) return TRUE;
46c40a93 1983 else {
bbd9d557 1984 GQuark quark = state->name;
c6832b57 1985 return se->op((gpointer)&quark,v);
46c40a93 1986 }
80f9611a 1987 break;
571ef1ed 1988 case LTTV_FILTER_STATE_T_BRAND:
7b5f6cf1 1989 if(state == NULL) return TRUE;
1990 else {
1991 GQuark quark = state->brand;
1992 return se->op((gpointer)&quark,v);
1993 }
1994 break;
80f9611a 1995 case LTTV_FILTER_STATE_EX_MODE:
4d9ff942 1996 if(state == NULL) return TRUE;
1997 else return se->op((gpointer)&state->state->t,v);
80f9611a 1998 break;
1999 case LTTV_FILTER_STATE_EX_SUBMODE:
4d9ff942 2000 if(state == NULL) return TRUE;
2001 else return se->op((gpointer)&state->state->n,v);
80f9611a 2002 break;
2003 case LTTV_FILTER_STATE_P_STATUS:
4d9ff942 2004 if(state == NULL) return TRUE;
2005 else return se->op((gpointer)&state->state->s,v);
80f9611a 2006 break;
2007 case LTTV_FILTER_STATE_CPU:
4d9ff942 2008 if(context == NULL) return TRUE;
46c40a93 2009 else {
348c6ba8 2010 if(state == NULL) return TRUE;
2011 else return se->op((gpointer)&state->cpu,v);
46c40a93 2012 }
80f9611a 2013 break;
2014 case LTTV_FILTER_EVENT_NAME:
4d9ff942 2015 if(event == NULL) return TRUE;
2016 else {
46c40a93 2017 LttEventType* et;
2018 et = ltt_event_eventtype(event);
eed2ef37 2019 GQuark quark = ltt_eventtype_name(et);
c6832b57 2020 return se->op((gpointer)&quark,v);
4d9ff942 2021 }
2022 break;
ffd088ef 2023 case LTTV_FILTER_EVENT_FACILITY:
2024 if(event == NULL) return TRUE;
2025 else {
2026 LttFacility* fac;
2027 fac = ltt_event_facility(event);
2028 GQuark quark = ltt_facility_name(fac);
2029 return se->op((gpointer)&quark,v);
2030 }
2031 break;
80f9611a 2032 case LTTV_FILTER_EVENT_CATEGORY:
2033 /*
c6832b57 2034 * TODO: Not yet implemented
80f9611a 2035 */
4d9ff942 2036 return TRUE;
80f9611a 2037 break;
2038 case LTTV_FILTER_EVENT_TIME:
4d9ff942 2039 if(event == NULL) return TRUE;
46c40a93 2040 else {
2041 LttTime time = ltt_event_time(event);
4d9ff942 2042 return se->op((gpointer)&time,v);
46c40a93 2043 }
80f9611a 2044 break;
2045 case LTTV_FILTER_EVENT_TSC:
bbd9d557 2046 if(event == NULL) return TRUE;
2047 else {
2048 LttCycleCount count = ltt_event_cycle_count(event);
2049 return se->op((gpointer)&count,v);
2050 }
80f9611a 2051 break;
2052 case LTTV_FILTER_EVENT_FIELD:
2053 /*
2054 * TODO: Use the offset to
2055 * find the dynamic field
2056 * in the event struct
2057 */
4d9ff942 2058 return TRUE;
80f9611a 2059 default:
2060 /*
2061 * This case should never be
4d9ff942 2062 * parsed, if so, the whole
2063 * filtering is cancelled
80f9611a 2064 */
2065 g_warning("Error while parsing the filter tree");
2066 return TRUE;
2067 }
4d9ff942 2068
2069 /* should never get here */
2070 return TRUE;
2071
80f9611a 2072}
0769c82f 2073
4d9ff942 2074
2075
80f9611a 2076/**
7e7af7f2 2077 * Debug function. Prints tree memory allocation.
56e29124 2078 * @param t the pointer to the current LttvFilterTree
80f9611a 2079 */
2080void
72911c5d 2081lttv_print_tree(const LttvFilterTree* t, const int count) {
0769c82f 2082
c2a4581e 2083 g_debug("node:%p lchild:%p rchild:%p depth:%i\n",t, //t->l_child.t,t->r_child.t);
80f9611a 2084 (t->left==LTTV_TREE_NODE)?t->l_child.t:NULL,
72911c5d 2085 (t->right==LTTV_TREE_NODE)?t->r_child.t:NULL,
2086 count);
c2a4581e 2087 g_debug("logic operator: %s\n",(t->node&1)?"OR":((t->node&2)?"AND":((t->node&4)?"NOT":((t->node&8)?"XOR":"IDLE"))));
2088 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 2089 if(t->left == LTTV_TREE_LEAF) {
c2a4581e 2090 g_debug("| |-> field type number: %i\n",t->l_child.leaf->field);
2091 g_debug("| |-> offset is: %i\n",t->l_child.leaf->offset);
2092 g_debug("| |-> operator function is: %p\n",t->l_child.leaf->op);
0769c82f 2093 }
c2a4581e 2094 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 2095 if(t->right == LTTV_TREE_LEAF) {
c2a4581e 2096 g_debug("| |-> field type number: %i\n",t->r_child.leaf->field);
2097 g_debug("| |-> offset is: %i\n",t->r_child.leaf->offset);
2098 g_debug("| |-> operator function is: %p\n",t->r_child.leaf->op);
80f9611a 2099 }
72911c5d 2100
2101 if(t->left == LTTV_TREE_NODE) lttv_print_tree(t->l_child.t,count+1);
2102 if(t->right == LTTV_TREE_NODE) lttv_print_tree(t->r_child.t,count+1);
80f9611a 2103}
2104
91ad3f0a 2105/**
56e29124 2106 * @fn static void module_init()
2107 *
91ad3f0a 2108 * Initializes the filter module and specific values
2109 */
1a7fa682 2110static void module_init()
2111{
91ad3f0a 2112
1a7fa682 2113}
2114
91ad3f0a 2115/**
7e7af7f2 2116 * Destroys the filter module and specific values
91ad3f0a 2117 */
1a7fa682 2118static void module_destroy()
2119{
56e29124 2120
1a7fa682 2121}
2122
2123
91ad3f0a 2124LTTV_MODULE("filter", "Filters traceset and events", \
2125 "Filters traceset and events specifically to user input", \
1a7fa682 2126 module_init, module_destroy)
2127
2128
2129
This page took 0.150486 seconds and 4 git commands to generate.