Program Listing for File ReaderLocator.h

Return to documentation for file (/tmp/ws/src/fastrtps/include/fastdds/rtps/writer/ReaderLocator.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_READERLOCATOR_H_
#define _FASTDDS_RTPS_READERLOCATOR_H_

#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC

#include <vector>
#include <fastdds/rtps/common/Locator.h>
#include <fastdds/rtps/common/Guid.h>
#include <fastdds/rtps/common/SequenceNumber.h>
#include <fastdds/rtps/messages/RTPSMessageGroup.h>
#include <fastdds/rtps/common/LocatorSelectorEntry.hpp>

namespace eprosima {
namespace fastrtps {
namespace rtps {

class RTPSParticipantImpl;
class RTPSWriter;
class RTPSReader;
class IDataSharingNotifier;

class ReaderLocator : public RTPSMessageSenderInterface
{
public:

    virtual ~ReaderLocator();

    ReaderLocator(
            RTPSWriter* owner,
            size_t max_unicast_locators,
            size_t max_multicast_locators);

    bool expects_inline_qos() const
    {
        return expects_inline_qos_;
    }

    bool is_local_reader() const
    {
        return is_local_reader_;
    }

    RTPSReader* local_reader();

    void local_reader(
            RTPSReader* local_reader)
    {
        local_reader_ = local_reader;
    }

    const GUID_t& remote_guid() const
    {
        return general_locator_info_.remote_guid;
    }

    LocatorSelectorEntry* general_locator_selector_entry()
    {
        return &general_locator_info_;
    }

    LocatorSelectorEntry* async_locator_selector_entry()
    {
        return &async_locator_info_;
    }

    bool start(
            const GUID_t& remote_guid,
            const ResourceLimitedVector<Locator_t>& unicast_locators,
            const ResourceLimitedVector<Locator_t>& multicast_locators,
            bool expects_inline_qos,
            bool is_datasharing = false);

    bool update(
            const ResourceLimitedVector<Locator_t>& unicast_locators,
            const ResourceLimitedVector<Locator_t>& multicast_locators,
            bool expects_inline_qos);

    bool stop(
            const GUID_t& remote_guid);

    void stop();

    bool destinations_have_changed() const override
    {
        return false;
    }

    GuidPrefix_t destination_guid_prefix() const override
    {
        return general_locator_info_.remote_guid.guidPrefix;
    }

    const std::vector<GuidPrefix_t>& remote_participants() const override
    {
        return guid_prefix_as_vector_;
    }

    const std::vector<GUID_t>& remote_guids() const override
    {
        return guid_as_vector_;
    }

    bool send(
            CDRMessage_t* message,
            std::chrono::steady_clock::time_point max_blocking_time_point) const override;

    bool is_datasharing_reader() const;

    IDataSharingNotifier* datasharing_notifier()
    {
        return datasharing_notifier_;
    }

    const IDataSharingNotifier* datasharing_notifier() const
    {
        return datasharing_notifier_;
    }

    void datasharing_notify();

    size_t locators_size() const
    {
        if (general_locator_info_.remote_guid != c_Guid_Unknown && !is_local_reader_)
        {
            if (general_locator_info_.unicast.size() > 0)
            {
                return general_locator_info_.unicast.size();
            }
            else
            {
                return general_locator_info_.multicast.size();
            }
        }

        return 0;

    }

    /*
     * Do nothing.
     * This object always is protected by writer's mutex.
     */
    void lock() override
    {
    }

    /*
     * Do nothing.
     * This object always is protected by writer's mutex.
     */
    void unlock() override
    {
    }

private:

    RTPSWriter* owner_;
    RTPSParticipantImpl* participant_owner_;
    LocatorSelectorEntry general_locator_info_;
    LocatorSelectorEntry async_locator_info_;
    bool expects_inline_qos_;
    bool is_local_reader_;
    RTPSReader* local_reader_;
    std::vector<GuidPrefix_t> guid_prefix_as_vector_;
    std::vector<GUID_t> guid_as_vector_;
    IDataSharingNotifier* datasharing_notifier_;
};

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

#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
#endif /* _FASTDDS_RTPS_READERLOCATOR_H_ */