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