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