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 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);
58 friend bool operator==(
59 trace_format_descriptor const& lhs, trace_format_descriptor const& rhs)
61 if (lhs.type() != rhs.type()) {
64 return lhs.equal_to(rhs);
67 friend bool operator!=(
68 trace_format_descriptor const& lhs, trace_format_descriptor const& rhs)
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>;
79 static deserializer_map _deserializer_map;
80 virtual bool equal_to(trace_format_descriptor const& rhs) const = 0;
83 enum lttng_trace_format_descriptor_type _type = LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_UNKNOWN;
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;
89 class trace_format_descriptor_ctf1 : public trace_format_descriptor {
91 trace_format_descriptor_ctf1() :
92 trace_format_descriptor(LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_CTF_1)
94 } // Default constructor.
96 trace_format_descriptor_ctf1(trace_format_descriptor_ctf1 const&) :
97 trace_format_descriptor_ctf1()
103 return uptr(new trace_format_descriptor_ctf1(*this));
106 uint64_t getMajor() const
110 uint64_t getMinor() const
116 static ssize_t deserialize(lttng_payload_view *view, uptr& descriptor);
117 bool equal_to(trace_format_descriptor const& rhs) const override;
120 lttng_error_code subtype_mi_serialize(mi_writer *writer) const override;
121 lttng_error_code subtype_config_serialize(config_writer *writer) const override;
123 const uint64_t _major = 1;
124 const uint64_t _minor = 8;
127 class trace_format_descriptor_ctf2 : public trace_format_descriptor {
129 trace_format_descriptor_ctf2() :
130 trace_format_descriptor(LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_CTF_2)
134 trace_format_descriptor_ctf2(trace_format_descriptor_ctf2 const&) :
135 trace_format_descriptor_ctf2()
137 } // Copy constructor
141 return uptr(new trace_format_descriptor_ctf2(*this));
144 uint64_t getMajor() const
148 uint64_t getMinor() const
154 static ssize_t deserialize(lttng_payload_view *view, uptr& descriptor);
155 bool equal_to(trace_format_descriptor const& rhs) const override;
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;
165 #endif /* LTTNG_TRACE_FORMAT_DESCRIPTOR_INTERNAL_HPP */