Commit | Line | Data |
---|---|---|
a58c490f | 1 | /* |
ab5be9fa | 2 | * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
a58c490f | 3 | * |
ab5be9fa | 4 | * SPDX-License-Identifier: LGPL-2.1-only |
a58c490f | 5 | * |
a58c490f JG |
6 | */ |
7 | ||
8 | #ifndef LTTNG_NOTIFICATION_CHANNEL_H | |
9 | #define LTTNG_NOTIFICATION_CHANNEL_H | |
10 | ||
4bd69c5f | 11 | #include <lttng/lttng-export.h> |
28f23191 | 12 | |
1d757b1c JG |
13 | #include <stdbool.h> |
14 | ||
a58c490f JG |
15 | #ifdef __cplusplus |
16 | extern "C" { | |
17 | #endif | |
18 | ||
19 | struct lttng_endpoint; | |
20 | struct lttng_condition; | |
21 | struct lttng_notification; | |
22 | struct lttng_notification_channel; | |
23 | ||
a58c490f JG |
24 | enum lttng_notification_channel_status { |
25 | LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED = 1, | |
f83bcd90 | 26 | LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED = 2, |
a58c490f JG |
27 | LTTNG_NOTIFICATION_CHANNEL_STATUS_OK = 0, |
28 | LTTNG_NOTIFICATION_CHANNEL_STATUS_ERROR = -1, | |
29 | LTTNG_NOTIFICATION_CHANNEL_STATUS_CLOSED = -2, | |
30 | LTTNG_NOTIFICATION_CHANNEL_STATUS_ALREADY_SUBSCRIBED = -3, | |
31 | /* Condition unknown. */ | |
32 | LTTNG_NOTIFICATION_CHANNEL_STATUS_UNKNOWN_CONDITION = -4, | |
33 | LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID = -5, | |
34 | LTTNG_NOTIFICATION_CHANNEL_STATUS_UNSUPPORTED_VERSION = -6, | |
35 | }; | |
36 | ||
92eda4bd JG |
37 | /** |
38 | * A notification channel is used to receive notifications from various | |
39 | * LTTng components. | |
40 | * | |
41 | * Notification channels connect a client to an LTTng endpoint | |
42 | * (see lttng/endpoint.h) and allows client to subscribe and unsubscribe | |
43 | * to various types of notifications which are associated to conditions. | |
44 | * | |
45 | * In order to emit a notification, a condition must be associated to a | |
46 | * notify action within a trigger. A client wishing to consume such | |
47 | * conditions must explicitly subscribe to them by using an equivalent | |
48 | * condition. | |
49 | */ | |
50 | ||
51 | /* | |
52 | * Create a notification channel connected to a given endpoint. | |
53 | * | |
54 | * The only supported endpoint, at the moment, is the | |
55 | * lttng_session_daemon_notification_endpoint, which is a singleton | |
56 | * declared in the lttng/endpoint.h header. | |
57 | * | |
58 | * Returns an lttng_notification_channel on success, NULL on failure. | |
59 | * The returned lttng_notification_channel must be destroyed using | |
60 | * the lttng_notification_channel_destroy() function. | |
61 | */ | |
28f23191 JG |
62 | LTTNG_EXPORT extern struct lttng_notification_channel * |
63 | lttng_notification_channel_create(struct lttng_endpoint *endpoint); | |
a58c490f | 64 | |
92eda4bd JG |
65 | /* |
66 | * Get the next notification received on a notification channel. | |
67 | * | |
68 | * This call will block until a notification is received on the notification | |
69 | * channel or until the endpoint closes the connection. | |
70 | * | |
71 | * The returned notification's ownership is transferred to the caller and | |
72 | * it must be destroyed using lttng_notification_destroy(). | |
73 | * | |
74 | * Notifications can be dropped if a client consumes the notifications sent | |
75 | * through the notification channel too slowly. | |
76 | * | |
f83bcd90 JG |
77 | * Returns |
78 | * - LTTNG_NOTIFICATION_CHANNEL_STATUS_OK and a notification on success, | |
79 | * - LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID if an invalid parameter was | |
80 | * provided, | |
81 | * - LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED if notifications | |
82 | * were dropped, | |
83 | * - LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED if a signal was received | |
84 | * that caused the reception to fail. | |
92eda4bd | 85 | */ |
4bd69c5f | 86 | LTTNG_EXPORT extern enum lttng_notification_channel_status |
28f23191 JG |
87 | lttng_notification_channel_get_next_notification(struct lttng_notification_channel *channel, |
88 | struct lttng_notification **notification); | |
a58c490f | 89 | |
1d757b1c JG |
90 | /* |
91 | * Check whether a notification is pending on a notification channel. | |
92 | * | |
93 | * This call allows the user to check whether a notification is pending on | |
94 | * the notification channel. | |
95 | * | |
96 | * If pending is set to true and the return value is | |
97 | * LTTNG_NOTIFICATION_CHANNEL_STATUS_OK, | |
98 | * lttng_notification_channel_get_next_notification() can be called and | |
99 | * is guaranteed to not block. | |
100 | * | |
f83bcd90 JG |
101 | * Returns |
102 | * - LTTNG_NOTIFICATION_CHANNEL_STATUS_OK on success, | |
103 | * - LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID if an invalid parameter was | |
104 | * provided. | |
1d757b1c | 105 | */ |
4bd69c5f | 106 | LTTNG_EXPORT extern enum lttng_notification_channel_status |
28f23191 JG |
107 | lttng_notification_channel_has_pending_notification(struct lttng_notification_channel *channel, |
108 | bool *notification_pending); | |
1d757b1c | 109 | |
92eda4bd JG |
110 | /* |
111 | * Subscribe to notifications of a condition through a notification channel. | |
112 | * | |
113 | * The caller retains the ownership of the condition passed through this call | |
114 | * and it can be disposed-of at any moment after this call. | |
115 | * | |
116 | * An error will be reported if the client tries to subscribe to the same | |
117 | * condition multiple times without unsubscribing. | |
118 | * | |
f83bcd90 JG |
119 | * Returns |
120 | * - LTTNG_NOTIFICATION_CHANNEL_STATUS_OK on success, | |
121 | * - LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID if an invalid parameter was | |
122 | * provided, or LTTNG_NOTIFICATION_CHANNEL_STATUS_ALREADY_SUBSCRIBED if the | |
123 | * client was already subscribed to the condition through this channel. | |
92eda4bd | 124 | */ |
4bd69c5f | 125 | LTTNG_EXPORT extern enum lttng_notification_channel_status |
28f23191 JG |
126 | lttng_notification_channel_subscribe(struct lttng_notification_channel *channel, |
127 | const struct lttng_condition *condition); | |
a58c490f | 128 | |
92eda4bd JG |
129 | /* |
130 | * Unsubscribe to notifications of a condition through a notification channel. | |
131 | * | |
132 | * The caller retains the ownership of the condition passed through this call | |
133 | * and it can be disposed-of at any moment after this call. | |
134 | * | |
135 | * An error will be reported if the client tries to unsubscribe to from a | |
136 | * conditions' notifications to which it was not previously subscribed. | |
137 | * | |
f83bcd90 JG |
138 | * Returns |
139 | * - LTTNG_NOTIFICATION_CHANNEL_STATUS_OK on success, | |
140 | * - LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID if an invalid parameter was | |
141 | * provided, or LTTNG_NOTIFICATION_CHANNEL_STATUS_UNKNOWN_CONDITION if the | |
142 | * client was not already subscribed to the condition through this channel. | |
92eda4bd | 143 | */ |
4bd69c5f | 144 | LTTNG_EXPORT extern enum lttng_notification_channel_status |
28f23191 JG |
145 | lttng_notification_channel_unsubscribe(struct lttng_notification_channel *channel, |
146 | const struct lttng_condition *condition); | |
a58c490f | 147 | |
92eda4bd JG |
148 | /* |
149 | * Closes and destroys (frees) a notification channel. | |
150 | */ | |
28f23191 JG |
151 | LTTNG_EXPORT extern void |
152 | lttng_notification_channel_destroy(struct lttng_notification_channel *channel); | |
a58c490f JG |
153 | |
154 | #ifdef __cplusplus | |
155 | } | |
156 | #endif | |
157 | ||
158 | #endif /* LTTNG_NOTIFICATION_CHANNEL_H */ |