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