2 * Copyright (C) 2022 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #ifndef LTTNG_TRACE_FORMAT_DESCRIPTOR_INTERNAL_HPP
9 #define LTTNG_TRACE_FORMAT_DESCRIPTOR_INTERNAL_HPP
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>
19 #include <lttng/lttng.h>
20 #include <lttng/trace-format-descriptor.h>
23 #include <sys/types.h>
24 #include <unordered_map>
28 struct lttng_payload_view;
31 struct lttng_trace_format_descriptor_comm {
36 class trace_format_descriptor {
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)
45 virtual ~trace_format_descriptor();
46 virtual uptr clone() const = 0; // Virtual constructor (copying)
48 enum lttng_trace_format_descriptor_type type() const
53 enum relayd_trace_format relayd_type() const
56 case LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_CTF_1:
57 return RELAYD_TRACE_FORMAT_CTF_1;
58 case LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_CTF_2:
59 return RELAYD_TRACE_FORMAT_CTF_2;
61 /* TODO/FIXME: throw??? */
65 virtual lttng_error_code mi_serialize(mi_writer *writer) const final;
66 virtual lttng_error_code config_serialize(config_writer *writer) const final;
67 virtual int serialize(lttng_payload *payload) const;
68 static ssize_t create_from_payload(lttng_payload_view *view, uptr& descriptor);
70 friend bool operator==(
71 trace_format_descriptor const& lhs, trace_format_descriptor const& rhs)
73 if (lhs.type() != rhs.type()) {
76 return lhs.equal_to(rhs);
79 friend bool operator!=(
80 trace_format_descriptor const& lhs, trace_format_descriptor const& rhs)
86 using DeserializerFunction =
87 std::function<ssize_t(lttng_payload_view *view, uptr& descriptor)>;
88 using deserializer_map =
89 std::unordered_map<lttng_trace_format_descriptor_type, DeserializerFunction>;
91 static deserializer_map _deserializer_map;
92 virtual bool equal_to(trace_format_descriptor const& rhs) const = 0;
95 enum lttng_trace_format_descriptor_type _type = LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_UNKNOWN;
97 virtual lttng_error_code subtype_mi_serialize(mi_writer *writer) const = 0;
98 virtual lttng_error_code subtype_config_serialize(config_writer *writer) const = 0;
101 class trace_format_descriptor_ctf1 : public trace_format_descriptor {
103 trace_format_descriptor_ctf1() :
104 trace_format_descriptor(LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_CTF_1)
106 } // Default constructor.
108 trace_format_descriptor_ctf1(trace_format_descriptor_ctf1 const&) :
109 trace_format_descriptor_ctf1()
111 } // Copy constructor
115 return uptr(new trace_format_descriptor_ctf1(*this));
118 uint64_t getMajor() const
122 uint64_t getMinor() const
128 static ssize_t deserialize(lttng_payload_view *view, uptr& descriptor);
129 bool equal_to(trace_format_descriptor const& rhs) const override;
132 lttng_error_code subtype_mi_serialize(mi_writer *writer) const override;
133 lttng_error_code subtype_config_serialize(config_writer *writer) const override;
135 const uint64_t _major = 1;
136 const uint64_t _minor = 8;
139 class trace_format_descriptor_ctf2 : public trace_format_descriptor {
141 trace_format_descriptor_ctf2() :
142 trace_format_descriptor(LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_CTF_2)
146 trace_format_descriptor_ctf2(trace_format_descriptor_ctf2 const&) :
147 trace_format_descriptor_ctf2()
149 } // Copy constructor
153 return uptr(new trace_format_descriptor_ctf2(*this));
156 uint64_t getMajor() const
160 uint64_t getMinor() const
166 static ssize_t deserialize(lttng_payload_view *view, uptr& descriptor);
167 bool equal_to(trace_format_descriptor const& rhs) const override;
170 lttng_error_code subtype_mi_serialize(mi_writer *writer) const override;
171 lttng_error_code subtype_config_serialize(config_writer *writer) const override;
172 const uint64_t _major = 2;
173 const uint64_t _minor = 0;
177 #endif /* LTTNG_TRACE_FORMAT_DESCRIPTOR_INTERNAL_HPP */