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