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