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);
64 template <
typename ValueType>
68 template <
typename ValueType>
80 template <ServiceType>
86 void set_parameters();
88 iox2_service_builder_blackboard_creator_h m_handle =
nullptr;
91template <
typename KeyType, ServiceType S>
95#ifdef DOXYGEN_MACRO_FIX
102#ifdef DOXYGEN_MACRO_FIX
126 template <ServiceType>
132 void set_parameters();
134 iox2_service_builder_blackboard_opener_h m_handle =
nullptr;
141 return (*
reinterpret_cast<const T*
>(lhs)) == (*
reinterpret_cast<const T*
>(rhs));
145template <
typename KeyType, ServiceType S>
147 : m_handle { iox2_service_builder_blackboard_creator(handle) } {
150 const auto key_type_result = iox2_service_builder_blackboard_creator_set_key_type_details(
151 &m_handle, type_name.unchecked_access().c_str(), type_name.size(),
sizeof(KeyType),
alignof(KeyType));
152 if (key_type_result != IOX2_OK) {
153 IOX2_PANIC(
"This should never happen! Implementation failure while setting the key type.");
157template <
typename KeyType, ServiceType S>
158inline void ServiceBuilderBlackboardCreator<KeyType, S>::drop() {
159 if (m_handle !=
nullptr) {
160 iox2_service_builder_blackboard_creator_drop(m_handle);
165template <
typename KeyType, ServiceType S>
168 *
this = std::move(rhs);
171template <
typename KeyType, ServiceType S>
176 m_handle = rhs.m_handle;
177 rhs.m_handle =
nullptr;
178 m_max_readers = std::move(rhs.m_max_readers);
179 m_max_nodes = std::move(rhs.m_max_nodes);
185template <
typename KeyType, ServiceType S>
190template <
typename KeyType, ServiceType S>
191inline void ServiceBuilderBlackboardCreator<KeyType, S>::set_parameters() {
192 if (m_max_readers.has_value()) {
193 iox2_service_builder_blackboard_creator_set_max_readers(&m_handle, m_max_readers.value());
195 if (m_max_nodes.has_value()) {
196 iox2_service_builder_blackboard_creator_set_max_nodes(&m_handle, m_max_nodes.value());
200 iox2_service_builder_blackboard_creator_set_key_eq_comparison_function(&m_handle,
204template <
typename KeyType, ServiceType S>
205template <
typename ValueType>
208 static_assert(std::is_trivially_copyable<ValueType>::value,
209 "The blackboard supports only trivially copyable value types.");
212 auto value_ptr =
new ValueType(value);
215 iox2_service_builder_blackboard_creator_add(
219 [](
void* value) ->
auto {
220 auto* value_ptr =
static_cast<ValueType*
>(value);
221 if (value_ptr !=
nullptr) {
227 type_name.unchecked_access().c_str(),
232 return std::move(*
this);
235template <
typename KeyType, ServiceType S>
236template <
typename ValueType>
239 return add(key, ValueType());
242template <
typename KeyType, ServiceType S>
247 iox2_port_factory_blackboard_h port_factory_handle {};
248 auto result = iox2_service_builder_blackboard_create(m_handle,
nullptr, &port_factory_handle);
251 if (result == IOX2_OK) {
258template <
typename KeyType, ServiceType S>
263 iox2_port_factory_blackboard_h port_factory_handle {};
264 auto result = iox2_service_builder_blackboard_create_with_attributes(
265 m_handle, &attributes.m_handle,
nullptr, &port_factory_handle);
268 if (result == IOX2_OK) {
275template <
typename KeyType, ServiceType S>
277 : m_handle { iox2_service_builder_blackboard_opener(handle) } {
280template <
typename KeyType, ServiceType S>
281inline void ServiceBuilderBlackboardOpener<KeyType, S>::drop() {
282 if (m_handle !=
nullptr) {
283 iox2_service_builder_blackboard_opener_drop(m_handle);
288template <
typename KeyType, ServiceType S>
291 *
this = std::move(rhs);
294template <
typename KeyType, ServiceType S>
299 m_handle = rhs.m_handle;
300 rhs.m_handle =
nullptr;
301 m_max_readers = std::move(rhs.m_max_readers);
302 m_max_nodes = std::move(rhs.m_max_nodes);
308template <
typename KeyType, ServiceType S>
313template <
typename KeyType, ServiceType S>
314inline void ServiceBuilderBlackboardOpener<KeyType, S>::set_parameters() {
315 if (m_max_readers.has_value()) {
316 iox2_service_builder_blackboard_opener_set_max_readers(&m_handle, m_max_readers.value());
318 if (m_max_nodes.has_value()) {
319 iox2_service_builder_blackboard_opener_set_max_nodes(&m_handle, m_max_nodes.value());
324 const auto key_type_result = iox2_service_builder_blackboard_opener_set_key_type_details(
325 &m_handle, type_name.unchecked_access().c_str(), type_name.size(),
sizeof(KeyType),
alignof(KeyType));
326 if (key_type_result != IOX2_OK) {
327 IOX2_PANIC(
"This should never happen! Implementation failure while setting the Key-Type.");
331 iox2_service_builder_blackboard_opener_set_key_eq_comparison_function(&m_handle,
335template <
typename KeyType, ServiceType S>
340 iox2_port_factory_blackboard_h port_factory_handle {};
341 auto result = iox2_service_builder_blackboard_open(m_handle,
nullptr, &port_factory_handle);
344 if (result == IOX2_OK) {
351template <
typename KeyType, ServiceType S>
357 iox2_port_factory_blackboard_h port_factory_handle {};
358 auto result = iox2_service_builder_blackboard_open_with_attributes(
359 m_handle, &required_attributes.m_handle,
nullptr, &port_factory_handle);
362 if (result == IOX2_OK) {
#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].
auto create_with_attributes(const AttributeSpecifier &attributes) &&-> bb::Expected< PortFactoryBlackboard< S, KeyType >, BlackboardCreateError >
Creates a new [Service] with a set of attributes.
ServiceBuilderBlackboardCreator(const ServiceBuilderBlackboardCreator &)=delete
auto operator=(ServiceBuilderBlackboardCreator &&rhs) noexcept -> ServiceBuilderBlackboardCreator &
auto max_nodes(const uint64_t value) -> decltype(auto)
Defines how many [Node]s shall be able to open it in parallel.
~ServiceBuilderBlackboardCreator()
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].
friend class ServiceBuilder
ServiceBuilderBlackboardCreator(ServiceBuilderBlackboardCreator &&rhs) noexcept
auto max_readers(const uint64_t value) -> decltype(auto)
Defines how many [Reader]s shall be supported at most.
auto operator=(const ServiceBuilderBlackboardCreator &) -> ServiceBuilderBlackboardCreator &=delete
auto add_with_default(KeyType key) -> ServiceBuilderBlackboardCreator &&
Adds key-value pairs to the blackboard where value is a default value.
auto operator=(ServiceBuilderBlackboardOpener &&rhs) noexcept -> ServiceBuilderBlackboardOpener &
auto max_nodes(const uint64_t value) -> decltype(auto)
Defines how many [Node]s must be at least supported.
auto operator=(const ServiceBuilderBlackboardOpener &) -> ServiceBuilderBlackboardOpener &=delete
ServiceBuilderBlackboardOpener(const ServiceBuilderBlackboardOpener &)=delete
ServiceBuilderBlackboardOpener(ServiceBuilderBlackboardOpener &&rhs) noexcept
auto open() &&-> bb::Expected< PortFactoryBlackboard< S, KeyType >, BlackboardOpenError >
Opens an existing [Service].
~ServiceBuilderBlackboardOpener()
friend class ServiceBuilder
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 >
constexpr auto into(const SourceType value) noexcept -> typename detail::ExtractIntoType< DestinationType >::TargetType
Converts a value of type SourceType to a corresponding value of type DestinationType....
constexpr auto err(const E &error) -> Unexpected< E >
iox2::bb::variation::Expected< T, E > Expected
auto default_key_eq_cmp_func(const void *lhs, const void *rhs) -> bool
auto get_type_name() -> TypeName
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.