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