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