cpp-common/bt2: make setters return `*this`
[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 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
299 using StreamBeginningMessage = CommonStreamBeginningMessage<bt_message>;
300 using ConstStreamBeginningMessage = CommonStreamBeginningMessage<const bt_message>;
301
302 namespace internal {
303
304 struct StreamBeginningMessageTypeDescr
305 {
306 using Const = ConstStreamBeginningMessage;
307 using NonConst = StreamBeginningMessage;
308 };
309
310 template <>
311 struct TypeDescr<StreamBeginningMessage> : public StreamBeginningMessageTypeDescr
312 {
313 };
314
315 template <>
316 struct TypeDescr<ConstStreamBeginningMessage> : public StreamBeginningMessageTypeDescr
317 {
318 };
319
320 template <typename LibObjT>
321 struct CommonStreamEndMessageSpec;
322
323 /* Functions specific to mutable stream end messages */
324 template <>
325 struct 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 */
334 template <>
335 struct 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
345 template <typename LibObjT>
346 class CommonStreamEndMessage final : public CommonMessage<LibObjT>
347 {
348 private:
349 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
350 using _Stream = internal::DepStream<LibObjT>;
351
352 public:
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
414 using StreamEndMessage = CommonStreamEndMessage<bt_message>;
415 using ConstStreamEndMessage = CommonStreamEndMessage<const bt_message>;
416
417 namespace internal {
418
419 struct StreamEndMessageTypeDescr
420 {
421 using Const = ConstStreamEndMessage;
422 using NonConst = StreamEndMessage;
423 };
424
425 template <>
426 struct TypeDescr<StreamEndMessage> : public StreamEndMessageTypeDescr
427 {
428 };
429
430 template <>
431 struct TypeDescr<ConstStreamEndMessage> : public StreamEndMessageTypeDescr
432 {
433 };
434
435 template <typename LibObjT>
436 struct CommonPacketBeginningMessageSpec;
437
438 /* Functions specific to mutable packet beginning messages */
439 template <>
440 struct 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 */
449 template <>
450 struct 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
460 template <typename LibObjT>
461 class CommonPacketBeginningMessage final : public CommonMessage<LibObjT>
462 {
463 private:
464 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
465 using _Packet = internal::DepPacket<LibObjT>;
466
467 public:
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
525 using PacketBeginningMessage = CommonPacketBeginningMessage<bt_message>;
526 using ConstPacketBeginningMessage = CommonPacketBeginningMessage<const bt_message>;
527
528 namespace internal {
529
530 struct PacketBeginningMessageTypeDescr
531 {
532 using Const = ConstPacketBeginningMessage;
533 using NonConst = PacketBeginningMessage;
534 };
535
536 template <>
537 struct TypeDescr<PacketBeginningMessage> : public PacketBeginningMessageTypeDescr
538 {
539 };
540
541 template <>
542 struct TypeDescr<ConstPacketBeginningMessage> : public PacketBeginningMessageTypeDescr
543 {
544 };
545
546 template <typename LibObjT>
547 struct CommonPacketEndMessageSpec;
548
549 /* Functions specific to mutable packet end messages */
550 template <>
551 struct 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 */
560 template <>
561 struct 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
571 template <typename LibObjT>
572 class CommonPacketEndMessage final : public CommonMessage<LibObjT>
573 {
574 private:
575 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
576 using _Packet = internal::DepPacket<LibObjT>;
577
578 public:
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
635 using PacketEndMessage = CommonPacketEndMessage<bt_message>;
636 using ConstPacketEndMessage = CommonPacketEndMessage<const bt_message>;
637
638 namespace internal {
639
640 struct PacketEndMessageTypeDescr
641 {
642 using Const = ConstPacketEndMessage;
643 using NonConst = PacketEndMessage;
644 };
645
646 template <>
647 struct TypeDescr<PacketEndMessage> : public PacketEndMessageTypeDescr
648 {
649 };
650
651 template <>
652 struct TypeDescr<ConstPacketEndMessage> : public PacketEndMessageTypeDescr
653 {
654 };
655
656 template <typename LibObjT>
657 struct CommonEventMessageSpec;
658
659 /* Functions specific to mutable event messages */
660 template <>
661 struct 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 */
670 template <>
671 struct 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
681 template <typename LibObjT>
682 class CommonEventMessage final : public CommonMessage<LibObjT>
683 {
684 private:
685 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
686 using _Event = internal::DepType<LibObjT, CommonEvent<bt_event>, CommonEvent<const bt_event>>;
687
688 public:
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
739 using EventMessage = CommonEventMessage<bt_message>;
740 using ConstEventMessage = CommonEventMessage<const bt_message>;
741
742 namespace internal {
743
744 struct EventMessageTypeDescr
745 {
746 using Const = ConstEventMessage;
747 using NonConst = EventMessage;
748 };
749
750 template <>
751 struct TypeDescr<EventMessage> : public EventMessageTypeDescr
752 {
753 };
754
755 template <>
756 struct TypeDescr<ConstEventMessage> : public EventMessageTypeDescr
757 {
758 };
759
760 template <typename LibObjT>
761 struct CommonDiscardedEventsMessageSpec;
762
763 /* Functions specific to mutable discarded events messages */
764 template <>
765 struct 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 */
774 template <>
775 struct 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
785 template <typename LibObjT>
786 class CommonDiscardedEventsMessage final : public CommonMessage<LibObjT>
787 {
788 private:
789 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
790 using _Stream = internal::DepStream<LibObjT>;
791
792 public:
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
870 using DiscardedEventsMessage = CommonDiscardedEventsMessage<bt_message>;
871 using ConstDiscardedEventsMessage = CommonDiscardedEventsMessage<const bt_message>;
872
873 namespace internal {
874
875 struct DiscardedEventsMessageTypeDescr
876 {
877 using Const = ConstDiscardedEventsMessage;
878 using NonConst = DiscardedEventsMessage;
879 };
880
881 template <>
882 struct TypeDescr<DiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
883 {
884 };
885
886 template <>
887 struct TypeDescr<ConstDiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
888 {
889 };
890
891 template <typename LibObjT>
892 struct CommonDiscardedPacketsMessageSpec;
893
894 /* Functions specific to mutable discarded packets messages */
895 template <>
896 struct 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 */
905 template <>
906 struct 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
916 template <typename LibObjT>
917 class CommonDiscardedPacketsMessage final : public CommonMessage<LibObjT>
918 {
919 private:
920 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
921 using _Stream = internal::DepStream<LibObjT>;
922
923 public:
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
1001 using DiscardedPacketsMessage = CommonDiscardedPacketsMessage<bt_message>;
1002 using ConstDiscardedPacketsMessage = CommonDiscardedPacketsMessage<const bt_message>;
1003
1004 namespace internal {
1005
1006 struct DiscardedPacketsMessageTypeDescr
1007 {
1008 using Const = ConstDiscardedPacketsMessage;
1009 using NonConst = DiscardedPacketsMessage;
1010 };
1011
1012 template <>
1013 struct TypeDescr<DiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1014 {
1015 };
1016
1017 template <>
1018 struct TypeDescr<ConstDiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1019 {
1020 };
1021
1022 } /* namespace internal */
1023
1024 template <typename LibObjT>
1025 class CommonMessageIteratorInactivityMessage final : public CommonMessage<LibObjT>
1026 {
1027 private:
1028 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
1029
1030 public:
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
1074 using MessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage<bt_message>;
1075 using ConstMessageIteratorInactivityMessage =
1076 CommonMessageIteratorInactivityMessage<const bt_message>;
1077
1078 namespace internal {
1079
1080 struct MessageIteratorInactivityMessageTypeDescr
1081 {
1082 using Const = ConstMessageIteratorInactivityMessage;
1083 using NonConst = MessageIteratorInactivityMessage;
1084 };
1085
1086 template <>
1087 struct TypeDescr<MessageIteratorInactivityMessage> :
1088 public MessageIteratorInactivityMessageTypeDescr
1089 {
1090 };
1091
1092 template <>
1093 struct TypeDescr<ConstMessageIteratorInactivityMessage> :
1094 public MessageIteratorInactivityMessageTypeDescr
1095 {
1096 };
1097
1098 } /* namespace internal */
1099
1100 template <typename LibObjT>
1101 CommonStreamBeginningMessage<LibObjT> CommonMessage<LibObjT>::asStreamBeginning() const noexcept
1102 {
1103 return CommonStreamBeginningMessage<LibObjT> {this->libObjPtr()};
1104 }
1105
1106 template <typename LibObjT>
1107 CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept
1108 {
1109 return CommonStreamEndMessage<LibObjT> {this->libObjPtr()};
1110 }
1111
1112 template <typename LibObjT>
1113 CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept
1114 {
1115 return CommonPacketBeginningMessage<LibObjT> {this->libObjPtr()};
1116 }
1117
1118 template <typename LibObjT>
1119 CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept
1120 {
1121 return CommonPacketEndMessage<LibObjT> {this->libObjPtr()};
1122 }
1123
1124 template <typename LibObjT>
1125 CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept
1126 {
1127 return CommonEventMessage<LibObjT> {this->libObjPtr()};
1128 }
1129
1130 template <typename LibObjT>
1131 CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept
1132 {
1133 return CommonDiscardedEventsMessage<LibObjT> {this->libObjPtr()};
1134 }
1135
1136 template <typename LibObjT>
1137 CommonDiscardedPacketsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedPackets() const noexcept
1138 {
1139 return CommonDiscardedPacketsMessage<LibObjT> {this->libObjPtr()};
1140 }
1141
1142 template <typename LibObjT>
1143 CommonMessageIteratorInactivityMessage<LibObjT>
1144 CommonMessage<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.054118 seconds and 4 git commands to generate.