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
15 #include <babeltrace2/babeltrace.h>
17 #include "compat/socket.hpp"
18 #include "cpp-common/bt2/value.hpp"
19 #include "cpp-common/bt2c/glib-up.hpp"
20 #include "cpp-common/bt2c/logging.hpp"
22 #define LTTNG_DEFAULT_NETWORK_VIEWER_PORT 5344
24 #define LTTNG_LIVE_MAJOR 2
25 #define LTTNG_LIVE_MINOR 4
27 enum lttng_live_viewer_status
29 LTTNG_LIVE_VIEWER_STATUS_OK = 0,
30 LTTNG_LIVE_VIEWER_STATUS_ERROR = -1,
31 LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED = -2,
34 enum lttng_live_get_one_metadata_status
36 /* The end of the metadata stream was reached. */
37 LTTNG_LIVE_GET_ONE_METADATA_STATUS_END = 1,
38 /* One metadata packet was received and written to file. */
39 LTTNG_LIVE_GET_ONE_METADATA_STATUS_OK = LTTNG_LIVE_VIEWER_STATUS_OK,
41 * A critical error occurred when contacting the relay or while
42 * handling its response.
44 LTTNG_LIVE_GET_ONE_METADATA_STATUS_ERROR = LTTNG_LIVE_VIEWER_STATUS_ERROR,
46 LTTNG_LIVE_GET_ONE_METADATA_STATUS_INTERRUPTED = LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED,
48 /* The metadata stream was not found on the relay. */
49 LTTNG_LIVE_GET_ONE_METADATA_STATUS_CLOSED = -3,
52 struct live_viewer_connection
54 using UP = std::unique_ptr<live_viewer_connection>;
56 explicit live_viewer_connection(const bt2c::Logger& parentLogger) :
57 logger {parentLogger, "PLUGIN/SRC.CTF.LTTNG-LIVE/VIEWER"}
61 ~live_viewer_connection();
67 bt2c::GStringUP relay_hostname;
68 bt2c::GStringUP target_hostname;
69 bt2c::GStringUP session_name;
70 bt2c::GStringUP proto;
72 BT_SOCKET control_sock {};
78 bool in_query = false;
79 struct lttng_live_msg_iter *lttng_live_msg_iter = nullptr;
82 struct packet_index_time
84 uint64_t timestamp_begin;
85 uint64_t timestamp_end;
90 off_t offset; /* offset of the packet in the file, in bytes */
91 int64_t data_offset; /* offset of data within the packet, in bits */
92 uint64_t packet_size; /* packet size, in bits */
93 uint64_t content_size; /* content size, in bits */
94 uint64_t events_discarded;
95 uint64_t events_discarded_len; /* length of the field, in bits */
96 struct packet_index_time ts_cycles; /* timestamp in cycles */
97 struct packet_index_time ts_real; /* realtime timestamp */
98 /* CTF_INDEX 1.0 limit */
99 uint64_t stream_instance_id; /* ID of the channel instance */
100 uint64_t packet_seq_num; /* packet sequence number */
103 enum lttng_live_viewer_status
104 live_viewer_connection_create(const char *url, bool in_query,
105 struct lttng_live_msg_iter *lttng_live_msg_iter,
106 const bt2c::Logger& parentLogger, live_viewer_connection::UP& viewer);
108 enum lttng_live_viewer_status
109 lttng_live_create_viewer_session(struct lttng_live_msg_iter *lttng_live_msg_iter);
112 live_viewer_connection_list_sessions(struct live_viewer_connection *viewer_connection);
114 #endif /* BABELTRACE_PLUGINS_CTF_LTTNG_LIVE_VIEWER_CONNECTION_HPP */