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