cpp-common/bt2: remove useless `avail` variable where applicable
[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
851 if (bt_message_discarded_events_get_count(this->libObjPtr(), &count)) {
852 return count;
853 }
854
855 return bt2s::nullopt;
856 }
857
858 Shared shared() const noexcept
859 {
860 return Shared::createWithRef(*this);
861 }
862 };
863
864 using DiscardedEventsMessage = CommonDiscardedEventsMessage<bt_message>;
865 using ConstDiscardedEventsMessage = CommonDiscardedEventsMessage<const bt_message>;
866
867 namespace internal {
868
869 struct DiscardedEventsMessageTypeDescr
870 {
871 using Const = ConstDiscardedEventsMessage;
872 using NonConst = DiscardedEventsMessage;
873 };
874
875 template <>
876 struct TypeDescr<DiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
877 {
878 };
879
880 template <>
881 struct TypeDescr<ConstDiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
882 {
883 };
884
885 template <typename LibObjT>
886 struct CommonDiscardedPacketsMessageSpec;
887
888 /* Functions specific to mutable discarded packets messages */
889 template <>
890 struct CommonDiscardedPacketsMessageSpec<bt_message> final
891 {
892 static bt_stream *stream(bt_message * const libObjPtr) noexcept
893 {
894 return bt_message_discarded_packets_borrow_stream(libObjPtr);
895 }
896 };
897
898 /* Functions specific to constant discarded packets messages */
899 template <>
900 struct CommonDiscardedPacketsMessageSpec<const bt_message> final
901 {
902 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
903 {
904 return bt_message_discarded_packets_borrow_stream_const(libObjPtr);
905 }
906 };
907
908 } /* namespace internal */
909
910 template <typename LibObjT>
911 class CommonDiscardedPacketsMessage final : public CommonMessage<LibObjT>
912 {
913 private:
914 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
915 using _Stream = internal::DepStream<LibObjT>;
916
917 public:
918 using typename CommonMessage<LibObjT>::LibObjPtr;
919 using Shared = SharedMessage<CommonDiscardedPacketsMessage<LibObjT>, LibObjT>;
920
921 explicit CommonDiscardedPacketsMessage(const LibObjPtr libObjPtr) noexcept :
922 _ThisCommonMessage {libObjPtr}
923 {
924 BT_ASSERT_DBG(this->isDiscardedPackets());
925 }
926
927 template <typename OtherLibObjT>
928 CommonDiscardedPacketsMessage(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept :
929 _ThisCommonMessage {val}
930 {
931 }
932
933 template <typename OtherLibObjT>
934 CommonDiscardedPacketsMessage<LibObjT>
935 operator=(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept
936 {
937 _ThisCommonMessage::operator=(val);
938 return *this;
939 }
940
941 CommonDiscardedPacketsMessage<const bt_message> asConst() const noexcept
942 {
943 return CommonDiscardedPacketsMessage<const bt_message> {*this};
944 }
945
946 _Stream stream() const noexcept
947 {
948 return _Stream {
949 internal::CommonDiscardedPacketsMessageSpec<LibObjT>::stream(this->libObjPtr())};
950 }
951
952 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
953 {
954 const auto libObjPtr =
955 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
956 this->libObjPtr());
957
958 return ConstClockSnapshot {libObjPtr};
959 }
960
961 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
962 {
963 const auto libObjPtr =
964 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(this->libObjPtr());
965
966 return ConstClockSnapshot {libObjPtr};
967 }
968
969 void count(const std::uint64_t count) const noexcept
970 {
971 static_assert(!std::is_const<LibObjT>::value,
972 "Not available with `bt2::ConstDiscardedPacketsMessage`.");
973
974 bt_message_discarded_packets_set_count(this->libObjPtr(), count);
975 }
976
977 bt2s::optional<std::uint64_t> count() const noexcept
978 {
979 std::uint64_t count;
980
981 if (bt_message_discarded_packets_get_count(this->libObjPtr(), &count)) {
982 return count;
983 }
984
985 return bt2s::nullopt;
986 }
987
988 Shared shared() const noexcept
989 {
990 return Shared::createWithRef(*this);
991 }
992 };
993
994 using DiscardedPacketsMessage = CommonDiscardedPacketsMessage<bt_message>;
995 using ConstDiscardedPacketsMessage = CommonDiscardedPacketsMessage<const bt_message>;
996
997 namespace internal {
998
999 struct DiscardedPacketsMessageTypeDescr
1000 {
1001 using Const = ConstDiscardedPacketsMessage;
1002 using NonConst = DiscardedPacketsMessage;
1003 };
1004
1005 template <>
1006 struct TypeDescr<DiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1007 {
1008 };
1009
1010 template <>
1011 struct TypeDescr<ConstDiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1012 {
1013 };
1014
1015 } /* namespace internal */
1016
1017 template <typename LibObjT>
1018 class CommonMessageIteratorInactivityMessage final : public CommonMessage<LibObjT>
1019 {
1020 private:
1021 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
1022
1023 public:
1024 using typename CommonMessage<LibObjT>::LibObjPtr;
1025 using Shared = SharedMessage<CommonMessageIteratorInactivityMessage<LibObjT>, LibObjT>;
1026
1027 explicit CommonMessageIteratorInactivityMessage(const LibObjPtr libObjPtr) noexcept :
1028 _ThisCommonMessage {libObjPtr}
1029 {
1030 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1031 }
1032
1033 template <typename OtherLibObjT>
1034 CommonMessageIteratorInactivityMessage(
1035 const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept :
1036 _ThisCommonMessage {val}
1037 {
1038 }
1039
1040 template <typename OtherLibObjT>
1041 CommonMessageIteratorInactivityMessage<LibObjT>
1042 operator=(const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept
1043 {
1044 _ThisCommonMessage::operator=(val);
1045 return *this;
1046 }
1047
1048 CommonMessageIteratorInactivityMessage<const bt_message> asConst() const noexcept
1049 {
1050 return CommonMessageIteratorInactivityMessage<const bt_message> {*this};
1051 }
1052
1053 ConstClockSnapshot clockSnapshot() const noexcept
1054 {
1055 const auto libObjPtr =
1056 bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(this->libObjPtr());
1057
1058 return ConstClockSnapshot {libObjPtr};
1059 }
1060
1061 Shared shared() const noexcept
1062 {
1063 return Shared::createWithRef(*this);
1064 }
1065 };
1066
1067 using MessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage<bt_message>;
1068 using ConstMessageIteratorInactivityMessage =
1069 CommonMessageIteratorInactivityMessage<const bt_message>;
1070
1071 namespace internal {
1072
1073 struct MessageIteratorInactivityMessageTypeDescr
1074 {
1075 using Const = ConstMessageIteratorInactivityMessage;
1076 using NonConst = MessageIteratorInactivityMessage;
1077 };
1078
1079 template <>
1080 struct TypeDescr<MessageIteratorInactivityMessage> :
1081 public MessageIteratorInactivityMessageTypeDescr
1082 {
1083 };
1084
1085 template <>
1086 struct TypeDescr<ConstMessageIteratorInactivityMessage> :
1087 public MessageIteratorInactivityMessageTypeDescr
1088 {
1089 };
1090
1091 } /* namespace internal */
1092
1093 template <typename LibObjT>
1094 CommonStreamBeginningMessage<LibObjT> CommonMessage<LibObjT>::asStreamBeginning() const noexcept
1095 {
1096 BT_ASSERT_DBG(this->isStreamBeginning());
1097 return CommonStreamBeginningMessage<LibObjT> {this->libObjPtr()};
1098 }
1099
1100 template <typename LibObjT>
1101 CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept
1102 {
1103 BT_ASSERT_DBG(this->isStreamEnd());
1104 return CommonStreamEndMessage<LibObjT> {this->libObjPtr()};
1105 }
1106
1107 template <typename LibObjT>
1108 CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept
1109 {
1110 BT_ASSERT_DBG(this->isPacketBeginning());
1111 return CommonPacketBeginningMessage<LibObjT> {this->libObjPtr()};
1112 }
1113
1114 template <typename LibObjT>
1115 CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept
1116 {
1117 BT_ASSERT_DBG(this->isPacketEnd());
1118 return CommonPacketEndMessage<LibObjT> {this->libObjPtr()};
1119 }
1120
1121 template <typename LibObjT>
1122 CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept
1123 {
1124 BT_ASSERT_DBG(this->isEvent());
1125 return CommonEventMessage<LibObjT> {this->libObjPtr()};
1126 }
1127
1128 template <typename LibObjT>
1129 CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept
1130 {
1131 BT_ASSERT_DBG(this->isDiscardedEvents());
1132 return CommonDiscardedEventsMessage<LibObjT> {this->libObjPtr()};
1133 }
1134
1135 template <typename LibObjT>
1136 CommonDiscardedPacketsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedPackets() const noexcept
1137 {
1138 BT_ASSERT_DBG(this->isDiscardedPackets());
1139 return CommonDiscardedPacketsMessage<LibObjT> {this->libObjPtr()};
1140 }
1141
1142 template <typename LibObjT>
1143 CommonMessageIteratorInactivityMessage<LibObjT>
1144 CommonMessage<LibObjT>::asMessageIteratorInactivity() const noexcept
1145 {
1146 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1147 return CommonMessageIteratorInactivityMessage<LibObjT> {this->libObjPtr()};
1148 }
1149
1150 } /* namespace bt2 */
1151
1152 #endif /* BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP */
This page took 0.086429 seconds and 5 git commands to generate.