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