iceoryx_doc  1.0.1
channel.hpp
1 // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
2 // Copyright (c) 2020 - 2021 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 
18 #ifndef IOX_POSH_GW_CHANNEL_HPP
19 #define IOX_POSH_GW_CHANNEL_HPP
20 
21 #include "iceoryx_posh/capro/service_description.hpp"
22 #include "iceoryx_posh/iceoryx_posh_types.hpp"
23 #include "iceoryx_utils/cxx/expected.hpp"
24 #include "iceoryx_utils/cxx/optional.hpp"
25 #include "iceoryx_utils/internal/objectpool/objectpool.hpp"
26 
27 #include <memory>
28 
29 namespace iox
30 {
31 namespace gw
32 {
33 enum class ChannelError : uint8_t
34 {
35  INVALID_STATE,
36  OBJECT_POOL_FULL
37 };
38 
56 template <typename IceoryxTerminal, typename ExternalTerminal>
57 class Channel
58 {
59  using IceoryxTerminalPtr = std::shared_ptr<IceoryxTerminal>;
60  using IceoryxTerminalPool = cxx::ObjectPool<IceoryxTerminal, MAX_CHANNEL_NUMBER>;
61  using ExternalTerminalPtr = std::shared_ptr<ExternalTerminal>;
62  using ExternalTerminalPool = cxx::ObjectPool<ExternalTerminal, MAX_CHANNEL_NUMBER>;
63 
64  public:
65  constexpr Channel(const capro::ServiceDescription& service,
66  const IceoryxTerminalPtr iceoryxTerminal,
67  const ExternalTerminalPtr externalTerminal) noexcept;
68 
69  constexpr bool operator==(const Channel<IceoryxTerminal, ExternalTerminal>& rhs) const noexcept;
70 
77  template <typename IceoryxPubSubOptions>
78  static cxx::expected<Channel, ChannelError> create(const capro::ServiceDescription& service,
79  const IceoryxPubSubOptions& options) noexcept;
80 
81  capro::ServiceDescription getServiceDescription() const noexcept;
82  IceoryxTerminalPtr getIceoryxTerminal() const noexcept;
83  ExternalTerminalPtr getExternalTerminal() const noexcept;
84 
85  private:
86  static IceoryxTerminalPool s_iceoryxTerminals;
87  static ExternalTerminalPool s_externalTerminals;
88 
89  capro::ServiceDescription m_service;
90  IceoryxTerminalPtr m_iceoryxTerminal;
91  ExternalTerminalPtr m_externalTerminal;
92 };
93 
94 } // namespace gw
95 } // namespace iox
96 
97 #include "iceoryx_posh/internal/gateway/channel.inl"
98 
99 #endif // IOX_POSH_GW_CHANNEL_HPP
class for the identification of a communication event including information on the service,...
Definition: service_description.hpp:86
A data structure representing a channel between Iceoryx and an external system.
Definition: channel.hpp:58
static cxx::expected< Channel, ChannelError > create(const capro::ServiceDescription &service, const IceoryxPubSubOptions &options) noexcept
create Creates a channel for the given service whose terminals reside in a static object pool.
Definition: service_description.hpp:29