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/assert.h"
13 #include "common/common.h"
15 #include "borrowed-object.hpp"
16 #include "message-iterator.hpp"
17 #include "self-component-port.hpp"
21 class SelfMessageIterator final : public BorrowedObject<bt_self_message_iterator>
24 explicit SelfMessageIterator(const _LibObjPtr libObjPtr) noexcept :
25 _ThisBorrowedObject {libObjPtr}
29 MessageIterator::Shared createMessageIterator(const SelfComponentInputPort port) const
31 bt_message_iterator *libMsgIterPtr = nullptr;
32 const auto status = bt_message_iterator_create_from_message_iterator(
33 this->libObjPtr(), port.libObjPtr(), &libMsgIterPtr);
36 case BT_MESSAGE_ITERATOR_CREATE_FROM_MESSAGE_ITERATOR_STATUS_OK:
37 BT_ASSERT(libMsgIterPtr);
38 return MessageIterator::Shared::createWithoutRef(libMsgIterPtr);
39 case BT_MESSAGE_ITERATOR_CREATE_FROM_MESSAGE_ITERATOR_STATUS_MEMORY_ERROR:
41 case BT_MESSAGE_ITERATOR_CREATE_FROM_MESSAGE_ITERATOR_STATUS_ERROR:
48 SelfComponent component() const noexcept
50 return SelfComponent {bt_self_message_iterator_borrow_component(this->libObjPtr())};
53 SelfComponentOutputPort port() const noexcept
55 return SelfComponentOutputPort {bt_self_message_iterator_borrow_port(this->libObjPtr())};
58 bool isInterrupted() const noexcept
60 return static_cast<bool>(bt_self_message_iterator_is_interrupted(this->libObjPtr()));
64 T& data() const noexcept
66 return *static_cast<T *>(bt_self_message_iterator_get_data(this->libObjPtr()));
70 void data(T& obj) const noexcept
72 bt_self_message_iterator_set_data(this->libObjPtr(), static_cast<void *>(&obj));
78 #endif /* BABELTRACE_CPP_COMMON_BT2_SELF_MESSAGE_ITERATOR_HPP */