17 #ifndef IOX_POSH_RUNTIME_POSH_RUNTIME_HPP
18 #define IOX_POSH_RUNTIME_POSH_RUNTIME_HPP
20 #include "iceoryx_posh/capro/service_description.hpp"
21 #include "iceoryx_posh/iceoryx_posh_types.hpp"
22 #include "iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp"
23 #include "iceoryx_posh/internal/popo/ports/application_port.hpp"
24 #include "iceoryx_posh/internal/popo/ports/interface_port.hpp"
25 #include "iceoryx_posh/internal/popo/ports/publisher_port_user.hpp"
26 #include "iceoryx_posh/internal/popo/ports/subscriber_port_user.hpp"
27 #include "iceoryx_posh/internal/runtime/ipc_runtime_interface.hpp"
28 #include "iceoryx_posh/internal/runtime/node_property.hpp"
29 #include "iceoryx_posh/internal/runtime/shared_memory_user.hpp"
30 #include "iceoryx_posh/popo/subscriber_options.hpp"
31 #include "iceoryx_posh/runtime/port_config_info.hpp"
32 #include "iceoryx_utils/cxx/method_callback.hpp"
33 #include "iceoryx_utils/cxx/string.hpp"
34 #include "iceoryx_utils/internal/concurrent/periodic_task.hpp"
46 class RuntimeTestInterface;
54 enum class FindServiceError
57 UNABLE_TO_WRITE_TO_ROUDI_CHANNEL,
58 INSTANCE_CONTAINER_OVERFLOW
90 cxx::expected<InstanceContainer, FindServiceError>
91 findService(const capro::ServiceDescription& serviceDescription) noexcept;
96 bool offerService(const capro::ServiceDescription& serviceDescription) noexcept;
110 const popo::PublisherOptions& publisherOptions = popo::PublisherOptions(),
121 const popo::SubscriberOptions& subscriberOptions = popo::SubscriberOptions(),
129 const NodeName_t& nodeName = {
""}) noexcept;
162 friend class roudi::RuntimeTestInterface;
165 using factory_t =
PoshRuntime& (*)(cxx::optional<const RuntimeName_t*>);
168 PoshRuntime(cxx::optional<const RuntimeName_t*> name, const
bool doMapSharedMemoryIntoThread = true) noexcept;
170 static
PoshRuntime& defaultRuntimeFactory(cxx::optional<const RuntimeName_t*> name) noexcept;
172 static RuntimeName_t& defaultRuntimeInstanceName() noexcept;
194 requestPublisherFromRoudi(const
IpcMessage& sendBuffer) noexcept;
197 requestSubscriberFromRoudi(const
IpcMessage& sendBuffer) noexcept;
199 cxx::expected<popo::ConditionVariableData*, IpcMessageErrorType>
200 requestConditionVariableFromRoudi(const
IpcMessage& sendBuffer) noexcept;
203 const RuntimeName_t& verifyInstanceName(cxx::optional<const RuntimeName_t*> name) noexcept;
205 const RuntimeName_t m_appName;
206 mutable std::mutex m_appIpcRequestMutex;
212 popo::ApplicationPort m_applicationPort;
214 std::atomic<
bool> m_shutdownRequested{
false};
215 void sendKeepAliveAndHandleShutdownPreparation() noexcept;
216 static_assert(PROCESS_KEEP_ALIVE_INTERVAL > roudi::DISCOVERY_INTERVAL, "Keep alive interval too small");
219 concurrent::PeriodicTask<cxx::MethodCallback<
void>> m_keepAliveTask{
220 concurrent::PeriodicTaskAutoStart,
221 PROCESS_KEEP_ALIVE_INTERVAL,
224 &PoshRuntime::sendKeepAliveAndHandleShutdownPreparation};
The PublisherPortUser provides the API for accessing a publisher port from the user side....
Definition: publisher_port_user.hpp:39
The SubscriberPortUser provides the API for accessing a subscriber port from the user side....
Definition: subscriber_port_user.hpp:41
Definition: ipc_message.hpp:43
Definition: ipc_runtime_interface.hpp:29
struct which contains all the members of an object of type Node
Definition: node_data.hpp:30
The runtime that is needed for each application to communicate with the RouDi daemon.
Definition: posh_runtime.hpp:63
RuntimeName_t getInstanceName() const noexcept
get the name that was used to register with RouDi
bool sendRequestToRouDi(const IpcMessage &msg, IpcMessage &answer) noexcept
send a request to the RouDi daemon and get the response currently each request is followed by a respo...
static PoshRuntime & initRuntime(const RuntimeName_t &name) noexcept
creates the runtime with given name
bool offerService(const capro::ServiceDescription &serviceDescription) noexcept
offer the provided service, sends the offer from application to RouDi daemon
popo::ConditionVariableData * getMiddlewareConditionVariable() noexcept
request the RouDi daemon to create a condition variable
static factory_t & getRuntimeFactory() noexcept
gets current runtime factory. If the runtime factory is not yet initialized it is set to defaultRunti...
popo::ApplicationPortData * getMiddlewareApplication() noexcept
request the RouDi daemon to create an application port
static void setRuntimeFactory(const factory_t &factory) noexcept
sets runtime factory, terminates if given factory is empty
popo::InterfacePortData * getMiddlewareInterface(const capro::Interfaces interface, const NodeName_t &nodeName={""}) noexcept
request the RouDi daemon to create an interface port
const std::atomic< uint64_t > * getServiceRegistryChangeCounter() noexcept
requests the serviceRegistryChangeCounter from the shared memory
void shutdown() noexcept
initiates the shutdown of the runtime to unblock all potentially blocking publisher with the Subscrib...
PublisherPortUserType::MemberType_t * getMiddlewarePublisher(const capro::ServiceDescription &service, const popo::PublisherOptions &publisherOptions=popo::PublisherOptions(), const PortConfigInfo &portConfigInfo=PortConfigInfo()) noexcept
request the RouDi daemon to create a publisher port
NodeData * createNode(const NodeProperty &nodeProperty) noexcept
request the RouDi daemon to create a node
void stopOfferService(const capro::ServiceDescription &serviceDescription) noexcept
stop offering the provided service
SubscriberPortUserType::MemberType_t * getMiddlewareSubscriber(const capro::ServiceDescription &service, const popo::SubscriberOptions &subscriberOptions=popo::SubscriberOptions(), const PortConfigInfo &portConfigInfo=PortConfigInfo()) noexcept
request the RouDi daemon to create a subscriber port
static PoshRuntime & getInstance() noexcept
returns active runtime
cxx::expected< InstanceContainer, FindServiceError > findService(const capro::ServiceDescription &serviceDescription) noexcept
find all services that match the provided service description
shared memory setup for the management segment user side
Definition: shared_memory_user.hpp:33
Definition: service_description.hpp:29
Definition: application_port_data.hpp:29
helper struct which is convertable to string and constructable from a string which is required to sen...
Definition: node_property.hpp:29
Stores information necessary to create the right type of port on RouDi side. Different types of ports...
Definition: port_config_info.hpp:32