Commit | Line | Data |
---|---|---|
55b1df44 JR |
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 <cstdint> | |
17 | #include <functional> | |
18 | #include <lttng/lttng.h> | |
19 | #include <lttng/trace-format-descriptor.h> | |
20 | #include <memory> | |
21 | #include <pthread.h> | |
22 | #include <sys/types.h> | |
23 | #include <unordered_map> | |
24 | #include <urcu/ref.h> | |
25 | ||
26 | struct lttng_payload; | |
27 | struct lttng_payload_view; | |
28 | struct mi_writer; | |
29 | ||
30 | struct lttng_trace_format_descriptor_comm { | |
31 | uint8_t type; | |
32 | }; | |
33 | ||
34 | namespace lttng { | |
35 | class trace_format_descriptor { | |
36 | public: | |
37 | using uptr = std::unique_ptr<trace_format_descriptor>; | |
38 | using sptr = std::shared_ptr<trace_format_descriptor>; | |
0e1fd1e8 | 39 | using csptr = std::shared_ptr<const trace_format_descriptor>; |
55b1df44 JR |
40 | explicit trace_format_descriptor(enum lttng_trace_format_descriptor_type type) : _type(type) |
41 | { | |
42 | } | |
43 | ||
44 | virtual ~trace_format_descriptor(); | |
45 | virtual uptr clone() const = 0; // Virtual constructor (copying) | |
46 | ||
47 | enum lttng_trace_format_descriptor_type type() const | |
48 | { | |
49 | return _type; | |
50 | } | |
51 | ||
52 | virtual lttng_error_code mi_serialize(mi_writer *writer) const final; | |
53 | virtual lttng_error_code config_serialize(config_writer *writer) const final; | |
54 | virtual int serialize(lttng_payload *payload) const; | |
55 | static ssize_t create_from_payload(lttng_payload_view *view, uptr& descriptor); | |
56 | ||
57 | friend bool operator==( | |
58 | trace_format_descriptor const& lhs, trace_format_descriptor const& rhs) | |
59 | { | |
60 | if (lhs.type() != rhs.type()) { | |
61 | return false; | |
62 | } | |
63 | return lhs.equal_to(rhs); | |
64 | } | |
65 | ||
66 | friend bool operator!=( | |
67 | trace_format_descriptor const& lhs, trace_format_descriptor const& rhs) | |
68 | { | |
69 | return !(lhs == rhs); | |
70 | } | |
71 | ||
72 | protected: | |
73 | using DeserializerFunction = | |
74 | std::function<ssize_t(lttng_payload_view *view, uptr& descriptor)>; | |
75 | using deserializer_map = | |
76 | std::unordered_map<lttng_trace_format_descriptor_type, DeserializerFunction>; | |
77 | ||
78 | static deserializer_map _deserializer_map; | |
79 | virtual bool equal_to(trace_format_descriptor const& rhs) const = 0; | |
80 | ||
81 | private: | |
82 | enum lttng_trace_format_descriptor_type _type = LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_UNKNOWN; | |
83 | ||
84 | virtual lttng_error_code subtype_mi_serialize(mi_writer *writer) const = 0; | |
85 | virtual lttng_error_code subtype_config_serialize(config_writer *writer) const = 0; | |
86 | }; | |
87 | ||
88 | class trace_format_descriptor_ctf1 : public trace_format_descriptor { | |
89 | public: | |
90 | trace_format_descriptor_ctf1() : | |
91 | trace_format_descriptor(LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_CTF_1) | |
92 | { | |
93 | } // Default constructor. | |
94 | ||
95 | trace_format_descriptor_ctf1(trace_format_descriptor_ctf1 const&) : | |
96 | trace_format_descriptor_ctf1() | |
97 | { | |
98 | } // Copy constructor | |
99 | ||
100 | uptr clone() const | |
101 | { | |
102 | return uptr(new trace_format_descriptor_ctf1(*this)); | |
103 | } | |
104 | ||
105 | uint64_t getMajor() const | |
106 | { | |
107 | return _major; | |
108 | } | |
109 | uint64_t getMinor() const | |
110 | { | |
111 | return _minor; | |
112 | } | |
113 | ||
114 | protected: | |
115 | static ssize_t deserialize(lttng_payload_view *view, uptr& descriptor); | |
116 | bool equal_to(trace_format_descriptor const& rhs) const override; | |
117 | ||
118 | private: | |
119 | lttng_error_code subtype_mi_serialize(mi_writer *writer) const override; | |
120 | lttng_error_code subtype_config_serialize(config_writer *writer) const override; | |
121 | ||
122 | const uint64_t _major = 1; | |
123 | const uint64_t _minor = 8; | |
124 | }; | |
125 | ||
126 | class trace_format_descriptor_ctf2 : public trace_format_descriptor { | |
127 | public: | |
128 | trace_format_descriptor_ctf2() : | |
129 | trace_format_descriptor(LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_CTF_2) | |
130 | { | |
131 | } | |
132 | ||
133 | trace_format_descriptor_ctf2(trace_format_descriptor_ctf2 const&) : | |
134 | trace_format_descriptor_ctf2() | |
135 | { | |
136 | } // Copy constructor | |
137 | ||
138 | uptr clone() const | |
139 | { | |
140 | return uptr(new trace_format_descriptor_ctf2(*this)); | |
141 | } | |
142 | ||
143 | uint64_t getMajor() const | |
144 | { | |
145 | return _major; | |
146 | } | |
147 | uint64_t getMinor() const | |
148 | { | |
149 | return _minor; | |
150 | } | |
151 | ||
152 | protected: | |
153 | static ssize_t deserialize(lttng_payload_view *view, uptr& descriptor); | |
154 | bool equal_to(trace_format_descriptor const& rhs) const override; | |
155 | ||
156 | private: | |
157 | lttng_error_code subtype_mi_serialize(mi_writer *writer) const override; | |
158 | lttng_error_code subtype_config_serialize(config_writer *writer) const override; | |
159 | const uint64_t _major = 2; | |
160 | const uint64_t _minor = 0; | |
161 | }; | |
162 | } // namespace lttng | |
163 | ||
164 | #endif /* LTTNG_TRACE_FORMAT_DESCRIPTOR_INTERNAL_HPP */ |