OpenDDS  Snapshot(2023/04/07-19:43)
Public Member Functions | Private Member Functions | Private Attributes | List of all members
OpenDDS::DCPS::ReceiveListenerSetMap Class Reference

#include <ReceiveListenerSetMap.h>

Public Member Functions

typedef OPENDDS_MAP_CMP (GUID_t, ReceiveListenerSet_rch, GUID_tKeyLessThan) MapType
 
 ReceiveListenerSetMap ()
 
virtual ~ReceiveListenerSetMap ()
 
int insert (GUID_t publisher_id, GUID_t subscriber_id, const TransportReceiveListener_wrch &receive_listener)
 
ReceiveListenerSet_rch find (GUID_t publisher_id) const
 
int remove (GUID_t publisher_id, GUID_t subscriber_id)
 
int release_subscriber (GUID_t publisher_id, GUID_t subscriber_id)
 
ReceiveListenerSet_rch remove_set (GUID_t publisher_id)
 
ssize_t size () const
 
MapType & map ()
 Give access to the underlying map for iteration purposes. More...
 
const MapType & map () const
 
void operator= (const ReceiveListenerSetMap &rh)
 
void clear ()
 

Private Member Functions

ReceiveListenerSet_rch find_or_create (GUID_t publisher_id)
 

Private Attributes

MapType map_
 

Detailed Description

Definition at line 24 of file ReceiveListenerSetMap.h.

Constructor & Destructor Documentation

◆ ReceiveListenerSetMap()

ACE_INLINE OpenDDS::DCPS::ReceiveListenerSetMap::ReceiveListenerSetMap ( )

Definition at line 14 of file ReceiveListenerSetMap.inl.

References ACE_INLINE, and DBG_ENTRY_LVL.

15 {
16  DBG_ENTRY_LVL("ReceiveListenerSetMap","ReceiveListenerSetMap",6);
17 }
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68

◆ ~ReceiveListenerSetMap()

OpenDDS::DCPS::ReceiveListenerSetMap::~ReceiveListenerSetMap ( )
virtual

Definition at line 17 of file ReceiveListenerSetMap.cpp.

References DBG_ENTRY_LVL, and insert().

18 {
19  DBG_ENTRY_LVL("ReceiveListenerSetMap","~ReceiveListenerSetMap",6);
20 }
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68

Member Function Documentation

◆ clear()

void OpenDDS::DCPS::ReceiveListenerSetMap::clear ( void  )

Definition at line 182 of file ReceiveListenerSetMap.cpp.

References DBG_ENTRY_LVL, and map_.

183 {
184  DBG_ENTRY_LVL("ReceiveListenerSetMap","clear",6);
185 
186  for (MapType::iterator itr = this->map_.begin();
187  itr != this->map_.end();
188  ++itr) {
189  itr->second->clear();
190  }
191 
192  this->map_.clear();
193 }
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68

◆ find()

ACE_INLINE OpenDDS::DCPS::ReceiveListenerSet_rch OpenDDS::DCPS::ReceiveListenerSetMap::find ( GUID_t  publisher_id) const

Definition at line 20 of file ReceiveListenerSetMap.inl.

References ACE_INLINE, DBG_ENTRY_LVL, OpenDDS::DCPS::find(), and map_.

21 {
22  DBG_ENTRY_LVL("ReceiveListenerSetMap","find",6);
23  ReceiveListenerSet_rch listener_set;
24 
25  if (OpenDDS::DCPS::find(map_, publisher_id, listener_set) != 0) {
26  return ReceiveListenerSet_rch();
27  }
28  return listener_set;
29 }
RcHandle< ReceiveListenerSet > ReceiveListenerSet_rch
The type definition for the smart-pointer to the underlying type.
int find(Container &c, const Key &key, typename Container::mapped_type *&value)
Definition: Util.h:71
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68

◆ find_or_create()

ACE_INLINE OpenDDS::DCPS::ReceiveListenerSet_rch OpenDDS::DCPS::ReceiveListenerSetMap::find_or_create ( GUID_t  publisher_id)
private

Definition at line 32 of file ReceiveListenerSetMap.inl.

References ACE_INLINE, DBG_ENTRY_LVL, and map_.

Referenced by insert().

