18 #ifndef IOX_POSH_GW_GATEWAY_GENERIC_HPP
19 #define IOX_POSH_GW_GATEWAY_GENERIC_HPP
21 #include "iceoryx_hoofs/cxx/expected.hpp"
22 #include "iceoryx_hoofs/cxx/function_ref.hpp"
23 #include "iceoryx_hoofs/cxx/optional.hpp"
24 #include "iceoryx_hoofs/cxx/string.hpp"
25 #include "iceoryx_hoofs/cxx/vector.hpp"
26 #include "iceoryx_hoofs/internal/concurrent/smart_lock.hpp"
27 #include "iceoryx_hoofs/internal/units/duration.hpp"
28 #include "iceoryx_posh/capro/service_description.hpp"
29 #include "iceoryx_posh/gateway/gateway_base.hpp"
30 #include "iceoryx_posh/gateway/gateway_config.hpp"
31 #include "iceoryx_posh/iceoryx_posh_config.hpp"
32 #include "iceoryx_posh/iceoryx_posh_types.hpp"
41 using namespace iox::units::duration_literals;
43 enum class GatewayError : uint8_t
45 UNSUPPORTED_SERVICE_TYPE,
46 UNSUCCESSFUL_CHANNEL_CREATION,
57 template <
typename channel_t,
typename gateway_t = GatewayBase>
60 using ChannelVector = cxx::vector<channel_t, MAX_CHANNEL_NUMBER>;
61 using ConcurrentChannelVector = concurrent::smart_lock<ChannelVector>;
71 void runMultithreaded() noexcept;
72 void shutdown() noexcept;
83 virtual void discover(
const capro::CaproMessage& msg) noexcept = 0;
88 virtual void forward(
const channel_t& channel) noexcept = 0;
90 uint64_t getNumberOfChannels() const noexcept;
94 units::Duration discoveryPeriod = 1000_ms,
95 units::Duration forwardingPeriod = 50_ms) noexcept;
114 template <typename IceoryxPubSubOptions>
115 cxx::expected<channel_t, GatewayError> addChannel(const capro::ServiceDescription& service,
116 const IceoryxPubSubOptions& options) noexcept;
124 cxx::optional<channel_t> findChannel(const capro::ServiceDescription& service) const noexcept;
131 void forEachChannel(const cxx::function_ref<
void(channel_t&)> f) const noexcept;
138 cxx::expected<GatewayError> discardChannel(const capro::ServiceDescription& service) noexcept;
141 ConcurrentChannelVector m_channels;
143 std::atomic_bool m_isRunning{
false};
145 units::Duration m_discoveryPeriod;
146 units::Duration m_forwardingPeriod;
148 std::thread m_discoveryThread;
149 std::thread m_forwardingThread;
151 void forwardingLoop() noexcept;
152 void discoveryLoop() noexcept;
158 #include "iceoryx_posh/internal/gateway/gateway_generic.inl"
A reference generic gateway implementation.
Definition: gateway_generic.hpp:59
virtual void discover(const capro::CaproMessage &msg) noexcept=0
discover Process discovery messages coming from iceoryx.
virtual void loadConfiguration(const config::GatewayConfig &config) noexcept=0
loadConfiguration Load the provided configuration.
virtual void forward(const channel_t &channel) noexcept=0
forward Forward data between the two terminals of the channel used by the implementation.
Generic configuration for gateways.
Definition: gateway_config.hpp:32