13#ifndef IOX2_SERVICE_BLACKBOARD_BUILDER_HPP
14#define IOX2_SERVICE_BLACKBOARD_BUILDER_HPP
30template <
typename KeyType, ServiceType S>
33 static_assert(std::is_trivially_copyable<KeyType>::value,
34 "The blackboard supports only trivially copyable key types.");
35 static_assert(std::alignment_of<KeyType>() <= IOX2_MAX_BLACKBOARD_KEY_ALIGNMENT,
36 "The blackboard supports only key types with an alignment <= IOX2_MAX_BLACKBOARD_KEY_ALIGNMENT.");
37 static_assert(
sizeof(KeyType) <= IOX2_MAX_BLACKBOARD_KEY_SIZE,
38 "The blackboard supports only key types with a size <= IOX2_MAX_BLACKBOARD_KEY_SIZE.");
42#ifdef DOXYGEN_MACRO_FIX
49#ifdef DOXYGEN_MACRO_FIX
50 auto max_nodes(
const uint64_t value) ->
decltype(
auto);
57 template <
typename ValueType>
61 template <
typename ValueType>
73 template <ServiceType>
78 void set_parameters();
80 iox2_service_builder_blackboard_creator_h m_handle =
nullptr;
83template <
typename KeyType, ServiceType S>
87#ifdef DOXYGEN_MACRO_FIX
94#ifdef DOXYGEN_MACRO_FIX
95 auto max_nodes(
const uint64_t value) ->
decltype(
auto);
111 template <ServiceType>
116 void set_parameters();
118 iox2_service_builder_blackboard_opener_h m_handle =
nullptr;
123auto default_key_eq_cmp_func(
const void* lhs,
const void* rhs) ->
bool {
125 return (*
reinterpret_cast<const T*
>(lhs)) == (*
reinterpret_cast<const T*
>(rhs));
129template <
typename KeyType, ServiceType S>
130inline ServiceBuilderBlackboardCreator<KeyType, S>::ServiceBuilderBlackboardCreator(iox2_service_builder_h handle)
131 : m_handle { iox2_service_builder_blackboard_creator(handle) } {
133 const auto type_name = internal::get_type_name<KeyType>();
134 const auto key_type_result = iox2_service_builder_blackboard_creator_set_key_type_details(
135 &m_handle, type_name.unchecked_access().c_str(), type_name.size(),
sizeof(KeyType),
alignof(KeyType));
136 if (key_type_result != IOX2_OK) {
137 IOX2_PANIC(
"This should never happen! Implementation failure while setting the key type.");
141template <
typename KeyType, ServiceType S>
142inline void ServiceBuilderBlackboardCreator<KeyType, S>::set_parameters() {
143 if (m_max_readers.has_value()) {
144 iox2_service_builder_blackboard_creator_set_max_readers(&m_handle, m_max_readers.value());
146 if (m_max_nodes.has_value()) {
147 iox2_service_builder_blackboard_creator_set_max_nodes(&m_handle, m_max_nodes.value());
151 iox2_service_builder_blackboard_creator_set_key_eq_comparison_function(&m_handle,
152 internal::default_key_eq_cmp_func<KeyType>);
155template <
typename KeyType, ServiceType S>
156template <
typename ValueType>
159 static_assert(std::is_trivially_copyable<ValueType>::value,
160 "The blackboard supports only trivially copyable value types.");
163 auto value_ptr =
new ValueType(value);
164 const auto type_name = internal::get_type_name<ValueType>();
166 iox2_service_builder_blackboard_creator_add(
170 [](
void* value) ->
auto {
171 auto* value_ptr =
static_cast<ValueType*
>(value);
172 if (value_ptr !=
nullptr) {
178 type_name.unchecked_access().c_str(),
183 return std::move(*
this);
186template <
typename KeyType, ServiceType S>
187template <
typename ValueType>
190 return add(key, ValueType());
193template <
typename KeyType, ServiceType S>
198 iox2_port_factory_blackboard_h port_factory_handle {};
199 auto result = iox2_service_builder_blackboard_create(m_handle,
nullptr, &port_factory_handle);
201 if (result == IOX2_OK) {
205 return bb::err(bb::into<BlackboardCreateError>(result));
208template <
typename KeyType, ServiceType S>
213 iox2_port_factory_blackboard_h port_factory_handle {};
214 auto result = iox2_service_builder_blackboard_create_with_attributes(
215 m_handle, &attributes.m_handle,
nullptr, &port_factory_handle);
217 if (result == IOX2_OK) {
221 return bb::err(bb::into<BlackboardCreateError>(result));
224template <
typename KeyType, ServiceType S>
226 : m_handle { iox2_service_builder_blackboard_opener(handle) } {
229template <
typename KeyType, ServiceType S>
230inline void ServiceBuilderBlackboardOpener<KeyType, S>::set_parameters() {
231 if (m_max_readers.has_value()) {
232 iox2_service_builder_blackboard_opener_set_max_readers(&m_handle, m_max_readers.value());
234 if (m_max_nodes.has_value()) {
235 iox2_service_builder_blackboard_opener_set_max_nodes(&m_handle, m_max_nodes.value());
239 const auto type_name = internal::get_type_name<KeyType>();
240 const auto key_type_result = iox2_service_builder_blackboard_opener_set_key_type_details(
241 &m_handle, type_name.unchecked_access().c_str(), type_name.size(),
sizeof(KeyType),
alignof(KeyType));
242 if (key_type_result != IOX2_OK) {
243 IOX2_PANIC(
"This should never happen! Implementation failure while setting the Key-Type.");
247template <
typename KeyType, ServiceType S>
252 iox2_port_factory_blackboard_h port_factory_handle {};
253 auto result = iox2_service_builder_blackboard_open(m_handle,
nullptr, &port_factory_handle);
255 if (result == IOX2_OK) {
259 return bb::err(bb::into<BlackboardOpenError>(result));
262template <
typename KeyType, ServiceType S>
268 iox2_port_factory_blackboard_h port_factory_handle {};
269 auto result = iox2_service_builder_blackboard_open_with_attributes(
270 m_handle, &required_attributes.m_handle,
nullptr, &port_factory_handle);
272 if (result == IOX2_OK) {
276 return bb::err(bb::into<BlackboardOpenError>(result));
#define IOX2_PANIC(message)
calls panic handler and does not return
#define IOX2_BUILDER_OPTIONAL(type, name)
Represents the port factory of a [Service] with [MessagingPattern::Blackboard].
Builder to create new [MessagingPattern::Blackboard] based [Service]s.
auto create_with_attributes(const AttributeSpecifier &attributes) &&-> bb::Expected< PortFactoryBlackboard< S, KeyType >, BlackboardCreateError >
Creates a new [Service] with a set of attributes.
auto max_nodes(const uint64_t value) -> decltype(auto)
Defines how many [Node]s shall be able to open it in parallel.
auto add(KeyType key, ValueType value) -> ServiceBuilderBlackboardCreator &&
Adds key-value pairs to the blackboard.
auto create() &&-> bb::Expected< PortFactoryBlackboard< S, KeyType >, BlackboardCreateError >
Creates a new [Service].
auto max_readers(const uint64_t value) -> decltype(auto)
Defines how many [Reader]s shall be supported at most.
auto add_with_default(KeyType key) -> ServiceBuilderBlackboardCreator &&
Adds key-value pairs to the blackboard where value is a default value.
auto max_nodes(const uint64_t value) -> decltype(auto)
Defines how many [Node]s must be at least supported.
auto open() &&-> bb::Expected< PortFactoryBlackboard< S, KeyType >, BlackboardOpenError >
Opens an existing [Service].
auto max_readers(const uint64_t value) -> decltype(auto)
Defines how many [Reader]s must be at least supported.
auto open_with_attributes(const AttributeVerifier &required_attributes) &&-> bb::Expected< PortFactoryBlackboard< S, KeyType >, BlackboardOpenError >
Builder to create or open [Service]s.
constexpr auto err(const E &error) -> Unexpected< E >
iox2::bb::variation::Expected< T, E > Expected
BlackboardOpenError
Errors that can occur when an existing [MessagingPattern::Blackboard] [Service] shall be opened.
BlackboardCreateError
Errors that can occur when a new [MessagingPattern::Blackboard] [Service] shall be created.