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