cpp-common/bt2: make setters return `*this`
[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 CommonStreamBeginningMessage 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 return *this;
278 }
279
280 OptionalBorrowedObject<ConstClockSnapshot> defaultClockSnapshot() const noexcept
281 {
282 const bt_clock_snapshot *libObjPtr;
283 const auto state = bt_message_stream_beginning_borrow_default_clock_snapshot_const(
284 this->libObjPtr(), &libObjPtr);
285
286 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
287 return libObjPtr;
288 }
289
290 return {};
291 }
292
293 Shared shared() const noexcept
294 {
295 return Shared::createWithRef(*this);
296 }
297};
298
299using StreamBeginningMessage = CommonStreamBeginningMessage<bt_message>;
300using ConstStreamBeginningMessage = CommonStreamBeginningMessage<const bt_message>;
301
302namespace internal {
303
304struct StreamBeginningMessageTypeDescr
305{
306 using Const = ConstStreamBeginningMessage;
307 using NonConst = StreamBeginningMessage;
308};
309
310template <>
311struct TypeDescr<StreamBeginningMessage> : public StreamBeginningMessageTypeDescr
312{
313};
314
315template <>
316struct TypeDescr<ConstStreamBeginningMessage> : public StreamBeginningMessageTypeDescr
317{
318};
319
320template <typename LibObjT>
321struct CommonStreamEndMessageSpec;
322
323/* Functions specific to mutable stream end messages */
324template <>
325struct 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
333/* Functions specific to constant stream end messages */
334template <>
335struct 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
343} /* namespace internal */
344
345template <typename LibObjT>
346class CommonStreamEndMessage final : public CommonMessage<LibObjT>
347{
348private:
349 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
350 using _Stream = internal::DepStream<LibObjT>;
351
352public:
353 using typename CommonMessage<LibObjT>::LibObjPtr;
354 using Shared = SharedMessage<CommonStreamEndMessage<LibObjT>, LibObjT>;
355
356 explicit CommonStreamEndMessage(const LibObjPtr libObjPtr) noexcept :
357 _ThisCommonMessage {libObjPtr}
358 {
359 BT_ASSERT_DBG(this->isStreamEnd());
360 }
361
362 template <typename OtherLibObjT>
363 CommonStreamEndMessage(const CommonStreamEndMessage<OtherLibObjT> val) noexcept :
364 _ThisCommonMessage {val}
365 {
366 }
367
368 template <typename OtherLibObjT>
369 CommonStreamEndMessage<LibObjT>
370 operator=(const CommonStreamEndMessage<OtherLibObjT> val) noexcept
371 {
372 _ThisCommonMessage::operator=(val);
373 return *this;
374 }
375
376 CommonStreamEndMessage<const bt_message> asConst() const noexcept
377 {
378 return CommonStreamEndMessage<const bt_message> {*this};
379 }
380
381 _Stream stream() const noexcept
382 {
383 return _Stream {internal::CommonStreamEndMessageSpec<LibObjT>::stream(this->libObjPtr())};
384 }
385
386 CommonStreamEndMessage defaultClockSnapshot(const std::uint64_t val) const noexcept
387 {
388 static_assert(!std::is_const<LibObjT>::value,
389 "Not available with `bt2::ConstStreamEndMessage`.");
390
391 bt_message_stream_end_set_default_clock_snapshot(this->libObjPtr(), val);
392 return *this;
393 }
394
395 OptionalBorrowedObject<ConstClockSnapshot> defaultClockSnapshot() const noexcept
396 {
397 const bt_clock_snapshot *libObjPtr;
398 const auto state = bt_message_stream_end_borrow_default_clock_snapshot_const(
399 this->libObjPtr(), &libObjPtr);
400
401 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
402 return libObjPtr;
403 }
404
405 return {};
406 }
407
408 Shared shared() const noexcept
409 {
410 return Shared::createWithRef(*this);
411 }
412};
413
414using StreamEndMessage = CommonStreamEndMessage<bt_message>;
415using ConstStreamEndMessage = CommonStreamEndMessage<const bt_message>;
416
417namespace internal {
418
419struct StreamEndMessageTypeDescr
420{
421 using Const = ConstStreamEndMessage;
422 using NonConst = StreamEndMessage;
423};
424
425template <>
426struct TypeDescr<StreamEndMessage> : public StreamEndMessageTypeDescr
427{
428};
429
430template <>
431struct TypeDescr<ConstStreamEndMessage> : public StreamEndMessageTypeDescr
432{
433};
434
435template <typename LibObjT>
436struct CommonPacketBeginningMessageSpec;
437
438/* Functions specific to mutable packet beginning messages */
439template <>
440struct CommonPacketBeginningMessageSpec<bt_message> final
441{
442 static bt_packet *packet(bt_message * const libObjPtr) noexcept
443 {
444 return bt_message_packet_beginning_borrow_packet(libObjPtr);
445 }
446};
447
448/* Functions specific to constant packet beginning messages */
449template <>
450struct CommonPacketBeginningMessageSpec<const bt_message> final
451{
452 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
453 {
454 return bt_message_packet_beginning_borrow_packet_const(libObjPtr);
455 }
456};
457
458} /* namespace internal */
459
460template <typename LibObjT>
461class CommonPacketBeginningMessage final : public CommonMessage<LibObjT>
462{
463private:
464 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
465 using _Packet = internal::DepPacket<LibObjT>;
466
467public:
468 using typename CommonMessage<LibObjT>::LibObjPtr;
469 using Shared = SharedMessage<CommonPacketBeginningMessage<LibObjT>, LibObjT>;
470
471 explicit CommonPacketBeginningMessage(const LibObjPtr libObjPtr) noexcept :
472 _ThisCommonMessage {libObjPtr}
473 {
474 BT_ASSERT_DBG(this->isPacketBeginning());
475 }
476
477 template <typename OtherLibObjT>
478 CommonPacketBeginningMessage(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept :
479 _ThisCommonMessage {val}
480 {
481 }
482
483 template <typename OtherLibObjT>
484 CommonPacketBeginningMessage<LibObjT>
485 operator=(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept
486 {
487 _ThisCommonMessage::operator=(val);
488 return *this;
489 }
490
491 CommonPacketBeginningMessage<const bt_message> asConst() const noexcept
492 {
493 return CommonPacketBeginningMessage<const bt_message> {*this};
494 }
495
496 _Packet packet() const noexcept
497 {
498 return _Packet {
499 internal::CommonPacketBeginningMessageSpec<LibObjT>::packet(this->libObjPtr())};
500 }
501
502 CommonPacketBeginningMessage defaultClockSnapshot(const std::uint64_t val) const noexcept
503 {
504 static_assert(!std::is_const<LibObjT>::value,
505 "Not available with `bt2::ConstPacketBeginningMessage`.");
506
507 bt_message_packet_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
508 return *this;
509 }
510
511 ConstClockSnapshot defaultClockSnapshot() const noexcept
512 {
513 const auto libObjPtr =
514 bt_message_packet_beginning_borrow_default_clock_snapshot_const(this->libObjPtr());
515
516 return ConstClockSnapshot {libObjPtr};
517 }
518
519 Shared shared() const noexcept
520 {
521 return Shared::createWithRef(*this);
522 }
523};
524
525using PacketBeginningMessage = CommonPacketBeginningMessage<bt_message>;
526using ConstPacketBeginningMessage = CommonPacketBeginningMessage<const bt_message>;
527
528namespace internal {
529
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
546template <typename LibObjT>
547struct CommonPacketEndMessageSpec;
548
549/* Functions specific to mutable packet end messages */
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
559/* Functions specific to constant packet end messages */
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
569} /* namespace internal */
570
571template <typename LibObjT>
572class CommonPacketEndMessage final : public CommonMessage<LibObjT>
573{
574private:
575 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
576 using _Packet = internal::DepPacket<LibObjT>;
577
578public:
579 using typename CommonMessage<LibObjT>::LibObjPtr;
580 using Shared = SharedMessage<CommonPacketEndMessage<LibObjT>, LibObjT>;
581
582 explicit CommonPacketEndMessage(const LibObjPtr libObjPtr) noexcept :
583 _ThisCommonMessage {libObjPtr}
584 {
585 BT_ASSERT_DBG(this->isPacketEnd());
586 }
587
588 template <typename OtherLibObjT>
589 CommonPacketEndMessage(const CommonPacketEndMessage<OtherLibObjT> val) noexcept :
590 _ThisCommonMessage {val}
591 {
592 }
593
594 template <typename OtherLibObjT>
595 CommonPacketEndMessage<LibObjT>
596 operator=(const CommonPacketEndMessage<OtherLibObjT> val) noexcept
597 {
598 _ThisCommonMessage::operator=(val);
599 return *this;
600 }
601
602 CommonPacketEndMessage<const bt_message> asConst() const noexcept
603 {
604 return CommonPacketEndMessage<const bt_message> {*this};
605 }
606
607 _Packet packet() const noexcept
608 {
609 return _Packet {internal::CommonPacketEndMessageSpec<LibObjT>::packet(this->libObjPtr())};
610 }
611
612 CommonPacketEndMessage defaultClockSnapshot(const std::uint64_t val) const noexcept
613 {
614 static_assert(!std::is_const<LibObjT>::value,
615 "Not available with `bt2::ConstPacketEndMessage`.");
616
617 bt_message_packet_end_set_default_clock_snapshot(this->libObjPtr(), val);
618 return *this;
619 }
620
621 ConstClockSnapshot defaultClockSnapshot() const noexcept
622 {
623 const auto libObjPtr =
624 bt_message_packet_end_borrow_default_clock_snapshot_const(this->libObjPtr());
625
626 return ConstClockSnapshot {libObjPtr};
627 }
628
629 Shared shared() const noexcept
630 {
631 return Shared::createWithRef(*this);
632 }
633};
634
635using PacketEndMessage = CommonPacketEndMessage<bt_message>;
636using ConstPacketEndMessage = CommonPacketEndMessage<const bt_message>;
637
638namespace internal {
639
640struct PacketEndMessageTypeDescr
641{
642 using Const = ConstPacketEndMessage;
643 using NonConst = PacketEndMessage;
644};
645
646template <>
647struct TypeDescr<PacketEndMessage> : public PacketEndMessageTypeDescr
648{
649};
650
651template <>
652struct TypeDescr<ConstPacketEndMessage> : public PacketEndMessageTypeDescr
653{
654};
655
656template <typename LibObjT>
657struct CommonEventMessageSpec;
658
659/* Functions specific to mutable event messages */
660template <>
661struct CommonEventMessageSpec<bt_message> final
662{
663 static bt_event *event(bt_message * const libObjPtr) noexcept
664 {
665 return bt_message_event_borrow_event(libObjPtr);
666 }
667};
668
669/* Functions specific to constant event messages */
670template <>
671struct CommonEventMessageSpec<const bt_message> final
672{
673 static const bt_event *event(const bt_message * const libObjPtr) noexcept
674 {
675 return bt_message_event_borrow_event_const(libObjPtr);
676 }
677};
678
679} /* namespace internal */
680
681template <typename LibObjT>
682class CommonEventMessage final : public CommonMessage<LibObjT>
683{
684private:
685 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
686 using _Event = internal::DepType<LibObjT, CommonEvent<bt_event>, CommonEvent<const bt_event>>;
687
688public:
689 using typename CommonMessage<LibObjT>::LibObjPtr;
690 using Shared = SharedMessage<CommonEventMessage<LibObjT>, LibObjT>;
691
692 explicit CommonEventMessage(const LibObjPtr libObjPtr) noexcept : _ThisCommonMessage {libObjPtr}
693 {
694 BT_ASSERT_DBG(this->isEvent());
695 }
696
697 template <typename OtherLibObjT>
698 CommonEventMessage(const CommonEventMessage<OtherLibObjT> val) noexcept :
699 _ThisCommonMessage {val}
700 {
701 }
702
703 template <typename OtherLibObjT>
704 CommonEventMessage<LibObjT> operator=(const CommonEventMessage<OtherLibObjT> val) noexcept
705 {
706 _ThisCommonMessage::operator=(val);
707 return *this;
708 }
709
710 CommonEventMessage<const bt_message> asConst() const noexcept
711 {
712 return CommonEventMessage<const bt_message> {*this};
713 }
714
715 _Event event() const noexcept
716 {
717 return _Event {internal::CommonEventMessageSpec<LibObjT>::event(this->libObjPtr())};
718 }
719
720 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
721 {
722 return bt_message_event_borrow_stream_class_default_clock_class_const(this->libObjPtr());
723 }
724
725 ConstClockSnapshot defaultClockSnapshot() const noexcept
726 {
727 const auto libObjPtr =
728 bt_message_event_borrow_default_clock_snapshot_const(this->libObjPtr());
729
730 return ConstClockSnapshot {libObjPtr};
731 }
732
733 Shared shared() const noexcept
734 {
735 return Shared::createWithRef(*this);
736 }
737};
738
739using EventMessage = CommonEventMessage<bt_message>;
740using ConstEventMessage = CommonEventMessage<const bt_message>;
741
742namespace internal {
743
744struct EventMessageTypeDescr
745{
746 using Const = ConstEventMessage;
747 using NonConst = EventMessage;
748};
749
750template <>
751struct TypeDescr<EventMessage> : public EventMessageTypeDescr
752{
753};
754
755template <>
756struct TypeDescr<ConstEventMessage> : public EventMessageTypeDescr
757{
758};
759
760template <typename LibObjT>
761struct CommonDiscardedEventsMessageSpec;
762
763/* Functions specific to mutable discarded events messages */
764template <>
765struct CommonDiscardedEventsMessageSpec<bt_message> final
766{
767 static bt_stream *stream(bt_message * const libObjPtr) noexcept
768 {
769 return bt_message_discarded_events_borrow_stream(libObjPtr);
770 }
771};
772
773/* Functions specific to constant discarded events messages */
774template <>
775struct CommonDiscardedEventsMessageSpec<const bt_message> final
776{
777 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
778 {
779 return bt_message_discarded_events_borrow_stream_const(libObjPtr);
780 }
781};
782
783} /* namespace internal */
784
785template <typename LibObjT>
786class CommonDiscardedEventsMessage final : public CommonMessage<LibObjT>
787{
788private:
789 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
790 using _Stream = internal::DepStream<LibObjT>;
791
792public:
793 using typename CommonMessage<LibObjT>::LibObjPtr;
794 using Shared = SharedMessage<CommonDiscardedEventsMessage<LibObjT>, LibObjT>;
795
796 explicit CommonDiscardedEventsMessage(const LibObjPtr libObjPtr) noexcept :
797 _ThisCommonMessage {libObjPtr}
798 {
799 BT_ASSERT_DBG(this->isDiscardedEvents());
800 }
801
802 template <typename OtherLibObjT>
803 CommonDiscardedEventsMessage(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept :
804 _ThisCommonMessage {val}
805 {
806 }
807
808 template <typename OtherLibObjT>
809 CommonDiscardedEventsMessage<LibObjT>
810 operator=(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept
811 {
812 _ThisCommonMessage::operator=(val);
813 return *this;
814 }
815
816 CommonDiscardedEventsMessage<const bt_message> asConst() const noexcept
817 {
818 return CommonDiscardedEventsMessage<const bt_message> {*this};
819 }
820
821 _Stream stream() const noexcept
822 {
823 return _Stream {
824 internal::CommonDiscardedEventsMessageSpec<LibObjT>::stream(this->libObjPtr())};
825 }
826
827 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
828 {
829 const auto libObjPtr =
830 bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
831 this->libObjPtr());
832
833 return ConstClockSnapshot {libObjPtr};
834 }
835
836 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
837 {
838 const auto libObjPtr =
839 bt_message_discarded_events_borrow_end_default_clock_snapshot_const(this->libObjPtr());
840
841 return ConstClockSnapshot {libObjPtr};
842 }
843
844 CommonDiscardedEventsMessage count(const std::uint64_t count) const noexcept
845 {
846 static_assert(!std::is_const<LibObjT>::value,
847 "Not available with `bt2::ConstDiscardedEventsMessage`.");
848
849 bt_message_discarded_events_set_count(this->libObjPtr(), count);
850 return *this;
851 }
852
853 bt2s::optional<std::uint64_t> count() const noexcept
854 {
855 std::uint64_t count;
856
857 if (bt_message_discarded_events_get_count(this->libObjPtr(), &count)) {
858 return count;
859 }
860
861 return bt2s::nullopt;
862 }
863
864 Shared shared() const noexcept
865 {
866 return Shared::createWithRef(*this);
867 }
868};
869
870using DiscardedEventsMessage = CommonDiscardedEventsMessage<bt_message>;
871using ConstDiscardedEventsMessage = CommonDiscardedEventsMessage<const bt_message>;
872
873namespace internal {
874
875struct DiscardedEventsMessageTypeDescr
876{
877 using Const = ConstDiscardedEventsMessage;
878 using NonConst = DiscardedEventsMessage;
879};
880
881template <>
882struct TypeDescr<DiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
883{
884};
885
886template <>
887struct TypeDescr<ConstDiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
888{
889};
890
891template <typename LibObjT>
892struct CommonDiscardedPacketsMessageSpec;
893
894/* Functions specific to mutable discarded packets messages */
895template <>
896struct CommonDiscardedPacketsMessageSpec<bt_message> final
897{
898 static bt_stream *stream(bt_message * const libObjPtr) noexcept
899 {
900 return bt_message_discarded_packets_borrow_stream(libObjPtr);
901 }
902};
903
904/* Functions specific to constant discarded packets messages */
905template <>
906struct CommonDiscardedPacketsMessageSpec<const bt_message> final
907{
908 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
909 {
910 return bt_message_discarded_packets_borrow_stream_const(libObjPtr);
911 }
912};
913
914} /* namespace internal */
915
916template <typename LibObjT>
917class CommonDiscardedPacketsMessage final : public CommonMessage<LibObjT>
918{
919private:
920 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
921 using _Stream = internal::DepStream<LibObjT>;
922
923public:
924 using typename CommonMessage<LibObjT>::LibObjPtr;
925 using Shared = SharedMessage<CommonDiscardedPacketsMessage<LibObjT>, LibObjT>;
926
927 explicit CommonDiscardedPacketsMessage(const LibObjPtr libObjPtr) noexcept :
928 _ThisCommonMessage {libObjPtr}
929 {
930 BT_ASSERT_DBG(this->isDiscardedPackets());
931 }
932
933 template <typename OtherLibObjT>
934 CommonDiscardedPacketsMessage(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept :
935 _ThisCommonMessage {val}
936 {
937 }
938
939 template <typename OtherLibObjT>
940 CommonDiscardedPacketsMessage<LibObjT>
941 operator=(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept
942 {
943 _ThisCommonMessage::operator=(val);
944 return *this;
945 }
946
947 CommonDiscardedPacketsMessage<const bt_message> asConst() const noexcept
948 {
949 return CommonDiscardedPacketsMessage<const bt_message> {*this};
950 }
951
952 _Stream stream() const noexcept
953 {
954 return _Stream {
955 internal::CommonDiscardedPacketsMessageSpec<LibObjT>::stream(this->libObjPtr())};
956 }
957
958 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
959 {
960 const auto libObjPtr =
961 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
962 this->libObjPtr());
963
964 return ConstClockSnapshot {libObjPtr};
965 }
966
967 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
968 {
969 const auto libObjPtr =
970 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(this->libObjPtr());
971
972 return ConstClockSnapshot {libObjPtr};
973 }
974
975 CommonDiscardedPacketsMessage count(const std::uint64_t count) const noexcept
976 {
977 static_assert(!std::is_const<LibObjT>::value,
978 "Not available with `bt2::ConstDiscardedPacketsMessage`.");
979
980 bt_message_discarded_packets_set_count(this->libObjPtr(), count);
981 return *this;
982 }
983
984 bt2s::optional<std::uint64_t> count() const noexcept
985 {
986 std::uint64_t count;
987
988 if (bt_message_discarded_packets_get_count(this->libObjPtr(), &count)) {
989 return count;
990 }
991
992 return bt2s::nullopt;
993 }
994
995 Shared shared() const noexcept
996 {
997 return Shared::createWithRef(*this);
998 }
999};
1000
1001using DiscardedPacketsMessage = CommonDiscardedPacketsMessage<bt_message>;
1002using ConstDiscardedPacketsMessage = CommonDiscardedPacketsMessage<const bt_message>;
1003
1004namespace internal {
1005
1006struct DiscardedPacketsMessageTypeDescr
1007{
1008 using Const = ConstDiscardedPacketsMessage;
1009 using NonConst = DiscardedPacketsMessage;
1010};
1011
1012template <>
1013struct TypeDescr<DiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1014{
1015};
1016
1017template <>
1018struct TypeDescr<ConstDiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1019{
1020};
1021
1022} /* namespace internal */
1023
1024template <typename LibObjT>
1025class CommonMessageIteratorInactivityMessage final : public CommonMessage<LibObjT>
1026{
1027private:
1028 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
1029
1030public:
1031 using typename CommonMessage<LibObjT>::LibObjPtr;
1032 using Shared = SharedMessage<CommonMessageIteratorInactivityMessage<LibObjT>, LibObjT>;
1033
1034 explicit CommonMessageIteratorInactivityMessage(const LibObjPtr libObjPtr) noexcept :
1035 _ThisCommonMessage {libObjPtr}
1036 {
1037 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1038 }
1039
1040 template <typename OtherLibObjT>
1041 CommonMessageIteratorInactivityMessage(
1042 const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept :
1043 _ThisCommonMessage {val}
1044 {
1045 }
1046
1047 template <typename OtherLibObjT>
1048 CommonMessageIteratorInactivityMessage<LibObjT>
1049 operator=(const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept
1050 {
1051 _ThisCommonMessage::operator=(val);
1052 return *this;
1053 }
1054
1055 CommonMessageIteratorInactivityMessage<const bt_message> asConst() const noexcept
1056 {
1057 return CommonMessageIteratorInactivityMessage<const bt_message> {*this};
1058 }
1059
1060 ConstClockSnapshot clockSnapshot() const noexcept
1061 {
1062 const auto libObjPtr =
1063 bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(this->libObjPtr());
1064
1065 return ConstClockSnapshot {libObjPtr};
1066 }
1067
1068 Shared shared() const noexcept
1069 {
1070 return Shared::createWithRef(*this);
1071 }
1072};
1073
1074using MessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage<bt_message>;
1075using ConstMessageIteratorInactivityMessage =
1076 CommonMessageIteratorInactivityMessage<const bt_message>;
1077
1078namespace internal {
1079
1080struct MessageIteratorInactivityMessageTypeDescr
1081{
1082 using Const = ConstMessageIteratorInactivityMessage;
1083 using NonConst = MessageIteratorInactivityMessage;
1084};
1085
1086template <>
1087struct TypeDescr<MessageIteratorInactivityMessage> :
1088 public MessageIteratorInactivityMessageTypeDescr
1089{
1090};
1091
1092template <>
1093struct TypeDescr<ConstMessageIteratorInactivityMessage> :
1094 public MessageIteratorInactivityMessageTypeDescr
1095{
1096};
1097
1098} /* namespace internal */
1099
1100template <typename LibObjT>
1101CommonStreamBeginningMessage<LibObjT> CommonMessage<LibObjT>::asStreamBeginning() const noexcept
1102{
1103 return CommonStreamBeginningMessage<LibObjT> {this->libObjPtr()};
1104}
1105
1106template <typename LibObjT>
1107CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept
1108{
1109 return CommonStreamEndMessage<LibObjT> {this->libObjPtr()};
1110}
1111
1112template <typename LibObjT>
1113CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept
1114{
1115 return CommonPacketBeginningMessage<LibObjT> {this->libObjPtr()};
1116}
1117
1118template <typename LibObjT>
1119CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept
1120{
1121 return CommonPacketEndMessage<LibObjT> {this->libObjPtr()};
1122}
1123
1124template <typename LibObjT>
1125CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept
1126{
1127 return CommonEventMessage<LibObjT> {this->libObjPtr()};
1128}
1129
1130template <typename LibObjT>
1131CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept
1132{
1133 return CommonDiscardedEventsMessage<LibObjT> {this->libObjPtr()};
1134}
1135
1136template <typename LibObjT>
1137CommonDiscardedPacketsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedPackets() const noexcept
1138{
1139 return CommonDiscardedPacketsMessage<LibObjT> {this->libObjPtr()};
1140}
1141
1142template <typename LibObjT>
1143CommonMessageIteratorInactivityMessage<LibObjT>
1144CommonMessage<LibObjT>::asMessageIteratorInactivity() const noexcept
1145{
1146 return CommonMessageIteratorInactivityMessage<LibObjT> {this->libObjPtr()};
1147}
1148
1149} /* namespace bt2 */
1150
1151#endif /* BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP */
This page took 0.027493 seconds and 4 git commands to generate.