Program Listing for File EDP.h

Return to documentation for file (/tmp/ws/src/fastrtps/include/fastdds/rtps/builtin/discovery/endpoint/EDP.h)

// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// 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.

#ifndef _FASTDDS_RTPS_EDP_H_
#define _FASTDDS_RTPS_EDP_H_
#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC

#include <fastdds/dds/core/status/IncompatibleQosStatus.hpp>
#include <fastdds/dds/core/status/PublicationMatchedStatus.hpp>
#include <fastdds/dds/core/status/SubscriptionMatchedStatus.hpp>
#include <fastdds/rtps/attributes/RTPSParticipantAttributes.h>
#include <fastdds/rtps/builtin/data/ContentFilterProperty.hpp>
#include <fastdds/rtps/builtin/data/ReaderProxyData.h>
#include <fastdds/rtps/builtin/data/WriterProxyData.h>
#include <fastdds/rtps/common/Guid.h>
#include <fastrtps/utils/ProxyPool.hpp>

#include <foonathan/memory/container.hpp>
#include <foonathan/memory/memory_pool.hpp>

#define MATCH_FAILURE_REASON_COUNT size_t(16)

namespace eprosima {
namespace fastrtps {

namespace types {
class TypeIdentifier;
} // namespace types

class TopicAttributes;

namespace rtps {

class PDP;
class ParticipantProxyData;
class RTPSWriter;
class RTPSReader;
class WriterProxyData;
class RTPSParticipantImpl;

class EDP
{
public:

    class MatchingFailureMask : public std::bitset<MATCH_FAILURE_REASON_COUNT>
    {
    public:

        static const uint32_t different_topic = (0x00000001 << 0u);

        static const uint32_t inconsistent_topic = (0x00000001 << 1u);

        static const uint32_t incompatible_qos = (0x00000001 << 2u);

        static const uint32_t partitions = (0x00000001 << 3u);
    };

    EDP(
            PDP* p,
            RTPSParticipantImpl* part);
    virtual ~EDP();

    virtual bool initEDP(
            BuiltinAttributes& attributes) = 0;
    virtual void assignRemoteEndpoints(
            const ParticipantProxyData& pdata) = 0;
    virtual void removeRemoteEndpoints(
            ParticipantProxyData* pdata)
    {
        (void) pdata;
    }

    virtual bool areRemoteEndpointsMatched(
            const ParticipantProxyData*)
    {
        return false;
    }

    virtual bool removeLocalReader(
            RTPSReader* R) = 0;
    virtual bool removeLocalWriter(
            RTPSWriter* W) = 0;

    virtual bool processLocalReaderProxyData(
            RTPSReader* reader,
            ReaderProxyData* rdata) = 0;

    virtual bool processLocalWriterProxyData(
            RTPSWriter* writer,
            WriterProxyData* wdata) = 0;

    bool newLocalReaderProxyData(
            RTPSReader* R,
            const TopicAttributes& att,
            const ReaderQos& qos,
            const fastdds::rtps::ContentFilterProperty* content_filter = nullptr);
    bool newLocalWriterProxyData(
            RTPSWriter* W,
            const TopicAttributes& att,
            const WriterQos& qos);
    bool updatedLocalReader(
            RTPSReader* R,
            const TopicAttributes& att,
            const ReaderQos& qos,
            const fastdds::rtps::ContentFilterProperty* content_filter = nullptr);
    bool updatedLocalWriter(
            RTPSWriter* W,
            const TopicAttributes& att,
            const WriterQos& qos);

    bool validMatching(
            const WriterProxyData* wdata,
            const ReaderProxyData* rdata);

    bool validMatching(
            const ReaderProxyData* rdata,
            const WriterProxyData* wdata);

    bool valid_matching(
            const WriterProxyData* wdata,
            const ReaderProxyData* rdata,
            MatchingFailureMask& reason,
            fastdds::dds::PolicyMask& incompatible_qos);

    bool valid_matching(
            const ReaderProxyData* rdata,
            const WriterProxyData* wdata,
            MatchingFailureMask& reason,
            fastdds::dds::PolicyMask& incompatible_qos);

