f7df8e5206999154a8afb3ebf480523a4a75497d
[lttng-tools.git] / include / lttng / notification / channel-internal.h
1 /*
2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8 #ifndef LTTNG_NOTIFICATION_CHANNEL_INTERNAL_H
9 #define LTTNG_NOTIFICATION_CHANNEL_INTERNAL_H
10
11 #include <lttng/notification/channel.h>
12 #include <common/macros.h>
13 #include <common/dynamic-buffer.h>
14 #include <stdint.h>
15 #include <stdbool.h>
16 #include <pthread.h>
17 #include <urcu/list.h>
18
19 /*
20 * Protocol version change log:
21 * - v1.0
22 * - Initial implementation of the notification channel protocol,
23 * - Supported conditions are LOW/HIGH buffer usage conditions,
24 * - v1.1
25 * - New condition type "LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE" added,
26 * - New condition type "LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING" added,
27 * - New condition type "LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED" added,
28 */
29 #define LTTNG_NOTIFICATION_CHANNEL_VERSION_MAJOR 1
30 #define LTTNG_NOTIFICATION_CHANNEL_VERSION_MINOR 1
31
32 enum lttng_notification_channel_message_type {
33 LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_UNKNOWN = -1,
34 LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_HANDSHAKE = 0,
35 LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_SUBSCRIBE = 1,
36 LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_UNSUBSCRIBE = 2,
37 LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_COMMAND_REPLY = 3,
38 LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_NOTIFICATION = 4,
39 LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_NOTIFICATION_DROPPED = 5,
40 };
41
42 struct lttng_notification_channel_message {
43 /* enum lttng_notification_channel_message_type */
44 int8_t type;
45 /* Size of the payload following this field. */
46 uint32_t size;
47 char payload[];
48 } LTTNG_PACKED;
49
50 struct lttng_notification_channel_command_handshake {
51 uint8_t major;
52 uint8_t minor;
53 } LTTNG_PACKED;
54
55 struct lttng_notification_channel_command_reply {
56 /* enum lttng_notification_channel_status */
57 int8_t status;
58 } LTTNG_PACKED;
59
60 struct pending_notification {
61 /* NULL means "notification dropped". */
62 struct lttng_notification *notification;
63 struct cds_list_head node;
64 };
65
66 /*
67 * The notification channel protocol is bidirectional and accommodates
68 * synchronous and asynchronous communication modes:
69 *
70 * - Synchronous: commands emitted by the client to which a reply is expected
71 * (e.g. subscribing/unsubscribing to conditions),
72 * - Asynchronous: notifications which are sent by the lttng_endpoint to the
73 * client as one of the subscribed condition has occurred.
74 *
75 * The nature of this hybrid communication mode means that asynchronous messages
76 * (e.g. notifications) may be interleaved between synchronous messages (e.g. a
77 * command and its reply).
78 *
79 * Notifications that are received between a command and its reply and enqueued
80 * in the pending_notifications list.
81 */
82 struct lttng_notification_channel {
83 pthread_mutex_t lock;
84 int socket;
85 struct {
86 /* Count of pending notifications. */
87 unsigned int count;
88 /* List of struct pending_notification. */
89 struct cds_list_head list;
90 } pending_notifications;
91 struct lttng_dynamic_buffer reception_buffer;
92 /* Sessiond notification protocol version. */
93 struct {
94 bool set;
95 int8_t major, minor;
96 } version;
97 };
98
99 #endif /* LTTNG_NOTIFICATION_CHANNEL_INTERNAL_H */
This page took 0.030736 seconds and 4 git commands to generate.