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