b010df12aa56b8194241fd17af947a0c8e2e1009
[lttng-tools.git] / include / lttng / notification / channel.h
1 /*
2 * Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License, version 2.1 only,
6 * as published by the Free Software Foundation.
7 *
8 * This library is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11 * for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18 #ifndef LTTNG_NOTIFICATION_CHANNEL_H
19 #define LTTNG_NOTIFICATION_CHANNEL_H
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 struct lttng_endpoint;
26 struct lttng_condition;
27 struct lttng_notification;
28 struct lttng_notification_channel;
29
30 enum lttng_notification_channel_status {
31 LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED = 1,
32 LTTNG_NOTIFICATION_CHANNEL_STATUS_OK = 0,
33 LTTNG_NOTIFICATION_CHANNEL_STATUS_ERROR = -1,
34 LTTNG_NOTIFICATION_CHANNEL_STATUS_CLOSED = -2,
35 LTTNG_NOTIFICATION_CHANNEL_STATUS_ALREADY_SUBSCRIBED = -3,
36 /* Condition unknown. */
37 LTTNG_NOTIFICATION_CHANNEL_STATUS_UNKNOWN_CONDITION = -4,
38 LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID = -5,
39 LTTNG_NOTIFICATION_CHANNEL_STATUS_UNSUPPORTED_VERSION = -6,
40 };
41
42 /**
43 * A notification channel is used to receive notifications from various
44 * LTTng components.
45 *
46 * Notification channels connect a client to an LTTng endpoint
47 * (see lttng/endpoint.h) and allows client to subscribe and unsubscribe
48 * to various types of notifications which are associated to conditions.
49 *
50 * In order to emit a notification, a condition must be associated to a
51 * notify action within a trigger. A client wishing to consume such
52 * conditions must explicitly subscribe to them by using an equivalent
53 * condition.
54 */
55
56 /*
57 * Create a notification channel connected to a given endpoint.
58 *
59 * The only supported endpoint, at the moment, is the
60 * lttng_session_daemon_notification_endpoint, which is a singleton
61 * declared in the lttng/endpoint.h header.
62 *
63 * Returns an lttng_notification_channel on success, NULL on failure.
64 * The returned lttng_notification_channel must be destroyed using
65 * the lttng_notification_channel_destroy() function.
66 */
67 extern struct lttng_notification_channel *lttng_notification_channel_create(
68 struct lttng_endpoint *endpoint);
69
70 /*
71 * Get the next notification received on a notification channel.
72 *
73 * This call will block until a notification is received on the notification
74 * channel or until the endpoint closes the connection.
75 *
76 * The returned notification's ownership is transferred to the caller and
77 * it must be destroyed using lttng_notification_destroy().
78 *
79 * Notifications can be dropped if a client consumes the notifications sent
80 * through the notification channel too slowly.
81 *
82 * Returns LTTNG_NOTIFICATION_CHANNEL_STATUS_OK and a notification on success,
83 * LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID if an invalid parameter was
84 * provided, or LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED if
85 * notifications were dropped.
86 */
87 extern enum lttng_notification_channel_status
88 lttng_notification_channel_get_next_notification(
89 struct lttng_notification_channel *channel,
90 struct lttng_notification **notification);
91
92 /*
93 * Subscribe to notifications of a condition through a notification channel.
94 *
95 * The caller retains the ownership of the condition passed through this call
96 * and it can be disposed-of at any moment after this call.
97 *
98 * An error will be reported if the client tries to subscribe to the same
99 * condition multiple times without unsubscribing.
100 *
101 * Returns LTTNG_NOTIFICATION_CHANNEL_STATUS_OK on success,
102 * LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID if an invalid parameter was
103 * provided, or LTTNG_NOTIFICATION_CHANNEL_STATUS_ALREADY_SUBSCRIBED if the
104 * client was already subscribed to the condition through this channel.
105 */
106 extern enum lttng_notification_channel_status
107 lttng_notification_channel_subscribe(
108 struct lttng_notification_channel *channel,
109 const struct lttng_condition *condition);
110
111 /*
112 * Unsubscribe to notifications of a condition through a notification channel.
113 *
114 * The caller retains the ownership of the condition passed through this call
115 * and it can be disposed-of at any moment after this call.
116 *
117 * An error will be reported if the client tries to unsubscribe to from a
118 * conditions' notifications to which it was not previously subscribed.
119 *
120 * Returns 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_UNKNOWN_CONDITION if the
123 * client was not already subscribed to the condition through this channel.
124 */
125 extern enum lttng_notification_channel_status
126 lttng_notification_channel_unsubscribe(
127 struct lttng_notification_channel *channel,
128 const struct lttng_condition *condition);
129
130 /*
131 * Closes and destroys (frees) a notification channel.
132 */
133 extern void lttng_notification_channel_destroy(
134 struct lttng_notification_channel *channel);
135
136 #ifdef __cplusplus
137 }
138 #endif
139
140 #endif /* LTTNG_NOTIFICATION_CHANNEL_H */
This page took 0.031042 seconds and 3 git commands to generate.