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 | ||
11 | #include <lttng/notification/channel.h> | |
12 | #include <common/macros.h> | |
882093ee | 13 | #include <common/payload.h> |
a58c490f JG |
14 | #include <stdint.h> |
15 | #include <stdbool.h> | |
16 | #include <pthread.h> | |
17 | #include <urcu/list.h> | |
18 | ||
5e1d3533 JG |
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 | */ | |
a58c490f | 29 | #define LTTNG_NOTIFICATION_CHANNEL_VERSION_MAJOR 1 |
5e1d3533 | 30 | #define LTTNG_NOTIFICATION_CHANNEL_VERSION_MINOR 1 |
a58c490f JG |
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; | |
882093ee JR |
47 | /* Number of FDs sent. */ |
48 | uint32_t fds; | |
a58c490f JG |
49 | char payload[]; |
50 | } LTTNG_PACKED; | |
51 | ||
52 | struct lttng_notification_channel_command_handshake { | |
53 | uint8_t major; | |
54 | uint8_t minor; | |
55 | } LTTNG_PACKED; | |
56 | ||
57 | struct lttng_notification_channel_command_reply { | |
58 | /* enum lttng_notification_channel_status */ | |
59 | int8_t status; | |
60 | } LTTNG_PACKED; | |
61 | ||
62 | struct pending_notification { | |
63 | /* NULL means "notification dropped". */ | |
64 | struct lttng_notification *notification; | |
65 | struct cds_list_head node; | |
66 | }; | |
67 | ||
68 | /* | |
1dd25e28 | 69 | * The notification channel protocol is bidirectional and accommodates |
a58c490f JG |
70 | * synchronous and asynchronous communication modes: |
71 | * | |
72 | * - Synchronous: commands emitted by the client to which a reply is expected | |
73 | * (e.g. subscribing/unsubscribing to conditions), | |
74 | * - Asynchronous: notifications which are sent by the lttng_endpoint to the | |
4149ace8 | 75 | * client as one of the subscribed condition has occurred. |
a58c490f JG |
76 | * |
77 | * The nature of this hybrid communication mode means that asynchronous messages | |
78 | * (e.g. notifications) may be interleaved between synchronous messages (e.g. a | |
79 | * command and its reply). | |
80 | * | |
81 | * Notifications that are received between a command and its reply and enqueued | |
82 | * in the pending_notifications list. | |
83 | */ | |
84 | struct lttng_notification_channel { | |
85 | pthread_mutex_t lock; | |
86 | int socket; | |
87 | struct { | |
88 | /* Count of pending notifications. */ | |
89 | unsigned int count; | |
90 | /* List of struct pending_notification. */ | |
91 | struct cds_list_head list; | |
92 | } pending_notifications; | |
882093ee | 93 | struct lttng_payload reception_payload; |
a58c490f JG |
94 | /* Sessiond notification protocol version. */ |
95 | struct { | |
96 | bool set; | |
97 | int8_t major, minor; | |
98 | } version; | |
99 | }; | |
100 | ||
101 | #endif /* LTTNG_NOTIFICATION_CHANNEL_INTERNAL_H */ |