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