Program Listing for File WLP.h

Return to documentation for file (/tmp/ws/src/fastrtps/include/fastdds/rtps/builtin/liveliness/WLP.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_WLP_H_
#define _FASTDDS_RTPS_WLP_H_
#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC

#include <vector>
#include <mutex>

#include <fastdds/rtps/common/Time_t.h>
#include <fastdds/rtps/common/Locator.h>
#include <fastdds/rtps/common/Guid.h>
#include <fastrtps/qos/QosPolicies.h>

#include <fastdds/rtps/builtin/data/WriterProxyData.h>
#include <fastdds/rtps/builtin/data/ReaderProxyData.h>

namespace eprosima {
namespace fastrtps {
namespace rtps {

class BuiltinProtocols;
class LivelinessManager;
class ReaderHistory;
class ReaderProxyData;
class RTPSParticipantImpl;
class RTPSReader;
class RTPSWriter;
class StatefulReader;
class StatefulWriter;
class ParticipantProxyData;
class TimedEvent;
class WLPListener;
class WriterHistory;
class WriterProxyData;
class ITopicPayloadPool;

class WLP
{
    friend class WLPListener;
    friend class StatefulReader;
    friend class StatelessReader;

public:

    WLP(
            BuiltinProtocols* prot);
    virtual ~WLP();
    bool initWL(
            RTPSParticipantImpl* p);
    bool assignRemoteEndpoints(
            const ParticipantProxyData& pdata);
    void removeRemoteEndpoints(
            ParticipantProxyData* pdata);
    bool add_local_writer(
            RTPSWriter* W,
            const WriterQos& wqos);
    bool remove_local_writer(
            RTPSWriter* W);

    bool add_local_reader(
            RTPSReader* reader,
            const ReaderQos& rqos);

    bool remove_local_reader(
            RTPSReader* reader);

    bool assert_liveliness(
            GUID_t writer,
            LivelinessQosPolicyKind kind,
            Duration_t lease_duration);

    bool assert_liveliness_manual_by_participant();

    StatefulWriter* builtin_writer();

    WriterHistory* builtin_writer_history();

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

    bool pairing_remote_writer_with_local_reader_after_security(
            const GUID_t& local_reader,
            const WriterProxyData& remote_writer_data);
#endif // if HAVE_SECURITY

private:

    bool createEndpoints();

    double min_automatic_ms_;
    double min_manual_by_participant_ms_;
    RTPSParticipantImpl* mp_participant;
    BuiltinProtocols* mp_builtinProtocols;
    StatefulWriter* mp_builtinWriter;
    StatefulReader* mp_builtinReader;
    WriterHistory* mp_builtinWriterHistory;
    ReaderHistory* mp_builtinReaderHistory;
    WLPListener* mp_listener;
    TimedEvent* automatic_liveliness_assertion_;
    TimedEvent* manual_liveliness_assertion_;
    std::vector<RTPSWriter*> automatic_writers_;
    std::vector<RTPSWriter*> manual_by_participant_writers_;
    std::vector<RTPSWriter*> manual_by_topic_writers_;

    std::vector<RTPSReader*> readers_;
    bool automatic_readers_;

    LivelinessManager* pub_liveliness_manager_;
    LivelinessManager* sub_liveliness_manager_;

    InstanceHandle_t automatic_instance_handle_;
    InstanceHandle_t manual_by_participant_instance_handle_;

    void pub_liveliness_changed(
            const GUID_t& writer,
            const LivelinessQosPolicyKind& kind,
            const Duration_t& lease_duration,
            int32_t alive_change,
            int32_t not_alive_change);

    void sub_liveliness_changed(
            const GUID_t& writer,
            const LivelinessQosPolicyKind& kind,
            const Duration_t& lease_duration,
            int32_t alive_change,
            int32_t not_alive_change);

    void update_liveliness_changed_status(
            GUID_t writer,
            RTPSReader* reader,
            int32_t alive_change,
            int32_t not_alive_change);

    bool automatic_liveliness_assertion();

    bool participant_liveliness_assertion();

    bool send_liveliness_message(
            const InstanceHandle_t& instance);

#if HAVE_SECURITY
    StatefulWriter* mp_builtinWriterSecure;
    StatefulReader* mp_builtinReaderSecure;
    WriterHistory* mp_builtinWriterSecureHistory;
    ReaderHistory* mp_builtinReaderSecureHistory;

    bool createSecureEndpoints();
#endif // if HAVE_SECURITY

    std::mutex temp_data_lock_;
    ReaderProxyData temp_reader_proxy_data_;
    WriterProxyData temp_writer_proxy_data_;

    std::shared_ptr<ITopicPayloadPool> payload_pool_;
#if HAVE_SECURITY
    std::shared_ptr<ITopicPayloadPool> secure_payload_pool_;
#endif // if HAVE_SECURITY
};

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

#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
#endif /* _FASTDDS_RTPS_WLP_H_ */