iceoryx_doc  1.0.1
service_description.hpp
1 // Copyright (c) 2019, 2021 by Robert Bosch GmbH. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // SPDX-License-Identifier: Apache-2.0
16 #ifndef IOX_POSH_CAPRO_SERVICE_DESCRIPTION_HPP
17 #define IOX_POSH_CAPRO_SERVICE_DESCRIPTION_HPP
18 
19 #include "iceoryx_posh/iceoryx_posh_types.hpp"
20 #include "iceoryx_utils/cxx/helplets.hpp"
21 #include "iceoryx_utils/cxx/serialization.hpp"
22 #include "iceoryx_utils/cxx/string.hpp"
23 #include "iceoryx_utils/cxx/vector.hpp"
24 
25 #include <cstdint>
26 #include <initializer_list>
27 
28 namespace iox
29 {
30 namespace capro
31 {
32 static constexpr uint16_t InvalidID = 0u;
33 static const IdString_t InvalidIDString{"0"};
34 static constexpr uint16_t AnyService = 0xFFFFu;
35 static constexpr uint16_t AnyInstance = 0xFFFFu;
36 static constexpr uint16_t AnyEvent = 0xFFFFu;
37 static constexpr char AnyServiceString[]{"65535"};
38 static constexpr char AnyInstanceString[]{"65535"};
39 static constexpr char AnyEventString[]{"65535"};
40 static constexpr int32_t MAX_NUMBER_OF_CHARS = 64;
41 static constexpr size_t CLASS_HASH_ELEMENT_COUNT{4u};
42 
44 enum class Interfaces : uint16_t
45 {
47  INTERNAL = 0,
49  ESOC,
51  SOMEIP,
53  AMQP,
55  MQTT,
57  DDS,
59  SIGNAL,
61  MTA,
63  ROS1,
65  INTERFACE_END
66 };
67 
68 constexpr const char* INTERFACE_NAMES[] = {"INTERNAL", "ESOC", "SOMEIP", "AMQP", "DDS", "SIGNAL", "MTA", "ROS1", "END"};
69 
71 enum class Scope : uint16_t
72 {
73  WORLDWIDE,
74  INTERNAL,
75  INVALID
76 };
77 
78 constexpr char ScopeTypeString[][MAX_NUMBER_OF_CHARS] = {"WORLDWIDE", "INTERNAL", "INVALID"};
79 
86 {
87  public:
88  struct ClassHash
89  {
90  ClassHash() noexcept;
91  ClassHash(const std::initializer_list<uint32_t>& values) noexcept;
92  uint32_t& operator[](iox::cxx::range<uint64_t, 0, CLASS_HASH_ELEMENT_COUNT - 1> index) noexcept;
93  const uint32_t& operator[](iox::cxx::range<uint64_t, 0, CLASS_HASH_ELEMENT_COUNT - 1> index) const noexcept;
94  bool operator==(const ClassHash& rhs) const noexcept;
95  bool operator!=(const ClassHash& rhs) const noexcept;
96 
97  private:
98  uint32_t data[CLASS_HASH_ELEMENT_COUNT];
99  };
100 
102  ServiceDescription(const cxx::Serialization& f_serial) noexcept;
103 
105  ServiceDescription() noexcept;
106  ServiceDescription(const ServiceDescription&) = default;
108  ~ServiceDescription() = default;
109 
111  ServiceDescription(uint16_t f_serviceID, uint16_t f_instanceID) noexcept;
112 
114  ServiceDescription(const IdString_t& f_service, const IdString_t& f_instance) noexcept;
115 
117  ServiceDescription(uint16_t f_serviceID, uint16_t f_eventID, uint16_t f_instanceID) noexcept;
118 
120  ServiceDescription(const IdString_t& f_service,
121  const IdString_t& f_instance,
122  const IdString_t& f_event,
123  ClassHash m_classHash = {0u, 0u, 0u, 0u},
124  Interfaces interfaceSource = Interfaces::INTERNAL) noexcept;
125 
128  bool operator==(const ServiceDescription& rhs) const;
129 
131  bool operator!=(const ServiceDescription& rhs) const;
132 
135  bool operator<(const ServiceDescription& rhs) const;
136 
137  ServiceDescription& operator=(const ServiceDescription&) = default;
138  ServiceDescription& operator=(ServiceDescription&&) = default;
139 
141  operator cxx::Serialization() const;
142 
145  bool hasServiceOnlyDescription() const noexcept;
146 
147  // @brief Returns if this service description is used for an RouDi-internal channel
148  bool isInternal() const noexcept;
149  // @brief Set this service description to be is used for an RouDi-internal channel
150  void setInternal() noexcept;
152  Scope getScope() noexcept;
153 
157  bool isValid() const noexcept;
158 
161  uint16_t getInstanceID() const noexcept;
162  uint16_t getServiceID() const noexcept;
163  uint16_t getEventID() const noexcept;
164  IdString_t getServiceIDString() const noexcept;
165  IdString_t getInstanceIDString() const noexcept;
166  IdString_t getEventIDString() const noexcept;
168 
171  ClassHash getClassHash() const noexcept;
173 
175  Interfaces getSourceInterface() const noexcept;
176 
177  private:
179  uint16_t m_serviceID;
181  uint16_t m_eventID;
183  uint16_t m_instanceID;
185  IdString_t m_serviceString;
187  IdString_t m_instanceString;
189  IdString_t m_eventString;
190 
191  bool m_hasServiceOnlyDescription = false;
193  ClassHash m_classHash{0, 0, 0, 0};
194 
196  Scope m_scope{Scope::WORLDWIDE};
197 
199  Interfaces m_interfaceSource{Interfaces::INTERNAL};
200 };
201 
208 bool serviceMatch(const ServiceDescription& first, const ServiceDescription& second) noexcept;
209 
210 } // namespace capro
211 } // namespace iox
212 
213 #endif // IOX_POSH_CAPRO_SERVICE_DESCRIPTION_HPP
class for the identification of a communication event including information on the service,...
Definition: service_description.hpp:86
ClassHash getClassHash() const noexcept
bool isValid() const noexcept
Returns true for valid ServiceDescription false for ServiceDescription that contains either of Invali...
Interfaces getSourceInterface() const noexcept
Returns the interface form where the service is coming from.
Scope getScope() noexcept
Returns the scope of a ServiceDescription.
bool operator==(const ServiceDescription &rhs) const
compare operator. If wildcards AnyService, AnyInstance or AnyEvent are used as integer IDs,...
bool operator<(const ServiceDescription &rhs) const
Uses the underlying m_**String compare method to provide an order. This is needed to use ServiceDescr...
ServiceDescription() noexcept
default C'tor
bool hasServiceOnlyDescription() const noexcept
Returns true if it contains a service description which does not have events, otherwise it returns fa...
ServiceDescription(const cxx::Serialization &f_serial) noexcept
construction of the capro service description using serialized strings
bool operator!=(const ServiceDescription &rhs) const
negation of compare operator.
uint16_t getInstanceID() const noexcept
Definition: service_description.hpp:29
Definition: service_description.hpp:89