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