Skip to content

iceoryx_posh/capro/service_description.hpp🔗

Namespaces🔗

Name
iox
iox::capro

Classes🔗

Name
class iox::capro::ServiceDescription
class for the identification of a communication event including information on the service, the service instance and the event id. A class object can be serialized/deserialized, so it is possible to send the information e.g. over a IPC channel.
struct iox::capro::ServiceDescription::ClassHash

Source code🔗

// Copyright (c) 2019, 2021 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_POSH_CAPRO_SERVICE_DESCRIPTION_HPP
#define IOX_POSH_CAPRO_SERVICE_DESCRIPTION_HPP

#include "iceoryx_hoofs/cxx/serialization.hpp"
#include "iceoryx_hoofs/cxx/string.hpp"
#include "iceoryx_hoofs/cxx/vector.hpp"
#include "iceoryx_hoofs/log/logstream.hpp"
#include "iceoryx_posh/iceoryx_posh_types.hpp"

#include <cstdint>
#include <initializer_list>

namespace iox
{
namespace capro
{
using Wildcard_t = iox::cxx::nullopt_t;
constexpr Wildcard_t Wildcard;

static constexpr int32_t MAX_NUMBER_OF_CHARS = 64;
static constexpr size_t CLASS_HASH_ELEMENT_COUNT{4U};

enum class Interfaces : uint16_t
{
    INTERNAL = 0,
    ESOC,
    SOMEIP,
    AMQP,
    MQTT,
    DDS,
    SIGNAL,
    MTA,
    ROS1,
    INTERFACE_END
};

constexpr const char* INTERFACE_NAMES[] = {"INTERNAL", "ESOC", "SOMEIP", "AMQP", "DDS", "SIGNAL", "MTA", "ROS1", "END"};

enum class Scope : uint16_t
{
    WORLDWIDE,
    LOCAL,
    INVALID
};

constexpr char ScopeTypeString[][MAX_NUMBER_OF_CHARS] = {"WORLDWIDE", "INTERNAL", "INVALID"};

class ServiceDescription
{
  public:
    struct ClassHash
    {
        ClassHash() noexcept;
        ClassHash(const std::initializer_list<uint32_t>& values) noexcept;
        uint32_t& operator[](iox::cxx::range<uint64_t, 0, CLASS_HASH_ELEMENT_COUNT - 1> index) noexcept;
        const uint32_t& operator[](iox::cxx::range<uint64_t, 0, CLASS_HASH_ELEMENT_COUNT - 1> index) const noexcept;
        bool operator==(const ClassHash& rhs) const noexcept;
        bool operator!=(const ClassHash& rhs) const noexcept;

      private:
        uint32_t data[CLASS_HASH_ELEMENT_COUNT];
    };

    ServiceDescription() noexcept;
    ServiceDescription(const ServiceDescription&) noexcept = default;
    ServiceDescription(ServiceDescription&&) noexcept = default;
    ~ServiceDescription() noexcept = default;

    ServiceDescription(const IdString_t& service,
                       const IdString_t& instance,
                       const IdString_t& event,
                       ClassHash m_classHash = {0U, 0U, 0U, 0U},
                       Interfaces interfaceSource = Interfaces::INTERNAL) noexcept;

    bool operator==(const ServiceDescription& rhs) const noexcept;

    bool operator!=(const ServiceDescription& rhs) const noexcept;

    bool operator<(const ServiceDescription& rhs) const noexcept;

    ServiceDescription& operator=(const ServiceDescription&) noexcept = default;
    ServiceDescription& operator=(ServiceDescription&&) noexcept = default;

    explicit operator cxx::Serialization() const noexcept;

    static cxx::expected<ServiceDescription, cxx::Serialization::Error>
    deserialize(const cxx::Serialization& serialized) noexcept;

    // @brief Returns if this service description is used for an RouDi-internal channel
    bool isLocal() const noexcept;
    // @brief Set this service description to be is used for an RouDi-internal channel
    void setLocal() noexcept;
    Scope getScope() const noexcept;


    const IdString_t& getServiceIDString() const noexcept;
    const IdString_t& getInstanceIDString() const noexcept;
    const IdString_t& getEventIDString() const noexcept;

    ClassHash getClassHash() const noexcept;

    Interfaces getSourceInterface() const noexcept;

  private:
    IdString_t m_serviceString;
    IdString_t m_instanceString;
    IdString_t m_eventString;

    ClassHash m_classHash{0, 0, 0, 0};

    Scope m_scope{Scope::WORLDWIDE};

    Interfaces m_interfaceSource{Interfaces::INTERNAL};
};

bool serviceMatch(const ServiceDescription& first, const ServiceDescription& second) noexcept;

std::ostream& operator<<(std::ostream& stream, const ServiceDescription& service) noexcept;

log::LogStream& operator<<(log::LogStream& stream, const ServiceDescription& service) noexcept;

} // namespace capro
} // namespace iox

#endif // IOX_POSH_CAPRO_SERVICE_DESCRIPTION_HPP

Updated on 31 May 2022 at 11:34:55 CEST