Commit | Line | Data |
---|---|---|
d28fcdec PP |
1 | /* |
2 | * Copyright (C) 2020 Philippe Proulx <pproulx@efficios.com> | |
3 | * | |
4 | * SPDX-License-Identifier: LGPL-2.1-only | |
5 | * | |
6 | */ | |
7 | ||
8 | #ifndef LTTNG_EVENT_FIELD_VALUE_INTERNAL_H | |
9 | #define LTTNG_EVENT_FIELD_VALUE_INTERNAL_H | |
10 | ||
c9e313bc | 11 | #include <common/dynamic-array.hpp> |
d28fcdec | 12 | |
28f23191 JG |
13 | #include <lttng/event-field-value.h> |
14 | ||
15 | #include <stdint.h> | |
16 | ||
d28fcdec PP |
17 | struct lttng_event_field_value { |
18 | enum lttng_event_field_value_type type; | |
19 | }; | |
20 | ||
21 | /* | |
22 | * `LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_INT`. | |
23 | */ | |
24 | struct lttng_event_field_value_uint { | |
25 | struct lttng_event_field_value parent; | |
26 | uint64_t val; | |
27 | }; | |
28 | ||
29 | /* | |
30 | * `LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_INT`. | |
31 | */ | |
32 | struct lttng_event_field_value_int { | |
33 | struct lttng_event_field_value parent; | |
34 | int64_t val; | |
35 | }; | |
36 | ||
37 | /* | |
38 | * `LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM` and | |
39 | * `LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM` (base). | |
40 | */ | |
41 | struct lttng_event_field_value_enum { | |
42 | struct lttng_event_field_value parent; | |
43 | ||
44 | /* | |
45 | * Array of `char *` (owned by this). | |
46 | */ | |
47 | struct lttng_dynamic_pointer_array labels; | |
48 | }; | |
49 | ||
50 | /* | |
51 | * `LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM`. | |
52 | */ | |
53 | struct lttng_event_field_value_enum_uint { | |
54 | struct lttng_event_field_value_enum parent; | |
55 | uint64_t val; | |
56 | }; | |
57 | ||
58 | /* | |
59 | * `LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM`. | |
60 | */ | |
61 | struct lttng_event_field_value_enum_int { | |
62 | struct lttng_event_field_value_enum parent; | |
63 | int64_t val; | |
64 | }; | |
65 | ||
66 | /* `LTTNG_EVENT_FIELD_VALUE_TYPE_REAL` */ | |
67 | struct lttng_event_field_value_real { | |
68 | struct lttng_event_field_value parent; | |
69 | double val; | |
70 | }; | |
71 | ||
72 | /* `LTTNG_EVENT_FIELD_VALUE_TYPE_STRING` */ | |
73 | struct lttng_event_field_value_string { | |
74 | struct lttng_event_field_value parent; | |
75 | ||
76 | /* Owned by this */ | |
77 | char *val; | |
78 | }; | |
79 | ||
80 | /* `LTTNG_EVENT_FIELD_VALUE_TYPE_STRING` */ | |
81 | struct lttng_event_field_value_array { | |
82 | struct lttng_event_field_value parent; | |
83 | ||
84 | /* | |
85 | * Array of `struct lttng_event_field_value *` (owned by this). | |
86 | * | |
87 | * A `NULL` element means it's unavailable | |
88 | * (`LTTNG_EVENT_FIELD_VALUE_STATUS_UNAVAILABLE` status). | |
89 | */ | |
90 | struct lttng_dynamic_pointer_array elems; | |
91 | }; | |
92 | ||
93 | /* | |
94 | * This is internal since the session daemon knows nothing about the | |
95 | * enumeration fields produced by the kernel tracer. Indeed, the kernel tracer | |
96 | * manages its own metadata which remains opaque to the rest of the toolchain. | |
97 | * | |
98 | * Enumerations could be supported for the user space tracer, but it is not the | |
99 | * case right now. | |
100 | */ | |
101 | ||
102 | /* | |
103 | * Sets `*count` to the number of labels of the enumeration event field | |
104 | * value `field_val`. | |
105 | * | |
106 | * Returns: | |
107 | * | |
108 | * `LTTNG_EVENT_FIELD_VALUE_STATUS_OK`: | |
109 | * Success. | |
110 | * | |
111 | * `LTTNG_EVENT_FIELD_VALUE_STATUS_INVALID`: | |
112 | * * `field_val` is `NULL`. | |
113 | * * The type of `field_val` is not | |
114 | * `LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM` or | |
115 | * `LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM`. | |
116 | * * `count` is `NULL`. | |
117 | */ | |
d28fcdec | 118 | enum lttng_event_field_value_status |
28f23191 JG |
119 | lttng_event_field_value_enum_get_label_count(const struct lttng_event_field_value *field_val, |
120 | unsigned int *count); | |
d28fcdec PP |
121 | |
122 | /* | |
123 | * Returns the label at index `index` of the enumeration event field | |
124 | * value `field_val`, or `NULL` if: | |
125 | * | |
126 | * * `field_val` is `NULL`. | |
127 | * * The type of `field_val` is not | |
128 | * `LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM` or | |
129 | * `LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM`. | |
130 | * * `index` is greater than or equal to the label count of `field_val`, | |
131 | * as returned by lttng_event_field_value_enum_get_label_count(). | |
132 | */ | |
28f23191 JG |
133 | const char * |
134 | lttng_event_field_value_enum_get_label_at_index(const struct lttng_event_field_value *field_val, | |
135 | unsigned int index); | |
d28fcdec | 136 | |
28f23191 | 137 | struct lttng_event_field_value *lttng_event_field_value_uint_create(uint64_t val); |
d28fcdec | 138 | |
28f23191 | 139 | struct lttng_event_field_value *lttng_event_field_value_int_create(int64_t val); |
d28fcdec | 140 | |
28f23191 | 141 | struct lttng_event_field_value *lttng_event_field_value_enum_uint_create(uint64_t val); |
d28fcdec | 142 | |
28f23191 | 143 | struct lttng_event_field_value *lttng_event_field_value_enum_int_create(int64_t val); |
d28fcdec | 144 | |
d28fcdec PP |
145 | struct lttng_event_field_value *lttng_event_field_value_real_create(double val); |
146 | ||
28f23191 | 147 | struct lttng_event_field_value *lttng_event_field_value_string_create(const char *val); |
d28fcdec | 148 | |
28f23191 JG |
149 | struct lttng_event_field_value *lttng_event_field_value_string_create_with_size(const char *val, |
150 | size_t size); | |
d28fcdec | 151 | |
cd9adb8b | 152 | struct lttng_event_field_value *lttng_event_field_value_array_create(); |
d28fcdec | 153 | |
28f23191 JG |
154 | int lttng_event_field_value_enum_append_label(struct lttng_event_field_value *field_val, |
155 | const char *label); | |
d28fcdec | 156 | |
28f23191 JG |
157 | int lttng_event_field_value_enum_append_label_with_size(struct lttng_event_field_value *field_val, |
158 | const char *label, | |
159 | size_t size); | |
d28fcdec | 160 | |
28f23191 JG |
161 | int lttng_event_field_value_array_append(struct lttng_event_field_value *array_field_val, |
162 | struct lttng_event_field_value *field_val); | |
d28fcdec | 163 | |
d28fcdec | 164 | int lttng_event_field_value_array_append_unavailable( |
28f23191 | 165 | struct lttng_event_field_value *array_field_val); |
d28fcdec | 166 | |
d28fcdec PP |
167 | void lttng_event_field_value_destroy(struct lttng_event_field_value *field_val); |
168 | ||
169 | #endif /* LTTNG_EVENT_FIELD_VALUE_INTERNAL_H */ |