Hide lttng_event_copy symbol
[lttng-tools.git] / src / lib / lttng-ctl / event.c
CommitLineData
eb5c4f4e
JG
1/*
2 * event.c
3 *
4 * Linux Trace Toolkit Control Library
5 *
6 * Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 *
8 * This library is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License, version 2.1 only,
10 * as published by the Free Software Foundation.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#define _LGPL_SOURCE
ef0e06bc 23#include <assert.h>
eb5c4f4e 24#include <stddef.h>
ef0e06bc
JG
25
26#include <common/error.h>
eb5c4f4e 27#include <common/sessiond-comm/sessiond-comm.h>
ef0e06bc
JG
28#include <lttng/event-internal.h>
29#include <lttng/event.h>
30#include <lttng/lttng-error.h>
31#include <lttng/userspace-probe-internal.h>
32
33struct lttng_event *lttng_event_create(void)
34{
35 struct lttng_event *event;
36 struct lttng_event_extended *event_extended;
37
38 event = zmalloc(sizeof(*event));
39 if (!event) {
40 PERROR("Error allocating event structure");
41 goto end;
42 }
43
44 event_extended = zmalloc(sizeof(*event_extended));
45 if (!event_extended) {
46 PERROR("Error allocating event extended structure");
47 goto error;
48 }
49 event->extended.ptr = event_extended;
50end:
51 return event;
52error:
53 free(event);
54 goto end;
55}
56
57void lttng_event_destroy(struct lttng_event *event)
58{
59 struct lttng_event_extended *event_extended;
60
61 if (!event) {
62 return;
63 }
64
65 event_extended = (struct lttng_event_extended *) event->extended.ptr;
66
67 if (event_extended) {
68 if (event_extended->probe_location) {
69 lttng_userspace_probe_location_destroy(
70 event_extended->probe_location);
71 }
72 free(event_extended);
73 }
74 free(event);
75}
eb5c4f4e
JG
76
77int lttng_event_get_filter_expression(struct lttng_event *event,
78 const char **filter_expression)
79{
80 int ret = 0;
de453daa 81 struct lttng_event_extended *event_extended;
eb5c4f4e
JG
82
83 if (!event || !filter_expression) {
84 ret = -LTTNG_ERR_INVALID;
85 goto end;
86 }
87
de453daa
JG
88 event_extended = (struct lttng_event_extended *) event->extended.ptr;
89 if (!event_extended) {
eb5c4f4e
JG
90 /*
91 * This can happen since the lttng_event structure is
92 * used for other tasks where this pointer is never set.
93 */
94 *filter_expression = NULL;
95 goto end;
96 }
97
de453daa 98 *filter_expression = event_extended->filter_expression;
eb5c4f4e
JG
99end:
100 return ret;
101}
102
103int lttng_event_get_exclusion_name_count(struct lttng_event *event)
104{
de453daa
JG
105 int ret = 0;
106 struct lttng_event_extended *event_extended;
eb5c4f4e
JG
107
108 if (!event) {
109 ret = -LTTNG_ERR_INVALID;
110 goto end;
111 }
112
de453daa
JG
113 event_extended = (struct lttng_event_extended *) event->extended.ptr;
114 if (!event_extended) {
eb5c4f4e
JG
115 /*
116 * This can happen since the lttng_event structure is
117 * used for other tasks where this pointer is never set.
118 */
eb5c4f4e
JG
119 goto end;
120 }
121
de453daa 122 if (event_extended->exclusions.count > INT_MAX) {
eb5c4f4e
JG
123 ret = -LTTNG_ERR_OVERFLOW;
124 goto end;
125 }
de453daa 126 ret = (int) event_extended->exclusions.count;
eb5c4f4e
JG
127end:
128 return ret;
129}
130
131int lttng_event_get_exclusion_name(struct lttng_event *event,
132 size_t index, const char **exclusion_name)
133{
134 int ret = 0;
de453daa 135 struct lttng_event_extended *event_extended;
eb5c4f4e
JG
136
137 if (!event || !exclusion_name) {
138 ret = -LTTNG_ERR_INVALID;
139 goto end;
140 }
141
de453daa
JG
142 if (index > UINT_MAX) {
143 ret = -LTTNG_ERR_OVERFLOW;
eb5c4f4e
JG
144 goto end;
145 }
146
de453daa
JG
147 event_extended = (struct lttng_event_extended *) event->extended.ptr;
148 if (!event_extended) {
149 /*
150 * This can happen since the lttng_event structure is
151 * used for other tasks where this pointer is never set.
152 */
eb5c4f4e
JG
153 ret = -LTTNG_ERR_INVALID;
154 goto end;
155 }
156
de453daa
JG
157 if (index >= event_extended->exclusions.count) {
158 ret = -LTTNG_ERR_INVALID;
159 goto end;
160 }
eb5c4f4e 161
de453daa
JG
162 *exclusion_name = event_extended->exclusions.strings +
163 (index * LTTNG_SYMBOL_NAME_LEN);
eb5c4f4e
JG
164end:
165 return ret;
166}
ef0e06bc 167
87597c2c
JG
168const struct lttng_userspace_probe_location *
169lttng_event_get_userspace_probe_location(const struct lttng_event *event)
ef0e06bc
JG
170{
171 struct lttng_userspace_probe_location *probe_location = NULL;
172 struct lttng_event_extended *event_extended;
173
174 if (!event) {
175 goto end;
176 }
177
178 event_extended = (struct lttng_event_extended *) event->extended.ptr;
179 if (!event_extended) {
180 goto end;
181 }
182 probe_location = event_extended->probe_location;
183end:
184 return probe_location;
185}
186
187int lttng_event_set_userspace_probe_location(struct lttng_event *event,
188 struct lttng_userspace_probe_location *probe_location)
189{
190 int ret = 0;
191 struct lttng_event_extended *event_extended;
192
193 if (!event || !probe_location) {
194 ret = -LTTNG_ERR_INVALID;
195 goto end;
196 }
197
198 event_extended = (struct lttng_event_extended *) event->extended.ptr;
199 assert(event_extended);
200 if (event_extended->probe_location) {
201 lttng_userspace_probe_location_destroy(
202 event_extended->probe_location);
203 }
204 event_extended->probe_location = probe_location;
205end:
206 return ret;
207}
This page took 0.031436 seconds and 4 git commands to generate.