cpp-common/bt2: add `streamClassDefaultClockClass()` methods
[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
afe77d4f
SM
271 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
272 {
273 return bt_message_stream_beginning_borrow_stream_class_default_clock_class_const(
274 this->libObjPtr());
275 }
276
2a24eba8 277 CommonStreamBeginningMessage defaultClockSnapshot(const std::uint64_t val) const noexcept
508053d4 278 {
5c895f64
PP
279 static_assert(!std::is_const<LibObjT>::value,
280 "Not available with `bt2::ConstStreamBeginningMessage`.");
508053d4 281
341a67c4 282 bt_message_stream_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
2a24eba8 283 return *this;
508053d4
PP
284 }
285
ca61ecbc 286 OptionalBorrowedObject<ConstClockSnapshot> defaultClockSnapshot() const noexcept
508053d4
PP
287 {
288 const bt_clock_snapshot *libObjPtr;
289 const auto state = bt_message_stream_beginning_borrow_default_clock_snapshot_const(
341a67c4 290 this->libObjPtr(), &libObjPtr);
508053d4
PP
291
292 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
ca61ecbc 293 return libObjPtr;
508053d4
PP
294 }
295
ca61ecbc 296 return {};
508053d4
PP
297 }
298
299 Shared shared() const noexcept
300 {
c9c0b6e2 301 return Shared::createWithRef(*this);
508053d4
PP
302 }
303};
304
305using StreamBeginningMessage = CommonStreamBeginningMessage<bt_message>;
306using ConstStreamBeginningMessage = CommonStreamBeginningMessage<const bt_message>;
307
308namespace internal {
309
4927bae7
PP
310struct StreamBeginningMessageTypeDescr
311{
312 using Const = ConstStreamBeginningMessage;
313 using NonConst = StreamBeginningMessage;
314};
315
316template <>
317struct TypeDescr<StreamBeginningMessage> : public StreamBeginningMessageTypeDescr
318{
319};
320
321template <>
322struct TypeDescr<ConstStreamBeginningMessage> : public StreamBeginningMessageTypeDescr
323{
324};
325
508053d4
PP
326template <typename LibObjT>
327struct CommonStreamEndMessageSpec;
328
b5f55e9f 329/* Functions specific to mutable stream end messages */
508053d4
PP
330template <>
331struct CommonStreamEndMessageSpec<bt_message> final
332{
333 static bt_stream *stream(bt_message * const libObjPtr) noexcept
334 {
335 return bt_message_stream_end_borrow_stream(libObjPtr);
336 }
337};
338
b5f55e9f 339/* Functions specific to constant stream end messages */
508053d4
PP
340template <>
341struct CommonStreamEndMessageSpec<const bt_message> final
342{
343 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
344 {
345 return bt_message_stream_end_borrow_stream_const(libObjPtr);
346 }
347};
348
b5f55e9f 349} /* namespace internal */
508053d4
PP
350
351template <typename LibObjT>
352class CommonStreamEndMessage final : public CommonMessage<LibObjT>
353{
354private:
508053d4 355 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
8047a175 356 using _Stream = internal::DepStream<LibObjT>;
508053d4
PP
357
358public:
d246c457 359 using typename CommonMessage<LibObjT>::LibObjPtr;
26b9d24c 360 using Shared = SharedMessage<CommonStreamEndMessage<LibObjT>, LibObjT>;
508053d4 361
d246c457 362 explicit CommonStreamEndMessage(const LibObjPtr libObjPtr) noexcept :
508053d4
PP
363 _ThisCommonMessage {libObjPtr}
364 {
365 BT_ASSERT_DBG(this->isStreamEnd());
366 }
367
368 template <typename OtherLibObjT>
100fa861 369 CommonStreamEndMessage(const CommonStreamEndMessage<OtherLibObjT> val) noexcept :
508053d4
PP
370 _ThisCommonMessage {val}
371 {
372 }
373
374 template <typename OtherLibObjT>
ac30a470 375 CommonStreamEndMessage<LibObjT>
100fa861 376 operator=(const CommonStreamEndMessage<OtherLibObjT> val) noexcept
508053d4
PP
377 {
378 _ThisCommonMessage::operator=(val);
379 return *this;
380 }
381
328a274a
PP
382 CommonStreamEndMessage<const bt_message> asConst() const noexcept
383 {
384 return CommonStreamEndMessage<const bt_message> {*this};
385 }
386
dcb8ae9b 387 _Stream stream() const noexcept
508053d4 388 {
341a67c4 389 return _Stream {internal::CommonStreamEndMessageSpec<LibObjT>::stream(this->libObjPtr())};
508053d4
PP
390 }
391
afe77d4f
SM
392 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
393 {
394 return bt_message_stream_end_borrow_stream_class_default_clock_class_const(
395 this->libObjPtr());
396 }
397
2a24eba8 398 CommonStreamEndMessage defaultClockSnapshot(const std::uint64_t val) const noexcept
508053d4 399 {
5c895f64
PP
400 static_assert(!std::is_const<LibObjT>::value,
401 "Not available with `bt2::ConstStreamEndMessage`.");
508053d4 402
341a67c4 403 bt_message_stream_end_set_default_clock_snapshot(this->libObjPtr(), val);
2a24eba8 404 return *this;
508053d4
PP
405 }
406
ca61ecbc 407 OptionalBorrowedObject<ConstClockSnapshot> defaultClockSnapshot() const noexcept
508053d4
PP
408 {
409 const bt_clock_snapshot *libObjPtr;
410 const auto state = bt_message_stream_end_borrow_default_clock_snapshot_const(
341a67c4 411 this->libObjPtr(), &libObjPtr);
508053d4
PP
412
413 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
ca61ecbc 414 return libObjPtr;
508053d4
PP
415 }
416
ca61ecbc 417 return {};
508053d4
PP
418 }
419
420 Shared shared() const noexcept
421 {
c9c0b6e2 422 return Shared::createWithRef(*this);
508053d4
PP
423 }
424};
425
426using StreamEndMessage = CommonStreamEndMessage<bt_message>;
427using ConstStreamEndMessage = CommonStreamEndMessage<const bt_message>;
428
429namespace internal {
430
4927bae7
PP
431struct StreamEndMessageTypeDescr
432{
433 using Const = ConstStreamEndMessage;
434 using NonConst = StreamEndMessage;
435};
436
437template <>
438struct TypeDescr<StreamEndMessage> : public StreamEndMessageTypeDescr
439{
440};
441
442template <>
443struct TypeDescr<ConstStreamEndMessage> : public StreamEndMessageTypeDescr
444{
445};
446
508053d4
PP
447template <typename LibObjT>
448struct CommonPacketBeginningMessageSpec;
449
b5f55e9f 450/* Functions specific to mutable packet beginning messages */
508053d4
PP
451template <>
452struct CommonPacketBeginningMessageSpec<bt_message> final
453{
454 static bt_packet *packet(bt_message * const libObjPtr) noexcept
455 {
456 return bt_message_packet_beginning_borrow_packet(libObjPtr);
457 }
458};
459
b5f55e9f 460/* Functions specific to constant packet beginning messages */
508053d4
PP
461template <>
462struct CommonPacketBeginningMessageSpec<const bt_message> final
463{
464 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
465 {
466 return bt_message_packet_beginning_borrow_packet_const(libObjPtr);
467 }
468};
469
b5f55e9f 470} /* namespace internal */
508053d4
PP
471
472template <typename LibObjT>
473class CommonPacketBeginningMessage final : public CommonMessage<LibObjT>
474{
475private:
508053d4 476 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
8047a175 477 using _Packet = internal::DepPacket<LibObjT>;
508053d4
PP
478
479public:
d246c457 480 using typename CommonMessage<LibObjT>::LibObjPtr;
26b9d24c 481 using Shared = SharedMessage<CommonPacketBeginningMessage<LibObjT>, LibObjT>;
508053d4 482
d246c457 483 explicit CommonPacketBeginningMessage(const LibObjPtr libObjPtr) noexcept :
508053d4
PP
484 _ThisCommonMessage {libObjPtr}
485 {
486 BT_ASSERT_DBG(this->isPacketBeginning());
487 }
488
489 template <typename OtherLibObjT>
100fa861 490 CommonPacketBeginningMessage(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept :
508053d4
PP
491 _ThisCommonMessage {val}
492 {
493 }
494
495 template <typename OtherLibObjT>
ac30a470 496 CommonPacketBeginningMessage<LibObjT>
100fa861 497 operator=(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept
508053d4
PP
498 {
499 _ThisCommonMessage::operator=(val);
500 return *this;
501 }
502
328a274a
PP
503 CommonPacketBeginningMessage<const bt_message> asConst() const noexcept
504 {
505 return CommonPacketBeginningMessage<const bt_message> {*this};
506 }
507
dcb8ae9b 508 _Packet packet() const noexcept
508053d4
PP
509 {
510 return _Packet {
341a67c4 511 internal::CommonPacketBeginningMessageSpec<LibObjT>::packet(this->libObjPtr())};
508053d4
PP
512 }
513
afe77d4f
SM
514 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
515 {
516 return bt_message_packet_beginning_borrow_stream_class_default_clock_class_const(
517 this->libObjPtr());
518 }
519
2a24eba8 520 CommonPacketBeginningMessage defaultClockSnapshot(const std::uint64_t val) const noexcept
508053d4 521 {
5c895f64
PP
522 static_assert(!std::is_const<LibObjT>::value,
523 "Not available with `bt2::ConstPacketBeginningMessage`.");
508053d4 524
341a67c4 525 bt_message_packet_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
2a24eba8 526 return *this;
508053d4
PP
527 }
528
529 ConstClockSnapshot defaultClockSnapshot() const noexcept
530 {
531 const auto libObjPtr =
341a67c4 532 bt_message_packet_beginning_borrow_default_clock_snapshot_const(this->libObjPtr());
508053d4
PP
533
534 return ConstClockSnapshot {libObjPtr};
535 }
536
537 Shared shared() const noexcept
538 {
c9c0b6e2 539 return Shared::createWithRef(*this);
508053d4
PP
540 }
541};
542
543using PacketBeginningMessage = CommonPacketBeginningMessage<bt_message>;
544using ConstPacketBeginningMessage = CommonPacketBeginningMessage<const bt_message>;
545
546namespace internal {
547
4927bae7
PP
548struct PacketBeginningMessageTypeDescr
549{
550 using Const = ConstPacketBeginningMessage;
551 using NonConst = PacketBeginningMessage;
552};
553
554template <>
555struct TypeDescr<PacketBeginningMessage> : public PacketBeginningMessageTypeDescr
556{
557};
558
559template <>
560struct TypeDescr<ConstPacketBeginningMessage> : public PacketBeginningMessageTypeDescr
561{
562};
563
508053d4
PP
564template <typename LibObjT>
565struct CommonPacketEndMessageSpec;
566
b5f55e9f 567/* Functions specific to mutable packet end messages */
508053d4
PP
568template <>
569struct CommonPacketEndMessageSpec<bt_message> final
570{
571 static bt_packet *packet(bt_message * const libObjPtr) noexcept
572 {
573 return bt_message_packet_end_borrow_packet(libObjPtr);
574 }
575};
576
b5f55e9f 577/* Functions specific to constant packet end messages */
508053d4
PP
578template <>
579struct CommonPacketEndMessageSpec<const bt_message> final
580{
581 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
582 {
583 return bt_message_packet_end_borrow_packet_const(libObjPtr);
584 }
585};
586
b5f55e9f 587} /* namespace internal */
508053d4
PP
588
589template <typename LibObjT>
590class CommonPacketEndMessage final : public CommonMessage<LibObjT>
591{
592private:
508053d4 593 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
8047a175 594 using _Packet = internal::DepPacket<LibObjT>;
508053d4
PP
595
596public:
d246c457 597 using typename CommonMessage<LibObjT>::LibObjPtr;
26b9d24c 598 using Shared = SharedMessage<CommonPacketEndMessage<LibObjT>, LibObjT>;
508053d4 599
d246c457 600 explicit CommonPacketEndMessage(const LibObjPtr libObjPtr) noexcept :
508053d4
PP
601 _ThisCommonMessage {libObjPtr}
602 {
603 BT_ASSERT_DBG(this->isPacketEnd());
604 }
605
606 template <typename OtherLibObjT>
100fa861 607 CommonPacketEndMessage(const CommonPacketEndMessage<OtherLibObjT> val) noexcept :
508053d4
PP
608 _ThisCommonMessage {val}
609 {
610 }
611
612 template <typename OtherLibObjT>
ac30a470 613 CommonPacketEndMessage<LibObjT>
100fa861 614 operator=(const CommonPacketEndMessage<OtherLibObjT> val) noexcept
508053d4
PP
615 {
616 _ThisCommonMessage::operator=(val);
617 return *this;
618 }
619
328a274a
PP
620 CommonPacketEndMessage<const bt_message> asConst() const noexcept
621 {
622 return CommonPacketEndMessage<const bt_message> {*this};
623 }
624
dcb8ae9b 625 _Packet packet() const noexcept
508053d4 626 {
341a67c4 627 return _Packet {internal::CommonPacketEndMessageSpec<LibObjT>::packet(this->libObjPtr())};
508053d4
PP
628 }
629
afe77d4f
SM
630 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
631 {
632 return bt_message_packet_end_borrow_stream_class_default_clock_class_const(
633 this->libObjPtr());
634 }
635
2a24eba8 636 CommonPacketEndMessage defaultClockSnapshot(const std::uint64_t val) const noexcept
508053d4 637 {
5c895f64
PP
638 static_assert(!std::is_const<LibObjT>::value,
639 "Not available with `bt2::ConstPacketEndMessage`.");
508053d4 640
341a67c4 641 bt_message_packet_end_set_default_clock_snapshot(this->libObjPtr(), val);
2a24eba8 642 return *this;
508053d4
PP
643 }
644
645 ConstClockSnapshot defaultClockSnapshot() const noexcept
646 {
647 const auto libObjPtr =
341a67c4 648 bt_message_packet_end_borrow_default_clock_snapshot_const(this->libObjPtr());
508053d4
PP
649
650 return ConstClockSnapshot {libObjPtr};
651 }
652
653 Shared shared() const noexcept
654 {
c9c0b6e2 655 return Shared::createWithRef(*this);
508053d4
PP
656 }
657};
658
659using PacketEndMessage = CommonPacketEndMessage<bt_message>;
660using ConstPacketEndMessage = CommonPacketEndMessage<const bt_message>;
661
662namespace internal {
663
4927bae7
PP
664struct PacketEndMessageTypeDescr
665{
666 using Const = ConstPacketEndMessage;
667 using NonConst = PacketEndMessage;
668};
669
670template <>
671struct TypeDescr<PacketEndMessage> : public PacketEndMessageTypeDescr
672{
673};
674
675template <>
676struct TypeDescr<ConstPacketEndMessage> : public PacketEndMessageTypeDescr
677{
678};
679
508053d4
PP
680template <typename LibObjT>
681struct CommonEventMessageSpec;
682
b5f55e9f 683/* Functions specific to mutable event messages */
508053d4
PP
684template <>
685struct CommonEventMessageSpec<bt_message> final
686{
687 static bt_event *event(bt_message * const libObjPtr) noexcept
688 {
689 return bt_message_event_borrow_event(libObjPtr);
690 }
691};
692
b5f55e9f 693/* Functions specific to constant event messages */
508053d4
PP
694template <>
695struct CommonEventMessageSpec<const bt_message> final
696{
697 static const bt_event *event(const bt_message * const libObjPtr) noexcept
698 {
699 return bt_message_event_borrow_event_const(libObjPtr);
700 }
701};
702
b5f55e9f 703} /* namespace internal */
508053d4
PP
704
705template <typename LibObjT>
706class CommonEventMessage final : public CommonMessage<LibObjT>
707{
708private:
508053d4 709 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
8047a175 710 using _Event = internal::DepType<LibObjT, CommonEvent<bt_event>, CommonEvent<const bt_event>>;
508053d4
PP
711
712public:
d246c457 713 using typename CommonMessage<LibObjT>::LibObjPtr;
26b9d24c 714 using Shared = SharedMessage<CommonEventMessage<LibObjT>, LibObjT>;
508053d4 715
d246c457 716 explicit CommonEventMessage(const LibObjPtr libObjPtr) noexcept : _ThisCommonMessage {libObjPtr}
508053d4
PP
717 {
718 BT_ASSERT_DBG(this->isEvent());
719 }
720
721 template <typename OtherLibObjT>
100fa861 722 CommonEventMessage(const CommonEventMessage<OtherLibObjT> val) noexcept :
508053d4
PP
723 _ThisCommonMessage {val}
724 {
725 }
726
727 template <typename OtherLibObjT>
ac30a470 728 CommonEventMessage<LibObjT> operator=(const CommonEventMessage<OtherLibObjT> val) noexcept
508053d4
PP
729 {
730 _ThisCommonMessage::operator=(val);
731 return *this;
732 }
733
328a274a
PP
734 CommonEventMessage<const bt_message> asConst() const noexcept
735 {
736 return CommonEventMessage<const bt_message> {*this};
737 }
738
dcb8ae9b 739 _Event event() const noexcept
508053d4 740 {
341a67c4 741 return _Event {internal::CommonEventMessageSpec<LibObjT>::event(this->libObjPtr())};
508053d4
PP
742 }
743
ca61ecbc 744 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
84cef782 745 {
ca61ecbc 746 return bt_message_event_borrow_stream_class_default_clock_class_const(this->libObjPtr());
84cef782
PP
747 }
748
508053d4
PP
749 ConstClockSnapshot defaultClockSnapshot() const noexcept
750 {
751 const auto libObjPtr =
341a67c4 752 bt_message_event_borrow_default_clock_snapshot_const(this->libObjPtr());
508053d4
PP
753
754 return ConstClockSnapshot {libObjPtr};
755 }
756
757 Shared shared() const noexcept
758 {
c9c0b6e2 759 return Shared::createWithRef(*this);
508053d4
PP
760 }
761};
762
763using EventMessage = CommonEventMessage<bt_message>;
764using ConstEventMessage = CommonEventMessage<const bt_message>;
765
766namespace internal {
767
4927bae7
PP
768struct EventMessageTypeDescr
769{
770 using Const = ConstEventMessage;
771 using NonConst = EventMessage;
772};
773
774template <>
775struct TypeDescr<EventMessage> : public EventMessageTypeDescr
776{
777};
778
779template <>
780struct TypeDescr<ConstEventMessage> : public EventMessageTypeDescr
781{
782};
783
508053d4
PP
784template <typename LibObjT>
785struct CommonDiscardedEventsMessageSpec;
786
b5f55e9f 787/* Functions specific to mutable discarded events messages */
508053d4
PP
788template <>
789struct CommonDiscardedEventsMessageSpec<bt_message> final
790{
791 static bt_stream *stream(bt_message * const libObjPtr) noexcept
792 {
793 return bt_message_discarded_events_borrow_stream(libObjPtr);
794 }
795};
796
b5f55e9f 797/* Functions specific to constant discarded events messages */
508053d4
PP
798template <>
799struct CommonDiscardedEventsMessageSpec<const bt_message> final
800{
801 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
802 {
803 return bt_message_discarded_events_borrow_stream_const(libObjPtr);
804 }
805};
806
b5f55e9f 807} /* namespace internal */
508053d4
PP
808
809template <typename LibObjT>
810class CommonDiscardedEventsMessage final : public CommonMessage<LibObjT>
811{
812private:
508053d4 813 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
8047a175 814 using _Stream = internal::DepStream<LibObjT>;
508053d4
PP
815
816public:
d246c457 817 using typename CommonMessage<LibObjT>::LibObjPtr;
26b9d24c 818 using Shared = SharedMessage<CommonDiscardedEventsMessage<LibObjT>, LibObjT>;
508053d4 819
d246c457 820 explicit CommonDiscardedEventsMessage(const LibObjPtr libObjPtr) noexcept :
508053d4
PP
821 _ThisCommonMessage {libObjPtr}
822 {
823 BT_ASSERT_DBG(this->isDiscardedEvents());
824 }
825
826 template <typename OtherLibObjT>
100fa861 827 CommonDiscardedEventsMessage(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept :
508053d4
PP
828 _ThisCommonMessage {val}
829 {
830 }
831
832 template <typename OtherLibObjT>
ac30a470 833 CommonDiscardedEventsMessage<LibObjT>
100fa861 834 operator=(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept
508053d4
PP
835 {
836 _ThisCommonMessage::operator=(val);
837 return *this;
838 }
839
328a274a
PP
840 CommonDiscardedEventsMessage<const bt_message> asConst() const noexcept
841 {
842 return CommonDiscardedEventsMessage<const bt_message> {*this};
843 }
844
dcb8ae9b 845 _Stream stream() const noexcept
508053d4
PP
846 {
847 return _Stream {
341a67c4 848 internal::CommonDiscardedEventsMessageSpec<LibObjT>::stream(this->libObjPtr())};
508053d4
PP
849 }
850
afe77d4f
SM
851 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
852 {
853 return bt_message_discarded_events_borrow_stream_class_default_clock_class_const(
854 this->libObjPtr());
855 }
856
508053d4
PP
857 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
858 {
859 const auto libObjPtr =
860 bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
341a67c4 861 this->libObjPtr());
508053d4
PP
862
863 return ConstClockSnapshot {libObjPtr};
864 }
865
866 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
867 {
868 const auto libObjPtr =
341a67c4 869 bt_message_discarded_events_borrow_end_default_clock_snapshot_const(this->libObjPtr());
508053d4
PP
870
871 return ConstClockSnapshot {libObjPtr};
872 }
873
2a24eba8 874 CommonDiscardedEventsMessage count(const std::uint64_t count) const noexcept
508053d4 875 {
5c895f64
PP
876 static_assert(!std::is_const<LibObjT>::value,
877 "Not available with `bt2::ConstDiscardedEventsMessage`.");
508053d4 878
341a67c4 879 bt_message_discarded_events_set_count(this->libObjPtr(), count);
2a24eba8 880 return *this;
508053d4
PP
881 }
882
c022776a 883 bt2s::optional<std::uint64_t> count() const noexcept
508053d4
PP
884 {
885 std::uint64_t count;
508053d4 886
b3a12e59 887 if (bt_message_discarded_events_get_count(this->libObjPtr(), &count)) {
508053d4
PP
888 return count;
889 }
890
c022776a 891 return bt2s::nullopt;
508053d4
PP
892 }
893
894 Shared shared() const noexcept
895 {
c9c0b6e2 896 return Shared::createWithRef(*this);
508053d4
PP
897 }
898};
899
900using DiscardedEventsMessage = CommonDiscardedEventsMessage<bt_message>;
901using ConstDiscardedEventsMessage = CommonDiscardedEventsMessage<const bt_message>;
902
903namespace internal {
904
4927bae7
PP
905struct DiscardedEventsMessageTypeDescr
906{
907 using Const = ConstDiscardedEventsMessage;
908 using NonConst = DiscardedEventsMessage;
909};
910
911template <>
912struct TypeDescr<DiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
913{
914};
915
916template <>
917struct TypeDescr<ConstDiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
918{
919};
920
508053d4
PP
921template <typename LibObjT>
922struct CommonDiscardedPacketsMessageSpec;
923
b5f55e9f 924/* Functions specific to mutable discarded packets messages */
508053d4
PP
925template <>
926struct CommonDiscardedPacketsMessageSpec<bt_message> final
927{
928 static bt_stream *stream(bt_message * const libObjPtr) noexcept
929 {
930 return bt_message_discarded_packets_borrow_stream(libObjPtr);
931 }
932};
933
b5f55e9f 934/* Functions specific to constant discarded packets messages */
508053d4
PP
935template <>
936struct CommonDiscardedPacketsMessageSpec<const bt_message> final
937{
938 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
939 {
940 return bt_message_discarded_packets_borrow_stream_const(libObjPtr);
941 }
942};
943
b5f55e9f 944} /* namespace internal */
508053d4
PP
945
946template <typename LibObjT>
947class CommonDiscardedPacketsMessage final : public CommonMessage<LibObjT>
948{
949private:
508053d4 950 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
8047a175 951 using _Stream = internal::DepStream<LibObjT>;
508053d4
PP
952
953public:
d246c457 954 using typename CommonMessage<LibObjT>::LibObjPtr;
26b9d24c 955 using Shared = SharedMessage<CommonDiscardedPacketsMessage<LibObjT>, LibObjT>;
508053d4 956
d246c457 957 explicit CommonDiscardedPacketsMessage(const LibObjPtr libObjPtr) noexcept :
508053d4
PP
958 _ThisCommonMessage {libObjPtr}
959 {
960 BT_ASSERT_DBG(this->isDiscardedPackets());
961 }
962
963 template <typename OtherLibObjT>
100fa861 964 CommonDiscardedPacketsMessage(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept :
508053d4
PP
965 _ThisCommonMessage {val}
966 {
967 }
968
969 template <typename OtherLibObjT>
ac30a470 970 CommonDiscardedPacketsMessage<LibObjT>
100fa861 971 operator=(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept
508053d4
PP
972 {
973 _ThisCommonMessage::operator=(val);
974 return *this;
975 }
976
328a274a
PP
977 CommonDiscardedPacketsMessage<const bt_message> asConst() const noexcept
978 {
979 return CommonDiscardedPacketsMessage<const bt_message> {*this};
980 }
981
dcb8ae9b 982 _Stream stream() const noexcept
508053d4
PP
983 {
984 return _Stream {
341a67c4 985 internal::CommonDiscardedPacketsMessageSpec<LibObjT>::stream(this->libObjPtr())};
508053d4
PP
986 }
987
afe77d4f
SM
988 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
989 {
990 return bt_message_discarded_packets_borrow_stream_class_default_clock_class_const(
991 this->libObjPtr());
992 }
993
508053d4
PP
994 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
995 {
996 const auto libObjPtr =
997 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
341a67c4 998 this->libObjPtr());
508053d4
PP
999
1000 return ConstClockSnapshot {libObjPtr};
1001 }
1002
1003 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
1004 {
341a67c4
FD
1005 const auto libObjPtr =
1006 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(this->libObjPtr());
508053d4
PP
1007
1008 return ConstClockSnapshot {libObjPtr};
1009 }
1010
2a24eba8 1011 CommonDiscardedPacketsMessage count(const std::uint64_t count) const noexcept
508053d4 1012 {
5c895f64
PP
1013 static_assert(!std::is_const<LibObjT>::value,
1014 "Not available with `bt2::ConstDiscardedPacketsMessage`.");
508053d4 1015
341a67c4 1016 bt_message_discarded_packets_set_count(this->libObjPtr(), count);
2a24eba8 1017 return *this;
508053d4
PP
1018 }
1019
c022776a 1020 bt2s::optional<std::uint64_t> count() const noexcept
508053d4
PP
1021 {
1022 std::uint64_t count;
508053d4 1023
b3a12e59 1024 if (bt_message_discarded_packets_get_count(this->libObjPtr(), &count)) {
508053d4
PP
1025 return count;
1026 }
1027
c022776a 1028 return bt2s::nullopt;
508053d4
PP
1029 }
1030
1031 Shared shared() const noexcept
1032 {
c9c0b6e2 1033 return Shared::createWithRef(*this);
508053d4
PP
1034 }
1035};
1036
1037using DiscardedPacketsMessage = CommonDiscardedPacketsMessage<bt_message>;
1038using ConstDiscardedPacketsMessage = CommonDiscardedPacketsMessage<const bt_message>;
1039
4927bae7
PP
1040namespace internal {
1041
1042struct DiscardedPacketsMessageTypeDescr
1043{
1044 using Const = ConstDiscardedPacketsMessage;
1045 using NonConst = DiscardedPacketsMessage;
1046};
1047
1048template <>
1049struct TypeDescr<DiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1050{
1051};
1052
1053template <>
1054struct TypeDescr<ConstDiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1055{
1056};
1057
1058} /* namespace internal */
1059
508053d4
PP
1060template <typename LibObjT>
1061class CommonMessageIteratorInactivityMessage final : public CommonMessage<LibObjT>
1062{
1063private:
508053d4
PP
1064 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
1065
1066public:
d246c457 1067 using typename CommonMessage<LibObjT>::LibObjPtr;
26b9d24c 1068 using Shared = SharedMessage<CommonMessageIteratorInactivityMessage<LibObjT>, LibObjT>;
508053d4 1069
d246c457 1070 explicit CommonMessageIteratorInactivityMessage(const LibObjPtr libObjPtr) noexcept :
508053d4
PP
1071 _ThisCommonMessage {libObjPtr}
1072 {
1073 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1074 }
1075
1076 template <typename OtherLibObjT>
1077 CommonMessageIteratorInactivityMessage(
100fa861 1078 const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept :
508053d4
PP
1079 _ThisCommonMessage {val}
1080 {
1081 }
1082
1083 template <typename OtherLibObjT>
ac30a470 1084 CommonMessageIteratorInactivityMessage<LibObjT>
100fa861 1085 operator=(const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept
508053d4
PP
1086 {
1087 _ThisCommonMessage::operator=(val);
1088 return *this;
1089 }
1090
328a274a
PP
1091 CommonMessageIteratorInactivityMessage<const bt_message> asConst() const noexcept
1092 {
1093 return CommonMessageIteratorInactivityMessage<const bt_message> {*this};
1094 }
1095
508053d4
PP
1096 ConstClockSnapshot clockSnapshot() const noexcept
1097 {
1098 const auto libObjPtr =
341a67c4 1099 bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(this->libObjPtr());
508053d4
PP
1100
1101 return ConstClockSnapshot {libObjPtr};
1102 }
1103
1104 Shared shared() const noexcept
1105 {
c9c0b6e2 1106 return Shared::createWithRef(*this);
508053d4
PP
1107 }
1108};
1109
1110using MessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage<bt_message>;
1111using ConstMessageIteratorInactivityMessage =
1112 CommonMessageIteratorInactivityMessage<const bt_message>;
1113
4927bae7
PP
1114namespace internal {
1115
1116struct MessageIteratorInactivityMessageTypeDescr
1117{
1118 using Const = ConstMessageIteratorInactivityMessage;
1119 using NonConst = MessageIteratorInactivityMessage;
1120};
1121
1122template <>
1123struct TypeDescr<MessageIteratorInactivityMessage> :
1124 public MessageIteratorInactivityMessageTypeDescr
1125{
1126};
1127
1128template <>
1129struct TypeDescr<ConstMessageIteratorInactivityMessage> :
1130 public MessageIteratorInactivityMessageTypeDescr
1131{
1132};
1133
1134} /* namespace internal */
1135
508053d4
PP
1136template <typename LibObjT>
1137CommonStreamBeginningMessage<LibObjT> CommonMessage<LibObjT>::asStreamBeginning() const noexcept
1138{
341a67c4 1139 return CommonStreamBeginningMessage<LibObjT> {this->libObjPtr()};
508053d4
PP
1140}
1141
1142template <typename LibObjT>
1143CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept
1144{
341a67c4 1145 return CommonStreamEndMessage<LibObjT> {this->libObjPtr()};
508053d4
PP
1146}
1147
1148template <typename LibObjT>
1149CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept
1150{
341a67c4 1151 return CommonPacketBeginningMessage<LibObjT> {this->libObjPtr()};
508053d4
PP
1152}
1153
1154template <typename LibObjT>
1155CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept
1156{
341a67c4 1157 return CommonPacketEndMessage<LibObjT> {this->libObjPtr()};
508053d4
PP
1158}
1159
1160template <typename LibObjT>
1161CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept
1162{
341a67c4 1163 return CommonEventMessage<LibObjT> {this->libObjPtr()};
508053d4
PP
1164}
1165
1166template <typename LibObjT>
1167CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept
1168{
341a67c4 1169 return CommonDiscardedEventsMessage<LibObjT> {this->libObjPtr()};
508053d4
PP
1170}
1171
bd7dbf87
FD
1172template <typename LibObjT>
1173CommonDiscardedPacketsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedPackets() const noexcept
1174{
bd7dbf87
FD
1175 return CommonDiscardedPacketsMessage<LibObjT> {this->libObjPtr()};
1176}
1177
508053d4
PP
1178template <typename LibObjT>
1179CommonMessageIteratorInactivityMessage<LibObjT>
1180CommonMessage<LibObjT>::asMessageIteratorInactivity() const noexcept
1181{
341a67c4 1182 return CommonMessageIteratorInactivityMessage<LibObjT> {this->libObjPtr()};
508053d4
PP
1183}
1184
b5f55e9f 1185} /* namespace bt2 */
508053d4 1186
b5f55e9f 1187#endif /* BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP */
This page took 0.100806 seconds and 4 git commands to generate.