2 * Copyright (c) 2023 Philippe Proulx <pproulx@efficios.com>
4 * SPDX-License-Identifier: MIT
7 #ifndef BABELTRACE_CPP_COMMON_BT2_SELF_MESSAGE_ITERATOR_HPP
8 #define BABELTRACE_CPP_COMMON_BT2_SELF_MESSAGE_ITERATOR_HPP
10 #include <babeltrace2/babeltrace.h>
12 #include "common/common.h"
14 #include "borrowed-object.hpp"
15 #include "message-iterator.hpp"
16 #include "self-component-port.hpp"
20 class SelfMessageIterator final : public BorrowedObject<bt_self_message_iterator>
23 explicit SelfMessageIterator(const LibObjPtr libObjPtr) noexcept :
24 _ThisBorrowedObject {libObjPtr}
28 MessageIterator::Shared createMessageIterator(const SelfComponentInputPort port) const
30 bt_message_iterator *libMsgIterPtr = nullptr;
31 const auto status = bt_message_iterator_create_from_message_iterator(
32 this->libObjPtr(), port.libObjPtr(), &libMsgIterPtr);
35 case BT_MESSAGE_ITERATOR_CREATE_FROM_MESSAGE_ITERATOR_STATUS_OK:
36 return MessageIterator::Shared::createWithoutRef(libMsgIterPtr);
37 case BT_MESSAGE_ITERATOR_CREATE_FROM_MESSAGE_ITERATOR_STATUS_MEMORY_ERROR:
39 case BT_MESSAGE_ITERATOR_CREATE_FROM_MESSAGE_ITERATOR_STATUS_ERROR:
46 SelfComponent component() const noexcept
48 return SelfComponent {bt_self_message_iterator_borrow_component(this->libObjPtr())};
51 SelfComponentOutputPort port() const noexcept
53 return SelfComponentOutputPort {bt_self_message_iterator_borrow_port(this->libObjPtr())};
56 bool isInterrupted() const noexcept
58 return static_cast<bool>(bt_self_message_iterator_is_interrupted(this->libObjPtr()));
62 T& data() const noexcept
64 return *static_cast<T *>(bt_self_message_iterator_get_data(this->libObjPtr()));
68 SelfMessageIterator data(T& obj) const noexcept
70 bt_self_message_iterator_set_data(this->libObjPtr(),
71 const_cast<void *>(static_cast<const void *>(&obj)));
75 StreamBeginningMessage::Shared createStreamBeginningMessage(const ConstStream stream) const
77 const auto libObjPtr =
78 bt_message_stream_beginning_create(this->libObjPtr(), stream.libObjPtr());
84 return StreamBeginningMessage::Shared::createWithoutRef(libObjPtr);
87 StreamEndMessage::Shared createStreamEndMessage(const ConstStream stream) const
89 const auto libObjPtr = bt_message_stream_end_create(this->libObjPtr(), stream.libObjPtr());
95 return StreamEndMessage::Shared::createWithoutRef(libObjPtr);
98 EventMessage::Shared createEventMessage(const ConstEventClass eventCls,
99 const ConstStream stream) const
101 const auto libObjPtr =
102 bt_message_event_create(this->libObjPtr(), eventCls.libObjPtr(), stream.libObjPtr());
105 throw MemoryError {};
108 return EventMessage::Shared::createWithoutRef(libObjPtr);
111 EventMessage::Shared createEventMessage(const ConstEventClass eventCls,
112 const ConstStream stream,
113 const std::uint64_t clockSnapshotValue) const
115 const auto libObjPtr = bt_message_event_create_with_default_clock_snapshot(
116 this->libObjPtr(), eventCls.libObjPtr(), stream.libObjPtr(), clockSnapshotValue);
119 throw MemoryError {};
122 return EventMessage::Shared::createWithoutRef(libObjPtr);
125 EventMessage::Shared createEventMessage(const ConstEventClass eventCls,
126 const ConstPacket packet) const
128 const auto libObjPtr = bt_message_event_create_with_packet(
129 this->libObjPtr(), eventCls.libObjPtr(), packet.libObjPtr());
132 throw MemoryError {};
135 return EventMessage::Shared::createWithoutRef(libObjPtr);
138 EventMessage::Shared createEventMessage(const ConstEventClass eventCls,
139 const ConstPacket packet,
140 const std::uint64_t clockSnapshotValue) const
142 const auto libObjPtr = bt_message_event_create_with_packet_and_default_clock_snapshot(
143 this->libObjPtr(), eventCls.libObjPtr(), packet.libObjPtr(), clockSnapshotValue);
146 throw MemoryError {};
149 return EventMessage::Shared::createWithoutRef(libObjPtr);
152 PacketBeginningMessage::Shared createPacketBeginningMessage(const ConstPacket packet) const
154 const auto libObjPtr =
155 bt_message_packet_beginning_create(this->libObjPtr(), packet.libObjPtr());
158 throw MemoryError {};
161 return PacketBeginningMessage::Shared::createWithoutRef(libObjPtr);
164 PacketBeginningMessage::Shared
165 createPacketBeginningMessage(const ConstPacket packet,
166 const std::uint64_t clockSnapshotValue) const
168 const auto libObjPtr = bt_message_packet_beginning_create_with_default_clock_snapshot(
169 this->libObjPtr(), packet.libObjPtr(), clockSnapshotValue);
172 throw MemoryError {};
175 return PacketBeginningMessage::Shared::createWithoutRef(libObjPtr);
178 PacketEndMessage::Shared createPacketEndMessage(const ConstPacket packet) const
180 const auto libObjPtr = bt_message_packet_end_create(this->libObjPtr(), packet.libObjPtr());
183 throw MemoryError {};
186 return PacketEndMessage::Shared::createWithoutRef(libObjPtr);
189 PacketEndMessage::Shared createPacketEndMessage(const ConstPacket packet,
190 const std::uint64_t clockSnapshotValue) const
192 const auto libObjPtr = bt_message_packet_end_create_with_default_clock_snapshot(
193 this->libObjPtr(), packet.libObjPtr(), clockSnapshotValue);
196 throw MemoryError {};
199 return PacketEndMessage::Shared::createWithoutRef(libObjPtr);
202 DiscardedEventsMessage::Shared createDiscardedEventsMessage(const ConstStream stream)
204 const auto libObjPtr =
205 bt_message_discarded_events_create(this->libObjPtr(), stream.libObjPtr());
208 throw MemoryError {};
211 return DiscardedEventsMessage::Shared::createWithoutRef(libObjPtr);
214 DiscardedEventsMessage::Shared
215 createDiscardedEventsMessage(const ConstStream stream,
216 const std::uint64_t beginningClockSnapshotValue,
217 const std::uint64_t endClockSnapshotValue) const
219 const auto libObjPtr = bt_message_discarded_events_create_with_default_clock_snapshots(
220 this->libObjPtr(), stream.libObjPtr(), beginningClockSnapshotValue,
221 endClockSnapshotValue);
224 throw MemoryError {};
227 return DiscardedEventsMessage::Shared::createWithoutRef(libObjPtr);
230 DiscardedPacketsMessage::Shared createDiscardedPacketsMessage(const ConstStream stream) const
232 const auto libObjPtr =
233 bt_message_discarded_packets_create(this->libObjPtr(), stream.libObjPtr());
236 throw MemoryError {};
239 return DiscardedPacketsMessage::Shared::createWithoutRef(libObjPtr);
242 DiscardedPacketsMessage::Shared
243 createDiscardedPacketsMessage(const ConstStream stream,
244 const std::uint64_t beginningClockSnapshotValue,
245 const std::uint64_t endClockSnapshotValue) const
247 const auto libObjPtr = bt_message_discarded_packets_create_with_default_clock_snapshots(
248 this->libObjPtr(), stream.libObjPtr(), beginningClockSnapshotValue,
249 endClockSnapshotValue);
252 throw MemoryError {};
255 return DiscardedPacketsMessage::Shared::createWithoutRef(libObjPtr);
258 MessageIteratorInactivityMessage::Shared
259 createMessageIteratorInactivityMessage(const ConstClockClass clockClass,
260 const std::uint64_t clockSnapshotValue) const
262 const auto libObjPtr = bt_message_message_iterator_inactivity_create(
263 this->libObjPtr(), clockClass.libObjPtr(), clockSnapshotValue);
266 throw MemoryError {};
269 return MessageIteratorInactivityMessage::Shared::createWithoutRef(libObjPtr);
273 } /* namespace bt2 */
275 #endif /* BABELTRACE_CPP_COMMON_BT2_SELF_MESSAGE_ITERATOR_HPP */