2 * SPDX-License-Identifier: MIT
4 * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 #ifndef BABELTRACE_PLUGINS_CTF_LTTNG_LIVE_VIEWER_CONNECTION_HPP
8 #define BABELTRACE_PLUGINS_CTF_LTTNG_LIVE_VIEWER_CONNECTION_HPP
16 #include <babeltrace2/babeltrace.h>
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"
23 #define LTTNG_DEFAULT_NETWORK_VIEWER_PORT 5344
25 #define LTTNG_LIVE_MAJOR 2
26 #define LTTNG_LIVE_MINOR 4
28 enum lttng_live_viewer_status
30 LTTNG_LIVE_VIEWER_STATUS_OK = 0,
31 LTTNG_LIVE_VIEWER_STATUS_ERROR = -1,
32 LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED = -2,
35 enum lttng_live_get_one_metadata_status
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,
42 * A critical error occurred when contacting the relay or while
43 * handling its response.
45 LTTNG_LIVE_GET_ONE_METADATA_STATUS_ERROR = LTTNG_LIVE_VIEWER_STATUS_ERROR,
47 LTTNG_LIVE_GET_ONE_METADATA_STATUS_INTERRUPTED = LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED,
49 /* The metadata stream was not found on the relay. */
50 LTTNG_LIVE_GET_ONE_METADATA_STATUS_CLOSED = -3,
53 struct live_viewer_connection
55 using UP = std::unique_ptr<live_viewer_connection>;
57 explicit live_viewer_connection(const bt2c::Logger& parentLogger) :
58 logger {parentLogger, "PLUGIN/SRC.CTF.LTTNG-LIVE/VIEWER"}
62 ~live_viewer_connection();
68 bt2c::GStringUP relay_hostname;
69 bt2c::GStringUP target_hostname;
70 bt2c::GStringUP session_name;
71 bt2c::GStringUP proto;
73 BT_SOCKET control_sock {};
79 bool in_query = false;
80 struct lttng_live_msg_iter *lttng_live_msg_iter = nullptr;
83 struct packet_index_time
85 uint64_t timestamp_begin;
86 uint64_t timestamp_end;
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 */
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);
109 enum lttng_live_viewer_status
110 lttng_live_create_viewer_session(struct lttng_live_msg_iter *lttng_live_msg_iter);
113 live_viewer_connection_list_sessions(struct live_viewer_connection *viewer_connection);
115 enum lttng_live_get_stream_bytes_status
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,
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);
128 #endif /* BABELTRACE_PLUGINS_CTF_LTTNG_LIVE_VIEWER_CONNECTION_HPP */