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