| 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 <glib.h> |
| 11 | #include <stdint.h> |
| 12 | |
| 13 | #include <babeltrace2/babeltrace.h> |
| 14 | |
| 15 | #include "compat/socket.h" |
| 16 | |
| 17 | #define LTTNG_DEFAULT_NETWORK_VIEWER_PORT 5344 |
| 18 | |
| 19 | #define LTTNG_LIVE_MAJOR 2 |
| 20 | #define LTTNG_LIVE_MINOR 4 |
| 21 | |
| 22 | enum lttng_live_viewer_status |
| 23 | { |
| 24 | LTTNG_LIVE_VIEWER_STATUS_OK = 0, |
| 25 | LTTNG_LIVE_VIEWER_STATUS_ERROR = -1, |
| 26 | LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED = -2, |
| 27 | }; |
| 28 | |
| 29 | enum lttng_live_get_one_metadata_status |
| 30 | { |
| 31 | /* The end of the metadata stream was reached. */ |
| 32 | LTTNG_LIVE_GET_ONE_METADATA_STATUS_END = 1, |
| 33 | /* One metadata packet was received and written to file. */ |
| 34 | LTTNG_LIVE_GET_ONE_METADATA_STATUS_OK = LTTNG_LIVE_VIEWER_STATUS_OK, |
| 35 | /* |
| 36 | * A critical error occurred when contacting the relay or while |
| 37 | * handling its response. |
| 38 | */ |
| 39 | LTTNG_LIVE_GET_ONE_METADATA_STATUS_ERROR = LTTNG_LIVE_VIEWER_STATUS_ERROR, |
| 40 | |
| 41 | LTTNG_LIVE_GET_ONE_METADATA_STATUS_INTERRUPTED = LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED, |
| 42 | |
| 43 | /* The metadata stream was not found on the relay. */ |
| 44 | LTTNG_LIVE_GET_ONE_METADATA_STATUS_CLOSED = -3, |
| 45 | }; |
| 46 | |
| 47 | struct live_viewer_connection |
| 48 | { |
| 49 | bt_logging_level log_level; |
| 50 | bt_self_component *self_comp; |
| 51 | bt_self_component_class *self_comp_class; |
| 52 | |
| 53 | GString *url; |
| 54 | |
| 55 | GString *relay_hostname; |
| 56 | GString *target_hostname; |
| 57 | GString *session_name; |
| 58 | GString *proto; |
| 59 | |
| 60 | BT_SOCKET control_sock; |
| 61 | int port; |
| 62 | |
| 63 | int32_t major; |
| 64 | int32_t minor; |
| 65 | |
| 66 | bool in_query; |
| 67 | struct lttng_live_msg_iter *lttng_live_msg_iter; |
| 68 | }; |
| 69 | |
| 70 | struct packet_index_time |
| 71 | { |
| 72 | uint64_t timestamp_begin; |
| 73 | uint64_t timestamp_end; |
| 74 | }; |
| 75 | |
| 76 | struct packet_index |
| 77 | { |
| 78 | off_t offset; /* offset of the packet in the file, in bytes */ |
| 79 | int64_t data_offset; /* offset of data within the packet, in bits */ |
| 80 | uint64_t packet_size; /* packet size, in bits */ |
| 81 | uint64_t content_size; /* content size, in bits */ |
| 82 | uint64_t events_discarded; |
| 83 | uint64_t events_discarded_len; /* length of the field, in bits */ |
| 84 | struct packet_index_time ts_cycles; /* timestamp in cycles */ |
| 85 | struct packet_index_time ts_real; /* realtime timestamp */ |
| 86 | /* CTF_INDEX 1.0 limit */ |
| 87 | uint64_t stream_instance_id; /* ID of the channel instance */ |
| 88 | uint64_t packet_seq_num; /* packet sequence number */ |
| 89 | }; |
| 90 | |
| 91 | enum lttng_live_viewer_status |
| 92 | live_viewer_connection_create(bt_self_component *self_comp, |
| 93 | bt_self_component_class *self_comp_class, bt_logging_level log_level, |
| 94 | const char *url, bool in_query, |
| 95 | struct lttng_live_msg_iter *lttng_live_msg_iter, |
| 96 | struct live_viewer_connection **viewer_connection); |
| 97 | |
| 98 | void live_viewer_connection_destroy(struct live_viewer_connection *conn); |
| 99 | |
| 100 | enum lttng_live_viewer_status |
| 101 | lttng_live_create_viewer_session(struct lttng_live_msg_iter *lttng_live_msg_iter); |
| 102 | |
| 103 | bt_component_class_query_method_status |
| 104 | live_viewer_connection_list_sessions(struct live_viewer_connection *viewer_connection, |
| 105 | const bt_value **user_result); |
| 106 | |
| 107 | #endif /* LTTNG_LIVE_VIEWER_CONNECTION_H */ |