00001
00002
00003
00004
00005
00006
00007
00008 #include "DCPS/DdsDcps_pch.h"
00009 #include "ReceiveListenerSetMap.h"
00010 #include "dds/DCPS/GuidConverter.h"
00011 #include "dds/DCPS/Util.h"
00012
00013 #if !defined (__ACE_INLINE__)
00014 #include "ReceiveListenerSetMap.inl"
00015 #endif
00016
00017 OpenDDS::DCPS::ReceiveListenerSetMap::~ReceiveListenerSetMap()
00018 {
00019 DBG_ENTRY_LVL("ReceiveListenerSetMap","~ReceiveListenerSetMap",6);
00020 }
00021
00022 int
00023 OpenDDS::DCPS::ReceiveListenerSetMap::insert
00024 (RepoId publisher_id,
00025 RepoId subscriber_id,
00026 TransportReceiveListener* receive_listener)
00027 {
00028 DBG_ENTRY_LVL("ReceiveListenerSetMap","insert",6);
00029 ReceiveListenerSet_rch listener_set = this->find_or_create(publisher_id);
00030
00031 if (listener_set.is_nil()) {
00032
00033 GuidConverter converter(publisher_id);
00034 ACE_ERROR_RETURN((LM_ERROR,
00035 ACE_TEXT("(%P|%t) ERROR: ReceiveListenerSetMap::insert: ")
00036 ACE_TEXT("failed to find_or_create entry for ")
00037 ACE_TEXT("publisher %C.\n"),
00038 OPENDDS_STRING(converter).c_str()), -1);
00039 }
00040
00041 int result = listener_set->insert(subscriber_id, receive_listener);
00042
00043 if (result == 0 || result == 1) {
00044 return 0;
00045 }
00046
00047 GuidConverter sub_converter(subscriber_id);
00048 GuidConverter pub_converter(publisher_id);
00049 ACE_ERROR((LM_ERROR,
00050 ACE_TEXT("(%P|%t) ERROR: ReceiveListenerSetMap::insert: ")
00051 ACE_TEXT("failed to insert subscriber %C for ")
00052 ACE_TEXT("publisher %C.\n"),
00053 OPENDDS_STRING(sub_converter).c_str(),
00054 OPENDDS_STRING(pub_converter).c_str()));
00055
00056
00057
00058
00059 if (listener_set->size() == 0) {
00060 listener_set = this->remove_set(publisher_id);
00061
00062 if (listener_set.is_nil()) {
00063 ACE_ERROR((LM_ERROR,
00064 ACE_TEXT("(%P|%t) ERROR: ReceiveListenerSetMap::insert: ")
00065 ACE_TEXT("failed to remove (undo create) ReceiveListenerSet ")
00066 ACE_TEXT("for publisher %C.\n"),
00067 OPENDDS_STRING(pub_converter).c_str()));
00068 }
00069 }
00070
00071 return -1;
00072 }
00073
00074 int
00075 OpenDDS::DCPS::ReceiveListenerSetMap::remove(RepoId publisher_id,
00076 RepoId subscriber_id)
00077 {
00078 DBG_ENTRY_LVL("ReceiveListenerSetMap","remove",6);
00079 ReceiveListenerSet_rch listener_set;
00080
00081 if (OpenDDS::DCPS::find(map_, publisher_id, listener_set) != 0) {
00082 return 0;
00083 }
00084
00085 int result = listener_set->remove(subscriber_id);
00086
00087
00088 ACE_UNUSED_ARG(result);
00089
00090 if (listener_set->size() == 0) {
00091 if (unbind(map_, publisher_id) != 0) {
00092 GuidConverter converter(publisher_id);
00093 ACE_ERROR_RETURN((LM_ERROR,
00094 ACE_TEXT("(%P|%t) ERROR: ReceiveListenerSetMap::remove: ")
00095 ACE_TEXT("failed to remove empty ReceiveListenerSet for ")
00096 ACE_TEXT("publisher %C.\n"),
00097 OPENDDS_STRING(converter).c_str()), -1);
00098 }
00099 }
00100
00101 return 0;
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 int
00119 OpenDDS::DCPS::ReceiveListenerSetMap::release_subscriber(RepoId publisher_id,
00120 RepoId subscriber_id)
00121 {
00122 DBG_ENTRY_LVL("ReceiveListenerSetMap","release_subscriber",6);
00123 ReceiveListenerSet_rch listener_set;
00124
00125 if (OpenDDS::DCPS::find(map_, publisher_id, listener_set) != 0) {
00126 GuidConverter converter(publisher_id);
00127 ACE_ERROR((LM_ERROR,
00128 ACE_TEXT("(%P|%t) ERROR: ReciveListenerSetMap::release_subscriber: ")
00129 ACE_TEXT("publisher %C not found in map_.\n"),
00130 OPENDDS_STRING(converter).c_str()));
00131
00132
00133 return 1;
00134 }
00135
00136 int result = listener_set->remove(subscriber_id);
00137
00138
00139 ACE_UNUSED_ARG(result);
00140
00141 if (listener_set->size() == 0) {
00142 if (unbind(map_, publisher_id) != 0) {
00143 GuidConverter converter(publisher_id);
00144 ACE_ERROR((LM_ERROR,
00145 ACE_TEXT("(%P|%t) ERROR: ReceiveListenerSetMap::release_subscriber: ")
00146 ACE_TEXT("failed to remove empty ReceiveListenerSet for ")
00147 ACE_TEXT("publisher %C.\n"),
00148 OPENDDS_STRING(converter).c_str()));
00149 }
00150
00151
00152
00153 return 1;
00154 }
00155
00156
00157
00158 return 0;
00159 }
00160
00161 void
00162 OpenDDS::DCPS::ReceiveListenerSetMap::operator= (const ReceiveListenerSetMap& rh)
00163 {
00164 DBG_ENTRY_LVL("ReceiveListenerSetMap","operator=",6);
00165 const MapType& map = rh.map();
00166
00167 for (MapType::const_iterator itr = map.begin();
00168 itr != map.end();
00169 ++itr) {
00170 ReceiveListenerSet_rch set = itr->second;
00171 ReceiveListenerSet::MapType& smap = set->map();
00172
00173 for (ReceiveListenerSet::MapType::iterator sitr = smap.begin();
00174 sitr != smap.end();
00175 ++sitr) {
00176 this->insert(itr->first, sitr->first, sitr->second);
00177 }
00178 }
00179 }
00180
00181 void
00182 OpenDDS::DCPS::ReceiveListenerSetMap::clear()
00183 {
00184 DBG_ENTRY_LVL("ReceiveListenerSetMap","clear",6);
00185
00186 for (MapType::iterator itr = this->map_.begin();
00187 itr != this->map_.end();
00188 ++itr) {
00189 itr->second->clear();
00190 }
00191
00192 this->map_.clear();
00193 }