123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
- #ifndef _FASTDDS_RTPS_RTPSWRITER_H_
- #define _FASTDDS_RTPS_RTPSWRITER_H_
- #include <fastdds/rtps/Endpoint.h>
- #include <fastdds/rtps/messages/RTPSMessageGroup.h>
- #include <fastdds/rtps/attributes/WriterAttributes.h>
- #include <fastrtps/qos/LivelinessLostStatus.h>
- #include <fastrtps/utils/collections/ResourceLimitedVector.hpp>
- #include <fastdds/rtps/common/LocatorSelector.hpp>
- #include <fastdds/rtps/messages/RTPSMessageSenderInterface.hpp>
- #include <vector>
- #include <memory>
- #include <functional>
- #include <chrono>
- #include <mutex>
- namespace eprosima {
- namespace fastrtps {
- namespace rtps {
- class WriterListener;
- class WriterHistory;
- class FlowController;
- struct CacheChange_t;
- class RTPSWriter : public Endpoint, public RTPSMessageSenderInterface
- {
- friend class WriterHistory;
- friend class RTPSParticipantImpl;
- friend class RTPSMessageGroup;
- friend class AsyncInterestTree;
- protected:
- RTPSWriter(
- RTPSParticipantImpl*,
- const GUID_t& guid,
- const WriterAttributes& att,
- WriterHistory* hist,
- WriterListener* listen = nullptr);
- virtual ~RTPSWriter();
- public:
-
- template<typename T>
- CacheChange_t* new_change(
- T& data,
- ChangeKind_t changeKind,
- InstanceHandle_t handle = c_InstanceHandle_Unknown)
- {
- return new_change([data]() -> uint32_t {
- return (uint32_t)T::getCdrSerializedSize(data);
- }, changeKind, handle);
- }
- RTPS_DllAPI CacheChange_t* new_change(
- const std::function<uint32_t()>& dataCdrSerializedSize,
- ChangeKind_t changeKind,
- InstanceHandle_t handle = c_InstanceHandle_Unknown);
-
- RTPS_DllAPI virtual bool matched_reader_add(
- const ReaderProxyData& data) = 0;
-
- RTPS_DllAPI virtual bool matched_reader_remove(
- const GUID_t& reader_guid) = 0;
-
- RTPS_DllAPI virtual bool matched_reader_is_matched(
- const GUID_t& reader_guid) = 0;
-
- RTPS_DllAPI virtual bool is_acked_by_all(
- const CacheChange_t* ) const
- {
- return false;
- }
-
- RTPS_DllAPI virtual bool wait_for_all_acked(
- const Duration_t& )
- {
- return true;
- }
-
- RTPS_DllAPI virtual void updateAttributes(
- const WriterAttributes& att) = 0;
-
- RTPS_DllAPI virtual void send_any_unsent_changes() = 0;
-
- RTPS_DllAPI SequenceNumber_t get_seq_num_min();
-
- RTPS_DllAPI SequenceNumber_t get_seq_num_max();
-
- RTPS_DllAPI uint32_t getTypeMaxSerialized();
-
- uint32_t getMaxDataSize();
-
- uint32_t calculateMaxDataSize(
- uint32_t length);
-
- RTPS_DllAPI inline WriterListener* getListener()
- {
- return mp_listener;
- }
- RTPS_DllAPI inline bool set_listener(
- WriterListener* listener)
- {
- mp_listener = listener;
- return true;
- }
-
- RTPS_DllAPI inline bool isAsync() const
- {
- return is_async_;
- }
-
- RTPS_DllAPI bool remove_older_changes(
- unsigned int max = 0);
-
- virtual bool try_remove_change(
- const std::chrono::steady_clock::time_point& max_blocking_time_point,
- std::unique_lock<RecursiveTimedMutex>& lock) = 0;
-
- virtual void add_flow_controller(
- std::unique_ptr<FlowController> controller) = 0;
-
- inline RTPSParticipantImpl* getRTPSParticipant() const
- {
- return mp_RTPSParticipant;
- }
-
- void set_separate_sending (
- bool enable)
- {
- m_separateSendingEnabled = enable;
- }
-
- bool get_separate_sending () const
- {
- return m_separateSendingEnabled;
- }
-
- virtual bool process_acknack(
- const GUID_t& writer_guid,
- const GUID_t& reader_guid,
- uint32_t ack_count,
- const SequenceNumberSet_t& sn_set,
- bool final_flag,
- bool& result)
- {
- (void)reader_guid; (void)ack_count; (void)sn_set; (void)final_flag;
- result = false;
- return writer_guid == m_guid;
- }
-
- virtual bool process_nack_frag(
- const GUID_t& writer_guid,
- const GUID_t& reader_guid,
- uint32_t ack_count,
- const SequenceNumber_t& seq_num,
- const FragmentNumberSet_t fragments_state,
- bool& result)
- {
- (void)reader_guid; (void)ack_count; (void)seq_num; (void)fragments_state;
- result = false;
- return writer_guid == m_guid;
- }
-
- const LivelinessQosPolicyKind& get_liveliness_kind() const;
-
- const Duration_t& get_liveliness_lease_duration() const;
-
- const Duration_t& get_liveliness_announcement_period() const;
-
- LivelinessLostStatus liveliness_lost_status_;
-
- bool destinations_have_changed() const override;
-
- GuidPrefix_t destination_guid_prefix() const override;
-
- const std::vector<GuidPrefix_t>& remote_participants() const override;
-
- const std::vector<GUID_t>& remote_guids() const override;
-
- bool send(
- CDRMessage_t* message,
- std::chrono::steady_clock::time_point& max_blocking_time_point) const override;
- protected:
-
- bool m_pushMode;
-
- WriterHistory* mp_history;
-
- WriterListener* mp_listener;
-
- bool is_async_;
-
- bool m_separateSendingEnabled;
- LocatorSelector locator_selector_;
- ResourceLimitedVector<GUID_t> all_remote_readers_;
- ResourceLimitedVector<GuidPrefix_t> all_remote_participants_;
- void add_guid(
- const GUID_t& remote_guid);
- void compute_selected_guids();
- void update_cached_info_nts();
-
- void init_header();
-
- virtual void unsent_change_added_to_history(
- CacheChange_t* change,
- const std::chrono::time_point<std::chrono::steady_clock>& max_blocking_time) = 0;
-
- virtual bool change_removed_by_history(
- CacheChange_t* a_change) = 0;
- #if HAVE_SECURITY
- SerializedPayload_t encrypt_payload_;
- bool encrypt_cachechange(
- CacheChange_t* change);
- #endif
-
- LivelinessQosPolicyKind liveliness_kind_;
-
- Duration_t liveliness_lease_duration_;
-
- Duration_t liveliness_announcement_period_;
- private:
- RTPSWriter& operator =(
- const RTPSWriter&) = delete;
- RTPSWriter* next_[2];
- };
- }
- }
- }
- #endif
|