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