iceoryx_posh 2.0.3
service_discovery.hpp
1// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
2// Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved.
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16// SPDX-License-Identifier: Apache-2.0
17#ifndef IOX_POSH_RUNTIME_SERVICE_DISCOVERY_HPP
18#define IOX_POSH_RUNTIME_SERVICE_DISCOVERY_HPP
19
20#include "iceoryx_posh/iceoryx_posh_types.hpp"
21#include "iceoryx_posh/internal/roudi/service_registry.hpp"
22#include "iceoryx_posh/popo/subscriber.hpp"
23#include "iceoryx_posh/runtime/posh_runtime.hpp"
24
25#include <memory>
26#include <mutex>
27
28namespace iox
29{
30namespace popo
31{
32enum class MessagingPattern
33{
34 PUB_SUB,
35 REQ_RES
36};
37} // namespace popo
38namespace runtime
39{
40enum class ServiceDiscoveryEvent : popo::EventEnumIdentifier
41{
42 SERVICE_REGISTRY_CHANGED
43};
45{
46 public:
47 ServiceDiscovery() noexcept;
48
49 ServiceDiscovery(const ServiceDiscovery&) = delete;
50 ServiceDiscovery& operator=(const ServiceDiscovery&) = delete;
52 ServiceDiscovery& operator=(ServiceDiscovery&&) = delete;
53 ~ServiceDiscovery() noexcept = default;
54
62 void findService(const cxx::optional<capro::IdString_t>& service,
63 const cxx::optional<capro::IdString_t>& instance,
64 const cxx::optional<capro::IdString_t>& event,
65 const cxx::function_ref<void(const capro::ServiceDescription&)>& callableForEach,
66 const popo::MessagingPattern pattern) noexcept;
67
69
70 private:
71 void enableEvent(popo::TriggerHandle&& triggerHandle, const ServiceDiscoveryEvent event) noexcept;
72 void disableEvent(const ServiceDiscoveryEvent event) noexcept;
73 void invalidateTrigger(const uint64_t uniqueTriggerId);
74 iox::popo::WaitSetIsConditionSatisfiedCallback
75 getCallbackForIsStateConditionSatisfied(const popo::SubscriberState state);
76
77 // use dynamic memory to reduce stack usage
79 std::unique_ptr<roudi::ServiceRegistry> m_serviceRegistry{new iox::roudi::ServiceRegistry};
80 std::mutex m_serviceRegistryMutex;
81
82 popo::Subscriber<roudi::ServiceRegistry> m_serviceRegistrySubscriber{
83 {SERVICE_DISCOVERY_SERVICE_NAME, SERVICE_DISCOVERY_INSTANCE_NAME, SERVICE_DISCOVERY_EVENT_NAME},
84 {1U, 1U, iox::NodeName_t("Service Registry"), true}};
85
86 void update();
87};
88
89} // namespace runtime
90} // namespace iox
91
92#endif // IOX_POSH_RUNTIME_SERVICE_DISCOVERY_HPP
class for the identification of a communication event including information on the service,...
Definition: service_description.hpp:81
Class which allows accessing private methods to friends of NotificationAttorney. Used for example by ...
Definition: notification_attorney.hpp:33
TriggerHandle is threadsafe without restrictions in a single process. Not qualified for inter process...
Definition: trigger_handle.hpp:38
Definition: service_discovery.hpp:45
void findService(const cxx::optional< capro::IdString_t > &service, const cxx::optional< capro::IdString_t > &instance, const cxx::optional< capro::IdString_t > &event, const cxx::function_ref< void(const capro::ServiceDescription &)> &callableForEach, const popo::MessagingPattern pattern) noexcept
Searches all services with the given messaging pattern that match the provided service description an...