Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

ProxyManager.cc

Go to the documentation of this file.
00001 //                            Package   : omniEvents
00002 // ProxyManager.cc            Created   : 2003/12/04
00003 //                            Author    : Alex Tingle
00004 //
00005 //    Copyright (C) 2003 Alex Tingle.
00006 //
00007 //    This file is part of the omniEvents application.
00008 //
00009 //    omniEvents is free software; you can redistribute it and/or
00010 //    modify it under the terms of the GNU Lesser General Public
00011 //    License as published by the Free Software Foundation; either
00012 //    version 2.1 of the License, or (at your option) any later version.
00013 //
00014 //    omniEvents is distributed in the hope that it will be useful,
00015 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 //    Lesser General Public License for more details.
00018 //
00019 //    You should have received a copy of the GNU Lesser General Public
00020 //    License along with this library; if not, write to the Free Software
00021 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 //  ProxyManager
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       // This will happen when (*iter)->getIor() fails to narrow.
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     // POLICIES:
00099     //  Lifespan          =PERSISTENT             // we can persist
00100     //  Assignment        =USER_ID                // write our own oid
00101     //  Uniqueness        =[default] UNIQUE_ID    // one servant per object
00102     //  ImplicitActivation=NO_IMPLICIT_ACTIVATION // disable auto activation
00103     //  RequestProcessing =USE_SERVANT_MANAGER
00104     //  ServantRetention  =[default] RETAIN
00105     //  Thread            =SINGLE_THREAD_MODEL    // keep it simple
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     // Create a POA for this proxy type in this channel.
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) // create_POA
00122   {
00123     cerr<<"POA::AdapterAlreadyExists"<<endl;
00124   }
00125   catch(POA::InvalidPolicy& ex) // create_POA
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   // pass
00138 }
00139 
00140 
00141 //
00142 // Proxy
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(); // No need to free 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   // pass
00175 }
00176 
00177 
00178 }; // end namespace OmniEvents

Generated on Fri Dec 12 10:53:02 2003 for OmniEvents by doxygen1.2.15