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>; | |
39 | explicit trace_format_descriptor(enum lttng_trace_format_descriptor_type type) : _type(type) | |
40 | { | |
41 | } | |
42 | ||
43 | virtual ~trace_format_descriptor(); | |
44 | virtual uptr clone() const = 0; // Virtual constructor (copying) | |
45 | ||
46 | enum lttng_trace_format_descriptor_type type() const | |
47 | { | |
48 | return _type; | |
49 | } | |
50 | ||
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); | |
55 | ||
56 | friend bool operator==( | |
57 | trace_format_descriptor const& lhs, trace_format_descriptor const& rhs) | |
58 | { | |
59 | if (lhs.type() != rhs.type()) { | |
60 | return false; | |
61 | } | |
62 | return lhs.equal_to(rhs); | |
63 | } | |
64 | ||
65 | friend bool operator!=( | |
66 | trace_format_descriptor const& lhs, trace_format_descriptor const& rhs) | |
67 | { | |
68 | return !(lhs == rhs); | |
69 | } | |
70 | ||
71 | protected: | |
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>; | |
76 | ||
77 | static deserializer_map _deserializer_map; | |
78 | virtual bool equal_to(trace_format_descriptor const& rhs) const = 0; | |
79 | ||
80 | private: | |
81 | enum lttng_trace_format_descriptor_type _type = LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_UNKNOWN; | |
82 | ||
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; | |
85 | }; | |
86 | ||
87 | class trace_format_descriptor_ctf1 : public trace_format_descriptor { | |
88 | public: | |
89 | trace_format_descriptor_ctf1() : | |
90 | trace_format_descriptor(LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_CTF_1) | |
91 | { | |
92 | } // Default constructor. | |
93 | ||
94 | trace_format_descriptor_ctf1(trace_format_descriptor_ctf1 const&) : | |
95 | trace_format_descriptor_ctf1() | |
96 | { | |
97 | } // Copy constructor | |
98 | ||
99 | uptr clone() const | |
100 | { | |
101 | return uptr(new trace_format_descriptor_ctf1(*this)); | |
102 | } | |
103 | ||
104 | uint64_t getMajor() const | |
105 | { | |
106 | return _major; | |
107 | } | |
108 | uint64_t getMinor() const | |
109 | { | |
110 | return _minor; | |
111 | } | |
112 | ||
113 | protected: | |
114 | static ssize_t deserialize(lttng_payload_view *view, uptr& descriptor); | |
115 | bool equal_to(trace_format_descriptor const& rhs) const override; | |
116 | ||
117 | private: | |
118 | lttng_error_code subtype_mi_serialize(mi_writer *writer) const override; | |
119 | lttng_error_code subtype_config_serialize(config_writer *writer) const override; | |
120 | ||
121 | const uint64_t _major = 1; | |
122 | const uint64_t _minor = 8; | |
123 | }; | |
124 | ||
125 | class trace_format_descriptor_ctf2 : public trace_format_descriptor { | |
126 | public: | |
127 | trace_format_descriptor_ctf2() : | |
128 | trace_format_descriptor(LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_CTF_2) | |
129 | { | |
130 | } | |
131 | ||
132 | trace_format_descriptor_ctf2(trace_format_descriptor_ctf2 const&) : | |
133 | trace_format_descriptor_ctf2() | |
134 | { | |
135 | } // Copy constructor | |
136 | ||
137 | uptr clone() const | |
138 | { | |
139 | return uptr(new trace_format_descriptor_ctf2(*this)); | |
140 | } | |
141 | ||
142 | uint64_t getMajor() const | |
143 | { | |
144 | return _major; | |
145 | } | |
146 | uint64_t getMinor() const | |
147 | { | |
148 | return _minor; | |
149 | } | |
150 | ||
151 | protected: | |
152 | static ssize_t deserialize(lttng_payload_view *view, uptr& descriptor); | |
153 | bool equal_to(trace_format_descriptor const& rhs) const override; | |
154 | ||
155 | private: | |
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; | |
160 | }; | |
161 | } // namespace lttng | |
162 | ||
163 | #endif /* LTTNG_TRACE_FORMAT_DESCRIPTOR_INTERNAL_HPP */ |