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