00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "ProxyManager.h"
00025 #include "Orb.h"
00026
00027 #include <string>
00028 #include <assert.h>
00029
00030 #define DB(l,x) ((omniORB::traceLevel >= l) && (cerr << x << endl))
00031
00032 namespace OmniEvents {
00033
00034
00035
00036
00037
00038 void
00039 ProxyManager::etherealize(
00040 const PortableServer::ObjectId& oid,
00041 PortableServer::POA_ptr adapter,
00042 PortableServer::Servant serv,
00043 CORBA::Boolean cleanup_in_progress,
00044 CORBA::Boolean remaining_activations
00045 )
00046 {
00047 Proxy* narrowed =dynamic_cast<Proxy*>(serv);
00048 assert(narrowed);
00049 set<Proxy*>::iterator pos =_servants.find(narrowed);
00050 if(pos!=_servants.end())
00051 _servants.erase(pos);
00052 else
00053 DB(1,"\t\teh? - POA attempted to etherealize unknown servant.");
00054 delete narrowed;
00055 }
00056
00057
00058 void ProxyManager::reincarnate(const OepPrxyList& pdat)
00059 {
00060 for(OepPrxyList::const_iterator iter=pdat.begin(); iter!=pdat.end(); iter++)
00061 {
00062 PortableServer::Servant serv =
00063 this->incarnate(PortableServer::ObjectId(),_managedPoa);
00064 Proxy* proxy =dynamic_cast<Proxy*>(serv);
00065 assert(proxy);
00066 try
00067 {
00068 proxy->reincarnate(**iter);
00069 }
00070 catch(CORBA::BAD_PARAM& ex)
00071 {
00072
00073 DB(1,"Failed to reincarnate proxy: "<<(*iter)->getKey());
00074 _servants.erase(proxy);
00075 delete proxy;
00076 }
00077 }
00078 }
00079
00080
00081 void ProxyManager::output(ostream& os)
00082 {
00083 for(set<Proxy*>::iterator i =_servants.begin(); i!=_servants.end(); ++i)
00084 {
00085 (*i)->output(os);
00086 }
00087 }
00088
00089
00090 ProxyManager::ProxyManager(PortableServer::POA_ptr p, const char* name)
00091 : Servant(p),
00092 _servants(),
00093 _managedPoa(PortableServer::POA::_nil())
00094 {
00095 using namespace PortableServer;
00096 try
00097 {
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 CORBA::PolicyList policies;
00108 policies.length(5);
00109 policies[0]=p->create_lifespan_policy(PERSISTENT);
00110 policies[1]=p->create_id_assignment_policy(USER_ID);
00111 policies[2]=p->create_implicit_activation_policy(NO_IMPLICIT_ACTIVATION);
00112 policies[3]=p->create_request_processing_policy(USE_SERVANT_MANAGER);
00113 policies[4]=p->create_thread_policy(SINGLE_THREAD_MODEL);
00114
00115
00116 CORBA::String_var parentName =p->the_name();
00117 string poaName =string(parentName.in())+"."+name;
00118 POAManager_var parentManager =p->the_POAManager();
00119 _managedPoa=p->create_POA(poaName.c_str(),parentManager.in(),policies);
00120 }
00121 catch(POA::AdapterAlreadyExists& ex)
00122 {
00123 cerr<<"POA::AdapterAlreadyExists"<<endl;
00124 }
00125 catch(POA::InvalidPolicy& ex)
00126 {
00127 cerr<<"POA::InvalidPolicy: "<<ex.index<<endl;
00128 }
00129 string oidStr =string(name)+"Manager";
00130 activateObjectWithId(oidStr.c_str());
00131 _managedPoa->set_servant_manager(_this());
00132 }
00133
00134
00135 ProxyManager::~ProxyManager()
00136 {
00137
00138 }
00139
00140
00141
00142
00143
00144
00145
00146 Proxy::~Proxy()
00147 {
00148 if(!CORBA::is_nil(_req))
00149 {
00150 Orb::inst().orphanRequest(_req._retn());
00151 _req=CORBA::Request::_nil();
00152 }
00153 }
00154
00155 bool Proxy::gotException()
00156 {
00157 CORBA::Environment_var env=_req->env();
00158 if(!CORBA::is_nil(env) && env->exception())
00159 {
00160 CORBA::Exception* ex =env->exception();
00161 DB(1,"Proxy got exception: "<<ex->_name()
00162 <<" while calling "<<_req->operation()<<"().");
00163 _req=CORBA::Request::_nil();
00164 deactivateObject();
00165 return true;
00166 }
00167 return false;
00168 }
00169
00170 Proxy::Proxy(PortableServer::POA_ptr poa)
00171 : Servant(poa),
00172 _req(CORBA::Request::_nil())
00173 {
00174
00175 }
00176
00177
00178 };