Commit | Line | Data |
---|---|---|
508053d4 PP |
1 | /* |
2 | * Copyright (c) 2021 Philippe Proulx <pproulx@efficios.com> | |
3 | * | |
4 | * SPDX-License-Identifier: MIT | |
5 | */ | |
6 | ||
7 | #ifndef BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP | |
8 | #define BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP | |
9 | ||
508053d4 | 10 | #include <cstdint> |
c802cacb SM |
11 | #include <type_traits> |
12 | ||
508053d4 PP |
13 | #include <babeltrace2/babeltrace.h> |
14 | ||
15 | #include "common/assert.h" | |
7ece2fc0 | 16 | #include "cpp-common/bt2/clock-snapshot.hpp" |
ccae279a | 17 | #include "cpp-common/bt2/trace-ir.hpp" |
508053d4 | 18 | #include "cpp-common/optional.hpp" |
c802cacb | 19 | |
0d218157 | 20 | #include "borrowed-object.hpp" |
c802cacb | 21 | #include "internal/utils.hpp" |
7f5cdaf0 | 22 | #include "shared-object.hpp" |
508053d4 PP |
23 | |
24 | namespace bt2 { | |
508053d4 PP |
25 | namespace internal { |
26 | ||
27 | struct MessageRefFuncs final | |
28 | { | |
c677c492 | 29 | static void get(const bt_message * const libObjPtr) noexcept |
508053d4 PP |
30 | { |
31 | bt_message_get_ref(libObjPtr); | |
32 | } | |
33 | ||
c677c492 | 34 | static void put(const bt_message * const libObjPtr) noexcept |
508053d4 PP |
35 | { |
36 | bt_message_put_ref(libObjPtr); | |
37 | } | |
38 | }; | |
39 | ||
b5f55e9f | 40 | } /* namespace internal */ |
508053d4 | 41 | |
26b9d24c | 42 | template <typename ObjT, typename LibObjT> |
7f5cdaf0 | 43 | using SharedMessage = SharedObject<ObjT, LibObjT, internal::MessageRefFuncs>; |
26b9d24c | 44 | |
508053d4 PP |
45 | template <typename LibObjT> |
46 | class CommonStreamBeginningMessage; | |
47 | ||
48 | template <typename LibObjT> | |
49 | class CommonStreamEndMessage; | |
50 | ||
51 | template <typename LibObjT> | |
52 | class CommonEventMessage; | |
53 | ||
54 | template <typename LibObjT> | |
55 | class CommonPacketBeginningMessage; | |
56 | ||
57 | template <typename LibObjT> | |
58 | class CommonPacketEndMessage; | |
59 | ||
60 | template <typename LibObjT> | |
61 | class CommonDiscardedEventsMessage; | |
62 | ||
63 | template <typename LibObjT> | |
64 | class CommonDiscardedPacketsMessage; | |
65 | ||
66 | template <typename LibObjT> | |
67 | class CommonMessageIteratorInactivityMessage; | |
68 | ||
69 | enum class MessageType | |
70 | { | |
71 | STREAM_BEGINNING = BT_MESSAGE_TYPE_STREAM_BEGINNING, | |
72 | STREAM_END = BT_MESSAGE_TYPE_STREAM_END, | |
73 | EVENT = BT_MESSAGE_TYPE_EVENT, | |
74 | PACKET_BEGINNING = BT_MESSAGE_TYPE_PACKET_BEGINNING, | |
75 | PACKET_END = BT_MESSAGE_TYPE_PACKET_END, | |
76 | DISCARDED_EVENTS = BT_MESSAGE_TYPE_DISCARDED_EVENTS, | |
77 | DISCARDED_PACKETS = BT_MESSAGE_TYPE_DISCARDED_PACKETS, | |
78 | MESSAGE_ITERATOR_INACTIVITY = BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY, | |
79 | }; | |
80 | ||
81 | template <typename LibObjT> | |
0d218157 | 82 | class CommonMessage : public BorrowedObject<LibObjT> |
508053d4 PP |
83 | { |
84 | private: | |
0d218157 | 85 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
508053d4 PP |
86 | |
87 | protected: | |
0d218157 | 88 | using typename BorrowedObject<LibObjT>::_LibObjPtr; |
508053d4 PP |
89 | using _ThisCommonMessage = CommonMessage<LibObjT>; |
90 | ||
91 | public: | |
26b9d24c | 92 | using Shared = SharedMessage<CommonMessage<LibObjT>, LibObjT>; |
508053d4 | 93 | |
0d218157 | 94 | explicit CommonMessage(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
508053d4 PP |
95 | { |
96 | } | |
97 | ||
98 | template <typename OtherLibObjT> | |
0d218157 | 99 | CommonMessage(const CommonMessage<OtherLibObjT> val) noexcept : _ThisBorrowedObject {val} |
508053d4 PP |
100 | { |
101 | } | |
102 | ||
103 | template <typename OtherLibObjT> | |
100fa861 | 104 | _ThisCommonMessage& operator=(const CommonMessage<OtherLibObjT> val) noexcept |
508053d4 | 105 | { |
0d218157 | 106 | _ThisBorrowedObject::operator=(val); |
508053d4 PP |
107 | return *this; |
108 | } | |
109 | ||
328a274a PP |
110 | CommonMessage<const bt_message> asConst() const noexcept |
111 | { | |
112 | return CommonMessage<const bt_message> {*this}; | |
113 | } | |
114 | ||
508053d4 PP |
115 | MessageType type() const noexcept |
116 | { | |
341a67c4 | 117 | return static_cast<MessageType>(bt_message_get_type(this->libObjPtr())); |
508053d4 PP |
118 | } |
119 | ||
120 | bool isStreamBeginning() const noexcept | |
121 | { | |
122 | return this->type() == MessageType::STREAM_BEGINNING; | |
123 | } | |
124 | ||
125 | bool isStreamEnd() const noexcept | |
126 | { | |
127 | return this->type() == MessageType::STREAM_END; | |
128 | } | |
129 | ||
130 | bool isEvent() const noexcept | |
131 | { | |
132 | return this->type() == MessageType::EVENT; | |
133 | } | |
134 | ||
135 | bool isPacketBeginning() const noexcept | |
136 | { | |
137 | return this->type() == MessageType::PACKET_BEGINNING; | |
138 | } | |
139 | ||
140 | bool isPacketEnd() const noexcept | |
141 | { | |
142 | return this->type() == MessageType::PACKET_END; | |
143 | } | |
144 | ||
145 | bool isDiscardedEvents() const noexcept | |
146 | { | |
147 | return this->type() == MessageType::DISCARDED_EVENTS; | |
148 | } | |
149 | ||
150 | bool isDiscardedPackets() const noexcept | |
151 | { | |
152 | return this->type() == MessageType::DISCARDED_PACKETS; | |
153 | } | |
154 | ||
155 | bool isMessageIteratorInactivity() const noexcept | |
156 | { | |
157 | return this->type() == MessageType::MESSAGE_ITERATOR_INACTIVITY; | |
158 | } | |
159 | ||
160 | Shared shared() const noexcept | |
161 | { | |
c9c0b6e2 | 162 | return Shared::createWithRef(*this); |
508053d4 PP |
163 | } |
164 | ||
45e0ded5 PP |
165 | template <typename MessageT> |
166 | MessageT as() const noexcept | |
167 | { | |
168 | return MessageT {this->libObjPtr()}; | |
169 | } | |
170 | ||
508053d4 PP |
171 | CommonStreamBeginningMessage<LibObjT> asStreamBeginning() const noexcept; |
172 | CommonStreamEndMessage<LibObjT> asStreamEnd() const noexcept; | |
173 | CommonEventMessage<LibObjT> asEvent() const noexcept; | |
174 | CommonPacketBeginningMessage<LibObjT> asPacketBeginning() const noexcept; | |
175 | CommonPacketEndMessage<LibObjT> asPacketEnd() const noexcept; | |
176 | CommonDiscardedEventsMessage<LibObjT> asDiscardedEvents() const noexcept; | |
177 | CommonDiscardedPacketsMessage<LibObjT> asDiscardedPackets() const noexcept; | |
178 | CommonMessageIteratorInactivityMessage<LibObjT> asMessageIteratorInactivity() const noexcept; | |
179 | }; | |
180 | ||
181 | using Message = CommonMessage<bt_message>; | |
182 | using ConstMessage = CommonMessage<const bt_message>; | |
183 | ||
184 | namespace internal { | |
185 | ||
4927bae7 PP |
186 | struct MessageTypeDescr |
187 | { | |
188 | using Const = ConstMessage; | |
189 | using NonConst = Message; | |
190 | }; | |
191 | ||
192 | template <> | |
193 | struct TypeDescr<Message> : public MessageTypeDescr | |
194 | { | |
195 | }; | |
196 | ||
197 | template <> | |
198 | struct TypeDescr<ConstMessage> : public MessageTypeDescr | |
199 | { | |
200 | }; | |
201 | ||
508053d4 PP |
202 | template <typename LibObjT> |
203 | struct CommonStreamBeginningMessageSpec; | |
204 | ||
b5f55e9f | 205 | /* Functions specific to mutable stream beginning messages */ |
508053d4 PP |
206 | template <> |
207 | struct CommonStreamBeginningMessageSpec<bt_message> final | |
208 | { | |
209 | static bt_stream *stream(bt_message * const libObjPtr) noexcept | |
210 | { | |
211 | return bt_message_stream_beginning_borrow_stream(libObjPtr); | |
212 | } | |
213 | }; | |
214 | ||
b5f55e9f | 215 | /* Functions specific to constant stream beginning messages */ |
508053d4 PP |
216 | template <> |
217 | struct CommonStreamBeginningMessageSpec<const bt_message> final | |
218 | { | |
219 | static const bt_stream *stream(const bt_message * const libObjPtr) noexcept | |
220 | { | |
221 | return bt_message_stream_beginning_borrow_stream_const(libObjPtr); | |
222 | } | |
223 | }; | |
224 | ||
b5f55e9f | 225 | } /* namespace internal */ |
508053d4 PP |
226 | |
227 | template <typename LibObjT> | |
228 | class CommonStreamBeginningMessage final : public CommonMessage<LibObjT> | |
229 | { | |
230 | private: | |
231 | using typename CommonMessage<LibObjT>::_LibObjPtr; | |
232 | using typename CommonMessage<LibObjT>::_ThisCommonMessage; | |
233 | ||
234 | using _Stream = | |
235 | typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>, | |
236 | CommonStream<bt_stream>>::type; | |
237 | ||
238 | public: | |
26b9d24c | 239 | using Shared = SharedMessage<CommonStreamBeginningMessage<LibObjT>, LibObjT>; |
508053d4 PP |
240 | |
241 | explicit CommonStreamBeginningMessage(const _LibObjPtr libObjPtr) noexcept : | |
242 | _ThisCommonMessage {libObjPtr} | |
243 | { | |
244 | BT_ASSERT_DBG(this->isStreamBeginning()); | |
245 | } | |
246 | ||
247 | template <typename OtherLibObjT> | |
100fa861 | 248 | CommonStreamBeginningMessage(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept : |
508053d4 PP |
249 | _ThisCommonMessage {val} |
250 | { | |
251 | } | |
252 | ||
253 | template <typename OtherLibObjT> | |
254 | CommonStreamBeginningMessage<LibObjT>& | |
100fa861 | 255 | operator=(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept |
508053d4 PP |
256 | { |
257 | _ThisCommonMessage::operator=(val); | |
258 | return *this; | |
259 | } | |
260 | ||
328a274a PP |
261 | CommonStreamBeginningMessage<const bt_message> asConst() const noexcept |
262 | { | |
263 | return CommonStreamBeginningMessage<const bt_message> {*this}; | |
264 | } | |
265 | ||
dcb8ae9b | 266 | _Stream stream() const noexcept |
508053d4 PP |
267 | { |
268 | return _Stream { | |
341a67c4 | 269 | internal::CommonStreamBeginningMessageSpec<LibObjT>::stream(this->libObjPtr())}; |
508053d4 PP |
270 | } |
271 | ||
dcb8ae9b | 272 | void defaultClockSnapshot(const std::uint64_t val) const noexcept |
508053d4 | 273 | { |
5c895f64 PP |
274 | static_assert(!std::is_const<LibObjT>::value, |
275 | "Not available with `bt2::ConstStreamBeginningMessage`."); | |
508053d4 | 276 | |
341a67c4 | 277 | bt_message_stream_beginning_set_default_clock_snapshot(this->libObjPtr(), val); |
508053d4 PP |
278 | } |
279 | ||
280 | nonstd::optional<ConstClockSnapshot> defaultClockSnapshot() const noexcept | |
281 | { | |
282 | const bt_clock_snapshot *libObjPtr; | |
283 | const auto state = bt_message_stream_beginning_borrow_default_clock_snapshot_const( | |
341a67c4 | 284 | this->libObjPtr(), &libObjPtr); |
508053d4 PP |
285 | |
286 | if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) { | |
287 | return ConstClockSnapshot {libObjPtr}; | |
288 | } | |
289 | ||
290 | return nonstd::nullopt; | |
291 | } | |
292 | ||
293 | Shared shared() const noexcept | |
294 | { | |
c9c0b6e2 | 295 | return Shared::createWithRef(*this); |
508053d4 PP |
296 | } |
297 | }; | |
298 | ||
299 | using StreamBeginningMessage = CommonStreamBeginningMessage<bt_message>; | |
300 | using ConstStreamBeginningMessage = CommonStreamBeginningMessage<const bt_message>; | |
301 | ||
302 | namespace internal { | |
303 | ||
4927bae7 PP |
304 | struct StreamBeginningMessageTypeDescr |
305 | { | |
306 | using Const = ConstStreamBeginningMessage; | |
307 | using NonConst = StreamBeginningMessage; | |
308 | }; | |
309 | ||
310 | template <> | |
311 | struct TypeDescr<StreamBeginningMessage> : public StreamBeginningMessageTypeDescr | |
312 | { | |
313 | }; | |
314 | ||
315 | template <> | |
316 | struct TypeDescr<ConstStreamBeginningMessage> : public StreamBeginningMessageTypeDescr | |
317 | { | |
318 | }; | |
319 | ||
508053d4 PP |
320 | template <typename LibObjT> |
321 | struct CommonStreamEndMessageSpec; | |
322 | ||
b5f55e9f | 323 | /* Functions specific to mutable stream end messages */ |
508053d4 PP |
324 | template <> |
325 | struct CommonStreamEndMessageSpec<bt_message> final | |
326 | { | |
327 | static bt_stream *stream(bt_message * const libObjPtr) noexcept | |
328 | { | |
329 | return bt_message_stream_end_borrow_stream(libObjPtr); | |
330 | } | |
331 | }; | |
332 | ||
b5f55e9f | 333 | /* Functions specific to constant stream end messages */ |
508053d4 PP |
334 | template <> |
335 | struct CommonStreamEndMessageSpec<const bt_message> final | |
336 | { | |
337 | static const bt_stream *stream(const bt_message * const libObjPtr) noexcept | |
338 | { | |
339 | return bt_message_stream_end_borrow_stream_const(libObjPtr); | |
340 | } | |
341 | }; | |
342 | ||
b5f55e9f | 343 | } /* namespace internal */ |
508053d4 PP |
344 | |
345 | template <typename LibObjT> | |
346 | class CommonStreamEndMessage final : public CommonMessage<LibObjT> | |
347 | { | |
348 | private: | |
349 | using typename CommonMessage<LibObjT>::_LibObjPtr; | |
350 | using typename CommonMessage<LibObjT>::_ThisCommonMessage; | |
351 | ||
352 | using _Stream = | |
353 | typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>, | |
354 | CommonStream<bt_stream>>::type; | |
355 | ||
356 | public: | |
26b9d24c | 357 | using Shared = SharedMessage<CommonStreamEndMessage<LibObjT>, LibObjT>; |
508053d4 PP |
358 | |
359 | explicit CommonStreamEndMessage(const _LibObjPtr libObjPtr) noexcept : | |
360 | _ThisCommonMessage {libObjPtr} | |
361 | { | |
362 | BT_ASSERT_DBG(this->isStreamEnd()); | |
363 | } | |
364 | ||
365 | template <typename OtherLibObjT> | |
100fa861 | 366 | CommonStreamEndMessage(const CommonStreamEndMessage<OtherLibObjT> val) noexcept : |
508053d4 PP |
367 | _ThisCommonMessage {val} |
368 | { | |
369 | } | |
370 | ||
371 | template <typename OtherLibObjT> | |
372 | CommonStreamEndMessage<LibObjT>& | |
100fa861 | 373 | operator=(const CommonStreamEndMessage<OtherLibObjT> val) noexcept |
508053d4 PP |
374 | { |
375 | _ThisCommonMessage::operator=(val); | |
376 | return *this; | |
377 | } | |
378 | ||
328a274a PP |
379 | CommonStreamEndMessage<const bt_message> asConst() const noexcept |
380 | { | |
381 | return CommonStreamEndMessage<const bt_message> {*this}; | |
382 | } | |
383 | ||
dcb8ae9b | 384 | _Stream stream() const noexcept |
508053d4 | 385 | { |
341a67c4 | 386 | return _Stream {internal::CommonStreamEndMessageSpec<LibObjT>::stream(this->libObjPtr())}; |
508053d4 PP |
387 | } |
388 | ||
dcb8ae9b | 389 | void defaultClockSnapshot(const std::uint64_t val) const noexcept |
508053d4 | 390 | { |
5c895f64 PP |
391 | static_assert(!std::is_const<LibObjT>::value, |
392 | "Not available with `bt2::ConstStreamEndMessage`."); | |
508053d4 | 393 | |
341a67c4 | 394 | bt_message_stream_end_set_default_clock_snapshot(this->libObjPtr(), val); |
508053d4 PP |
395 | } |
396 | ||
397 | nonstd::optional<ConstClockSnapshot> defaultClockSnapshot() const noexcept | |
398 | { | |
399 | const bt_clock_snapshot *libObjPtr; | |
400 | const auto state = bt_message_stream_end_borrow_default_clock_snapshot_const( | |
341a67c4 | 401 | this->libObjPtr(), &libObjPtr); |
508053d4 PP |
402 | |
403 | if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) { | |
404 | return ConstClockSnapshot {libObjPtr}; | |
405 | } | |
406 | ||
407 | return nonstd::nullopt; | |
408 | } | |
409 | ||
410 | Shared shared() const noexcept | |
411 | { | |
c9c0b6e2 | 412 | return Shared::createWithRef(*this); |
508053d4 PP |
413 | } |
414 | }; | |
415 | ||
416 | using StreamEndMessage = CommonStreamEndMessage<bt_message>; | |
417 | using ConstStreamEndMessage = CommonStreamEndMessage<const bt_message>; | |
418 | ||
419 | namespace internal { | |
420 | ||
4927bae7 PP |
421 | struct StreamEndMessageTypeDescr |
422 | { | |
423 | using Const = ConstStreamEndMessage; | |
424 | using NonConst = StreamEndMessage; | |
425 | }; | |
426 | ||
427 | template <> | |
428 | struct TypeDescr<StreamEndMessage> : public StreamEndMessageTypeDescr | |
429 | { | |
430 | }; | |
431 | ||
432 | template <> | |
433 | struct TypeDescr<ConstStreamEndMessage> : public StreamEndMessageTypeDescr | |
434 | { | |
435 | }; | |
436 | ||
508053d4 PP |
437 | template <typename LibObjT> |
438 | struct CommonPacketBeginningMessageSpec; | |
439 | ||
b5f55e9f | 440 | /* Functions specific to mutable packet beginning messages */ |
508053d4 PP |
441 | template <> |
442 | struct CommonPacketBeginningMessageSpec<bt_message> final | |
443 | { | |
444 | static bt_packet *packet(bt_message * const libObjPtr) noexcept | |
445 | { | |
446 | return bt_message_packet_beginning_borrow_packet(libObjPtr); | |
447 | } | |
448 | }; | |
449 | ||
b5f55e9f | 450 | /* Functions specific to constant packet beginning messages */ |
508053d4 PP |
451 | template <> |
452 | struct CommonPacketBeginningMessageSpec<const bt_message> final | |
453 | { | |
454 | static const bt_packet *packet(const bt_message * const libObjPtr) noexcept | |
455 | { | |
456 | return bt_message_packet_beginning_borrow_packet_const(libObjPtr); | |
457 | } | |
458 | }; | |
459 | ||
b5f55e9f | 460 | } /* namespace internal */ |
508053d4 PP |
461 | |
462 | template <typename LibObjT> | |
463 | class CommonPacketBeginningMessage final : public CommonMessage<LibObjT> | |
464 | { | |
465 | private: | |
466 | using typename CommonMessage<LibObjT>::_LibObjPtr; | |
467 | using typename CommonMessage<LibObjT>::_ThisCommonMessage; | |
468 | ||
469 | using _Packet = | |
470 | typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>, | |
471 | CommonPacket<bt_packet>>::type; | |
472 | ||
473 | public: | |
26b9d24c | 474 | using Shared = SharedMessage<CommonPacketBeginningMessage<LibObjT>, LibObjT>; |
508053d4 PP |
475 | |
476 | explicit CommonPacketBeginningMessage(const _LibObjPtr libObjPtr) noexcept : | |
477 | _ThisCommonMessage {libObjPtr} | |
478 | { | |
479 | BT_ASSERT_DBG(this->isPacketBeginning()); | |
480 | } | |
481 | ||
482 | template <typename OtherLibObjT> | |
100fa861 | 483 | CommonPacketBeginningMessage(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept : |
508053d4 PP |
484 | _ThisCommonMessage {val} |
485 | { | |
486 | } | |
487 | ||
488 | template <typename OtherLibObjT> | |
489 | CommonPacketBeginningMessage<LibObjT>& | |
100fa861 | 490 | operator=(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept |
508053d4 PP |
491 | { |
492 | _ThisCommonMessage::operator=(val); | |
493 | return *this; | |
494 | } | |
495 | ||
328a274a PP |
496 | CommonPacketBeginningMessage<const bt_message> asConst() const noexcept |
497 | { | |
498 | return CommonPacketBeginningMessage<const bt_message> {*this}; | |
499 | } | |
500 | ||
dcb8ae9b | 501 | _Packet packet() const noexcept |
508053d4 PP |
502 | { |
503 | return _Packet { | |
341a67c4 | 504 | internal::CommonPacketBeginningMessageSpec<LibObjT>::packet(this->libObjPtr())}; |
508053d4 PP |
505 | } |
506 | ||
dcb8ae9b | 507 | void defaultClockSnapshot(const std::uint64_t val) const noexcept |
508053d4 | 508 | { |
5c895f64 PP |
509 | static_assert(!std::is_const<LibObjT>::value, |
510 | "Not available with `bt2::ConstPacketBeginningMessage`."); | |
508053d4 | 511 | |
341a67c4 | 512 | bt_message_packet_beginning_set_default_clock_snapshot(this->libObjPtr(), val); |
508053d4 PP |
513 | } |
514 | ||
515 | ConstClockSnapshot defaultClockSnapshot() const noexcept | |
516 | { | |
517 | const auto libObjPtr = | |
341a67c4 | 518 | bt_message_packet_beginning_borrow_default_clock_snapshot_const(this->libObjPtr()); |
508053d4 PP |
519 | |
520 | return ConstClockSnapshot {libObjPtr}; | |
521 | } | |
522 | ||
523 | Shared shared() const noexcept | |
524 | { | |
c9c0b6e2 | 525 | return Shared::createWithRef(*this); |
508053d4 PP |
526 | } |
527 | }; | |
528 | ||
529 | using PacketBeginningMessage = CommonPacketBeginningMessage<bt_message>; | |
530 | using ConstPacketBeginningMessage = CommonPacketBeginningMessage<const bt_message>; | |
531 | ||
532 | namespace internal { | |
533 | ||
4927bae7 PP |
534 | struct PacketBeginningMessageTypeDescr |
535 | { | |
536 | using Const = ConstPacketBeginningMessage; | |
537 | using NonConst = PacketBeginningMessage; | |
538 | }; | |
539 | ||
540 | template <> | |
541 | struct TypeDescr<PacketBeginningMessage> : public PacketBeginningMessageTypeDescr | |
542 | { | |
543 | }; | |
544 | ||
545 | template <> | |
546 | struct TypeDescr<ConstPacketBeginningMessage> : public PacketBeginningMessageTypeDescr | |
547 | { | |
548 | }; | |
549 | ||
508053d4 PP |
550 | template <typename LibObjT> |
551 | struct CommonPacketEndMessageSpec; | |
552 | ||
b5f55e9f | 553 | /* Functions specific to mutable packet end messages */ |
508053d4 PP |
554 | template <> |
555 | struct CommonPacketEndMessageSpec<bt_message> final | |
556 | { | |
557 | static bt_packet *packet(bt_message * const libObjPtr) noexcept | |
558 | { | |
559 | return bt_message_packet_end_borrow_packet(libObjPtr); | |
560 | } | |
561 | }; | |
562 | ||
b5f55e9f | 563 | /* Functions specific to constant packet end messages */ |
508053d4 PP |
564 | template <> |
565 | struct CommonPacketEndMessageSpec<const bt_message> final | |
566 | { | |
567 | static const bt_packet *packet(const bt_message * const libObjPtr) noexcept | |
568 | { | |
569 | return bt_message_packet_end_borrow_packet_const(libObjPtr); | |
570 | } | |
571 | }; | |
572 | ||
b5f55e9f | 573 | } /* namespace internal */ |
508053d4 PP |
574 | |
575 | template <typename LibObjT> | |
576 | class CommonPacketEndMessage final : public CommonMessage<LibObjT> | |
577 | { | |
578 | private: | |
579 | using typename CommonMessage<LibObjT>::_LibObjPtr; | |
580 | using typename CommonMessage<LibObjT>::_ThisCommonMessage; | |
581 | ||
582 | using _Packet = | |
583 | typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>, | |
584 | CommonPacket<bt_packet>>::type; | |
585 | ||
586 | public: | |
26b9d24c | 587 | using Shared = SharedMessage<CommonPacketEndMessage<LibObjT>, LibObjT>; |
508053d4 PP |
588 | |
589 | explicit CommonPacketEndMessage(const _LibObjPtr libObjPtr) noexcept : | |
590 | _ThisCommonMessage {libObjPtr} | |
591 | { | |
592 | BT_ASSERT_DBG(this->isPacketEnd()); | |
593 | } | |
594 | ||
595 | template <typename OtherLibObjT> | |
100fa861 | 596 | CommonPacketEndMessage(const CommonPacketEndMessage<OtherLibObjT> val) noexcept : |
508053d4 PP |
597 | _ThisCommonMessage {val} |
598 | { | |
599 | } | |
600 | ||
601 | template <typename OtherLibObjT> | |
602 | CommonPacketEndMessage<LibObjT>& | |
100fa861 | 603 | operator=(const CommonPacketEndMessage<OtherLibObjT> val) noexcept |
508053d4 PP |
604 | { |
605 | _ThisCommonMessage::operator=(val); | |
606 | return *this; | |
607 | } | |
608 | ||
328a274a PP |
609 | CommonPacketEndMessage<const bt_message> asConst() const noexcept |
610 | { | |
611 | return CommonPacketEndMessage<const bt_message> {*this}; | |
612 | } | |
613 | ||
dcb8ae9b | 614 | _Packet packet() const noexcept |
508053d4 | 615 | { |
341a67c4 | 616 | return _Packet {internal::CommonPacketEndMessageSpec<LibObjT>::packet(this->libObjPtr())}; |
508053d4 PP |
617 | } |
618 | ||
dcb8ae9b | 619 | void defaultClockSnapshot(const std::uint64_t val) const noexcept |
508053d4 | 620 | { |
5c895f64 PP |
621 | static_assert(!std::is_const<LibObjT>::value, |
622 | "Not available with `bt2::ConstPacketEndMessage`."); | |
508053d4 | 623 | |
341a67c4 | 624 | bt_message_packet_end_set_default_clock_snapshot(this->libObjPtr(), val); |
508053d4 PP |
625 | } |
626 | ||
627 | ConstClockSnapshot defaultClockSnapshot() const noexcept | |
628 | { | |
629 | const auto libObjPtr = | |
341a67c4 | 630 | bt_message_packet_end_borrow_default_clock_snapshot_const(this->libObjPtr()); |
508053d4 PP |
631 | |
632 | return ConstClockSnapshot {libObjPtr}; | |
633 | } | |
634 | ||
635 | Shared shared() const noexcept | |
636 | { | |
c9c0b6e2 | 637 | return Shared::createWithRef(*this); |
508053d4 PP |
638 | } |
639 | }; | |
640 | ||
641 | using PacketEndMessage = CommonPacketEndMessage<bt_message>; | |
642 | using ConstPacketEndMessage = CommonPacketEndMessage<const bt_message>; | |
643 | ||
644 | namespace internal { | |
645 | ||
4927bae7 PP |
646 | struct PacketEndMessageTypeDescr |
647 | { | |
648 | using Const = ConstPacketEndMessage; | |
649 | using NonConst = PacketEndMessage; | |
650 | }; | |
651 | ||
652 | template <> | |
653 | struct TypeDescr<PacketEndMessage> : public PacketEndMessageTypeDescr | |
654 | { | |
655 | }; | |
656 | ||
657 | template <> | |
658 | struct TypeDescr<ConstPacketEndMessage> : public PacketEndMessageTypeDescr | |
659 | { | |
660 | }; | |
661 | ||
508053d4 PP |
662 | template <typename LibObjT> |
663 | struct CommonEventMessageSpec; | |
664 | ||
b5f55e9f | 665 | /* Functions specific to mutable event messages */ |
508053d4 PP |
666 | template <> |
667 | struct CommonEventMessageSpec<bt_message> final | |
668 | { | |
669 | static bt_event *event(bt_message * const libObjPtr) noexcept | |
670 | { | |
671 | return bt_message_event_borrow_event(libObjPtr); | |
672 | } | |
673 | }; | |
674 | ||
b5f55e9f | 675 | /* Functions specific to constant event messages */ |
508053d4 PP |
676 | template <> |
677 | struct CommonEventMessageSpec<const bt_message> final | |
678 | { | |
679 | static const bt_event *event(const bt_message * const libObjPtr) noexcept | |
680 | { | |
681 | return bt_message_event_borrow_event_const(libObjPtr); | |
682 | } | |
683 | }; | |
684 | ||
b5f55e9f | 685 | } /* namespace internal */ |
508053d4 PP |
686 | |
687 | template <typename LibObjT> | |
688 | class CommonEventMessage final : public CommonMessage<LibObjT> | |
689 | { | |
690 | private: | |
691 | using typename CommonMessage<LibObjT>::_LibObjPtr; | |
692 | using typename CommonMessage<LibObjT>::_ThisCommonMessage; | |
693 | ||
694 | using _Event = | |
695 | typename std::conditional<std::is_const<LibObjT>::value, CommonEvent<const bt_event>, | |
696 | CommonEvent<bt_event>>::type; | |
697 | ||
698 | public: | |
26b9d24c | 699 | using Shared = SharedMessage<CommonEventMessage<LibObjT>, LibObjT>; |
508053d4 PP |
700 | |
701 | explicit CommonEventMessage(const _LibObjPtr libObjPtr) noexcept : | |
702 | _ThisCommonMessage {libObjPtr} | |
703 | { | |
704 | BT_ASSERT_DBG(this->isEvent()); | |
705 | } | |
706 | ||
707 | template <typename OtherLibObjT> | |
100fa861 | 708 | CommonEventMessage(const CommonEventMessage<OtherLibObjT> val) noexcept : |
508053d4 PP |
709 | _ThisCommonMessage {val} |
710 | { | |
711 | } | |
712 | ||
713 | template <typename OtherLibObjT> | |
100fa861 | 714 | CommonEventMessage<LibObjT>& operator=(const CommonEventMessage<OtherLibObjT> val) noexcept |
508053d4 PP |
715 | { |
716 | _ThisCommonMessage::operator=(val); | |
717 | return *this; | |
718 | } | |
719 | ||
328a274a PP |
720 | CommonEventMessage<const bt_message> asConst() const noexcept |
721 | { | |
722 | return CommonEventMessage<const bt_message> {*this}; | |
723 | } | |
724 | ||
dcb8ae9b | 725 | _Event event() const noexcept |
508053d4 | 726 | { |
341a67c4 | 727 | return _Event {internal::CommonEventMessageSpec<LibObjT>::event(this->libObjPtr())}; |
508053d4 PP |
728 | } |
729 | ||
730 | ConstClockSnapshot defaultClockSnapshot() const noexcept | |
731 | { | |
732 | const auto libObjPtr = | |
341a67c4 | 733 | bt_message_event_borrow_default_clock_snapshot_const(this->libObjPtr()); |
508053d4 PP |
734 | |
735 | return ConstClockSnapshot {libObjPtr}; | |
736 | } | |
737 | ||
738 | Shared shared() const noexcept | |
739 | { | |
c9c0b6e2 | 740 | return Shared::createWithRef(*this); |
508053d4 PP |
741 | } |
742 | }; | |
743 | ||
744 | using EventMessage = CommonEventMessage<bt_message>; | |
745 | using ConstEventMessage = CommonEventMessage<const bt_message>; | |
746 | ||
747 | namespace internal { | |
748 | ||
4927bae7 PP |
749 | struct EventMessageTypeDescr |
750 | { | |
751 | using Const = ConstEventMessage; | |
752 | using NonConst = EventMessage; | |
753 | }; | |
754 | ||
755 | template <> | |
756 | struct TypeDescr<EventMessage> : public EventMessageTypeDescr | |
757 | { | |
758 | }; | |
759 | ||
760 | template <> | |
761 | struct TypeDescr<ConstEventMessage> : public EventMessageTypeDescr | |
762 | { | |
763 | }; | |
764 | ||
508053d4 PP |
765 | template <typename LibObjT> |
766 | struct CommonDiscardedEventsMessageSpec; | |
767 | ||
b5f55e9f | 768 | /* Functions specific to mutable discarded events messages */ |
508053d4 PP |
769 | template <> |
770 | struct CommonDiscardedEventsMessageSpec<bt_message> final | |
771 | { | |
772 | static bt_stream *stream(bt_message * const libObjPtr) noexcept | |
773 | { | |
774 | return bt_message_discarded_events_borrow_stream(libObjPtr); | |
775 | } | |
776 | }; | |
777 | ||
b5f55e9f | 778 | /* Functions specific to constant discarded events messages */ |
508053d4 PP |
779 | template <> |
780 | struct CommonDiscardedEventsMessageSpec<const bt_message> final | |
781 | { | |
782 | static const bt_stream *stream(const bt_message * const libObjPtr) noexcept | |
783 | { | |
784 | return bt_message_discarded_events_borrow_stream_const(libObjPtr); | |
785 | } | |
786 | }; | |
787 | ||
b5f55e9f | 788 | } /* namespace internal */ |
508053d4 PP |
789 | |
790 | template <typename LibObjT> | |
791 | class CommonDiscardedEventsMessage final : public CommonMessage<LibObjT> | |
792 | { | |
793 | private: | |
794 | using typename CommonMessage<LibObjT>::_LibObjPtr; | |
795 | using typename CommonMessage<LibObjT>::_ThisCommonMessage; | |
796 | ||
797 | using _Stream = | |
798 | typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>, | |
799 | CommonStream<bt_stream>>::type; | |
800 | ||
801 | public: | |
26b9d24c | 802 | using Shared = SharedMessage<CommonDiscardedEventsMessage<LibObjT>, LibObjT>; |
508053d4 PP |
803 | |
804 | explicit CommonDiscardedEventsMessage(const _LibObjPtr libObjPtr) noexcept : | |
805 | _ThisCommonMessage {libObjPtr} | |
806 | { | |
807 | BT_ASSERT_DBG(this->isDiscardedEvents()); | |
808 | } | |
809 | ||
810 | template <typename OtherLibObjT> | |
100fa861 | 811 | CommonDiscardedEventsMessage(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept : |
508053d4 PP |
812 | _ThisCommonMessage {val} |
813 | { | |
814 | } | |
815 | ||
816 | template <typename OtherLibObjT> | |
817 | CommonDiscardedEventsMessage<LibObjT>& | |
100fa861 | 818 | operator=(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept |
508053d4 PP |
819 | { |
820 | _ThisCommonMessage::operator=(val); | |
821 | return *this; | |
822 | } | |
823 | ||
328a274a PP |
824 | CommonDiscardedEventsMessage<const bt_message> asConst() const noexcept |
825 | { | |
826 | return CommonDiscardedEventsMessage<const bt_message> {*this}; | |
827 | } | |
828 | ||
dcb8ae9b | 829 | _Stream stream() const noexcept |
508053d4 PP |
830 | { |
831 | return _Stream { | |
341a67c4 | 832 | internal::CommonDiscardedEventsMessageSpec<LibObjT>::stream(this->libObjPtr())}; |
508053d4 PP |
833 | } |
834 | ||
835 | ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept | |
836 | { | |
837 | const auto libObjPtr = | |
838 | bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const( | |
341a67c4 | 839 | this->libObjPtr()); |
508053d4 PP |
840 | |
841 | return ConstClockSnapshot {libObjPtr}; | |
842 | } | |
843 | ||
844 | ConstClockSnapshot endDefaultClockSnapshot() const noexcept | |
845 | { | |
846 | const auto libObjPtr = | |
341a67c4 | 847 | bt_message_discarded_events_borrow_end_default_clock_snapshot_const(this->libObjPtr()); |
508053d4 PP |
848 | |
849 | return ConstClockSnapshot {libObjPtr}; | |
850 | } | |
851 | ||
dcb8ae9b | 852 | void count(const std::uint64_t count) const noexcept |
508053d4 | 853 | { |
5c895f64 PP |
854 | static_assert(!std::is_const<LibObjT>::value, |
855 | "Not available with `bt2::ConstDiscardedEventsMessage`."); | |
508053d4 | 856 | |
341a67c4 | 857 | bt_message_discarded_events_set_count(this->libObjPtr(), count); |
508053d4 PP |
858 | } |
859 | ||
860 | nonstd::optional<std::uint64_t> count() const noexcept | |
861 | { | |
862 | std::uint64_t count; | |
341a67c4 | 863 | const auto avail = bt_message_discarded_events_get_count(this->libObjPtr(), &count); |
508053d4 PP |
864 | |
865 | if (avail) { | |
866 | return count; | |
867 | } | |
868 | ||
869 | return nonstd::nullopt; | |
870 | } | |
871 | ||
872 | Shared shared() const noexcept | |
873 | { | |
c9c0b6e2 | 874 | return Shared::createWithRef(*this); |
508053d4 PP |
875 | } |
876 | }; | |
877 | ||
878 | using DiscardedEventsMessage = CommonDiscardedEventsMessage<bt_message>; | |
879 | using ConstDiscardedEventsMessage = CommonDiscardedEventsMessage<const bt_message>; | |
880 | ||
881 | namespace internal { | |
882 | ||
4927bae7 PP |
883 | struct DiscardedEventsMessageTypeDescr |
884 | { | |
885 | using Const = ConstDiscardedEventsMessage; | |
886 | using NonConst = DiscardedEventsMessage; | |
887 | }; | |
888 | ||
889 | template <> | |
890 | struct TypeDescr<DiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr | |
891 | { | |
892 | }; | |
893 | ||
894 | template <> | |
895 | struct TypeDescr<ConstDiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr | |
896 | { | |
897 | }; | |
898 | ||
508053d4 PP |
899 | template <typename LibObjT> |
900 | struct CommonDiscardedPacketsMessageSpec; | |
901 | ||
b5f55e9f | 902 | /* Functions specific to mutable discarded packets messages */ |
508053d4 PP |
903 | template <> |
904 | struct CommonDiscardedPacketsMessageSpec<bt_message> final | |
905 | { | |
906 | static bt_stream *stream(bt_message * const libObjPtr) noexcept | |
907 | { | |
908 | return bt_message_discarded_packets_borrow_stream(libObjPtr); | |
909 | } | |
910 | }; | |
911 | ||
b5f55e9f | 912 | /* Functions specific to constant discarded packets messages */ |
508053d4 PP |
913 | template <> |
914 | struct CommonDiscardedPacketsMessageSpec<const bt_message> final | |
915 | { | |
916 | static const bt_stream *stream(const bt_message * const libObjPtr) noexcept | |
917 | { | |
918 | return bt_message_discarded_packets_borrow_stream_const(libObjPtr); | |
919 | } | |
920 | }; | |
921 | ||
b5f55e9f | 922 | } /* namespace internal */ |
508053d4 PP |
923 | |
924 | template <typename LibObjT> | |
925 | class CommonDiscardedPacketsMessage final : public CommonMessage<LibObjT> | |
926 | { | |
927 | private: | |
928 | using typename CommonMessage<LibObjT>::_LibObjPtr; | |
929 | using typename CommonMessage<LibObjT>::_ThisCommonMessage; | |
930 | ||
931 | using _Stream = | |
932 | typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>, | |
933 | CommonStream<bt_stream>>::type; | |
934 | ||
935 | public: | |
26b9d24c | 936 | using Shared = SharedMessage<CommonDiscardedPacketsMessage<LibObjT>, LibObjT>; |
508053d4 PP |
937 | |
938 | explicit CommonDiscardedPacketsMessage(const _LibObjPtr libObjPtr) noexcept : | |
939 | _ThisCommonMessage {libObjPtr} | |
940 | { | |
941 | BT_ASSERT_DBG(this->isDiscardedPackets()); | |
942 | } | |
943 | ||
944 | template <typename OtherLibObjT> | |
100fa861 | 945 | CommonDiscardedPacketsMessage(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept : |
508053d4 PP |
946 | _ThisCommonMessage {val} |
947 | { | |
948 | } | |
949 | ||
950 | template <typename OtherLibObjT> | |
951 | CommonDiscardedPacketsMessage<LibObjT>& | |
100fa861 | 952 | operator=(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept |
508053d4 PP |
953 | { |
954 | _ThisCommonMessage::operator=(val); | |
955 | return *this; | |
956 | } | |
957 | ||
328a274a PP |
958 | CommonDiscardedPacketsMessage<const bt_message> asConst() const noexcept |
959 | { | |
960 | return CommonDiscardedPacketsMessage<const bt_message> {*this}; | |
961 | } | |
962 | ||
dcb8ae9b | 963 | _Stream stream() const noexcept |
508053d4 PP |
964 | { |
965 | return _Stream { | |
341a67c4 | 966 | internal::CommonDiscardedPacketsMessageSpec<LibObjT>::stream(this->libObjPtr())}; |
508053d4 PP |
967 | } |
968 | ||
969 | ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept | |
970 | { | |
971 | const auto libObjPtr = | |
972 | bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const( | |
341a67c4 | 973 | this->libObjPtr()); |
508053d4 PP |
974 | |
975 | return ConstClockSnapshot {libObjPtr}; | |
976 | } | |
977 | ||
978 | ConstClockSnapshot endDefaultClockSnapshot() const noexcept | |
979 | { | |
341a67c4 FD |
980 | const auto libObjPtr = |
981 | bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(this->libObjPtr()); | |
508053d4 PP |
982 | |
983 | return ConstClockSnapshot {libObjPtr}; | |
984 | } | |
985 | ||
dcb8ae9b | 986 | void count(const std::uint64_t count) const noexcept |
508053d4 | 987 | { |
5c895f64 PP |
988 | static_assert(!std::is_const<LibObjT>::value, |
989 | "Not available with `bt2::ConstDiscardedPacketsMessage`."); | |
508053d4 | 990 | |
341a67c4 | 991 | bt_message_discarded_packets_set_count(this->libObjPtr(), count); |
508053d4 PP |
992 | } |
993 | ||
994 | nonstd::optional<std::uint64_t> count() const noexcept | |
995 | { | |
996 | std::uint64_t count; | |
341a67c4 | 997 | const auto avail = bt_message_discarded_packets_get_count(this->libObjPtr(), &count); |
508053d4 PP |
998 | |
999 | if (avail) { | |
1000 | return count; | |
1001 | } | |
1002 | ||
1003 | return nonstd::nullopt; | |
1004 | } | |
1005 | ||
1006 | Shared shared() const noexcept | |
1007 | { | |
c9c0b6e2 | 1008 | return Shared::createWithRef(*this); |
508053d4 PP |
1009 | } |
1010 | }; | |
1011 | ||
1012 | using DiscardedPacketsMessage = CommonDiscardedPacketsMessage<bt_message>; | |
1013 | using ConstDiscardedPacketsMessage = CommonDiscardedPacketsMessage<const bt_message>; | |
1014 | ||
4927bae7 PP |
1015 | namespace internal { |
1016 | ||
1017 | struct DiscardedPacketsMessageTypeDescr | |
1018 | { | |
1019 | using Const = ConstDiscardedPacketsMessage; | |
1020 | using NonConst = DiscardedPacketsMessage; | |
1021 | }; | |
1022 | ||
1023 | template <> | |
1024 | struct TypeDescr<DiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr | |
1025 | { | |
1026 | }; | |
1027 | ||
1028 | template <> | |
1029 | struct TypeDescr<ConstDiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr | |
1030 | { | |
1031 | }; | |
1032 | ||
1033 | } /* namespace internal */ | |
1034 | ||
508053d4 PP |
1035 | template <typename LibObjT> |
1036 | class CommonMessageIteratorInactivityMessage final : public CommonMessage<LibObjT> | |
1037 | { | |
1038 | private: | |
1039 | using typename CommonMessage<LibObjT>::_LibObjPtr; | |
1040 | using typename CommonMessage<LibObjT>::_ThisCommonMessage; | |
1041 | ||
1042 | public: | |
26b9d24c | 1043 | using Shared = SharedMessage<CommonMessageIteratorInactivityMessage<LibObjT>, LibObjT>; |
508053d4 PP |
1044 | |
1045 | explicit CommonMessageIteratorInactivityMessage(const _LibObjPtr libObjPtr) noexcept : | |
1046 | _ThisCommonMessage {libObjPtr} | |
1047 | { | |
1048 | BT_ASSERT_DBG(this->isMessageIteratorInactivity()); | |
1049 | } | |
1050 | ||
1051 | template <typename OtherLibObjT> | |
1052 | CommonMessageIteratorInactivityMessage( | |
100fa861 | 1053 | const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept : |
508053d4 PP |
1054 | _ThisCommonMessage {val} |
1055 | { | |
1056 | } | |
1057 | ||
1058 | template <typename OtherLibObjT> | |
1059 | CommonMessageIteratorInactivityMessage<LibObjT>& | |
100fa861 | 1060 | operator=(const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept |
508053d4 PP |
1061 | { |
1062 | _ThisCommonMessage::operator=(val); | |
1063 | return *this; | |
1064 | } | |
1065 | ||
328a274a PP |
1066 | CommonMessageIteratorInactivityMessage<const bt_message> asConst() const noexcept |
1067 | { | |
1068 | return CommonMessageIteratorInactivityMessage<const bt_message> {*this}; | |
1069 | } | |
1070 | ||
508053d4 PP |
1071 | ConstClockSnapshot clockSnapshot() const noexcept |
1072 | { | |
1073 | const auto libObjPtr = | |
341a67c4 | 1074 | bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(this->libObjPtr()); |
508053d4 PP |
1075 | |
1076 | return ConstClockSnapshot {libObjPtr}; | |
1077 | } | |
1078 | ||
1079 | Shared shared() const noexcept | |
1080 | { | |
c9c0b6e2 | 1081 | return Shared::createWithRef(*this); |
508053d4 PP |
1082 | } |
1083 | }; | |
1084 | ||
1085 | using MessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage<bt_message>; | |
1086 | using ConstMessageIteratorInactivityMessage = | |
1087 | CommonMessageIteratorInactivityMessage<const bt_message>; | |
1088 | ||
4927bae7 PP |
1089 | namespace internal { |
1090 | ||
1091 | struct MessageIteratorInactivityMessageTypeDescr | |
1092 | { | |
1093 | using Const = ConstMessageIteratorInactivityMessage; | |
1094 | using NonConst = MessageIteratorInactivityMessage; | |
1095 | }; | |
1096 | ||
1097 | template <> | |
1098 | struct TypeDescr<MessageIteratorInactivityMessage> : | |
1099 | public MessageIteratorInactivityMessageTypeDescr | |
1100 | { | |
1101 | }; | |
1102 | ||
1103 | template <> | |
1104 | struct TypeDescr<ConstMessageIteratorInactivityMessage> : | |
1105 | public MessageIteratorInactivityMessageTypeDescr | |
1106 | { | |
1107 | }; | |
1108 | ||
1109 | } /* namespace internal */ | |
1110 | ||
508053d4 PP |
1111 | template <typename LibObjT> |
1112 | CommonStreamBeginningMessage<LibObjT> CommonMessage<LibObjT>::asStreamBeginning() const noexcept | |
1113 | { | |
1114 | BT_ASSERT_DBG(this->isStreamBeginning()); | |
341a67c4 | 1115 | return CommonStreamBeginningMessage<LibObjT> {this->libObjPtr()}; |
508053d4 PP |
1116 | } |
1117 | ||
1118 | template <typename LibObjT> | |
1119 | CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept | |
1120 | { | |
1121 | BT_ASSERT_DBG(this->isStreamEnd()); | |
341a67c4 | 1122 | return CommonStreamEndMessage<LibObjT> {this->libObjPtr()}; |
508053d4 PP |
1123 | } |
1124 | ||
1125 | template <typename LibObjT> | |
1126 | CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept | |
1127 | { | |
1128 | BT_ASSERT_DBG(this->isPacketBeginning()); | |
341a67c4 | 1129 | return CommonPacketBeginningMessage<LibObjT> {this->libObjPtr()}; |
508053d4 PP |
1130 | } |
1131 | ||
1132 | template <typename LibObjT> | |
1133 | CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept | |
1134 | { | |
1135 | BT_ASSERT_DBG(this->isPacketEnd()); | |
341a67c4 | 1136 | return CommonPacketEndMessage<LibObjT> {this->libObjPtr()}; |
508053d4 PP |
1137 | } |
1138 | ||
1139 | template <typename LibObjT> | |
1140 | CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept | |
1141 | { | |
1142 | BT_ASSERT_DBG(this->isEvent()); | |
341a67c4 | 1143 | return CommonEventMessage<LibObjT> {this->libObjPtr()}; |
508053d4 PP |
1144 | } |
1145 | ||
1146 | template <typename LibObjT> | |
1147 | CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept | |
1148 | { | |
1149 | BT_ASSERT_DBG(this->isDiscardedEvents()); | |
341a67c4 | 1150 | return CommonDiscardedEventsMessage<LibObjT> {this->libObjPtr()}; |
508053d4 PP |
1151 | } |
1152 | ||
bd7dbf87 FD |
1153 | template <typename LibObjT> |
1154 | CommonDiscardedPacketsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedPackets() const noexcept | |
1155 | { | |
1156 | BT_ASSERT_DBG(this->isDiscardedPackets()); | |
1157 | return CommonDiscardedPacketsMessage<LibObjT> {this->libObjPtr()}; | |
1158 | } | |
1159 | ||
508053d4 PP |
1160 | template <typename LibObjT> |
1161 | CommonMessageIteratorInactivityMessage<LibObjT> | |
1162 | CommonMessage<LibObjT>::asMessageIteratorInactivity() const noexcept | |
1163 | { | |
1164 | BT_ASSERT_DBG(this->isMessageIteratorInactivity()); | |
341a67c4 | 1165 | return CommonMessageIteratorInactivityMessage<LibObjT> {this->libObjPtr()}; |
508053d4 PP |
1166 | } |
1167 | ||
b5f55e9f | 1168 | } /* namespace bt2 */ |
508053d4 | 1169 | |
b5f55e9f | 1170 | #endif /* BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP */ |