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