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