Run clang-format on the whole tree
[lttng-tools.git] / src / lib / lttng-ctl / event.cpp
CommitLineData
eb5c4f4e
JG
1/*
2 * event.c
3 *
4 * Linux Trace Toolkit Control Library
5 *
ab5be9fa 6 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
eb5c4f4e 7 *
ab5be9fa 8 * SPDX-License-Identifier: LGPL-2.1-only
eb5c4f4e 9 *
eb5c4f4e
JG
10 */
11
12#define _LGPL_SOURCE
c9e313bc
SM
13#include <common/error.hpp>
14#include <common/sessiond-comm/sessiond-comm.hpp>
28ab034a 15
c9e313bc 16#include <lttng/event-internal.hpp>
ef0e06bc
JG
17#include <lttng/event.h>
18#include <lttng/lttng-error.h>
c9e313bc 19#include <lttng/userspace-probe-internal.hpp>
ef0e06bc 20
28ab034a
JG
21#include <stddef.h>
22
ef0e06bc
JG
23struct lttng_event *lttng_event_create(void)
24{
25 struct lttng_event *event;
26 struct lttng_event_extended *event_extended;
27
64803277 28 event = zmalloc<lttng_event>();
ef0e06bc
JG
29 if (!event) {
30 PERROR("Error allocating event structure");
31 goto end;
32 }
33
64803277 34 event_extended = zmalloc<lttng_event_extended>();
ef0e06bc
JG
35 if (!event_extended) {
36 PERROR("Error allocating event extended structure");
37 goto error;
38 }
39 event->extended.ptr = event_extended;
40end:
41 return event;
42error:
43 free(event);
37750a61 44 event = NULL;
ef0e06bc
JG
45 goto end;
46}
47
48void lttng_event_destroy(struct lttng_event *event)
49{
50 struct lttng_event_extended *event_extended;
51
52 if (!event) {
53 return;
54 }
55
56 event_extended = (struct lttng_event_extended *) event->extended.ptr;
57
58 if (event_extended) {
59 if (event_extended->probe_location) {
28ab034a 60 lttng_userspace_probe_location_destroy(event_extended->probe_location);
ef0e06bc
JG
61 }
62 free(event_extended);
63 }
64 free(event);
65}
eb5c4f4e 66
28ab034a 67int lttng_event_get_filter_expression(struct lttng_event *event, const char **filter_expression)
eb5c4f4e
JG
68{
69 int ret = 0;
de453daa 70 struct lttng_event_extended *event_extended;
eb5c4f4e
JG
71
72 if (!event || !filter_expression) {
73 ret = -LTTNG_ERR_INVALID;
74 goto end;
75 }
76
de453daa
JG
77 event_extended = (struct lttng_event_extended *) event->extended.ptr;
78 if (!event_extended) {
eb5c4f4e
JG
79 /*
80 * This can happen since the lttng_event structure is
81 * used for other tasks where this pointer is never set.
82 */
83 *filter_expression = NULL;
84 goto end;
85 }
86
de453daa 87 *filter_expression = event_extended->filter_expression;
eb5c4f4e
JG
88end:
89 return ret;
90}
91
92int lttng_event_get_exclusion_name_count(struct lttng_event *event)
93{
de453daa
JG
94 int ret = 0;
95 struct lttng_event_extended *event_extended;
eb5c4f4e
JG
96
97 if (!event) {
98 ret = -LTTNG_ERR_INVALID;
99 goto end;
100 }
101
de453daa
JG
102 event_extended = (struct lttng_event_extended *) event->extended.ptr;
103 if (!event_extended) {
eb5c4f4e
JG
104 /*
105 * This can happen since the lttng_event structure is
106 * used for other tasks where this pointer is never set.
107 */
eb5c4f4e
JG
108 goto end;
109 }
110
de453daa 111 if (event_extended->exclusions.count > INT_MAX) {
eb5c4f4e
JG
112 ret = -LTTNG_ERR_OVERFLOW;
113 goto end;
114 }
de453daa 115 ret = (int) event_extended->exclusions.count;
eb5c4f4e
JG
116end:
117 return ret;
118}
119
120int lttng_event_get_exclusion_name(struct lttng_event *event,
28ab034a
JG
121 size_t index,
122 const char **exclusion_name)
eb5c4f4e
JG
123{
124 int ret = 0;
de453daa 125 struct lttng_event_extended *event_extended;
eb5c4f4e
JG
126
127 if (!event || !exclusion_name) {
128 ret = -LTTNG_ERR_INVALID;
129 goto end;
130 }
131
de453daa
JG
132 if (index > UINT_MAX) {
133 ret = -LTTNG_ERR_OVERFLOW;
eb5c4f4e
JG
134 goto end;
135 }
136
de453daa
JG
137 event_extended = (struct lttng_event_extended *) event->extended.ptr;
138 if (!event_extended) {
139 /*
140 * This can happen since the lttng_event structure is
141 * used for other tasks where this pointer is never set.
142 */
eb5c4f4e
JG
143 ret = -LTTNG_ERR_INVALID;
144 goto end;
145 }
146
de453daa
JG
147 if (index >= event_extended->exclusions.count) {
148 ret = -LTTNG_ERR_INVALID;
149 goto end;
150 }
eb5c4f4e 151
28ab034a 152 *exclusion_name = event_extended->exclusions.strings + (index * LTTNG_SYMBOL_NAME_LEN);
eb5c4f4e
JG
153end:
154 return ret;
155}
ef0e06bc 156
87597c2c
JG
157const struct lttng_userspace_probe_location *
158lttng_event_get_userspace_probe_location(const struct lttng_event *event)
ef0e06bc
JG
159{
160 struct lttng_userspace_probe_location *probe_location = NULL;
161 struct lttng_event_extended *event_extended;
162
163 if (!event) {
164 goto end;
165 }
166
167 event_extended = (struct lttng_event_extended *) event->extended.ptr;
168 if (!event_extended) {
169 goto end;
170 }
171 probe_location = event_extended->probe_location;
172end:
173 return probe_location;
174}
175
176int lttng_event_set_userspace_probe_location(struct lttng_event *event,
28ab034a 177 struct lttng_userspace_probe_location *probe_location)
ef0e06bc
JG
178{
179 int ret = 0;
180 struct lttng_event_extended *event_extended;
181
182 if (!event || !probe_location) {
183 ret = -LTTNG_ERR_INVALID;
184 goto end;
185 }
186
187 event_extended = (struct lttng_event_extended *) event->extended.ptr;
a0377dfe 188 LTTNG_ASSERT(event_extended);
ef0e06bc 189 if (event_extended->probe_location) {
28ab034a 190 lttng_userspace_probe_location_destroy(event_extended->probe_location);
ef0e06bc
JG
191 }
192 event_extended->probe_location = probe_location;
193end:
194 return ret;
195}
This page took 0.049516 seconds and 4 git commands to generate.