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