Refactoring: context structures
[lttng-ust.git] / include / ust-context-provider.h
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (C) 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * The context provider feature is part of the ABI and used by the Java jni
7 * interface. This header should be moved to the public header directory once
8 * some test code and documentation is written.
9 */
10
11 #ifndef _LTTNG_UST_CONTEXT_PROVIDER_H
12 #define _LTTNG_UST_CONTEXT_PROVIDER_H
13
14 #include <stddef.h>
15 #include <lttng/ust-events.h>
16 #include <urcu/hlist.h>
17
18 #include "ust-dynamic-type.h"
19
20 /*
21 * Context value
22 *
23 * IMPORTANT: this structure is part of the ABI between the probe and
24 * UST. Fields need to be only added at the end, never reordered, never
25 * removed.
26 *
27 * The field @struct_size should be used to determine the size of the
28 * structure. It should be queried before using additional fields added
29 * at the end of the structure.
30 */
31
32 struct lttng_ust_ctx_value {
33 uint32_t struct_size;
34
35 enum lttng_ust_dynamic_type sel;
36 union {
37 int64_t s64;
38 uint64_t u64;
39 const char *str;
40 double d;
41 } u;
42
43 /* End of base ABI. Fields below should be used after checking struct_size. */
44 };
45
46 /*
47 * Context field
48 *
49 * IMPORTANT: this structure is part of the ABI between the probe and
50 * UST. Fields need to be only added at the end, never reordered, never
51 * removed.
52 *
53 * The field @struct_size should be used to determine the size of the
54 * structure. It should be queried before using additional fields added
55 * at the end of the structure.
56 */
57
58 struct lttng_ust_ctx_field {
59 uint32_t struct_size;
60 void *priv;
61
62 struct lttng_ust_event_field *event_field;
63 size_t (*get_size)(struct lttng_ust_ctx_field *field, size_t offset);
64 void (*record)(struct lttng_ust_ctx_field *field,
65 struct lttng_ust_lib_ring_buffer_ctx *ctx,
66 struct lttng_channel *chan);
67 void (*get_value)(struct lttng_ust_ctx_field *field,
68 struct lttng_ust_ctx_value *value);
69 void (*destroy)(struct lttng_ust_ctx_field *field);
70 char *field_name; /* Has ownership, dynamically allocated. */
71
72 /* End of base ABI. Fields below should be used after checking struct_size. */
73 };
74
75 /*
76 * All context fields for a given event/channel
77 *
78 * IMPORTANT: this structure is part of the ABI between the probe and
79 * UST. Fields need to be only added at the end, never reordered, never
80 * removed.
81 *
82 * The field @struct_size should be used to determine the size of the
83 * structure. It should be queried before using additional fields added
84 * at the end of the structure.
85 */
86
87 struct lttng_ust_ctx {
88 uint32_t struct_size;
89
90 struct lttng_ust_ctx_field **fields;
91 unsigned int nr_fields;
92 unsigned int allocated_fields;
93 unsigned int largest_align;
94
95 /* End of base ABI. Fields below should be used after checking struct_size. */
96 };
97
98 /*
99 * Context provider
100 *
101 * IMPORTANT: this structure is part of the ABI between the probe and
102 * UST. Fields need to be only added at the end, never reordered, never
103 * removed.
104 *
105 * The field @struct_size should be used to determine the size of the
106 * structure. It should be queried before using additional fields added
107 * at the end of the structure.
108 */
109
110 struct lttng_ust_context_provider {
111 uint32_t struct_size;
112
113 char *name;
114 size_t (*get_size)(struct lttng_ust_ctx_field *field, size_t offset);
115 void (*record)(struct lttng_ust_ctx_field *field,
116 struct lttng_ust_lib_ring_buffer_ctx *ctx,
117 struct lttng_channel *chan);
118 void (*get_value)(struct lttng_ust_ctx_field *field,
119 struct lttng_ust_ctx_value *value);
120 struct cds_hlist_node node;
121
122 /* End of base ABI. Fields below should be used after checking struct_size. */
123 };
124
125 int lttng_ust_context_provider_register(struct lttng_ust_context_provider *provider);
126 void lttng_ust_context_provider_unregister(struct lttng_ust_context_provider *provider);
127
128 void lttng_ust_context_set_session_provider(const char *name,
129 size_t (*get_size)(struct lttng_ust_ctx_field *field, size_t offset),
130 void (*record)(struct lttng_ust_ctx_field *field,
131 struct lttng_ust_lib_ring_buffer_ctx *ctx,
132 struct lttng_channel *chan),
133 void (*get_value)(struct lttng_ust_ctx_field *field,
134 struct lttng_ust_ctx_value *value));
135
136 int lttng_ust_add_app_context_to_ctx_rcu(const char *name, struct lttng_ust_ctx **ctx);
137 int lttng_ust_context_set_provider_rcu(struct lttng_ust_ctx **_ctx,
138 const char *name,
139 size_t (*get_size)(struct lttng_ust_ctx_field *field, size_t offset),
140 void (*record)(struct lttng_ust_ctx_field *field,
141 struct lttng_ust_lib_ring_buffer_ctx *ctx,
142 struct lttng_channel *chan),
143 void (*get_value)(struct lttng_ust_ctx_field *field,
144 struct lttng_ust_ctx_value *value));
145
146 #endif /* _LTTNG_UST_CONTEXT_PROVIDER_H */
This page took 0.052758 seconds and 4 git commands to generate.