//------------------------------------------------------------------------------ namespace { //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // this is part of the workaround that will force omniORB to delete our servants // in the main thread (to address memory footprint issues) class MtsServantManager_ : public POA_PortableServer::ServantActivator { public: // implicit ctor, cctor, dtor & op= are ok // overrides virtual PortableServer::Servant incarnate(PortableServer::ObjectId const& oid, PortableServer::POA_ptr adapter) { // someone tries to send a request to long dead object throw CORBA::OBJECT_NOT_EXIST(omni::OBJECT_NOT_EXIST_NoMatch); } virtual void etherealize(PortableServer::ObjectId const& oid, PortableServer::POA_ptr adapter, PortableServer::Servant serv, CORBA::Boolean cleanup_in_progress, CORBA::Boolean remaining_activations) { // 'release' servant if POA does not hold it in ActiveObject table anymore if (!remaining_activations) serv->_remove_ref(); } }; //------------------------------------------------------------------------------ } // unnamed namespace //------------------------------------------------------------------------------ CORBA::ORB_var Utils2::m_orb; PortableServer::POA_var Utils2::m_defaultPOA; CORBA::ORB_ptr Utils2::orb_init(int& argc, char** argv) { using namespace CORBA; using namespace PortableServer; m_orb = ORB_init( argc, argv ); // init RootPOA also: Object_var obj = m_orb->resolve_initial_references("RootPOA"); POA_var rootPOA = POA::_narrow(obj); // create one more poa with different policy list // NO_IMPLICIT_ACTIVATION is used by efault, but we'll specify it anyway // PolicyList pl; pl.length(3); pl[0] = rootPOA->create_thread_policy(MAIN_THREAD_MODEL); pl[1] = rootPOA->create_implicit_activation_policy(NO_IMPLICIT_ACTIVATION); pl[2] = rootPOA->create_request_processing_policy(USE_SERVANT_MANAGER); m_defaultPOA = rootPOA->create_POA("GenericPOA", POAManager::_nil(), pl); /* all omniORB examples omit this. Also, it is not C++-ish anyway, since create_POA() could throw and these 'cleanup' steps won't be executed pl[0]->destroy(); pl[1]->destroy(); pl[2]->destroy(); */ // register our servant manager (he will ensure all objects are delete'd in the main thread) Servant_var pManagerServant( new MtsServantManager_() ); ObjectId_var srvman_id = m_defaultPOA->activate_object(pManagerServant); Object_var pObjectRef = m_defaultPOA->id_to_reference(srvman_id); // make sure we use properly activated reference ServantManager_var pSrvManRef = ServantManager::_narrow(pObjectRef); m_defaultPOA->set_servant_manager(pSrvManRef); // activate POA manager POAManager_var pman = rootPOA->the_POAManager(); pman->activate(); pman = m_defaultPOA->the_POAManager(); pman->activate(); return m_orb; }