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