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