OpenDDS  Snapshot(2023/04/28-20:55)
ReceiveListenerSet.inl
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
9 #include "ReceivedDataSample.h"
10 #include "EntryExit.h"
11 #include "dds/DCPS/Util.h"
12 #include "dds/DCPS/GuidConverter.h"
13 
15 
16 namespace OpenDDS {
17 namespace DCPS {
18 
21 {
22  DBG_ENTRY_LVL("ReceiveListenerSet", "ReceiveListenerSet", 6);
23 }
24 
27  : RcObject()
28  , lock_()
29  , map_()
30 {
31  DBG_ENTRY_LVL("ReceiveListenerSet", "ReceiveListenerSet(rhs)", 6);
32  *this = rhs;
33 }
34 
37 {
38  DBG_ENTRY_LVL("ReceiveListenerSet", "operator=", 6);
39  if (&rhs != this) {
40  GuardType guard_lt(&lock_ < &rhs.lock_ ? lock_ : rhs.lock_);
41  GuardType guard_gt(&lock_ < &rhs.lock_ ? rhs.lock_ : lock_);
42  map_ = rhs.map_;
43  }
44  return *this;
45 }
46 
47 ACE_INLINE int
49  const TransportReceiveListener_wrch& listener)
50 {
51  DBG_ENTRY_LVL("ReceiveListenerSet", "insert", 6);
52  GuardType guard(lock_);
53 
54  std::pair<MapType::iterator,bool> r = map_.insert(std::make_pair(subscriber_id,listener));
55  if (!r.second) {
56  // subscriber_id is already in the map
57  if (!r.first->second) {
58  // subscriber_id is in the map with a null listener, update it.
59  r.first->second = listener;
60  }
61  return 1; // 1 ==> key already existed in map
62  }
63  return 0;
64 }
65 
66 ACE_INLINE int
68 {
69  DBG_ENTRY_LVL("ReceiveListenerSet", "remove", 6);
70  GuardType guard(lock_);
71 
72  if (unbind(map_, subscriber_id) != 0) {
74  "(%P|%t) ERROR: subscriber_id (%C) not found in map_.\n",
75  LogGuid(subscriber_id).c_str()),
76  -1);
77  }
78 
79  return 0;
80 }
81 
82 ACE_INLINE void
84 {
85  DBG_ENTRY_LVL("ReceiveListenerSet", "remove_all", 6);
86  GuardType guard(lock_);
87  const CORBA::ULong len = to_remove.length();
88  for (CORBA::ULong i(0); i < len; ++i) {
89  unbind(map_, to_remove[i]);
90  }
91 }
92 
95 {
96  DBG_ENTRY_LVL("ReceiveListenerSet", "size", 6);
97  GuardType guard(lock_);
98  return map_.size();
99 }
100 
101 ACE_INLINE ReceiveListenerSet::MapType&
103 {
104  return map_;
105 }
106 
107 ACE_INLINE const ReceiveListenerSet::MapType&
109 {
110  return map_;
111 }
112 
113 } // namespace DCPS
114 } // namespace OpenDDS
115 
MapType & map()
Give access to the underlying map for iteration purposes.
int ssize_t
int insert(GUID_t subscriber_id, const TransportReceiveListener_wrch &listener)
ACE_CDR::ULong ULong
LockType lock_
This lock will protect the map.
sequence< GUID_t > GUIDSeq
Definition: DdsDcpsGuid.idl:62
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68
int remove(GUID_t subscriber_id)
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
#define ACE_INLINE
#define ACE_ERROR_RETURN(X, Y)
void remove_all(const GUIDSeq &to_remove)
LM_ERROR
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
int unbind(Container &c, const typename Container::key_type &k, typename Container::mapped_type &v)
Definition: Util.h:40
ReceiveListenerSet & operator=(const ReceiveListenerSet &)