fix: relayd: unaligned access in trace_chunk_registry_ht_key_hash
[lttng-tools.git] / include / lttng / notification / channel-internal.hpp
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 <common/macros.hpp>
12 #include <common/make-unique-wrapper.hpp>
13 #include <common/payload.hpp>
14
15 #include <lttng/notification/channel.h>
16
17 #include <pthread.h>
18 #include <stdbool.h>
19 #include <stdint.h>
20 #include <urcu/list.h>
21
22 /*
23 * Protocol version change log:
24 * - v1.0
25 * - Initial implementation of the notification channel protocol,
26 * - Supported conditions are LOW/HIGH buffer usage conditions,
27 * - v1.1
28 * - New condition type "LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE" added,
29 * - New condition type "LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING" added,
30 * - New condition type "LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED" added,
31 */
32 #define LTTNG_NOTIFICATION_CHANNEL_VERSION_MAJOR 1
33 #define LTTNG_NOTIFICATION_CHANNEL_VERSION_MINOR 1
34
35 enum lttng_notification_channel_message_type {
36 LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_UNKNOWN = -1,
37 LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_HANDSHAKE = 0,
38 LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_SUBSCRIBE = 1,
39 LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_UNSUBSCRIBE = 2,
40 LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_COMMAND_REPLY = 3,
41 LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_NOTIFICATION = 4,
42 LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_NOTIFICATION_DROPPED = 5,
43 };
44
45 struct lttng_notification_channel_message {
46 /* enum lttng_notification_channel_message_type */
47 int8_t type;
48 /* Size of the payload following this field. */
49 uint32_t size;
50 /* Number of FDs sent. */
51 uint32_t fds;
52 char payload[];
53 } LTTNG_PACKED;
54
55 struct lttng_notification_channel_command_handshake {
56 uint8_t major;
57 uint8_t minor;
58 } LTTNG_PACKED;
59
60 struct lttng_notification_channel_command_reply {
61 /* enum lttng_notification_channel_status */
62 int8_t status;
63 } LTTNG_PACKED;
64
65 struct pending_notification {
66 /* NULL means "notification dropped". */
67 struct lttng_notification *notification;
68 struct cds_list_head node;
69 };
70
71 /*
72 * The notification channel protocol is bidirectional and accommodates
73 * synchronous and asynchronous communication modes:
74 *
75 * - Synchronous: commands emitted by the client to which a reply is expected
76 * (e.g. subscribing/unsubscribing to conditions),
77 * - Asynchronous: notifications which are sent by the lttng_endpoint to the
78 * client as one of the subscribed condition has occurred.
79 *
80 * The nature of this hybrid communication mode means that asynchronous messages
81 * (e.g. notifications) may be interleaved between synchronous messages (e.g. a
82 * command and its reply).
83 *
84 * Notifications that are received between a command and its reply and enqueued
85 * in the pending_notifications list.
86 */
87 struct lttng_notification_channel {
88 using uptr = std::unique_ptr<
89 lttng_notification_channel,
90 lttng::memory::create_deleter_class<lttng_notification_channel,
91 lttng_notification_channel_destroy>::deleter>;
92
93 pthread_mutex_t lock;
94 int socket;
95 struct {
96 /* Count of pending notifications. */
97 unsigned int count;
98 /* List of struct pending_notification. */
99 struct cds_list_head list;
100 } pending_notifications;
101 struct lttng_payload reception_payload;
102 /* Sessiond notification protocol version. */
103 struct {
104 bool set;
105 int8_t major, minor;
106 } version;
107 };
108
109 #endif /* LTTNG_NOTIFICATION_CHANNEL_INTERNAL_H */
This page took 0.03058 seconds and 4 git commands to generate.