Line data Source code
1 : /* 2 : * 3 : * 4 : * Distributed under the OpenDDS License. 5 : * See: http://www.opendds.org/license.html 6 : */ 7 : 8 : #ifndef OPENDDS_DCPS_TRANSPORT_FRAMEWORK_DATALINKSET_H 9 : #define OPENDDS_DCPS_TRANSPORT_FRAMEWORK_DATALINKSET_H 10 : 11 : #include "dds/DCPS/dcps_export.h" 12 : #include "dds/DCPS/RcObject.h" 13 : #include "dds/DCPS/PoolAllocator.h" 14 : #include "DataLink_rch.h" 15 : #include "SendResponseListener.h" 16 : #include "TransportDefs.h" 17 : #include "TransportSendControlElement.h" 18 : #include "ace/Synch_Traits.h" 19 : 20 : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 21 : 22 : namespace OpenDDS { 23 : namespace DCPS { 24 : 25 : class TransportSendListener; 26 : class DataSampleElement; 27 : class DataLinkSet; 28 : typedef RcHandle<DataLinkSet> DataLinkSet_rch; 29 : 30 : class OpenDDS_Dcps_Export DataLinkSet : public virtual RcObject { 31 : public: 32 : 33 : DataLinkSet(); 34 : virtual ~DataLinkSet(); 35 : 36 : // Returns 0 for success, -1 for failure, and 1 for failure due 37 : // to duplicate entry (link is already a member of the set). 38 : int insert_link(const DataLink_rch& link); 39 : 40 : void remove_link(const DataLink_rch& link); 41 : 42 : /// Send to each DataLink in the set. 43 : void send(DataSampleElement* sample); 44 : 45 : /// Send a control message that is wrapped in a DataSampleElement 46 : void send_control(DataSampleElement* sample); 47 : 48 : /// Send control message to each DataLink in the set. 49 : SendControlStatus send_control(GUID_t pub_id, 50 : const TransportSendListener_rch& listener, 51 : const DataSampleHeader& header, 52 : Message_Block_Ptr msg); 53 : 54 : void send_response(GUID_t sub_id, 55 : const DataSampleHeader& header, 56 : Message_Block_Ptr response); 57 : 58 : bool remove_sample(const DataSampleElement* sample); 59 : 60 : bool remove_all_msgs(const GUID_t& pub_id); 61 : 62 : /// Calls send_start() on the links in link_set and also adds 63 : /// the links from link_set to *this. 64 : void send_start(DataLinkSet* link_set); 65 : 66 : /// Calls send_stop() on the links with ID repoId and then 67 : /// clears the set. 68 : void send_stop(GUID_t repoId); 69 : 70 : DataLinkSet_rch select_links(const GUID_t* remoteIds, 71 : const CORBA::ULong num_targets); 72 : 73 : bool empty(); 74 : 75 : void send_final_acks(const GUID_t& readerid); 76 : 77 : typedef ACE_SYNCH_MUTEX LockType; 78 : typedef ACE_Guard<LockType> GuardType; 79 : 80 : typedef OPENDDS_MAP(DataLinkIdType, DataLink_rch) MapType; 81 : 82 : //{@ 83 : /// Accessors for external iteration 84 0 : LockType& lock() { return lock_; } 85 0 : MapType& map() { return map_; } 86 : //@} 87 : 88 : void terminate_send_if_suspended(); 89 : 90 : bool is_leading(const GUID_t& writer_id, 91 : const GUID_t& reader_id) const; 92 : 93 : private: 94 : 95 : /// Hash map for DataLinks. 96 : MapType map_; 97 : 98 : /// This lock will protect critical sections of code that play a 99 : /// role in the sending of data. 100 : mutable LockType lock_; 101 : 102 : /// Listener for TransportSendControlElements created in send_response 103 : SendResponseListener send_response_listener_; 104 : 105 : /// lock and copy map for lock-free access 106 : void copy_map_to(MapType& target); 107 : }; 108 : 109 : } // namespace DCPS 110 : } // namespace OpenDDS 111 : 112 : OPENDDS_END_VERSIONED_NAMESPACE_DECL 113 : 114 : #if defined (__ACE_INLINE__) 115 : #include "DataLinkSet.inl" 116 : #endif /* __ACE_INLINE__ */ 117 : 118 : #endif /* OPENDDS_DCPS_DATALINKSET_H */