33 {
34  DBG_ENTRY_LVL("ReceiveListenerSetMap","find_or_create",6);
35 
36  ReceiveListenerSet_rch& listener_set = map_[publisher_id];
37  if (!listener_set) {
38  listener_set = make_rch<ReceiveListenerSet>();
39  }
40  return listener_set;
41 }
RcHandle< ReceiveListenerSet > ReceiveListenerSet_rch
The type definition for the smart-pointer to the underlying type.
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68

◆ insert()

int OpenDDS::DCPS::ReceiveListenerSetMap::insert ( GUID_t  publisher_id,
GUID_t  subscriber_id,
const TransportReceiveListener_wrch receive_listener 
)

Definition at line 24 of file ReceiveListenerSetMap.cpp.

References ACE_ERROR, ACE_ERROR_RETURN, ACE_TEXT(), OpenDDS::DCPS::LogGuid::c_str(), DBG_ENTRY_LVL, find_or_create(), OpenDDS::DCPS::RcHandle< T >::is_nil(), LM_ERROR, and remove_set().

Referenced by operator=(), and ~ReceiveListenerSetMap().

27 {
28  DBG_ENTRY_LVL("ReceiveListenerSetMap","insert",6);
29  ReceiveListenerSet_rch listener_set (this->find_or_create(publisher_id));
30 
31  if (listener_set.is_nil()) {
32  // find_or_create failure
33  LogGuid pub_log(publisher_id);
34  ACE_ERROR_RETURN((LM_ERROR,
35  ACE_TEXT("(%P|%t) ERROR: ReceiveListenerSetMap::insert: ")
36  ACE_TEXT("failed to find_or_create entry for ")
37  ACE_TEXT("publisher %C.\n"),
38  pub_log.c_str()), -1);
39  }
40 
41  int result = listener_set->insert(subscriber_id, receive_listener);
42 
43  if (result == 0 || result == 1) {
44  return 0;
45  }
46 
47  LogGuid sub_log(subscriber_id);
48  LogGuid pub_log(publisher_id);
49  ACE_ERROR((LM_ERROR,
50  ACE_TEXT("(%P|%t) ERROR: ReceiveListenerSetMap::insert: ")
51  ACE_TEXT("failed to insert subscriber %C for ")
52  ACE_TEXT("publisher %C.\n"),
53  sub_log.c_str(),
54  pub_log.c_str()));
55 
56  // Deal with possibility that the listener_set just got
57  // created - and just for us. This is to make sure we don't leave any
58  // empty ReceiveListenerSets in our map_.
59  if (listener_set->size() == 0) {
60  listener_set = this->remove_set(publisher_id);
61 
62  if (listener_set.is_nil()) {
63  ACE_ERROR((LM_ERROR,
64  ACE_TEXT("(%P|%t) ERROR: ReceiveListenerSetMap::insert: ")
65  ACE_TEXT("failed to remove (undo create) ReceiveListenerSet ")
66  ACE_TEXT("for publisher %C.\n"),
67  pub_log.c_str()));
68  }
69  }
70 
71  return -1;
72 }
#define ACE_ERROR(X)
RcHandle< ReceiveListenerSet > ReceiveListenerSet_rch
The type definition for the smart-pointer to the underlying type.
ReceiveListenerSet_rch find_or_create(GUID_t publisher_id)
ACE_TEXT("TCP_Factory")
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68
#define ACE_ERROR_RETURN(X, Y)
ReceiveListenerSet_rch remove_set(GUID_t publisher_id)

◆ map() [1/2]

ACE_INLINE OpenDDS::DCPS::ReceiveListenerSetMap::MapType & OpenDDS::DCPS::ReceiveListenerSetMap::map ( void  )

Give access to the underlying map for iteration purposes.

Definition at line 69 of file ReceiveListenerSetMap.inl.

References ACE_INLINE, DBG_ENTRY_LVL, and map_.

Referenced by operator=().

70 {
71  DBG_ENTRY_LVL("ReceiveListenerSetMap","map",6);
72  return map_;
73 }
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68

◆ map() [2/2]

ACE_INLINE const OpenDDS::DCPS::ReceiveListenerSetMap::MapType & OpenDDS::DCPS::ReceiveListenerSetMap::map ( void  ) const

