ebbb7467e105f37a13886a547f7c56cdcef214fc
[babeltrace.git] / src / plugins / ctf / lttng-live / viewer-connection.hpp
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 */
6
7 #ifndef BABELTRACE_PLUGINS_CTF_LTTNG_LIVE_VIEWER_CONNECTION_HPP
8 #define BABELTRACE_PLUGINS_CTF_LTTNG_LIVE_VIEWER_CONNECTION_HPP
9
10 #include <memory>
11 #include <string>
12
13 #include <glib.h>
14 #include <stdint.h>
15
16 #include <babeltrace2/babeltrace.h>
17
18 #include "compat/socket.hpp"
19 #include "cpp-common/bt2/value.hpp"
20 #include "cpp-common/bt2c/glib-up.hpp"
21 #include "cpp-common/bt2c/logging.hpp"
22
23 #define LTTNG_DEFAULT_NETWORK_VIEWER_PORT 5344
24
25 #define LTTNG_LIVE_MAJOR 2
26 #define LTTNG_LIVE_MINOR 4
27
28 enum lttng_live_viewer_status
29 {
30 LTTNG_LIVE_VIEWER_STATUS_OK = 0,
31 LTTNG_LIVE_VIEWER_STATUS_ERROR = -1,
32 LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED = -2,
33 };
34
35 enum lttng_live_get_one_metadata_status
36 {
37 /* The end of the metadata stream was reached. */
38 LTTNG_LIVE_GET_ONE_METADATA_STATUS_END = 1,
39 /* One metadata packet was received and written to file. */
40 LTTNG_LIVE_GET_ONE_METADATA_STATUS_OK = LTTNG_LIVE_VIEWER_STATUS_OK,
41 /*
42 * A critical error occurred when contacting the relay or while
43 * handling its response.
44 */
45 LTTNG_LIVE_GET_ONE_METADATA_STATUS_ERROR = LTTNG_LIVE_VIEWER_STATUS_ERROR,
46
47 LTTNG_LIVE_GET_ONE_METADATA_STATUS_INTERRUPTED = LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED,
48
49 /* The metadata stream was not found on the relay. */
50 LTTNG_LIVE_GET_ONE_METADATA_STATUS_CLOSED = -3,
51 };
52
53 struct live_viewer_connection
54 {
55 using UP = std::unique_ptr<live_viewer_connection>;
56
57 explicit live_viewer_connection(const bt2c::Logger& parentLogger) :
58 logger {parentLogger, "PLUGIN/SRC.CTF.LTTNG-LIVE/VIEWER"}
59 {
60 }
61
62 ~live_viewer_connection();
63
64 bt2c::Logger logger;
65
66 std::string url;
67
68 bt2c::GStringUP relay_hostname;
69 bt2c::GStringUP target_hostname;
70 bt2c::GStringUP session_name;
71 bt2c::GStringUP proto;
72
73 BT_SOCKET control_sock {};
74 int port = 0;
75
76 int32_t major = 0;
77 int32_t minor = 0;
78
79 bool in_query = false;
80 struct lttng_live_msg_iter *lttng_live_msg_iter = nullptr;
81 };
82
83 struct packet_index_time
84 {
85 uint64_t timestamp_begin;
86 uint64_t timestamp_end;
87 };
88
89 struct packet_index
90 {
91 off_t offset; /* offset of the packet in the file, in bytes */
92 int64_t data_offset; /* offset of data within the packet, in bits */
93 uint64_t packet_size; /* packet size, in bits */
94 uint64_t content_size; /* content size, in bits */
95 uint64_t events_discarded;
96 uint64_t events_discarded_len; /* length of the field, in bits */
97 struct packet_index_time ts_cycles; /* timestamp in cycles */
98 struct packet_index_time ts_real; /* realtime timestamp */
99 /* CTF_INDEX 1.0 limit */
100 uint64_t stream_instance_id; /* ID of the channel instance */
101 uint64_t packet_seq_num; /* packet sequence number */
102 };
103
104 enum lttng_live_viewer_status
105 live_viewer_connection_create(const char *url, bool in_query,
106 struct lttng_live_msg_iter *lttng_live_msg_iter,
107 const bt2c::Logger& parentLogger, live_viewer_connection::UP& viewer);
108
109 enum lttng_live_viewer_status
110 lttng_live_create_viewer_session(struct lttng_live_msg_iter *lttng_live_msg_iter);
111
112 bt2::Value::Shared
113 live_viewer_connection_list_sessions(struct live_viewer_connection *viewer_connection);
114
115 enum lttng_live_get_stream_bytes_status
116 {
117 LTTNG_LIVE_GET_STREAM_BYTES_STATUS_OK = __BT_FUNC_STATUS_OK,
118 LTTNG_LIVE_GET_STREAM_BYTES_STATUS_AGAIN = __BT_FUNC_STATUS_AGAIN,
119 LTTNG_LIVE_GET_STREAM_BYTES_STATUS_ERROR = __BT_FUNC_STATUS_ERROR,
120 LTTNG_LIVE_GET_STREAM_BYTES_STATUS_EOF = __BT_FUNC_STATUS_END,
121 };
122
123 lttng_live_get_stream_bytes_status
124 lttng_live_get_stream_bytes(struct lttng_live_msg_iter *lttng_live_msg_iter,
125 struct lttng_live_stream_iterator *stream, uint8_t *buf,
126 uint64_t offset, uint64_t req_len, uint64_t *recv_len);
127
128 #endif /* BABELTRACE_PLUGINS_CTF_LTTNG_LIVE_VIEWER_CONNECTION_HPP */
This page took 0.034088 seconds and 5 git commands to generate.