Program Listing for File ReaderHistory.h

Return to documentation for file (/tmp/ws/src/fastrtps/include/fastdds/rtps/history/ReaderHistory.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_READERHISTORY_H_
#define _FASTDDS_RTPS_READERHISTORY_H_

#include <fastdds/rtps/history/History.h>
#include <fastdds/rtps/common/CacheChange.h>
#include <fastdds/dds/core/status/SampleRejectedStatus.hpp>

namespace eprosima {
namespace fastrtps {
namespace rtps {

class WriterProxy;
class RTPSReader;

class ReaderHistory : public History
{
    friend class RTPSReader;

    ReaderHistory(
            ReaderHistory&&) = delete;
    ReaderHistory& operator =(
            ReaderHistory&&) = delete;

public:

    RTPS_DllAPI ReaderHistory(
            const HistoryAttributes& att);
    RTPS_DllAPI ~ReaderHistory() override;

    RTPS_DllAPI virtual bool can_change_be_added_nts(
            const GUID_t& writer_guid,
            uint32_t total_payload_size,
            size_t unknown_missing_changes_up_to,
            bool& will_never_be_accepted) const;

    RTPS_DllAPI virtual bool received_change(
            CacheChange_t* change,
            size_t unknown_missing_changes_up_to);

    RTPS_DllAPI virtual bool received_change(
            CacheChange_t* change,
            size_t unknown_missing_changes_up_to,
            fastdds::dds::SampleRejectedStatusKind& rejection_reason)
    {
        rejection_reason = fastdds::dds::NOT_REJECTED;
        return received_change(change, unknown_missing_changes_up_to);
    }

    RTPS_DllAPI bool virtual completed_change(
            rtps::CacheChange_t* change)
    {
        (void)change;
        return true;
    }

    RTPS_DllAPI virtual bool completed_change(
            CacheChange_t* change,
            size_t unknown_missing_changes_up_to,
            fastdds::dds::SampleRejectedStatusKind& rejection_reason)
    {
        (void)change;
        (void)unknown_missing_changes_up_to;
        (void)rejection_reason;
        return true;
    }

    RTPS_DllAPI bool add_change(
            CacheChange_t* a_change);

    RTPS_DllAPI iterator remove_change_nts(
            const_iterator removal,
            bool release = true) override;

    RTPS_DllAPI bool matches_change(
            const CacheChange_t* inner,
            CacheChange_t* outer) override;

    using History::remove_change;

    RTPS_DllAPI bool remove_changes_with_guid(
            const GUID_t& a_guid);

    bool remove_fragmented_changes_until(
            const SequenceNumber_t& seq_num,
            const GUID_t& writer_guid);

    RTPS_DllAPI bool get_min_change_from(
            CacheChange_t** min_change,
            const GUID_t& writerGuid);

    RTPS_DllAPI virtual void writer_unmatched(
            const GUID_t& writer_guid,
            const SequenceNumber_t& last_notified_seq);

    RTPS_DllAPI virtual void writer_update_its_ownership_strength_nts(
            const GUID_t& writer_guid,
            const uint32_t ownership_strength)
    {
        static_cast<void>(writer_guid);
        static_cast<void>(ownership_strength);
    }

protected:

    RTPS_DllAPI bool do_reserve_cache(
            CacheChange_t** change,
            uint32_t size) override;

    RTPS_DllAPI void do_release_cache(
            CacheChange_t* ch) override;

    template<typename Pred>
    inline void remove_changes_with_pred(
            Pred pred)
    {
        assert(nullptr != mp_reader);
        assert(nullptr != mp_mutex);

        std::lock_guard<RecursiveTimedMutex> guard(*mp_mutex);
        std::vector<CacheChange_t*>::iterator chit = m_changes.begin();
        while (chit != m_changes.end())
        {
            if (pred(*chit))
            {
                chit = remove_change_nts(chit);
            }
            else
            {
                ++chit;
            }
        }
    }

    RTPSReader* mp_reader;

};

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

#endif /* _FASTDDS_RTPS_READERHISTORY_H_ */