relayd: Extend relayd get configuration command to check for trace format support
[lttng-tools.git] / include / lttng / trace-format-descriptor-internal.hpp
1 /*
2 * Copyright (C) 2022 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8 #ifndef LTTNG_TRACE_FORMAT_DESCRIPTOR_INTERNAL_HPP
9 #define LTTNG_TRACE_FORMAT_DESCRIPTOR_INTERNAL_HPP
10
11 #include <bits/stdint-uintn.h>
12 #include <common/config/session-config.hpp>
13 #include <common/dynamic-array.hpp>
14 #include <common/macros.hpp>
15 #include <common/optional.hpp>
16 #include <common/sessiond-comm/relayd.hpp>
17 #include <cstdint>
18 #include <functional>
19 #include <lttng/lttng.h>
20 #include <lttng/trace-format-descriptor.h>
21 #include <memory>
22 #include <pthread.h>
23 #include <sys/types.h>
24 #include <unordered_map>
25 #include <urcu/ref.h>
26
27 struct lttng_payload;
28 struct lttng_payload_view;
29 struct mi_writer;
30
31 struct lttng_trace_format_descriptor_comm {
32 uint8_t type;
33 };
34
35 namespace lttng {
36 class trace_format_descriptor {
37 public:
38 using uptr = std::unique_ptr<trace_format_descriptor>;
39 using sptr = std::shared_ptr<trace_format_descriptor>;
40 using csptr = std::shared_ptr<const trace_format_descriptor>;
41 explicit trace_format_descriptor(enum lttng_trace_format_descriptor_type type) : _type(type)
42 {
43 }
44
45 virtual ~trace_format_descriptor();
46 virtual uptr clone() const = 0; // Virtual constructor (copying)
47
48 enum lttng_trace_format_descriptor_type type() const
49 {
50 return _type;
51 }
52
53 virtual lttng_error_code mi_serialize(mi_writer *writer) const final;
54 virtual lttng_error_code config_serialize(config_writer *writer) const final;
55 virtual int serialize(lttng_payload *payload) const;
56 static ssize_t create_from_payload(lttng_payload_view *view, uptr& descriptor);
57
58 friend bool operator==(
59 trace_format_descriptor const& lhs, trace_format_descriptor const& rhs)
60 {
61 if (lhs.type() != rhs.type()) {
62 return false;
63 }
64 return lhs.equal_to(rhs);
65 }
66
67 friend bool operator!=(
68 trace_format_descriptor const& lhs, trace_format_descriptor const& rhs)
69 {
70 return !(lhs == rhs);
71 }
72
73 protected:
74 using DeserializerFunction =
75 std::function<ssize_t(lttng_payload_view *view, uptr& descriptor)>;
76 using deserializer_map =
77 std::unordered_map<lttng_trace_format_descriptor_type, DeserializerFunction>;
78
79 static deserializer_map _deserializer_map;
80 virtual bool equal_to(trace_format_descriptor const& rhs) const = 0;
81
82 private:
83 enum lttng_trace_format_descriptor_type _type = LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_UNKNOWN;
84
85 virtual lttng_error_code subtype_mi_serialize(mi_writer *writer) const = 0;
86 virtual lttng_error_code subtype_config_serialize(config_writer *writer) const = 0;
87 };
88
89 class trace_format_descriptor_ctf1 : public trace_format_descriptor {
90 public:
91 trace_format_descriptor_ctf1() :
92 trace_format_descriptor(LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_CTF_1)
93 {
94 } // Default constructor.
95
96 trace_format_descriptor_ctf1(trace_format_descriptor_ctf1 const&) :
97 trace_format_descriptor_ctf1()
98 {
99 } // Copy constructor
100
101 uptr clone() const
102 {
103 return uptr(new trace_format_descriptor_ctf1(*this));
104 }
105
106 uint64_t getMajor() const
107 {
108 return _major;
109 }
110 uint64_t getMinor() const
111 {
112 return _minor;
113 }
114
115 protected:
116 static ssize_t deserialize(lttng_payload_view *view, uptr& descriptor);
117 bool equal_to(trace_format_descriptor const& rhs) const override;
118
119 private:
120 lttng_error_code subtype_mi_serialize(mi_writer *writer) const override;
121 lttng_error_code subtype_config_serialize(config_writer *writer) const override;
122
123 const uint64_t _major = 1;
124 const uint64_t _minor = 8;
125 };
126
127 class trace_format_descriptor_ctf2 : public trace_format_descriptor {
128 public:
129 trace_format_descriptor_ctf2() :
130 trace_format_descriptor(LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_CTF_2)
131 {
132 }
133
134 trace_format_descriptor_ctf2(trace_format_descriptor_ctf2 const&) :
135 trace_format_descriptor_ctf2()
136 {
137 } // Copy constructor
138
139 uptr clone() const
140 {
141 return uptr(new trace_format_descriptor_ctf2(*this));
142 }
143
144 uint64_t getMajor() const
145 {
146 return _major;
147 }
148 uint64_t getMinor() const
149 {
150 return _minor;
151 }
152
153 protected:
154 static ssize_t deserialize(lttng_payload_view *view, uptr& descriptor);
155 bool equal_to(trace_format_descriptor const& rhs) const override;
156
157 private:
158 lttng_error_code subtype_mi_serialize(mi_writer *writer) const override;
159 lttng_error_code subtype_config_serialize(config_writer *writer) const override;
160 const uint64_t _major = 2;
161 const uint64_t _minor = 0;
162 };
163 } // namespace lttng
164
165 #endif /* LTTNG_TRACE_FORMAT_DESCRIPTOR_INTERNAL_HPP */
This page took 0.037313 seconds and 6 git commands to generate.