ReceiveListenerSetMap.cpp

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 
00008 #include "DCPS/DdsDcps_pch.h" //Only the _pch include should start with DCPS/
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 /* __ACE_INLINE__ */
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     // find_or_create failure
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   // Deal with possibility that the listener_set just got
00057   // created - and just for us.  This is to make sure we don't leave any
00058   // empty ReceiveListenerSets in our map_.
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   // Ignore the result
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 //MJM: Other than funky return values, the previous and next methods
00105 //MJM: appear to be identical.  Can't you implement remove(a,b) as
00106 //MJM: "release_subscriber(a,b) ; return 0 ;"  Oh.  I guess it returns
00107 //MJM: -1 from one spot as well.  Could the calling code be happy with
00108 //MJM: either of these?  Is this to place where I found no return value
00109 //MJM: of "1".  Could you have been meaning to call the other method?
00110 
00111 /// This method is called when the (remote) subscriber is being
00112 /// released.  This method will return a 0 if the subscriber_id is
00113 /// successfully disassociated with the publisher_id *and* there
00114 /// are still other subscribers associated with the publisher_id.
00115 /// This method will return 1 if, after the disassociation, the
00116 /// publisher_id is no longer associated with any subscribers (which
00117 /// also means it's element was removed from our map_).
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     // Return 1 to indicate that the publisher_id is no longer associated
00132     // with any subscribers at all.
00133     return 1;
00134   }
00135 
00136   int result = listener_set->remove(subscriber_id);
00137 
00138   // Ignore the result
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     // We always return 1 if we know the publisher_id is no longer
00152     // associated with any ReceiveListeners.
00153     return 1;
00154   }
00155 
00156   // There are still ReceiveListeners associated with the publisher_id.
00157   // We return a 0 in this case.
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 }

Generated on Fri Feb 12 20:05:25 2016 for OpenDDS by  doxygen 1.4.7