| 1 | /* |
| 2 | * SPDX-License-Identifier: MIT |
| 3 | * |
| 4 | * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 5 | */ |
| 6 | |
| 7 | #ifndef LTTNG_LIVE_VIEWER_CONNECTION_H |
| 8 | #define LTTNG_LIVE_VIEWER_CONNECTION_H |
| 9 | |
| 10 | #include <string> |
| 11 | |
| 12 | #include <glib.h> |
| 13 | #include <stdint.h> |
| 14 | |
| 15 | #include <babeltrace2/babeltrace.h> |
| 16 | |
| 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" |
| 21 | |
| 22 | #define LTTNG_DEFAULT_NETWORK_VIEWER_PORT 5344 |
| 23 | |
| 24 | #define LTTNG_LIVE_MAJOR 2 |
| 25 | #define LTTNG_LIVE_MINOR 4 |
| 26 | |
| 27 | enum lttng_live_viewer_status |
| 28 | { |
| 29 | LTTNG_LIVE_VIEWER_STATUS_OK = 0, |
| 30 | LTTNG_LIVE_VIEWER_STATUS_ERROR = -1, |
| 31 | LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED = -2, |
| 32 | }; |
| 33 | |
| 34 | enum lttng_live_get_one_metadata_status |
| 35 | { |
| 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, |
| 40 | /* |
| 41 | * A critical error occurred when contacting the relay or while |
| 42 | * handling its response. |
| 43 | */ |
| 44 | LTTNG_LIVE_GET_ONE_METADATA_STATUS_ERROR = LTTNG_LIVE_VIEWER_STATUS_ERROR, |
| 45 | |
| 46 | LTTNG_LIVE_GET_ONE_METADATA_STATUS_INTERRUPTED = LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED, |
| 47 | |
| 48 | /* The metadata stream was not found on the relay. */ |
| 49 | LTTNG_LIVE_GET_ONE_METADATA_STATUS_CLOSED = -3, |
| 50 | }; |
| 51 | |
| 52 | struct live_viewer_connection |
| 53 | { |
| 54 | using UP = std::unique_ptr<live_viewer_connection>; |
| 55 | |
| 56 | explicit live_viewer_connection(const bt2c::Logger& parentLogger) : |
| 57 | logger {parentLogger, "PLUGIN/SRC.CTF.LTTNG-LIVE/VIEWER"} |
| 58 | { |
| 59 | } |
| 60 | |
| 61 | ~live_viewer_connection(); |
| 62 | |
| 63 | bt2c::Logger logger; |
| 64 | |
| 65 | std::string url; |
| 66 | |
| 67 | bt2c::GStringUP relay_hostname; |
| 68 | bt2c::GStringUP target_hostname; |
| 69 | bt2c::GStringUP session_name; |
| 70 | bt2c::GStringUP proto; |
| 71 | |
| 72 | BT_SOCKET control_sock {}; |
| 73 | int port = 0; |
| 74 | |
| 75 | int32_t major = 0; |
| 76 | int32_t minor = 0; |
| 77 | |
| 78 | bool in_query = false; |
| 79 | struct lttng_live_msg_iter *lttng_live_msg_iter = nullptr; |
| 80 | }; |
| 81 | |
| 82 | struct packet_index_time |
| 83 | { |
| 84 | uint64_t timestamp_begin; |
| 85 | uint64_t timestamp_end; |
| 86 | }; |
| 87 | |
| 88 | struct packet_index |
| 89 | { |
| 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 */ |
| 101 | }; |
| 102 | |
| 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); |
| 107 | |
| 108 | enum lttng_live_viewer_status |
| 109 | lttng_live_create_viewer_session(struct lttng_live_msg_iter *lttng_live_msg_iter); |
| 110 | |
| 111 | bt2::Value::Shared |
| 112 | live_viewer_connection_list_sessions(struct live_viewer_connection *viewer_connection); |
| 113 | |
| 114 | #endif /* LTTNG_LIVE_VIEWER_CONNECTION_H */ |