work on the core filter.c filter.h
[lttv.git] / ltt / branches / poly / lttv / lttv / filter.c
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
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
19 /*
20 consist in AND, OR and NOT nested expressions, forming a tree with
21 simple relations as leaves. The simple relations test is a field
22 in an event is equal, not equal, smaller, smaller or equal, larger, or
23 larger or equal to a specified value. */
24
25 #include <lttv/filter.h>
26
27 /*
28 read_token
29
30 read_expression
31 ( read expr )
32 simple expr [ op expr ]
33
34 read_simple_expression
35 read_field_path [ rel value ]
36
37 read_field_path
38 read_field_component [. field path]
39
40 read_field_component
41 name [ \[ value \] ]
42
43 data struct:
44 and/or(left/right)
45 not(child)
46 op(left/right)
47 path(component...) -> field
48 */
49
50 /**
51 * Add an filtering option to the current tree
52 * @param expression Current expression to parse
53 * @return success/failure of operation
54 */
55 gboolean
56 parse_simple_expression(GString* expression) {
57
58 unsigned i;
59
60 for(i=0;i<strlen(expression);i++) {
61
62
63 }
64 }
65
66 /**
67 * Creates a new lttv_filter
68 * @param expression filtering options string
69 * @param t pointer to the current LttvTrace
70 * @return the current lttv_filter or NULL if error
71 */
72 lttv_filter*
73 lttv_filter_new(char *expression, LttvTrace *t) {
74
75 unsigned
76 i,
77 p=0, /* parenthesis nesting value */
78 b=0; /* current breakpoint in expression string */
79
80 gpointer tree;
81
82 GString *currentOption = g_string_new("");
83
84 g_print("filter::lttv_filter_new()\n"); /* debug */
85
86 /*
87 * 1. parse expression
88 * 2. construct binary tree
89 * 3. return corresponding filter
90 */
91
92 /*
93 * Binary tree memory allocation
94 * - based upon a preliminary block size
95 */
96 gulong size = (strlen(expression)/6) * 1.5;
97 tree = g_malloc(size*sizeof(lttv_filter_tree));
98
99 /*
100 * Parse entire expression and construct
101 * the binary tree
102 */
103 for(i=0;i<strlen(expression);i++) {
104 switch(expression[i]) {
105 case '&': /* and */
106 parse_simple_expression(currentOption);
107 g_print("%s\n",&currentOption);
108 currentOption = g_string_new("");
109 break;
110 case '|': /* or */
111 g_print("%s\n",currentOption);
112 currentOption = g_string_new("");
113 break;
114 case '^': /* xor */
115 g_print("%s\n",currentOption);
116 currentOption = g_string_new("");
117 break;
118 case '!': /* not */
119 g_print("%s\n",currentOption);
120 currentOption = g_string_new("");
121 break;
122 case '(': /* start of parenthesis */
123 p++;
124 break;
125 case ')': /* end of parenthesis */
126 p--;
127 break;
128 default: /* concatening current string */
129 g_string_append_c(currentOption,expression[i]);
130 }
131
132
133 }
134
135 if( p>0 ) {
136 g_warning("Wrong filtering options, the string\n\"%s\"\n\
137 is not valid due to parenthesis incorrect use",expression);
138 return NULL;
139 }
140 }
141
142 /**
143 * Apply the filter to a specific trace
144 * @param filter the current filter applied
145 * @param tracefile the trace to apply the filter to
146 * @return success/failure of operation
147 */
148 gboolean
149 lttv_filter_tracefile(lttv_filter *filter, void *tracefile) {
150
151 }
152
153 /**
154 * Apply the filter to a specific event
155 * @param filter the current filter applied
156 * @param event the event to apply the filter to
157 * @return success/failure of operation
158 */
159 gboolean
160 lttv_filter_event(lttv_filter *filter, void *event) {
161
162 }
This page took 0.031408 seconds and 4 git commands to generate.