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