iceoryx_posh  2.0.2
service_description.hpp
1 // Copyright (c) 2019, 2021 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_CAPRO_SERVICE_DESCRIPTION_HPP
18 #define IOX_POSH_CAPRO_SERVICE_DESCRIPTION_HPP
19 
20 #include "iceoryx_hoofs/cxx/serialization.hpp"
21 #include "iceoryx_hoofs/cxx/string.hpp"
22 #include "iceoryx_hoofs/cxx/vector.hpp"
23 #include "iceoryx_hoofs/log/logstream.hpp"
24 #include "iceoryx_posh/iceoryx_posh_types.hpp"
25 
26 #include <cstdint>
27 #include <initializer_list>
28 
29 namespace iox
30 {
31 namespace capro
32 {
34 using Wildcard_t = iox::cxx::nullopt_t;
35 constexpr Wildcard_t Wildcard;
36 
37 static constexpr int32_t MAX_NUMBER_OF_CHARS = 64;
38 static constexpr size_t CLASS_HASH_ELEMENT_COUNT{4U};
39 
41 enum class Interfaces : uint16_t
42 {
44  INTERNAL = 0,
46  ESOC,
48  SOMEIP,
50  AMQP,
52  MQTT,
54  DDS,
56  SIGNAL,
58  MTA,
60  ROS1,
62  INTERFACE_END
63 };
64 
65 constexpr const char* INTERFACE_NAMES[] = {"INTERNAL", "ESOC", "SOMEIP", "AMQP", "DDS", "SIGNAL", "MTA", "ROS1", "END"};
66 
68 enum class Scope : uint16_t
69 {
70  WORLDWIDE,
71  LOCAL,
72  INVALID
73 };
74 
75 constexpr char ScopeTypeString[][MAX_NUMBER_OF_CHARS] = {"WORLDWIDE", "INTERNAL", "INVALID"};
76 
81 {
82  public:
83  struct ClassHash
84  {
85  ClassHash() noexcept;
86  ClassHash(const std::initializer_list<uint32_t>& values) noexcept;
87  uint32_t& operator[](iox::cxx::range<uint64_t, 0, CLASS_HASH_ELEMENT_COUNT - 1> index) noexcept;
88  const uint32_t& operator[](iox::cxx::range<uint64_t, 0, CLASS_HASH_ELEMENT_COUNT - 1> index) const noexcept;
89  bool operator==(const ClassHash& rhs) const noexcept;
90  bool operator!=(const ClassHash& rhs) const noexcept;
91 
92  private:
93  uint32_t data[CLASS_HASH_ELEMENT_COUNT];
94  };
95 
97  ServiceDescription() noexcept;
98  ServiceDescription(const ServiceDescription&) noexcept = default;
99  ServiceDescription(ServiceDescription&&) noexcept = default;
100  ~ServiceDescription() noexcept = default;
101 
103  ServiceDescription(const IdString_t& service,
104  const IdString_t& instance,
105  const IdString_t& event,
106  ClassHash m_classHash = {0U, 0U, 0U, 0U},
107  Interfaces interfaceSource = Interfaces::INTERNAL) noexcept;
108 
110  bool operator==(const ServiceDescription& rhs) const noexcept;
111 
113  bool operator!=(const ServiceDescription& rhs) const noexcept;
114 
117  bool operator<(const ServiceDescription& rhs) const noexcept;
118 
119  ServiceDescription& operator=(const ServiceDescription&) noexcept = default;
120  ServiceDescription& operator=(ServiceDescription&&) noexcept = default;
121 
123  explicit operator cxx::Serialization() const noexcept;
124 
128  static cxx::expected<ServiceDescription, cxx::Serialization::Error>
129  deserialize(const cxx::Serialization& serialized) noexcept;
130 
131  // @brief Returns if this service description is used for an RouDi-internal channel
132  bool isLocal() const noexcept;
133  // @brief Set this service description to be is used for an RouDi-internal channel
134  void setLocal() noexcept;
136  Scope getScope() const noexcept;
137 
138 
141  const IdString_t& getServiceIDString() const noexcept;
142  const IdString_t& getInstanceIDString() const noexcept;
143  const IdString_t& getEventIDString() const noexcept;
145 
148  ClassHash getClassHash() const noexcept;
150 
152  Interfaces getSourceInterface() const noexcept;
153 
154  private:
156  IdString_t m_serviceString;
158  IdString_t m_instanceString;
160  IdString_t m_eventString;
161 
163  ClassHash m_classHash{0, 0, 0, 0};
164 
166  Scope m_scope{Scope::WORLDWIDE};
167 
169  Interfaces m_interfaceSource{Interfaces::INTERNAL};
170 };
171 
178 bool serviceMatch(const ServiceDescription& first, const ServiceDescription& second) noexcept;
179 
184 std::ostream& operator<<(std::ostream& stream, const ServiceDescription& service) noexcept;
185 
190 log::LogStream& operator<<(log::LogStream& stream, const ServiceDescription& service) noexcept;
191 
192 } // namespace capro
193 } // namespace iox
194 
195 #endif // IOX_POSH_CAPRO_SERVICE_DESCRIPTION_HPP
class for the identification of a communication event including information on the service,...
Definition: service_description.hpp:81
ClassHash getClassHash() const noexcept
const IdString_t & getServiceIDString() const noexcept
Interfaces getSourceInterface() const noexcept
Returns the interface form where the service is coming from.
bool operator<(const ServiceDescription &rhs) const noexcept
Uses the underlying m_**String compare method to provide an order. This is needed to use ServiceDescr...
bool operator==(const ServiceDescription &rhs) const noexcept
compare operator.
ServiceDescription() noexcept
default C'tor
static cxx::expected< ServiceDescription, cxx::Serialization::Error > deserialize(const cxx::Serialization &serialized) noexcept
de-serialization of a ServiceDescription.
Scope getScope() const noexcept
Returns the scope of a ServiceDescription.
bool operator!=(const ServiceDescription &rhs) const noexcept
negation of compare operator.
Definition: service_description.hpp:84