2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #ifndef LTTNG_NOTIFICATION_CHANNEL_H
9 #define LTTNG_NOTIFICATION_CHANNEL_H
17 struct lttng_endpoint
;
18 struct lttng_condition
;
19 struct lttng_notification
;
20 struct lttng_notification_channel
;
22 enum lttng_notification_channel_status
{
23 LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED
= 1,
24 LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
= 2,
25 LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
= 0,
26 LTTNG_NOTIFICATION_CHANNEL_STATUS_ERROR
= -1,
27 LTTNG_NOTIFICATION_CHANNEL_STATUS_CLOSED
= -2,
28 LTTNG_NOTIFICATION_CHANNEL_STATUS_ALREADY_SUBSCRIBED
= -3,
29 /* Condition unknown. */
30 LTTNG_NOTIFICATION_CHANNEL_STATUS_UNKNOWN_CONDITION
= -4,
31 LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
= -5,
32 LTTNG_NOTIFICATION_CHANNEL_STATUS_UNSUPPORTED_VERSION
= -6,
36 * A notification channel is used to receive notifications from various
39 * Notification channels connect a client to an LTTng endpoint
40 * (see lttng/endpoint.h) and allows client to subscribe and unsubscribe
41 * to various types of notifications which are associated to conditions.
43 * In order to emit a notification, a condition must be associated to a
44 * notify action within a trigger. A client wishing to consume such
45 * conditions must explicitly subscribe to them by using an equivalent
50 * Create a notification channel connected to a given endpoint.
52 * The only supported endpoint, at the moment, is the
53 * lttng_session_daemon_notification_endpoint, which is a singleton
54 * declared in the lttng/endpoint.h header.
56 * Returns an lttng_notification_channel on success, NULL on failure.
57 * The returned lttng_notification_channel must be destroyed using
58 * the lttng_notification_channel_destroy() function.
60 extern struct lttng_notification_channel
*lttng_notification_channel_create(
61 struct lttng_endpoint
*endpoint
);
64 * Get the next notification received on a notification channel.
66 * This call will block until a notification is received on the notification
67 * channel or until the endpoint closes the connection.
69 * The returned notification's ownership is transferred to the caller and
70 * it must be destroyed using lttng_notification_destroy().
72 * Notifications can be dropped if a client consumes the notifications sent
73 * through the notification channel too slowly.
76 * - LTTNG_NOTIFICATION_CHANNEL_STATUS_OK and a notification on success,
77 * - LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID if an invalid parameter was
79 * - LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED if notifications
81 * - LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED if a signal was received
82 * that caused the reception to fail.
84 extern enum lttng_notification_channel_status
85 lttng_notification_channel_get_next_notification(
86 struct lttng_notification_channel
*channel
,
87 struct lttng_notification
**notification
);
90 * Check whether a notification is pending on a notification channel.
92 * This call allows the user to check whether a notification is pending on
93 * the notification channel.
95 * If pending is set to true and the return value is
96 * LTTNG_NOTIFICATION_CHANNEL_STATUS_OK,
97 * lttng_notification_channel_get_next_notification() can be called and
98 * is guaranteed to not block.
101 * - LTTNG_NOTIFICATION_CHANNEL_STATUS_OK on success,
102 * - LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID if an invalid parameter was
105 extern enum lttng_notification_channel_status
106 lttng_notification_channel_has_pending_notification(
107 struct lttng_notification_channel
*channel
,
108 bool *notification_pending
);
111 * Subscribe to notifications of a condition through a notification channel.
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.
116 * An error will be reported if the client tries to subscribe to the same
117 * condition multiple times without unsubscribing.
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.
125 extern enum lttng_notification_channel_status
126 lttng_notification_channel_subscribe(
127 struct lttng_notification_channel
*channel
,
128 const struct lttng_condition
*condition
);
131 * Unsubscribe to notifications of a condition through a notification channel.
133 * The caller retains the ownership of the condition passed through this call
134 * and it can be disposed-of at any moment after this call.
136 * An error will be reported if the client tries to unsubscribe to from a
137 * conditions' notifications to which it was not previously subscribed.
140 * - LTTNG_NOTIFICATION_CHANNEL_STATUS_OK on success,
141 * - LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID if an invalid parameter was
142 * provided, or LTTNG_NOTIFICATION_CHANNEL_STATUS_UNKNOWN_CONDITION if the
143 * client was not already subscribed to the condition through this channel.
145 extern enum lttng_notification_channel_status
146 lttng_notification_channel_unsubscribe(
147 struct lttng_notification_channel
*channel
,
148 const struct lttng_condition
*condition
);
151 * Closes and destroys (frees) a notification channel.
153 extern void lttng_notification_channel_destroy(
154 struct lttng_notification_channel
*channel
);
160 #endif /* LTTNG_NOTIFICATION_CHANNEL_H */