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 void data(T& obj) const noexcept
70 bt_self_message_iterator_set_data(this->libObjPtr(),
71 const_cast<void *>(static_cast<const void *>(&obj)));
74 bt2::StreamBeginningMessage::Shared
75 createStreamBeginningMessage(const bt2::ConstStream stream) const
77 const auto libObjPtr =
78 bt_message_stream_beginning_create(this->libObjPtr(), stream.libObjPtr());
84 return bt2::StreamBeginningMessage::Shared::createWithoutRef(libObjPtr);
87 bt2::StreamEndMessage::Shared createStreamEndMessage(const bt2::ConstStream stream) const
89 const auto libObjPtr = bt_message_stream_end_create(this->libObjPtr(), stream.libObjPtr());
95 return bt2::StreamEndMessage::Shared::createWithoutRef(libObjPtr);
98 bt2::EventMessage::Shared createEventMessage(const bt2::ConstEventClass eventCls,
99 const bt2::ConstStream stream) const
101 const auto libObjPtr =
102 bt_message_event_create(this->libObjPtr(), eventCls.libObjPtr(), stream.libObjPtr());
105 throw MemoryError {};
108 return bt2::EventMessage::Shared::createWithoutRef(libObjPtr);
111 bt2::EventMessage::Shared createEventMessage(const bt2::ConstEventClass eventCls,
112 const bt2::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 bt2::EventMessage::Shared::createWithoutRef(libObjPtr);
125 bt2::EventMessage::Shared createEventMessage(const bt2::ConstEventClass eventCls,
126 const bt2::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 bt2::EventMessage::Shared::createWithoutRef(libObjPtr);
138 bt2::EventMessage::Shared createEventMessage(const bt2::ConstEventClass eventCls,
139 const bt2::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 bt2::EventMessage::Shared::createWithoutRef(libObjPtr);
152 bt2::PacketBeginningMessage::Shared
153 createPacketBeginningMessage(const bt2::ConstPacket packet) const
155 const auto libObjPtr =
156 bt_message_packet_beginning_create(this->libObjPtr(), packet.libObjPtr());
159 throw MemoryError {};
162 return bt2::PacketBeginningMessage::Shared::createWithoutRef(libObjPtr);
165 bt2::PacketBeginningMessage::Shared
166 createPacketBeginningMessage(const bt2::ConstPacket packet,
167 const std::uint64_t clockSnapshotValue) const
169 const auto libObjPtr = bt_message_packet_beginning_create_with_default_clock_snapshot(
170 this->libObjPtr(), packet.libObjPtr(), clockSnapshotValue);
173 throw MemoryError {};
176 return bt2::PacketBeginningMessage::Shared::createWithoutRef(libObjPtr);
179 bt2::PacketEndMessage::Shared createPacketEndMessage(const bt2::ConstPacket packet) const
181 const auto libObjPtr = bt_message_packet_end_create(this->libObjPtr(), packet.libObjPtr());
184 throw MemoryError {};
187 return bt2::PacketEndMessage::Shared::createWithoutRef(libObjPtr);
190 bt2::PacketEndMessage::Shared
191 createPacketEndMessage(const bt2::ConstPacket packet,
192 const std::uint64_t clockSnapshotValue) const
194 const auto libObjPtr = bt_message_packet_end_create_with_default_clock_snapshot(
195 this->libObjPtr(), packet.libObjPtr(), clockSnapshotValue);
198 throw MemoryError {};
201 return bt2::PacketEndMessage::Shared::createWithoutRef(libObjPtr);
204 bt2::DiscardedEventsMessage::Shared createDiscardedEventsMessage(const bt2::ConstStream stream)
206 const auto libObjPtr =
207 bt_message_discarded_events_create(this->libObjPtr(), stream.libObjPtr());
210 throw MemoryError {};
213 return bt2::DiscardedEventsMessage::Shared::createWithoutRef(libObjPtr);
216 bt2::DiscardedEventsMessage::Shared
217 createDiscardedEventsMessage(const bt2::ConstStream stream,
218 const std::uint64_t beginningClockSnapshotValue,
219 const std::uint64_t endClockSnapshotValue) const
221 const auto libObjPtr = bt_message_discarded_events_create_with_default_clock_snapshots(
222 this->libObjPtr(), stream.libObjPtr(), beginningClockSnapshotValue,
223 endClockSnapshotValue);
226 throw MemoryError {};
229 return bt2::DiscardedEventsMessage::Shared::createWithoutRef(libObjPtr);
232 bt2::DiscardedPacketsMessage::Shared
233 createDiscardedPacketsMessage(const bt2::ConstStream stream) const
235 const auto libObjPtr =
236 bt_message_discarded_packets_create(this->libObjPtr(), stream.libObjPtr());
239 throw MemoryError {};
242 return bt2::DiscardedPacketsMessage::Shared::createWithoutRef(libObjPtr);
245 bt2::DiscardedPacketsMessage::Shared
246 createDiscardedPacketsMessage(const bt2::ConstStream stream,
247 const std::uint64_t beginningClockSnapshotValue,
248 const std::uint64_t endClockSnapshotValue) const
250 const auto libObjPtr = bt_message_discarded_packets_create_with_default_clock_snapshots(
251 this->libObjPtr(), stream.libObjPtr(), beginningClockSnapshotValue,
252 endClockSnapshotValue);
255 throw MemoryError {};
258 return bt2::DiscardedPacketsMessage::Shared::createWithoutRef(libObjPtr);
261 bt2::MessageIteratorInactivityMessage::Shared
262 createMessageIteratorInactivityMessage(const bt2::ConstClockClass clockClass,
263 const std::uint64_t clockSnapshotValue) const
265 const auto libObjPtr = bt_message_message_iterator_inactivity_create(
266 this->libObjPtr(), clockClass.libObjPtr(), clockSnapshotValue);
269 throw MemoryError {};
272 return bt2::MessageIteratorInactivityMessage::Shared::createWithoutRef(libObjPtr);
276 } /* namespace bt2 */
278 #endif /* BABELTRACE_CPP_COMMON_BT2_SELF_MESSAGE_ITERATOR_HPP */