00001
00002
00003
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 ACE_ENV_ARG_DECL_NOT_USED) ACE_THROW_SPEC ((CORBA::SystemException))
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 ACE_DECLARE_NEW_CORBA_ENV;
00068 ACE_TRY
00069 {
00070 rh.wait_for_startup (si.in () ACE_ENV_ARG_PARAMETER);
00071 ACE_TRY_CHECK;
00072 }
00073 ACE_CATCHANY
00074 {
00075 if (debug_)
00076 ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "AsyncStartupWaiter_i::send_response ()");
00077 }
00078 ACE_ENDTRY;
00079 }
00080
00081 void
00082 AsyncStartupWaiter_i::unblock_one (const char* name, const char* partial_ior, const char* ior, bool queue) {
00083 ImplementationRepository::AMH_AsyncStartupWaiterResponseHandler_var rh = get_one_waiter(name);
00084 if (! CORBA::is_nil(rh.in ()))
00085 {
00086 send_response (*rh.in (), name, partial_ior, ior);
00087 }
00088 else if (queue)
00089 {
00090 if (debug_)
00091 ACE_DEBUG((LM_DEBUG, "ImR: Queuing startup info.\n"));
00092
00093 PendingListPtr lst;
00094 pending_.find (name, lst);
00095 if (lst.null ())
00096 {
00097 lst = PendingListPtr (new PendingList);
00098 int err = pending_.bind (name, lst);
00099 ACE_ASSERT (err == 0);
00100 ACE_UNUSED_ARG (err);
00101 }
00102 lst->push_back (PendingData (partial_ior, ior));
00103 }
00104 }
00105
00106 void
00107 AsyncStartupWaiter_i::unblock_all (const char* name) {
00108 RHList tmp;
00109
00110 get_all_waiters (name, tmp);
00111
00112
00113
00114 StartupInfo_var si = new StartupInfo ();
00115 si->name = name;
00116
00117
00118
00119 for (size_t i = 0; i < tmp.size(); ++i)
00120 {
00121 ACE_DECLARE_NEW_CORBA_ENV;
00122 ACE_TRY
00123 {
00124 ImplementationRepository::AMH_AsyncStartupWaiterResponseHandler_var& rh = tmp[i];
00125
00126 rh->wait_for_startup (si.in () ACE_ENV_ARG_PARAMETER);
00127 ACE_TRY_CHECK;
00128 }
00129 ACE_CATCHANY
00130 {
00131 if (debug_)
00132 ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "AsyncStartupWaiter_i::unblock_all ()");
00133 }
00134 ACE_ENDTRY;
00135 }
00136 }
00137
00138 ImplementationRepository::AMH_AsyncStartupWaiterResponseHandler_ptr
00139 AsyncStartupWaiter_i::get_one_waiter (const char* name)
00140 {
00141 RHListPtr lst;
00142 waiting_.find (name, lst);
00143 if (! lst.null() && lst->size () > 0)
00144 {
00145 RHList& rhlst = *lst;
00146 ImplementationRepository::AMH_AsyncStartupWaiterResponseHandler_var& tmp = rhlst[rhlst.size () - 1];
00147 ImplementationRepository::AMH_AsyncStartupWaiterResponseHandler_ptr ret = tmp._retn ();
00148 rhlst.pop_back ();
00149 return ret;
00150 }
00151 return ImplementationRepository::AMH_AsyncStartupWaiterResponseHandler::_nil ();
00152 }
00153
00154 void
00155 AsyncStartupWaiter_i::get_all_waiters (const char* name, RHList& ret)
00156 {
00157 RHListPtr lst;
00158 waiting_.find (name, lst);
00159 if (! lst.null ()) {
00160 for (size_t i = 0; i < lst->size (); ++i)
00161 {
00162 RHList& tmp = *lst;
00163 ret.push_back (tmp[i]);
00164
00165
00166 tmp[i] = ImplementationRepository::AMH_AsyncStartupWaiterResponseHandler::_nil ();
00167 }
00168 lst->clear ();
00169 }
00170 }
00171