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