PortableServer::POA_ptr createPOA (PortableServer::POA_ptr root_poa, bool share_mgr, const char* poa_name) { PortableServer::LifespanPolicy_var life = root_poa->create_lifespan_policy(PortableServer::PERSISTENT); PortableServer::IdAssignmentPolicy_var assign = root_poa->create_id_assignment_policy(PortableServer::USER_ID); CORBA::PolicyList pols; pols.length(2); pols[0] = PortableServer::LifespanPolicy::_duplicate(life.in()); pols[1] = PortableServer::IdAssignmentPolicy::_duplicate(assign.in()); PortableServer::POAManager_var mgr = PortableServer::POAManager::_nil(); if (share_mgr) { mgr = root_poa->the_POAManager(); } PortableServer::POA_var poa = root_poa->create_POA(poa_name, mgr.in(), pols); life->destroy(); assign->destroy(); return poa._retn(); }
PortableServer::POA_ptr VOmniORBHelper::poaGetOrCreatePoa(const char* program, const char* object, int telescopenumber) throw(CORBA::SystemException) { ZThread::Guard<ZThread::RecursiveMutex> guard(m_mutex); // Munge the path name into a unique POA name char* poa_name = poaPathToPoaName(program, object, telescopenumber); // Check to see if we created this one already, if so then return it now std::map<std::string,PortableServer::POA_var>::iterator poaFound = m_poaMap.find(poa_name); if(poaFound != m_poaMap.end()) return PortableServer::POA::_duplicate(poaFound->second); // Grab the root POA PortableServer::POA_var root_poa = poaRootPoa(); // Must create the POA, use the PERSISTENT and USER_ID policies PortableServer::LifespanPolicy_var lifespan = root_poa -> create_lifespan_policy(PortableServer::PERSISTENT); PortableServer::IdAssignmentPolicy_var assign = root_poa -> create_id_assignment_policy(PortableServer::USER_ID); CORBA::PolicyList policy_list; policy_list.length(2); policy_list[0] = PortableServer::LifespanPolicy::_duplicate(lifespan); policy_list[1] = PortableServer::IdAssignmentPolicy::_duplicate(assign); // Root POA manager PortableServer::POAManager_var root_poa_manager = PortableServer::POAManager::_duplicate(m_rootPoaManager); // Create the POA PortableServer::POA_var poa = root_poa -> create_POA(poa_name, root_poa_manager, policy_list); // Make a copy of the POA object and remember it in case we are asked // for it again some time m_poaMap[poa_name] = PortableServer::POA::_duplicate(poa); CORBA::string_free(poa_name); lifespan->destroy(); assign->destroy(); return poa._retn(); }
int TAO_CosEventChannelFactory_i::init (PortableServer::POA_ptr poa, const char* child_poa_name, CosNaming::NamingContext_ptr naming) { // Check if we have a parent poa. if (CORBA::is_nil (poa)) return -1; this->naming_ = CosNaming::NamingContext::_duplicate (naming); // Save the naming context. // Create a UNIQUE_ID and USER_ID policy because we want the POA // to detect duplicates for us. PortableServer::IdUniquenessPolicy_var idpolicy = poa->create_id_uniqueness_policy (PortableServer::UNIQUE_ID); PortableServer::IdAssignmentPolicy_var assignpolicy = poa->create_id_assignment_policy (PortableServer::USER_ID); // Create a PolicyList CORBA::PolicyList policy_list; policy_list.length (2); policy_list [0] = PortableServer::IdUniquenessPolicy::_duplicate (idpolicy.in ()); policy_list [1] = PortableServer::IdAssignmentPolicy::_duplicate (assignpolicy.in ()); PortableServer::POAManager_ptr manager = poa->the_POAManager (); // @@ Pradeep : TODO - find a way to destroy the policy_list if we return here. // Create the child POA. this->poa_ = poa->create_POA (child_poa_name, manager, policy_list); idpolicy->destroy (); assignpolicy->destroy (); //this->poa_ = PortableServer::POA::_duplicate (poa); // uncomment this if we want to use the parent poa for some reason. return 0; }
int main(int argc, char* argv[]){ char aux1[1000]; try{ // // Inicializacion del ORB // CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, ""); CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj); PortableServer::POAManager_var manager = root_poa->the_POAManager(); // // Obtain NamincContext reference ... // CORBA::Object_var naming_context_object; CosNaming::NamingContext_ptr naming_context; try { naming_context_object = orb->string_to_object("corbaloc:iiop:[email protected]:2809/NameService"); naming_context = CosNaming::NamingContext::_narrow (naming_context_object.in ()); } catch (...) { cerr << "Error: cannot obtain naming service initial reference" << endl; throw; } // // Crea un POA para el supplier: PERSISTENT LifespanPolicy, USER_ID policy // PortableServer::LifespanPolicy_var lifespan = root_poa->create_lifespan_policy(PortableServer::PERSISTENT); PortableServer::IdAssignmentPolicy_var idAssignment = root_poa->create_id_assignment_policy(PortableServer::USER_ID); CORBA::PolicyList policies(2); policies.length(2); policies[0] = PortableServer::IdAssignmentPolicy::_duplicate(idAssignment); policies[1] = PortableServer::LifespanPolicy::_duplicate(lifespan); PortableServer::POA_var consumer_poa = root_poa->create_POA("consumerPOA", manager.in(), policies); PortableServer::POAManager_var consumer_poa_manager = consumer_poa->the_POAManager(); idAssignment->destroy(); lifespan->destroy(); // Activa el POAManager manager->activate(); // // Crea y activa el servant del consumer // PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId("MyConsumer"); MyConsumerImpl servant_consumer; try{ consumer_poa->activate_object_with_id(oid.in(), &servant_consumer); } catch(...){ cerr << "[supplier] ERROR: activating servant_supplier " << endl; } CORBA::Object_var consumer_obj = consumer_poa->id_to_reference(oid.in()); CosEventComm::PushConsumer_var consumer = CosEventComm::PushConsumer::_narrow(consumer_obj); // // Recoge la referencia al canal // // readChannelIOR(); // obj = orb->string_to_object(ChannelIOR); CosNaming::NamingContext_var naming_context_notif = NULL; CosNaming::Name name_notif(2); name_notif.length (2); name_notif[0].id = CORBA::string_dup ("MyNotif"); name_notif[0].kind = CORBA::string_dup (""); name_notif[1].id = CORBA::string_dup ("channel"); name_notif[1].kind = CORBA::string_dup (""); obj = naming_context->resolve(name_notif); CosNotifyChannelAdmin::EventChannel_var channel; channel = CosNotifyChannelAdmin::EventChannel::_narrow(obj); if (CORBA::is_nil(channel)) { cerr << "[consumer] ERROR: canal nulo " << endl; return -1; } // cerr << "[consumer] ChannelId " << channel->get_channelID() << endl; // // Obtenemos el manager // CosNotifyChannelAdmin::ConsumerAdmin_var consumerAdmin; CosNotifyChannelAdmin::AdminID adminid; try{ consumerAdmin = channel->default_consumer_admin(); } catch(CORBA::Exception &ce){ fprintf(stderr,"(%s)%i CORBA::Exception - %s\n", __FILE__,__LINE__,ce._name()); } catch(...){ fprintf(stderr,"(%s)%i - Unexpected exception!", __FILE__,__LINE__); } // // Obtenemos el proxy // CosNotifyChannelAdmin::ProxyPushSupplier_var pushSupplier; CosNotifyChannelAdmin::ProxyID proxy_id; CosNotifyChannelAdmin::ClientType ctype = CosNotifyChannelAdmin::ANY_EVENT; try{ CosNotifyChannelAdmin::ProxySupplier_var obj = consumerAdmin->obtain_notification_push_supplier(ctype, proxy_id); pushSupplier = CosNotifyChannelAdmin::ProxyPushSupplier::_narrow(obj); // Conecta proxy pushSupplier->connect_any_push_consumer(consumer); } catch(CosEventChannelAdmin::AlreadyConnected &ac){ fprintf(stderr,"(%s)%i CosEventChannelAdmin::AlreadyConnected\n", __FILE__,__LINE__); } catch(CORBA::SystemException& se){ fprintf(stderr,"(%s)%i CORBA::SystemException\n", __FILE__,__LINE__); } catch(CosNotifyChannelAdmin::AdminLimitExceeded err){ fprintf(stderr,"(%s)%i CosNotifyChannelAdmin::AdminLimitExceeded\n", __FILE__,__LINE__); } catch(CORBA::Exception &ce){ fprintf(stderr,"(%s)%i CORBA::Exception - %s\n", __FILE__,__LINE__,ce._name()); } catch(...){ fprintf(stderr,"Unexpected exception!\n"); } // // // // Guarda la referencia en el Servicio de Nombres // // // CosNaming::NamingContext_var naming_context_notif = NULL; // CosNaming::Name name_notif(1); // name_notif.length (1); // name_notif[0].id = CORBA::string_dup ("MyNotif"); // name_notif[0].kind = CORBA::string_dup (""); // naming_context_notif = naming_context->bind_new_context(name_notif); // CosNaming::Name name_consumer(1); // name_consumer.length (1); // name_consumer[0].id = CORBA::string_dup ("consumer"); // name_consumer[0].kind = CORBA::string_dup (""); // naming_context_notif->bind(name_consumer, consumer_obj); cerr << "[consumer] Esperando eventos.... " << endl; orb->run(); cerr << "[consumer] disconnect .... " << endl; // supplier->disconnect_push_supplier(); // consumeradmin->destroy(); cerr << "[consumer] Terminando " << endl; orb->shutdown(true); orb->destroy(); } catch(CORBA::Exception& exc) { cerr << "[consumer] Excepcion: " << exc << endl; return 1; } }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var poa_object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); if (CORBA::is_nil (root_poa.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); PortableServer::LifespanPolicy_var life = root_poa->create_lifespan_policy (PortableServer::PERSISTENT); PortableServer::IdAssignmentPolicy_var assign = root_poa->create_id_assignment_policy (PortableServer::USER_ID); CORBA::PolicyList pols; pols.length (2); pols[0] = PortableServer::LifespanPolicy::_duplicate (life.in ()); pols[1] = PortableServer::IdAssignmentPolicy::_duplicate (assign.in ()); PortableServer::POA_var poa = root_poa->create_POA ("ImRified POA", poa_manager.in (), pols); life->destroy (); assign->destroy (); Hello *hello_impl = 0; ACE_NEW_RETURN (hello_impl, Hello, 1); PortableServer::ServantBase_var owner_transfer (hello_impl); PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId ("Test 3891 Object"); poa->activate_object_with_id (id.in (), hello_impl); CORBA::Object_var obj = poa->id_to_reference (id.in ()); if (!obj->_stubobj ()->type_id.in () || ACE_OS::strcmp (obj->_stubobj ()->type_id.in (), hello_impl->_repository_id ())) { ACE_ERROR_RETURN ((LM_ERROR, "ERROR: type_id is incorrect\n"), 1); } root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
RtecEventChannelAdmin::EventChannel_ptr FTEC_Gateway::activate(PortableServer::POA_ptr root_poa) { PortableServer::POA_var poa; PortableServer::POAManager_var mgr; if (impl_->local_orb) { int argc = 0; char** argv = 0; impl_->orb = CORBA::ORB_init(argc, argv, "FTEC_GatewayORB"); Interceptor_Destoryer::execute(impl_->orb.in()); poa = resolve_init<PortableServer::POA>(impl_->orb.in(), "RootPOA"); mgr = poa->the_POAManager(); mgr->activate(); } else { poa = PortableServer::POA::_duplicate(root_poa); mgr = poa->the_POAManager(); } PortableServer::IdUniquenessPolicy_var id_uniqueness_policy = poa->create_id_uniqueness_policy(PortableServer::MULTIPLE_ID); PortableServer::LifespanPolicy_var lifespan = poa->create_lifespan_policy(PortableServer::PERSISTENT); // create a USER_ID IdAssignmentPolicy object PortableServer::IdAssignmentPolicy_var assign = poa->create_id_assignment_policy(PortableServer::USER_ID); CORBA::PolicyList policy_list; policy_list.length(3); policy_list[0] = PortableServer::IdUniquenessPolicy::_duplicate( id_uniqueness_policy.in()); policy_list[1]= PortableServer::LifespanPolicy::_duplicate(lifespan.in()); policy_list[2]= PortableServer::IdAssignmentPolicy::_duplicate(assign.in()); impl_->poa = poa->create_POA("gateway_poa", mgr.in(), policy_list); id_uniqueness_policy->destroy(); lifespan->destroy(); assign->destroy(); FtRtecEventComm::ObjectId oid; oid.length(16); TAO_FtRt::UUID::create(oid.get_buffer()); RtecEventChannelAdmin::EventChannel_var gateway; activate_object_with_id(gateway.out(), impl_->poa.in(), this, oid); ++oid[9]; activate_object_with_id(impl_->consumer_admin.out(), impl_->poa.in(), &impl_->consumer_admin_servant, oid); ++oid[9]; activate_object_with_id(impl_->supplier_admin.out(), impl_->poa.in(), &impl_->supplier_admin_servant, oid); return gateway._retn(); }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // Initialze the ORB. CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); // Get a reference to the RootPOA. CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); // Get the POA_var object from Object_var. PortableServer::POA_var root_poa = PortableServer::POA::_narrow (obj.in ()); // Get the POAManager of the RootPOA. PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); poa_manager->activate (); // Create a USER_ID IdAssignmentpolicy object. PortableServer::IdAssignmentPolicy_var idassignment = root_poa->create_id_assignment_policy (PortableServer::USER_ID); // Create a PERSISTENT LifespanPolicy object. PortableServer::LifespanPolicy_var lifespan = root_poa->create_lifespan_policy (PortableServer::PERSISTENT); // Policies for the childPOA to be created. CORBA::PolicyList policies; policies.length (2); policies[0] = PortableServer::IdAssignmentPolicy::_duplicate (idassignment.in ()); policies[1] = PortableServer::LifespanPolicy::_duplicate (lifespan.in ()); // Create the childPOA under the RootPOA. PortableServer::POA_var child_poa = root_poa->create_POA ("childPOA", poa_manager.in (), policies); // Destroy policy objects. idassignment->destroy (); lifespan->destroy (); // Create an instance of class Quoter_Stock_Factory_i. Quoter_Stock_Factory_i stock_factory_i; // Get the Object ID. PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId ("Stock_Factory"); // Activate the Stock_Factory object. child_poa->activate_object_with_id (oid.in (), &stock_factory_i); // Get the object reference. CORBA::Object_var stock_factory = child_poa->id_to_reference (oid.in ()); // Stringify all the object referencs. CORBA::String_var ior = orb->object_to_string (stock_factory.in ()); // Print them out ! cout << ior.in () << endl; orb-> run (); // Destroy POA, waiting until the destruction terminates. root_poa->destroy (1, 1); orb->destroy (); } catch (CORBA::Exception &) { cerr << "CORBA exception raised !" << endl; } return 0; }