Line data Source code
1 : /* 2 : * 3 : * 4 : * Distributed under the OpenDDS License. 5 : * See: http://www.opendds.org/license.html 6 : */ 7 : 8 : #include "TransportReceiveListener.h" 9 : #include "ReceivedDataSample.h" 10 : #include "EntryExit.h" 11 : #include "dds/DCPS/Util.h" 12 : #include "dds/DCPS/GuidConverter.h" 13 : 14 : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 15 : 16 : namespace OpenDDS { 17 : namespace DCPS { 18 : 19 : ACE_INLINE 20 0 : ReceiveListenerSet::ReceiveListenerSet() 21 : { 22 : DBG_ENTRY_LVL("ReceiveListenerSet", "ReceiveListenerSet", 6); 23 0 : } 24 : 25 : ACE_INLINE 26 0 : ReceiveListenerSet::ReceiveListenerSet(const ReceiveListenerSet& rhs) 27 : : RcObject() 28 0 : , lock_() 29 0 : , map_() 30 : { 31 : DBG_ENTRY_LVL("ReceiveListenerSet", "ReceiveListenerSet(rhs)", 6); 32 0 : *this = rhs; 33 0 : } 34 : 35 : ACE_INLINE ReceiveListenerSet& 36 0 : ReceiveListenerSet::operator=(const ReceiveListenerSet& rhs) 37 : { 38 : DBG_ENTRY_LVL("ReceiveListenerSet", "operator=", 6); 39 0 : if (&rhs != this) { 40 0 : GuardType guard_lt(&lock_ < &rhs.lock_ ? lock_ : rhs.lock_); 41 0 : GuardType guard_gt(&lock_ < &rhs.lock_ ? rhs.lock_ : lock_); 42 0 : map_ = rhs.map_; 43 0 : } 44 0 : return *this; 45 : } 46 : 47 : ACE_INLINE int 48 0 : ReceiveListenerSet::insert(GUID_t subscriber_id, 49 : const TransportReceiveListener_wrch& listener) 50 : { 51 : DBG_ENTRY_LVL("ReceiveListenerSet", "insert", 6); 52 0 : GuardType guard(lock_); 53 : 54 0 : std::pair<MapType::iterator,bool> r = map_.insert(std::make_pair(subscriber_id,listener)); 55 0 : if (!r.second) { 56 : // subscriber_id is already in the map 57 0 : if (!r.first->second) { 58 : // subscriber_id is in the map with a null listener, update it. 59 0 : r.first->second = listener; 60 : } 61 0 : return 1; // 1 ==> key already existed in map 62 : } 63 0 : return 0; 64 0 : } 65 : 66 : ACE_INLINE int 67 0 : ReceiveListenerSet::remove(GUID_t subscriber_id) 68 : { 69 : DBG_ENTRY_LVL("ReceiveListenerSet", "remove", 6); 70 0 : GuardType guard(lock_); 71 : 72 0 : if (unbind(map_, subscriber_id) != 0) { 73 0 : ACE_ERROR_RETURN((LM_ERROR, 74 : "(%P|%t) ERROR: subscriber_id (%C) not found in map_.\n", 75 : LogGuid(subscriber_id).c_str()), 76 : -1); 77 : } 78 : 79 0 : return 0; 80 0 : } 81 : 82 : ACE_INLINE void 83 0 : ReceiveListenerSet::remove_all(const GUIDSeq& to_remove) 84 : { 85 : DBG_ENTRY_LVL("ReceiveListenerSet", "remove_all", 6); 86 0 : GuardType guard(lock_); 87 0 : const CORBA::ULong len = to_remove.length(); 88 0 : for (CORBA::ULong i(0); i < len; ++i) { 89 0 : unbind(map_, to_remove[i]); 90 : } 91 0 : } 92 : 93 : ACE_INLINE ssize_t 94 0 : ReceiveListenerSet::size() const 95 : { 96 : DBG_ENTRY_LVL("ReceiveListenerSet", "size", 6); 97 0 : GuardType guard(lock_); 98 0 : return map_.size(); 99 0 : } 100 : 101 : ACE_INLINE ReceiveListenerSet::MapType& 102 : ReceiveListenerSet::map() 103 : { 104 : return map_; 105 : } 106 : 107 : ACE_INLINE const ReceiveListenerSet::MapType& 108 : ReceiveListenerSet::map() const 109 : { 110 : return map_; 111 : } 112 : 113 : } // namespace DCPS 114 : } // namespace OpenDDS 115 : 116 : OPENDDS_END_VERSIONED_NAMESPACE_DECL