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