Commit | Line | Data |
---|---|---|
a58c490f | 1 | /* |
ab5be9fa | 2 | * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
a58c490f | 3 | * |
ab5be9fa | 4 | * SPDX-License-Identifier: LGPL-2.1-only |
a58c490f | 5 | * |
a58c490f JG |
6 | */ |
7 | ||
8 | #ifndef LTTNG_NOTIFICATION_CHANNEL_INTERNAL_H | |
9 | #define LTTNG_NOTIFICATION_CHANNEL_INTERNAL_H | |
10 | ||
c9e313bc | 11 | #include <common/macros.hpp> |
0038180d | 12 | #include <common/make-unique-wrapper.hpp> |
c9e313bc | 13 | #include <common/payload.hpp> |
0038180d JG |
14 | |
15 | #include <lttng/notification/channel.h> | |
16 | ||
a58c490f | 17 | #include <pthread.h> |
0038180d JG |
18 | #include <stdbool.h> |
19 | #include <stdint.h> | |
a58c490f JG |
20 | #include <urcu/list.h> |
21 | ||
5e1d3533 JG |
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 | */ | |
a58c490f | 32 | #define LTTNG_NOTIFICATION_CHANNEL_VERSION_MAJOR 1 |
5e1d3533 | 33 | #define LTTNG_NOTIFICATION_CHANNEL_VERSION_MINOR 1 |
a58c490f JG |
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; | |
882093ee JR |
50 | /* Number of FDs sent. */ |
51 | uint32_t fds; | |
a58c490f JG |
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 | /* | |
1dd25e28 | 72 | * The notification channel protocol is bidirectional and accommodates |
a58c490f JG |
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 | |
4149ace8 | 78 | * client as one of the subscribed condition has occurred. |
a58c490f JG |
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 { | |
0038180d JG |
88 | using uptr = std::unique_ptr< |
89 | lttng_notification_channel, | |
f053d40c | 90 | lttng::memory::create_deleter_class<lttng_notification_channel, |
28f23191 | 91 | lttng_notification_channel_destroy>::deleter>; |
0038180d | 92 | |
a58c490f JG |
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; | |
882093ee | 101 | struct lttng_payload reception_payload; |
a58c490f JG |
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 */ |