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