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
11 #include <lttng/lttng-export.h>
19 struct lttng_endpoint
;
20 struct lttng_condition
;
21 struct lttng_notification
;
22 struct lttng_notification_channel
;
24 enum lttng_notification_channel_status
{
25 LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED
= 1,
26 LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
= 2,
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,
38 * A notification channel is used to receive notifications from various
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.
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
52 * Create a notification channel connected to a given endpoint.
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.
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.
62 LTTNG_EXPORT
extern struct lttng_notification_channel
*
63 lttng_notification_channel_create(struct lttng_endpoint
*endpoint
);
66 * Get the next notification received on a notification channel.
68 * This call will block until a notification is received on the notification
69 * channel or until the endpoint closes the connection.
71 * The returned notification's ownership is transferred to the caller and
72 * it must be destroyed using lttng_notification_destroy().
74 * Notifications can be dropped if a client consumes the notifications sent
75 * through the notification channel too slowly.
78 * - LTTNG_NOTIFICATION_CHANNEL_STATUS_OK and a notification on success,
79 * - LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID if an invalid parameter was
81 * - LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED if notifications
83 * - LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED if a signal was received
84 * that caused the reception to fail.
86 LTTNG_EXPORT
extern enum lttng_notification_channel_status
87 lttng_notification_channel_get_next_notification(struct lttng_notification_channel
*channel
,
88 struct lttng_notification
**notification
);
91 * Check whether a notification is pending on a notification channel.
93 * This call allows the user to check whether a notification is pending on
94 * the notification channel.
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.
102 * - LTTNG_NOTIFICATION_CHANNEL_STATUS_OK on success,
103 * - LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID if an invalid parameter was
106 LTTNG_EXPORT
extern enum lttng_notification_channel_status
107 lttng_notification_channel_has_pending_notification(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 LTTNG_EXPORT
extern enum lttng_notification_channel_status
126 lttng_notification_channel_subscribe(struct lttng_notification_channel
*channel
,
127 const struct lttng_condition
*condition
);
130 * Unsubscribe to notifications of a condition through a notification channel.
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.
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.
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.
144 LTTNG_EXPORT
extern enum lttng_notification_channel_status
145 lttng_notification_channel_unsubscribe(struct lttng_notification_channel
*channel
,
146 const struct lttng_condition
*condition
);
149 * Closes and destroys (frees) a notification channel.
151 LTTNG_EXPORT
extern void
152 lttng_notification_channel_destroy(struct lttng_notification_channel
*channel
);
158 #endif /* LTTNG_NOTIFICATION_CHANNEL_H */