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>
18 #include <lttng/lttng.h>
19 #include <lttng/trace-format-descriptor.h>
22 #include <sys/types.h>
23 #include <unordered_map>
27 struct lttng_payload_view;
30 struct lttng_trace_format_descriptor_comm {
35 class trace_format_descriptor {
37 using uptr = std::unique_ptr<trace_format_descriptor>;
38 using sptr = std::shared_ptr<trace_format_descriptor>;
39 explicit trace_format_descriptor(enum lttng_trace_format_descriptor_type type) : _type(type)
43 virtual ~trace_format_descriptor();
44 virtual uptr clone() const = 0; // Virtual constructor (copying)
46 enum lttng_trace_format_descriptor_type type() const
51 virtual lttng_error_code mi_serialize(mi_writer *writer) const final;
52 virtual lttng_error_code config_serialize(config_writer *writer) const final;
53 virtual int serialize(lttng_payload *payload) const;
54 static ssize_t create_from_payload(lttng_payload_view *view, uptr& descriptor);
56 friend bool operator==(
57 trace_format_descriptor const& lhs, trace_format_descriptor const& rhs)
59 if (lhs.type() != rhs.type()) {
62 return lhs.equal_to(rhs);
65 friend bool operator!=(
66 trace_format_descriptor const& lhs, trace_format_descriptor const& rhs)
72 using DeserializerFunction =
73 std::function<ssize_t(lttng_payload_view *view, uptr& descriptor)>;
74 using deserializer_map =
75 std::unordered_map<lttng_trace_format_descriptor_type, DeserializerFunction>;
77 static deserializer_map _deserializer_map;
78 virtual bool equal_to(trace_format_descriptor const& rhs) const = 0;
81 enum lttng_trace_format_descriptor_type _type = LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_UNKNOWN;
83 virtual lttng_error_code subtype_mi_serialize(mi_writer *writer) const = 0;
84 virtual lttng_error_code subtype_config_serialize(config_writer *writer) const = 0;
87 class trace_format_descriptor_ctf1 : public trace_format_descriptor {
89 trace_format_descriptor_ctf1() :
90 trace_format_descriptor(LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_CTF_1)
92 } // Default constructor.
94 trace_format_descriptor_ctf1(trace_format_descriptor_ctf1 const&) :
95 trace_format_descriptor_ctf1()
101 return uptr(new trace_format_descriptor_ctf1(*this));
104 uint64_t getMajor() const
108 uint64_t getMinor() const
114 static ssize_t deserialize(lttng_payload_view *view, uptr& descriptor);
115 bool equal_to(trace_format_descriptor const& rhs) const override;
118 lttng_error_code subtype_mi_serialize(mi_writer *writer) const override;
119 lttng_error_code subtype_config_serialize(config_writer *writer) const override;
121 const uint64_t _major = 1;
122 const uint64_t _minor = 8;
125 class trace_format_descriptor_ctf2 : public trace_format_descriptor {
127 trace_format_descriptor_ctf2() :
128 trace_format_descriptor(LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_CTF_2)
132 trace_format_descriptor_ctf2(trace_format_descriptor_ctf2 const&) :
133 trace_format_descriptor_ctf2()
135 } // Copy constructor
139 return uptr(new trace_format_descriptor_ctf2(*this));
142 uint64_t getMajor() const
146 uint64_t getMinor() const
152 static ssize_t deserialize(lttng_payload_view *view, uptr& descriptor);
153 bool equal_to(trace_format_descriptor const& rhs) const override;
156 lttng_error_code subtype_mi_serialize(mi_writer *writer) const override;
157 lttng_error_code subtype_config_serialize(config_writer *writer) const override;
158 const uint64_t _major = 2;
159 const uint64_t _minor = 0;
163 #endif /* LTTNG_TRACE_FORMAT_DESCRIPTOR_INTERNAL_HPP */