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