2 * Copyright (C) 2019 - Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License, version 2.1 only,
6 * as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #include <common/defaults.h>
20 #include <common/error.h>
21 #include <common/macros.h>
22 #include <common/sessiond-comm/sessiond-comm.h>
23 #include <common/uri.h>
24 #include <lttng/tracker-internal.h>
28 struct lttng_tracker_id
*lttng_tracker_id_create(void)
30 struct lttng_tracker_id
*id
;
32 id
= zmalloc(sizeof(*id
));
37 id
->type
= LTTNG_ID_UNKNOWN
;
42 lttng_tracker_id_destroy(id
);
46 enum lttng_tracker_id_status
lttng_tracker_id_set_value(
47 struct lttng_tracker_id
*id
, int value
)
52 return LTTNG_TRACKER_ID_STATUS_INVALID
;
55 id
->type
= LTTNG_ID_VALUE
;
57 return LTTNG_TRACKER_ID_STATUS_OK
;
60 enum lttng_tracker_id_status
lttng_tracker_id_set_string(
61 struct lttng_tracker_id
*id
, const char *value
)
66 id
->type
= LTTNG_ID_STRING
;
67 id
->string
= strdup(value
);
68 if (id
->string
== NULL
) {
73 return LTTNG_TRACKER_ID_STATUS_OK
;
75 return LTTNG_TRACKER_ID_STATUS_INVALID
;
78 enum lttng_tracker_id_status
lttng_tracker_id_set_all(
79 struct lttng_tracker_id
*id
)
83 id
->type
= LTTNG_ID_ALL
;
85 return LTTNG_TRACKER_ID_STATUS_OK
;
88 void lttng_tracker_id_destroy(struct lttng_tracker_id
*id
)
94 if (id
->string
!= NULL
) {
101 void lttng_tracker_ids_destroy(struct lttng_tracker_id
**ids
, size_t nr_ids
)
107 for (int i
= 0; i
< nr_ids
; i
++) {
108 lttng_tracker_id_destroy(ids
[i
]);
112 enum lttng_tracker_id_type
lttng_tracker_id_get_type(
113 const struct lttng_tracker_id
*id
)
119 enum lttng_tracker_id_status
lttng_tracker_id_get_value(
120 const struct lttng_tracker_id
*id
, int *value
)
123 if (id
->type
== LTTNG_ID_UNKNOWN
) {
124 return LTTNG_TRACKER_ID_STATUS_UNSET
;
127 if (id
->type
!= LTTNG_ID_VALUE
) {
128 return LTTNG_TRACKER_ID_STATUS_INVALID
;
132 return LTTNG_TRACKER_ID_STATUS_OK
;
135 bool lttng_tracker_id_is_equal(const struct lttng_tracker_id
*left
,
136 const struct lttng_tracker_id
*right
)
138 if (left
->type
!= right
->type
) {
142 switch (left
->type
) {
146 if (left
->value
!= right
->value
) {
150 case LTTNG_ID_STRING
:
151 if (strcmp(left
->string
, right
->string
) != 0) {
157 * Normally this should return true, but comparing unset tracker
165 struct lttng_tracker_id
*lttng_tracker_id_copy(
166 const struct lttng_tracker_id
*orig
)
168 struct lttng_tracker_id
*copy
= NULL
;
169 enum lttng_tracker_id_status status
;
171 copy
= lttng_tracker_id_create();
176 switch (orig
->type
) {
178 status
= lttng_tracker_id_set_all(copy
);
181 status
= lttng_tracker_id_set_value(copy
, orig
->value
);
182 if (status
!= LTTNG_TRACKER_ID_STATUS_OK
) {
186 case LTTNG_ID_STRING
:
187 status
= lttng_tracker_id_set_string(copy
, orig
->string
);
188 if (status
!= LTTNG_TRACKER_ID_STATUS_OK
) {
193 status
= LTTNG_TRACKER_ID_STATUS_OK
;
197 if (status
!= LTTNG_TRACKER_ID_STATUS_OK
) {
203 lttng_tracker_id_destroy(copy
);
207 enum lttng_tracker_id_status
lttng_tracker_id_get_string(
208 const struct lttng_tracker_id
*id
, const char **value
)
211 if (id
->type
== LTTNG_ID_UNKNOWN
) {
213 return LTTNG_TRACKER_ID_STATUS_UNSET
;
216 if (id
->type
!= LTTNG_ID_STRING
) {
218 return LTTNG_TRACKER_ID_STATUS_INVALID
;
222 return LTTNG_TRACKER_ID_STATUS_OK
;