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