AsyncStartupWaiter_i.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // $Id: AsyncStartupWaiter_i.cpp 77076 2007-02-12 19:34:51Z johnnyw $
00004 
00005 #include "AsyncStartupWaiter_i.h"
00006 #include "ImR_Locator_i.h"
00007 
00008 using namespace ImplementationRepository;
00009 
00010 AsyncStartupWaiter_i::PendingData::PendingData (const char* p, const char* i)
00011 : partial_ior (p)
00012 , ior( i)
00013 {
00014 }
00015 
00016 AsyncStartupWaiter_i::PendingData::PendingData ()
00017 {
00018 }
00019 
00020 
00021 void AsyncStartupWaiter_i::debug (bool dbg)
00022 {
00023   debug_ = dbg;
00024 }
00025 
00026 void AsyncStartupWaiter_i::wait_for_startup (AMH_AsyncStartupWaiterResponseHandler_ptr rh,
00027    const char* name)
00028 {
00029   PendingListPtr plst;
00030   pending_.find(name, plst);
00031   if (! plst.null () && plst->size () > 0)
00032     {
00033       PendingList& tmp = *plst;
00034       PendingData& pd = tmp[tmp.size () - 1];
00035       tmp.pop_back ();
00036 
00037       if (debug_)
00038         ACE_DEBUG ((LM_DEBUG, "ImR: Skipping wait due to queued startup info for <%s>.\n", name));
00039 
00040       send_response (*rh, name, pd.partial_ior.c_str(), pd.ior.c_str());
00041 
00042     }
00043   else
00044     {
00045       RHListPtr lst;
00046       waiting_.find (name, lst);
00047       if (lst.null ())
00048       {
00049         lst = RHListPtr (new RHList);
00050         int err = waiting_.bind (name, lst);
00051         ACE_ASSERT (err == 0);
00052         ACE_UNUSED_ARG (err);
00053       }
00054       lst->push_back (AMH_AsyncStartupWaiterResponseHandler::_duplicate (rh));
00055     }
00056 }
00057 
00058 void
00059 AsyncStartupWaiter_i::send_response (ImplementationRepository::AMH_AsyncStartupWaiterResponseHandler& rh,
00060                                     const char* name, const char* partial_ior, const char* ior)
00061 {
00062   StartupInfo_var si = new StartupInfo();
00063   si->name = name;
00064   si->partial_ior = partial_ior;
00065   si->ior = ior;
00066 
00067   try
00068     {
00069       rh.wait_for_startup (si.in ());
00070     }
00071   catch (const CORBA::Exception& ex)
00072     {
00073       if (debug_)
00074         ex._tao_print_exception (
00075           "AsyncStartupWaiter_i::send_response ()");
00076     }
00077 }
00078 
00079 void
00080 AsyncStartupWaiter_i::unblock_one (const char* name, const char* partial_ior, const char* ior, bool queue) {
00081   ImplementationRepository::AMH_AsyncStartupWaiterResponseHandler_var rh = get_one_waiter(name);
00082   if (! CORBA::is_nil(rh.in ()))
00083     {
00084       send_response (*rh.in (), name, partial_ior, ior);
00085     }
00086   else if (queue)
00087     {
00088       if (debug_)
00089         ACE_DEBUG((LM_DEBUG, "ImR: Queuing startup info.\n"));
00090 
00091       PendingListPtr lst;
00092       pending_.find (name, lst);
00093       if (lst.null ())
00094         {
00095           lst = PendingListPtr (new PendingList);
00096           int err = pending_.bind (name, lst);
00097           ACE_ASSERT (err == 0);
00098           ACE_UNUSED_ARG (err);
00099         }
00100       lst->push_back (PendingData (partial_ior, ior));
00101     }
00102 }
00103 
00104 void
00105 AsyncStartupWaiter_i::unblock_all (const char* name) {
00106   RHList tmp;
00107 
00108   get_all_waiters (name, tmp);
00109 
00110   // This startup info should be ignored when unblocking all, because we
00111   // don't know the ior or partial_ior at this point.
00112   StartupInfo_var si = new StartupInfo ();
00113   si->name = name;
00114 
00115   // Note : This method may be called when there are no waiters.
00116 
00117   for (size_t i = 0; i < tmp.size(); ++i)
00118   {
00119     try
00120       {
00121         ImplementationRepository::AMH_AsyncStartupWaiterResponseHandler_var& rh = tmp[i];
00122 
00123         rh->wait_for_startup (si.in ());
00124       }
00125     catch (const CORBA::Exception& ex)
00126       {
00127         if (debug_)
00128           ex._tao_print_exception (
00129             "AsyncStartupWaiter_i::unblock_all ()");
00130       }
00131   }
00132 }
00133 
00134 ImplementationRepository::AMH_AsyncStartupWaiterResponseHandler_ptr
00135 AsyncStartupWaiter_i::get_one_waiter (const char* name)
00136 {
00137   RHListPtr lst;
00138   waiting_.find (name, lst);
00139   if (! lst.null() && lst->size () > 0)
00140     {
00141       RHList& rhlst = *lst;
00142       ImplementationRepository::AMH_AsyncStartupWaiterResponseHandler_var& tmp = rhlst[rhlst.size () - 1];
00143       ImplementationRepository::AMH_AsyncStartupWaiterResponseHandler_ptr ret = tmp._retn ();
00144       rhlst.pop_back ();
00145       return ret;
00146     }
00147   return ImplementationRepository::AMH_AsyncStartupWaiterResponseHandler::_nil ();
00148 }
00149 
00150 void
00151 AsyncStartupWaiter_i::get_all_waiters (const char* name, RHList& ret)
00152 {
00153   RHListPtr lst;
00154   waiting_.find (name, lst);
00155   if (! lst.null ()) {
00156     for (size_t i = 0; i < lst->size (); ++i)
00157       {
00158         RHList& tmp = *lst;
00159         ret.push_back (tmp[i]);
00160         // The ACE_Vector will not destruct the elements when cleared, so we must
00161         // make sure to do so here.
00162         tmp[i] = ImplementationRepository::AMH_AsyncStartupWaiterResponseHandler::_nil ();
00163       }
00164     lst->clear ();
00165   }
00166 }
00167 

Generated on Sun Jan 27 15:54:50 2008 for TAO_Implementation_Repository by doxygen 1.3.6