Filter: receive, attach and link empty filter
[lttng-ust.git] / liblttng-ust / lttng-filter.c
1 /*
2 * lttng-filter.c
3 *
4 * LTTng UST filter code.
5 *
6 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include <errno.h>
24 #include <stdio.h>
25 #include <helper.h>
26 #include <lttng/ust-events.h>
27
28 static
29 int lttng_filter_interpret_bytecode(void *filter_data,
30 const char *filter_stack_data)
31 {
32 /* TODO */
33 return 0;
34 }
35
36 static
37 int _lttng_filter_event_link_bytecode(struct ltt_event *event,
38 struct lttng_ust_filter_bytecode *filter_bytecode)
39 {
40 if (!filter_bytecode)
41 return 0;
42
43 event->filter = lttng_filter_interpret_bytecode;
44 /* TODO */
45 /* event->filter_data = ; */
46 return 0;
47 }
48
49 void lttng_filter_event_link_bytecode(struct ltt_event *event,
50 struct lttng_ust_filter_bytecode *filter_bytecode)
51 {
52 int ret;
53
54 ret = _lttng_filter_event_link_bytecode(event, event->filter_bytecode);
55 if (ret) {
56 fprintf(stderr, "[lttng filter] error linking event bytecode\n");
57 }
58 }
59
60 /*
61 * Link bytecode to all events for a wildcard. Skips events that already
62 * have a bytecode linked.
63 * We do not set each event's filter_bytecode field, because they do not
64 * own the filter_bytecode: the wildcard owns it.
65 */
66 void lttng_filter_wildcard_link_bytecode(struct session_wildcard *wildcard)
67 {
68 struct ltt_event *event;
69 int ret;
70
71 if (!wildcard->filter_bytecode)
72 return;
73
74 cds_list_for_each_entry(event, &wildcard->events, wildcard_list) {
75 if (event->filter)
76 continue;
77 ret = _lttng_filter_event_link_bytecode(event,
78 wildcard->filter_bytecode);
79 if (ret) {
80 fprintf(stderr, "[lttng filter] error linking wildcard bytecode\n");
81 }
82
83 }
84 return;
85 }
86
87 /*
88 * Need to attach filter to an event before starting tracing for the
89 * session.
90 */
91 int lttng_filter_event_attach_bytecode(struct ltt_event *event,
92 struct lttng_ust_filter_bytecode *filter_bytecode)
93 {
94 struct lttng_ust_filter_bytecode *bc;
95
96 if (event->chan->session->been_active)
97 return -EPERM;
98 if (event->filter_bytecode)
99 return -EEXIST;
100
101 bc = zmalloc(sizeof(struct lttng_ust_filter_bytecode)
102 + filter_bytecode->len);
103 if (!bc)
104 return -ENOMEM;
105 event->filter_bytecode = bc;
106 return 0;
107 }
108
109 /*
110 * Need to attach filter to a wildcard before starting tracing for the
111 * session.
112 */
113 int lttng_filter_wildcard_attach_bytecode(struct session_wildcard *wildcard,
114 struct lttng_ust_filter_bytecode *filter_bytecode)
115 {
116 struct lttng_ust_filter_bytecode *bc;
117
118 if (wildcard->chan->session->been_active)
119 return -EPERM;
120 if (wildcard->filter_bytecode)
121 return -EEXIST;
122
123 bc = zmalloc(sizeof(struct lttng_ust_filter_bytecode)
124 + filter_bytecode->len);
125 if (!bc)
126 return -ENOMEM;
127 wildcard->filter_bytecode = bc;
128 return 0;
129 }
This page took 0.034174 seconds and 5 git commands to generate.