iceoryx_posh  2.0.2
posh_runtime.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_POSH_RUNTIME_HPP
18 #define IOX_POSH_RUNTIME_POSH_RUNTIME_HPP
19 
20 #include "iceoryx_hoofs/cxx/optional.hpp"
21 #include "iceoryx_posh/capro/service_description.hpp"
22 #include "iceoryx_posh/iceoryx_posh_types.hpp"
23 #include "iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp"
24 #include "iceoryx_posh/internal/popo/ports/client_port_user.hpp"
25 #include "iceoryx_posh/internal/popo/ports/interface_port.hpp"
26 #include "iceoryx_posh/internal/popo/ports/publisher_port_user.hpp"
27 #include "iceoryx_posh/internal/popo/ports/server_port_user.hpp"
28 #include "iceoryx_posh/internal/popo/ports/subscriber_port_user.hpp"
29 #include "iceoryx_posh/internal/runtime/ipc_runtime_interface.hpp"
30 #include "iceoryx_posh/internal/runtime/node_property.hpp"
31 #include "iceoryx_posh/popo/client_options.hpp"
32 #include "iceoryx_posh/popo/server_options.hpp"
33 #include "iceoryx_posh/popo/subscriber_options.hpp"
34 #include "iceoryx_posh/runtime/port_config_info.hpp"
35 
36 #include <atomic>
37 
38 namespace iox
39 {
40 namespace roudi
41 {
42 class RuntimeTestInterface;
43 } // namespace roudi
44 
45 namespace runtime
46 {
47 class Node;
48 class NodeData;
49 
52 {
53  public:
54  PoshRuntime(const PoshRuntime&) = delete;
55  PoshRuntime& operator=(const PoshRuntime&) = delete;
56  PoshRuntime(PoshRuntime&&) = delete;
57  PoshRuntime& operator=(PoshRuntime&&) = delete;
58  virtual ~PoshRuntime() noexcept = default;
59 
63  static PoshRuntime& getInstance() noexcept;
64 
70  static PoshRuntime& initRuntime(const RuntimeName_t& name) noexcept;
71 
74  RuntimeName_t getInstanceName() const noexcept;
75 
78  void shutdown() noexcept;
79 
86  virtual PublisherPortUserType::MemberType_t*
87  getMiddlewarePublisher(const capro::ServiceDescription& service,
88  const popo::PublisherOptions& publisherOptions = {},
89  const PortConfigInfo& portConfigInfo = {}) noexcept = 0;
90 
97  virtual SubscriberPortUserType::MemberType_t*
99  const popo::SubscriberOptions& subscriberOptions = {},
100  const PortConfigInfo& portConfigInfo = {}) noexcept = 0;
101 
108  virtual popo::ClientPortData*
110  const popo::ClientOptions& clientOptions = {},
111  const PortConfigInfo& portConfigInfo = PortConfigInfo()) noexcept = 0;
112 
119  virtual popo::ServerPortData*
121  const popo::ServerOptions& serverOptions = {},
122  const PortConfigInfo& portConfigInfo = PortConfigInfo()) noexcept = 0;
123 
128  virtual popo::InterfacePortData* getMiddlewareInterface(const capro::Interfaces interface,
129  const NodeName_t& nodeName = {}) noexcept = 0;
130 
133  virtual popo::ConditionVariableData* getMiddlewareConditionVariable() noexcept = 0;
134 
138  virtual NodeData* createNode(const NodeProperty& nodeProperty) noexcept = 0;
139 
145  virtual bool sendRequestToRouDi(const IpcMessage& msg, IpcMessage& answer) noexcept = 0;
146 
147  protected:
148  friend class roudi::RuntimeTestInterface;
149  using factory_t = PoshRuntime& (*)(cxx::optional<const RuntimeName_t*>);
150 
151  // Protected constructor for derived classes
152  PoshRuntime(cxx::optional<const RuntimeName_t*> name) noexcept;
153 
154  static PoshRuntime& defaultRuntimeFactory(cxx::optional<const RuntimeName_t*> name) noexcept;
155 
160  static factory_t& getRuntimeFactory() noexcept;
161 
165  static void setRuntimeFactory(const factory_t& factory) noexcept;
166 
172  static PoshRuntime& getInstance(cxx::optional<const RuntimeName_t*> name) noexcept;
173 
175  const RuntimeName_t& verifyInstanceName(cxx::optional<const RuntimeName_t*> name) noexcept;
176 
177  const RuntimeName_t m_appName;
178  std::atomic<bool> m_shutdownRequested{false};
179 };
180 
181 } // namespace runtime
182 } // namespace iox
183 
184 #endif // IOX_POSH_RUNTIME_POSH_RUNTIME_HPP
class for the identification of a communication event including information on the service,...
Definition: service_description.hpp:81
The runtime that is needed for each application to communicate with the RouDi daemon.
Definition: posh_runtime.hpp:52
RuntimeName_t getInstanceName() const noexcept
get the name that was used to register with RouDi
virtual popo::InterfacePortData * getMiddlewareInterface(const capro::Interfaces interface, const NodeName_t &nodeName={}) noexcept=0
request the RouDi daemon to create an interface port
virtual popo::ClientPortData * getMiddlewareClient(const capro::ServiceDescription &service, const popo::ClientOptions &clientOptions={}, const PortConfigInfo &portConfigInfo=PortConfigInfo()) noexcept=0
request the RouDi daemon to create a client port
static PoshRuntime & initRuntime(const RuntimeName_t &name) noexcept
creates the runtime with given name
virtual SubscriberPortUserType::MemberType_t * getMiddlewareSubscriber(const capro::ServiceDescription &service, const popo::SubscriberOptions &subscriberOptions={}, const PortConfigInfo &portConfigInfo={}) noexcept=0
request the RouDi daemon to create a subscriber port
virtual bool sendRequestToRouDi(const IpcMessage &msg, IpcMessage &answer) noexcept=0
send a request to the RouDi daemon and get the response currently each request is followed by a respo...
static factory_t & getRuntimeFactory() noexcept
gets current runtime factory. If the runtime factory is not yet initialized it is set to defaultRunti...
static void setRuntimeFactory(const factory_t &factory) noexcept
sets runtime factory, terminates if given factory is empty
void shutdown() noexcept
initiates the shutdown of the runtime to unblock all potentially blocking publisher with the Consumer...
static PoshRuntime & getInstance() noexcept
returns active runtime
virtual PublisherPortUserType::MemberType_t * getMiddlewarePublisher(const capro::ServiceDescription &service, const popo::PublisherOptions &publisherOptions={}, const PortConfigInfo &portConfigInfo={}) noexcept=0
request the RouDi daemon to create a publisher port
virtual popo::ConditionVariableData * getMiddlewareConditionVariable() noexcept=0
request the RouDi daemon to create a condition variable
const RuntimeName_t & verifyInstanceName(cxx::optional< const RuntimeName_t * > name) noexcept
checks the given application name for certain constraints like length or if is empty
virtual NodeData * createNode(const NodeProperty &nodeProperty) noexcept=0
request the RouDi daemon to create a node
virtual popo::ServerPortData * getMiddlewareServer(const capro::ServiceDescription &service, const popo::ServerOptions &serverOptions={}, const PortConfigInfo &portConfigInfo=PortConfigInfo()) noexcept=0
request the RouDi daemon to create a server port
This struct is used to configure the client.
Definition: client_options.hpp:33
This struct is used to configure the server.
Definition: server_options.hpp:33
This struct is used to configure the subscriber.
Definition: subscriber_options.hpp:33
Stores information necessary to create the right type of port on RouDi side. Different types of ports...
Definition: port_config_info.hpp:33