Definition at line 76 of file ReceiveListenerSetMap.inl.

References DBG_ENTRY_LVL, and map_.

77 {
78  DBG_ENTRY_LVL("ReceiveListenerSetMap","map",6);
79  return map_;
80 }
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68

◆ OPENDDS_MAP_CMP()

typedef OpenDDS::DCPS::ReceiveListenerSetMap::OPENDDS_MAP_CMP ( GUID_t  ,
ReceiveListenerSet_rch  ,
GUID_tKeyLessThan   
)

◆ operator=()

void OpenDDS::DCPS::ReceiveListenerSetMap::operator= ( const ReceiveListenerSetMap rh)

Definition at line 162 of file ReceiveListenerSetMap.cpp.

References DBG_ENTRY_LVL, insert(), and map().

163 {
164  DBG_ENTRY_LVL("ReceiveListenerSetMap","operator=",6);
165  const MapType& map = rh.map();
166 
167  for (MapType::const_iterator itr = map.begin();
168  itr != map.end();
169  ++itr) {
170  ReceiveListenerSet_rch set = itr->second;
171  ReceiveListenerSet::MapType& smap = set->map();
172 
173  for (ReceiveListenerSet::MapType::iterator sitr = smap.begin();
174  sitr != smap.end();
175  ++sitr) {
176  this->insert(itr->first, sitr->first, sitr->second);
177  }
178  }
179 }
int insert(GUID_t publisher_id, GUID_t subscriber_id, const TransportReceiveListener_wrch &receive_listener)
RcHandle< ReceiveListenerSet > ReceiveListenerSet_rch
The type definition for the smart-pointer to the underlying type.
MapType & map()
Give access to the underlying map for iteration purposes.
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68

◆ release_subscriber()

int OpenDDS::DCPS::ReceiveListenerSetMap::release_subscriber ( GUID_t  publisher_id,
GUID_t  subscriber_id 
)

