Skip to content

Commit c245c07

Browse files
committed
iox-#2408 add Node builder listener support
1 parent 9950a3c commit c245c07

File tree

5 files changed

+118
-0
lines changed

5 files changed

+118
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) 2024 by ekxide IO GmbH. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
17+
#ifndef IOX_POSH_EXPERIMENTAL_LISTENER_INL
18+
#define IOX_POSH_EXPERIMENTAL_LISTENER_INL
19+
20+
#include "iox/posh/experimental/listener.hpp"
21+
22+
namespace iox::posh::experimental
23+
{
24+
inline ListenerBuilder::ListenerBuilder(runtime::PoshRuntime& runtime) noexcept
25+
: m_runtime(runtime)
26+
{
27+
}
28+
29+
inline expected<unique_ptr<Listener>, ListenerBuilderError> ListenerBuilder::create() noexcept
30+
{
31+
auto* condition_variable_data = m_runtime.getMiddlewareConditionVariable();
32+
33+
if (condition_variable_data == nullptr)
34+
{
35+
return err(ListenerBuilderError::OUT_OF_RESOURCES);
36+
}
37+
return ok(unique_ptr<Listener>{new (std::nothrow) Listener{*condition_variable_data}, [&](auto* const listener) {
38+
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory) raw pointer is required by the unique_ptr API
39+
delete listener;
40+
}});
41+
}
42+
43+
} // namespace iox::posh::experimental
44+
45+
#endif // IOX_POSH_EXPERIMENTAL_LISTENER_INL
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) 2024 by ekxide IO GmbH. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
17+
#ifndef IOX_POSH_EXPERIMENTAL_LISTENER_HPP
18+
#define IOX_POSH_EXPERIMENTAL_LISTENER_HPP
19+
20+
#include "iceoryx_posh/iceoryx_posh_types.hpp"
21+
#include "iceoryx_posh/internal/runtime/posh_runtime_impl.hpp"
22+
#include "iceoryx_posh/popo/listener.hpp"
23+
#include "iox/builder.hpp"
24+
#include "iox/expected.hpp"
25+
#include "iox/optional.hpp"
26+
#include "iox/unique_ptr.hpp"
27+
28+
namespace iox::posh::experimental
29+
{
30+
31+
using Listener = iox::popo::Listener;
32+
33+
enum class ListenerBuilderError : uint8_t
34+
{
35+
OUT_OF_RESOURCES,
36+
};
37+
38+
/// @brief A builder for the listener
39+
class ListenerBuilder
40+
{
41+
public:
42+
/// @brief Creates a listener
43+
/// @return a 'listener' on success and a 'ListenerBuilderError' on failure
44+
expected<unique_ptr<Listener>, ListenerBuilderError> create() noexcept;
45+
46+
private:
47+
friend class Node;
48+
explicit ListenerBuilder(runtime::PoshRuntime& runtime) noexcept;
49+
50+
private:
51+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members) Intentionally used since the ListenerBuilder is not intended to be moved
52+
runtime::PoshRuntime& m_runtime;
53+
};
54+
} // namespace iox::posh::experimental
55+
56+
#include "iox/posh/experimental/detail/listener.inl"
57+
58+
#endif // IOX_POSH_EXPERIMENTAL_LISTENER_HPP

iceoryx_posh/experimental/include/iox/posh/experimental/node.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "iox/expected.hpp"
2828
#include "iox/optional.hpp"
2929
#include "iox/posh/experimental/client.hpp"
30+
#include "iox/posh/experimental/listener.hpp"
3031
#include "iox/posh/experimental/publisher.hpp"
3132
#include "iox/posh/experimental/server.hpp"
3233
#include "iox/posh/experimental/subscriber.hpp"
@@ -132,6 +133,9 @@ class Node
132133
/// @brief Initiates a 'WaitSetBuilder'
133134
WaitSetBuilder wait_set() noexcept;
134135

136+
/// @brief Initiates a 'Listener'
137+
ListenerBuilder listener() noexcept;
138+
135139
/// @brief Set Node Runtime as default Runtime
136140
void setDefaultRuntime();
137141

iceoryx_posh/experimental/source/node.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ WaitSetBuilder Node::wait_set() noexcept
172172
return WaitSetBuilder{*m_runtime.get()};
173173
}
174174

175+
ListenerBuilder Node::listener() noexcept
176+
{
177+
return ListenerBuilder{*m_runtime.get()};
178+
}
179+
175180
iox::runtime::PoshRuntime& Node::getNodeRuntime([[maybe_unused]] optional<const RuntimeName_t*> name)
176181
{
177182
IOX_ASSERT(s_defaultRuntime, "Node Default Runtime has not been created");

iceoryx_posh/include/iceoryx_posh/popo/listener.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131

3232
#include <thread>
3333

34+
namespace iox::posh::experimental
35+
{
36+
class ListenerBuilder;
37+
}
38+
3439
namespace iox
3540
{
3641
namespace popo
@@ -168,6 +173,7 @@ class Listener
168173
uint64_t size() const noexcept;
169174

170175
protected:
176+
friend class iox::posh::experimental::ListenerBuilder;
171177
Listener(ConditionVariableData& conditionVariableData) noexcept;
172178

173179
private:

0 commit comments

Comments
 (0)