    bool unpairWriterProxy(
            const GUID_t& participant_guid,
            const GUID_t& writer_guid,
            bool removed_by_lease);

    bool unpairReaderProxy(
            const GUID_t& participant_guid,
            const GUID_t& reader_guid);

    bool pairing_reader_proxy_with_any_local_writer(
            const GUID_t& participant_guid,
            ReaderProxyData* rdata);

#if HAVE_SECURITY
    bool pairing_reader_proxy_with_local_writer(
            const GUID_t& local_writer,
            const GUID_t& remote_participant_guid,
            ReaderProxyData& rdata);

    bool pairing_remote_reader_with_local_writer_after_security(
            const GUID_t& local_writer,
            const ReaderProxyData& remote_reader_data);
#endif // if HAVE_SECURITY

    bool pairing_writer_proxy_with_any_local_reader(
            const GUID_t& participant_guid,
            WriterProxyData* wdata);

#if HAVE_SECURITY
    bool pairing_writer_proxy_with_local_reader(
            const GUID_t& local_reader,
            const GUID_t& remote_participant_guid,
            WriterProxyData& wdata);

    bool pairing_remote_writer_with_local_reader_after_security(
            const GUID_t& local_reader,
            const WriterProxyData& remote_writer_data);

    virtual bool pairing_remote_writer_with_local_builtin_reader_after_security(
            const GUID_t& /*local_reader*/,
            const WriterProxyData& /*remote_writer_data*/)
    {
        return false;
    }

    virtual bool pairing_remote_reader_with_local_builtin_writer_after_security(
            const GUID_t& /*local_writer*/,
            const ReaderProxyData& /*remote_reader_data*/)
    {
        return false;
    }

#endif // if HAVE_SECURITY
    const fastdds::dds::SubscriptionMatchedStatus& update_subscription_matched_status(
            const GUID_t& reader_guid,
            const GUID_t& writer_guid,
            int change);

    const fastdds::dds::PublicationMatchedStatus& update_publication_matched_status(
            const GUID_t& reader_guid,
            const GUID_t& writer_guid,
            int change);

    PDP* mp_PDP;
    RTPSParticipantImpl* mp_RTPSParticipant;

    ProxyPool<ReaderProxyData>& get_temporary_reader_proxies_pool();

    ProxyPool<WriterProxyData>& get_temporary_writer_proxies_pool();

private:

    bool pairingReader(
            RTPSReader* R,
            const GUID_t& participant_guid,
            const ReaderProxyData& rdata);
    bool pairingWriter(
            RTPSWriter* W,
            const GUID_t& participant_guid,
            const WriterProxyData& wdata);

    bool checkDataRepresentationQos(
            const WriterProxyData* wdata,
            const ReaderProxyData* rdata) const;

    bool checkTypeValidation(
            const WriterProxyData* wdata,
            const ReaderProxyData* rdata) const;

    bool checkTypeIdentifier(
            const WriterProxyData* wdata,
            const ReaderProxyData* rdata) const;

    bool hasTypeIdentifier(
            const WriterProxyData* wdata,
            const ReaderProxyData* rdata) const;

    bool checkTypeObject(
            const WriterProxyData* wdata,
            const ReaderProxyData* rdata) const;

    bool hasTypeObject(
            const WriterProxyData* wdata,
            const ReaderProxyData* rdata) const;

    using pool_allocator_t =
            foonathan::memory::memory_pool<foonathan::memory::node_pool, foonathan::memory::heap_allocator>;

    pool_allocator_t reader_status_allocator_;
    pool_allocator_t writer_status_allocator_;

    foonathan::memory::map<GUID_t, fastdds::dds::SubscriptionMatchedStatus, pool_allocator_t> reader_status_;
    foonathan::memory::map<GUID_t, fastdds::dds::PublicationMatchedStatus, pool_allocator_t> writer_status_;
};

} /* namespace rtps */
} /* namespace fastrtps */
} /* namespace eprosima */

#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
#endif /* _FASTDDS_RTPS_EDP_H_ */