This method is called when the (remote) subscriber is being released. This method will return a 0 if the subscriber_id is successfully disassociated with the publisher_id and there are still other subscribers associated with the publisher_id. This method will return 1 if, after the disassociation, the publisher_id is no longer associated with any subscribers (which also means it's element was removed from our map_).

Definition at line 119 of file ReceiveListenerSetMap.cpp.

References ACE_ERROR, ACE_TEXT(), OpenDDS::DCPS::LogGuid::c_str(), DBG_ENTRY_LVL, OpenDDS::DCPS::find(), LM_ERROR, map_, and OpenDDS::DCPS::unbind().

121 {
122  DBG_ENTRY_LVL("ReceiveListenerSetMap","release_subscriber",6);
123  ReceiveListenerSet_rch listener_set;
124 
125  if (OpenDDS::DCPS::find(map_, publisher_id, listener_set) != 0) {
126  LogGuid pub_log(publisher_id);
127  ACE_ERROR((LM_ERROR,
128  ACE_TEXT("(%P|%t) ERROR: ReciveListenerSetMap::release_subscriber: ")
129  ACE_TEXT("publisher %C not found in map_.\n"),
130  pub_log.c_str()));
131  // Return 1 to indicate that the publisher_id is no longer associated
132  // with any subscribers at all.
133  return 1;
134  }
135 
136  int result = listener_set->remove(subscriber_id);
137 
138  // Ignore the result
139  ACE_UNUSED_ARG(result);
140 
141  if (listener_set->size() == 0) {
142  if (unbind(map_, publisher_id) != 0) {
143  LogGuid pub_log(publisher_id);
144  ACE_ERROR((LM_ERROR,
145  ACE_TEXT("(%P|%t) ERROR: ReceiveListenerSetMap::release_subscriber: ")
146  ACE_TEXT("failed to remove empty ReceiveListenerSet for ")
147  ACE_TEXT("publisher %C.\n"),
148  pub_log.c_str()));
149  }
150 
151  // We always return 1 if we know the publisher_id is no longer
152  // associated with any ReceiveListeners.
153  return 1;
154  }
155 
156  // There are still ReceiveListeners associated with the publisher_id.
157  // We return a 0 in this case.
158  return 0;
159 }
#define ACE_ERROR(X)
RcHandle< ReceiveListenerSet > ReceiveListenerSet_rch
The type definition for the smart-pointer to the underlying type.
ACE_TEXT("TCP_Factory")
int find(Container &c, const Key &key, typename Container::mapped_type *&value)
Definition: Util.h:71
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68
int unbind(Container &c, const typename Container::key_type &k, typename Container::mapped_type &v)
Definition: Util.h:40

◆ remove()

int OpenDDS::DCPS::ReceiveListenerSetMap::remove ( GUID_t  publisher_id,
GUID_t  subscriber_id 
)

Definition at line 75 of file ReceiveListenerSetMap.cpp.

References ACE_ERROR_RETURN, ACE_TEXT(), OpenDDS::DCPS::LogGuid::c_str(), DBG_ENTRY_LVL, OpenDDS::DCPS::find(), LM_ERROR, map_, and OpenDDS::DCPS::unbind().

77 {
78  DBG_ENTRY_LVL("ReceiveListenerSetMap","remove",6);
79  ReceiveListenerSet_rch listener_set;
80 
81  if (OpenDDS::DCPS::find(map_, publisher_id, listener_set) != 0) {
82  return 0;
83  }
84 
85  int result = listener_set->remove(subscriber_id);
86 
87  // Ignore the result
88  ACE_UNUSED_ARG(result);
89 
90  if (listener_set->size() == 0) {
91  if (unbind(map_, publisher_id) != 0) {
92  LogGuid pub_log(publisher_id);
93  ACE_ERROR_RETURN((LM_ERROR,
94  ACE_TEXT("(%P|%t) ERROR: ReceiveListenerSetMap::remove: ")
95  ACE_TEXT("failed to remove empty ReceiveListenerSet for ")
96  ACE_TEXT("publisher %C.\n"),
97  pub_log.c_str()), -1);
98  }
99  }
100 
101  return 0;
102 }
RcHandle< ReceiveListenerSet > ReceiveListenerSet_rch
The type definition for the smart-pointer to the underlying type.
ACE_TEXT("TCP_Factory")
int find(Container &c, const Key &key, typename Container::mapped_type *&value)
Definition: Util.h:71
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68
#define ACE_ERROR_RETURN(X, Y)
int unbind(Container &c, const typename Container::key_type &k, typename Container::mapped_type &v)
Definition: Util.h:40

◆ remove_set()

ACE_INLINE OpenDDS::DCPS::ReceiveListenerSet_rch OpenDDS::DCPS::ReceiveListenerSetMap::remove_set ( GUID_t  publisher_id)

Definition at line 44 of file ReceiveListenerSetMap.inl.

References ACE_INLINE, DBG_ENTRY_LVL, LM_DEBUG, map_, OpenDDS::DCPS::unbind(), and VDBG.

Referenced by insert().

45 {
46  DBG_ENTRY_LVL("ReceiveListenerSetMap","remove_set",6);
47  ReceiveListenerSet_rch listener_set;
48 
49  if (unbind(map_, publisher_id, listener_set) != 0) {
50  VDBG((LM_DEBUG,
51  "(%P|%t) Unable to remove ReceiveListenerSet from the "
52  "ReceiveListenerSetMap for id %d.\n",
53  LogGuid(publisher_id).c_str()));
54  // Return a 'nil' ReceiveListenerSet*
55  return ReceiveListenerSet_rch();
56  }
57 
58  return listener_set;
59 }
RcHandle< ReceiveListenerSet > ReceiveListenerSet_rch
The type definition for the smart-pointer to the underlying type.
#define VDBG(DBG_ARGS)
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68
int unbind(Container &c, const typename Container::key_type &k, typename Container::mapped_type &v)
Definition: Util.h:40

◆ size()

ACE_INLINE ssize_t OpenDDS::DCPS::ReceiveListenerSetMap::size ( void  ) const

Definition at line 62 of file ReceiveListenerSetMap.inl.

References ACE_INLINE, DBG_ENTRY_LVL, and map_.

63 {
64  DBG_ENTRY_LVL("ReceiveListenerSetMap","size",6);
65  return map_.size();
66 }
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68

Member Data Documentation

◆ map_

MapType OpenDDS::DCPS::ReceiveListenerSetMap::map_
private

The documentation for this class was generated from the following files: