void TAO_Notify_POA_Helper::create_i ( PortableServer::POA_ptr parent_poa, const char* poa_name, CORBA::PolicyList &policy_list) { PortableServer::POAManager_var manager = parent_poa->the_POAManager (); // Create the child POA. this->poa_ = parent_poa->create_POA (poa_name, manager.in (), policy_list); if (DEBUG_LEVEL > 0) { CORBA::String_var the_name = this->poa_->the_name (); ORBSVCS_DEBUG ((LM_DEBUG, "Created POA : %C\n", the_name.in ())); } /* // Destroy the policies for (CORBA::ULong index = 0; index < policy_list.length (); ++index) { policy_list[index]->destroy (); } */ }
TAO_BEGIN_VERSIONED_NAMESPACE_DECL PortableServer::POA_var create_persistent_poa(PortableServer::POA_var root_poa, PortableServer::POAManager_var mgr, const char* name, CORBA::PolicyList& policy_list) { PortableServer::POA_var result; PortableServer::LifespanPolicy_var lifespan = root_poa->create_lifespan_policy(PortableServer::PERSISTENT); // create a USER_ID IdAssignmentPolicy object PortableServer::IdAssignmentPolicy_var assign = root_poa->create_id_assignment_policy(PortableServer::USER_ID); // create PolicyList. size_t orig_len = policy_list.length(); policy_list.length(orig_len+2); policy_list[orig_len+0]= PortableServer::LifespanPolicy::_duplicate(lifespan.in()); policy_list[orig_len+1]= PortableServer::IdAssignmentPolicy::_duplicate(assign.in()); // create the child POA result = root_poa->create_POA(name, mgr.in(), policy_list); return result; }
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(); }
void createPOAs(ACE_CString &base) { 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(); ACE_CString poa_name = base + ACE_CString ("_a"); poa_a = root_poa->create_POA(poa_name.c_str(), mgr.in(), pols); poa_name = base + ACE_CString ("_b"); poa_b = root_poa->create_POA(poa_name.c_str(), mgr.in(), pols); }
PortableServer::POA_var MACIContainerServices::createOffShootPOA() { // Check if the POA was already created if (!CORBA::is_nil(m_offShootPOA.ptr())) { return m_offShootPOA; } // get the container POA PortableServer::POA_var containerPOA = m_poa; try{ m_offShootPOA = containerPOA->find_POA("OffShootPOA", false); return m_offShootPOA; }catch(CORBA::Exception &ex){ //if does not exist we just continue and create a new one } // get the POA Manager PortableServer::POAManager_var poaManager = m_poa->the_POAManager(); // // Prepare policies OffShoot POA will be using. // PortableServer::IdAssignmentPolicy_var offshoot_system_id_policy = containerPOA->create_id_assignment_policy(PortableServer::SYSTEM_ID); PortableServer::LifespanPolicy_var offshoot_transient_policy = containerPOA->create_lifespan_policy(PortableServer::TRANSIENT); PortableServer::RequestProcessingPolicy_var offshoot_use_active_object_map_only_policy = containerPOA->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY); PortableServer::ServantRetentionPolicy_var offshoot_servant_retention_policy = containerPOA->create_servant_retention_policy (PortableServer::RETAIN); CORBA::PolicyList policiesOffShoot; policiesOffShoot.length(4); policiesOffShoot[0] = PortableServer::LifespanPolicy::_duplicate(offshoot_transient_policy.in()); policiesOffShoot[1] = PortableServer::IdAssignmentPolicy::_duplicate(offshoot_system_id_policy.in()); policiesOffShoot[2] = PortableServer::ServantRetentionPolicy::_duplicate(offshoot_servant_retention_policy.in()); policiesOffShoot[3] = PortableServer::RequestProcessingPolicy::_duplicate(offshoot_use_active_object_map_only_policy.in()); m_offShootPOA = containerPOA->create_POA("OffShootPOA",poaManager.in(),policiesOffShoot); return m_offShootPOA; }
void DAnCE_NodeManager_Module::create_poas (void) { DANCE_TRACE("DAnCE_NodeManager_Module::create_poas"); // Get reference to Root POA. DANCE_TRACE_LOG (DANCE_LOG_DETAILED_TRACE, (LM_TRACE, DLINFO ACE_TEXT ("DAnCE_NodeManager_Module::create_poas - ") ACE_TEXT ("Resolving root POA\n"))); CORBA::Object_var obj = this->orb_->resolve_initial_references ("RootPOA"); this->root_poa_ = PortableServer::POA::_narrow (obj.in ()); DANCE_TRACE_LOG (DANCE_LOG_DETAILED_TRACE, (LM_TRACE, DLINFO ACE_TEXT ("DAnCE_NodeManager_Module::create_poas - ") ACE_TEXT ("Obtaining the POAManager\n"))); PortableServer::POAManager_var mgr = this->root_poa_->the_POAManager (); TAO::Utils::PolicyList_Destroyer policies (2); policies.length (2); try { DANCE_TRACE_LOG (DANCE_LOG_TRACE, (LM_TRACE, DLINFO ACE_TEXT ("DAnCE_NodeManager_Module::create_poas - ") ACE_TEXT ("DAnCE_NodeManager_Module::create_poas - ") ACE_TEXT ("Creating the \"Managers\" POA.\n"))); policies[0] = this->root_poa_->create_id_assignment_policy (PortableServer::USER_ID); policies[1] = this->root_poa_->create_lifespan_policy (PortableServer::PERSISTENT); this->nm_poa_ = this->root_poa_->create_POA ("Managers", mgr.in(), policies); } catch (const PortableServer::POA::AdapterAlreadyExists &) { DANCE_TRACE_LOG (DANCE_LOG_TRACE, (LM_INFO, DLINFO ACE_TEXT ("DAnCE_NodeManager_Module::create_poas - ") ACE_TEXT ("Using existing \"Managers\" POA\n"))); this->nm_poa_ = this->root_poa_->find_POA ("Managers", 0); } }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { CORBA::ORB_var orb; try { orb = CORBA::ORB_init (argc, argv); CORBA::Object_var root_poa_o = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var rootPOA = PortableServer::POA::_narrow (root_poa_o.in ()); if (CORBA::is_nil (rootPOA.in ())) { ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); } PortableServer::POAManager_var poaMgr = rootPOA->the_POAManager (); poaMgr->activate (); CORBA::PolicyList policies; policies.length (3); policies[0] = rootPOA->create_id_assignment_policy ( PortableServer::SYSTEM_ID); policies[1] = rootPOA->create_implicit_activation_policy ( PortableServer::NO_IMPLICIT_ACTIVATION); policies[2] = rootPOA->create_lifespan_policy ( PortableServer::TRANSIENT); PortableServer::POA_var fooPoa = rootPOA->create_POA ( "FOO_POA", poaMgr.in (), policies ); for (CORBA::ULong i = 0; i < policies.length (); ++i) { policies[i]->destroy (); } Foo_i servant; PortableServer::ObjectId_var oid = fooPoa->activate_object( &servant ); CORBA::Object_var obj = fooPoa->id_to_reference (oid.in ()); foo_var client = foo::_narrow (obj.in()); client->check(); if (vc_check(client.in())) { orb->destroy(); return 1; } fooPoa->deactivate_object (oid.in () ); //servant is gone if (vc_check(client.in(), false)) //exception expected { orb->destroy(); return 2; } } catch(...) { return 3; } return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // Initialize orb CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); // Get reference to Root POA. CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var rootpoa = PortableServer::POA::_narrow (obj.in ()); // Activate POA manager PortableServer::POAManager_var mgr = rootpoa->the_POAManager (); mgr->activate (); PortableServer::POA_var poa; TAO::Utils::PolicyList_Destroyer PolicyList (3); PolicyList.length (3); PolicyList [0] = rootpoa->create_lifespan_policy (PortableServer::PERSISTENT); PolicyList [1] = rootpoa->create_id_assignment_policy (PortableServer::USER_ID); CORBA::Any CallbackPolicy; CallbackPolicy <<= BiDirPolicy::BOTH; const char* sServerPoaName = "TelemetryServer"; PolicyList [2] = orb->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE, CallbackPolicy); poa = rootpoa->create_POA (sServerPoaName, mgr.in(), PolicyList); PortableServer::ObjectId_var ServerId = PortableServer::string_to_ObjectId ("TimeServer"); // Create an object Time_impl *time_servant = new Time_impl; PortableServer::ServantBase_var self_manage (time_servant); poa->activate_object_with_id (ServerId.in (), time_servant); // Get a reference after activating the object CORBA::Object_var object = poa->id_to_reference (ServerId.in ()); TimeModule::Time_var tm = TimeModule::Time::_narrow (object.in ()); // Get reference to initial naming context CORBA::Object_var name_obj = orb->resolve_initial_references ("NameService"); CosNaming::NamingContext_var inc = CosNaming::NamingContext::_narrow (name_obj.in ()); if (CORBA::is_nil (inc.in ())) { ACE_ERROR ((LM_ERROR, "(%P|%t) Error fetching naming context\n")); } CosNaming::Name service_name; service_name.length(1); service_name[0].id = CORBA::string_dup ("Time"); inc->rebind (service_name, tm.in ()); // Run the event loop for fun ACE_Time_Value tv (3, 0); // Accept requests orb->run (&tv); rootpoa->destroy (0 , 0); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Caught an exception\n"); return -1; } return 0; }
int main( int argc, char *argv[] ) { try { // Initialize orb CORBA::ORB_var orb = CORBA::ORB_init( argc, argv ); // Destringify ior CORBA::Object_var obj = orb->string_to_object( "file://IOR" ); if( CORBA::is_nil( obj.in() ) ) { cerr << "Nil reference" << endl; throw 0; } // Narrow CallbackServer_var cb_server = CallbackServer::_narrow( obj.in() ); if( CORBA::is_nil( cb_server.in() ) ) { cerr << "Argument is not a CallbackServer reference" << endl; throw 0; } //Get reference to Root POA obj = orb->resolve_initial_references( "RootPOA" ); PortableServer::POA_var poa = PortableServer::POA::_narrow( obj.in() ); // Policies for the childPOA to be created. CORBA::PolicyList policies (4); policies.length (4); CORBA::Any pol; pol <<= BiDirPolicy::BOTH; policies[0] = orb->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE, pol); policies[1] = poa->create_id_assignment_policy(PortableServer::SYSTEM_ID); policies[2] = poa->create_implicit_activation_policy( PortableServer::IMPLICIT_ACTIVATION ); policies[3] = poa->create_lifespan_policy(PortableServer::TRANSIENT); PortableServer::POAManager_var mgr = poa->the_POAManager(); // Create POA as child of RootPOA with the above policies. This POA // will receive request in the same connection in which it sent // the request PortableServer::POA_var child_poa = poa->create_POA ("childPOA", mgr.in(), policies); // Creation of childPOA is over. Destroy the Policy objects. for (CORBA::ULong i = 0; i < policies.length (); ++i) { policies[i]->destroy (); } // Activate POA Manager mgr->activate(); // Create an object ClientCallback_i servant; // Register the servant with the RootPOA, obtain its object // reference, stringify it, and write it to a file. obj = child_poa->servant_to_reference( &servant ); //ClientCallback_var ccb = ClientCallback::_narrow( obj.in() ); cb_server->callback_hello( ClientCallback::_narrow( obj.in() ), CORBA::string_dup( "Greetings earthling" )); } catch( const CORBA::Exception &ex ) { cerr << "Uncaught CORBA exception: " << ex << endl; return 1; } }
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[]) { DANCE_DISABLE_TRACE (); int retval = 0; try { DAnCE::Logger_Service * dlf = ACE_Dynamic_Service<DAnCE::Logger_Service>::instance ("DAnCE_Logger"); if (dlf) { dlf->init (argc, argv); } DANCE_TRACE_LOG (DANCE_LOG_TRACE, (LM_TRACE, DLINFO ACE_TEXT("PL_Daemon - initializing ORB\n"))); CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); DANCE_TRACE_LOG (DANCE_LOG_TRACE, (LM_TRACE, DLINFO ACE_TEXT("PL_Daemon - initializing module instance\n"))); TAO::Utils::ORB_Destroyer safe_orb (orb); CORBA::Object_var poa_obj = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_obj.in ()); PortableServer::POAManager_var mgr = poa->the_POAManager (); PortableServer::POA_var persistent_poa; TAO::Utils::PolicyList_Destroyer policies (2); policies.length (2); try { DANCE_TRACE_LOG (DANCE_LOG_TRACE, (LM_TRACE, DLINFO ACE_TEXT("PL_Daemon - ") ACE_TEXT("before creating the \"Managers\" POA.\n"))); policies[0] = poa->create_id_assignment_policy (PortableServer::USER_ID); policies[1] = poa->create_lifespan_policy (PortableServer::PERSISTENT); persistent_poa = poa->create_POA ("Managers", mgr.in(), policies); } catch (const PortableServer::POA::AdapterAlreadyExists &) { persistent_poa = poa->find_POA ("Managers", 0); } DAnCE::Plan_Launcher_Daemon_i *pl_daemon (0); ACE_NEW_RETURN (pl_daemon, DAnCE::Plan_Launcher_Daemon_i (orb.in ()), 0); PortableServer::ServantBase_var safe_servant (pl_daemon); PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId ("Plan_Launcher_Daemon"); persistent_poa->activate_object_with_id (oid, pl_daemon); CORBA::Object_var pl_obj = persistent_poa->id_to_reference (oid.in ()); CORBA::String_var pl_ior = orb->object_to_string (pl_obj.in ()); DAnCE::Utility::write_IOR (ACE_TEXT ("PL_Daemon.ior"), pl_ior.in ()); orb->run (); DANCE_TRACE_LOG (DANCE_LOG_TRACE, (LM_TRACE, DLINFO ACE_TEXT("PL_Daemon - destroying ORB\n"))); orb->destroy (); } catch (const CORBA::Exception& ex) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_EMERGENCY, DLINFO "PL_Daemon - Error - CORBA Exception :%C\n", ex._info ().c_str ())); retval = -1; } catch (...) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, "PL_Daemon - Error: Unknown exception.\n")); retval = -1; } return retval; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { // Initialize the ORB first. CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "POAManagerFactoryTest"); if (parse_args (argc, argv) != 0) return 1; // Obtain the RootPOA. CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); // Narrow to POA. PortableServer::POA_var root_poa = PortableServer::POA::_narrow (obj.in ()); if (verbose) ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Obtain PoaManagerFactory reference: "))); pretest = fail; // Obtain the POAManagerFactory. PortableServer::POAManagerFactory_var poa_manager_factory = root_poa->the_POAManagerFactory (); VERIFY_CONDITION (!CORBA::is_nil(poa_manager_factory.in())); if (verbose) ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"), (pretest == fail) ? ACE_TEXT ("passed") : ACE_TEXT ("failed"))); if (CORBA::is_nil(poa_manager_factory.in())) return 1; CORBA::PolicyList policies (0); policies.length (0); if (verbose) ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Create a POAManager: "))); pretest = fail; // Explicitly create a POAManager - "POAManager1" . PortableServer::POAManager_var poa_manager_1 = poa_manager_factory->create_POAManager ("POAManager1", policies); VERIFY_CONDITION (!CORBA::is_nil(poa_manager_1.in())); if (verbose) ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"), (pretest == fail) ? ACE_TEXT ("passed") : ACE_TEXT ("failed"))); if (CORBA::is_nil(poa_manager_1.in())) return 1; // Creating a POAManager with an exiting POAManager name raises exception. if (verbose) ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Prevent duplicated POAManagers: "))); pretest = fail; CORBA::Boolean got_expected_exception = false; try { PortableServer::POAManager_var poa_manager = poa_manager_factory->create_POAManager ("POAManager1", policies); } catch (const PortableServer::POAManagerFactory::ManagerAlreadyExists& ) { got_expected_exception = true; } VERIFY_CONDITION (got_expected_exception); if (verbose) ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"), (pretest == fail) ? ACE_TEXT ("passed") : ACE_TEXT ("failed"))); if (! got_expected_exception) return 1; { if (verbose) ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Implicitly create a POAManagers: "))); pretest = fail; // Implicitly create a POAManager instance which has an automatically // assigned name. PortableServer::POA_var child_poa = root_poa->create_POA ("childPOA2", PortableServer::POAManager::_nil (), policies); PortableServer::POAManager_var poa_manager_2 = child_poa->the_POAManager (); VERIFY_CONDITION (!CORBA::is_nil(poa_manager_2.in())); if (verbose) ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"), (pretest == fail) ? ACE_TEXT ("passed") : ACE_TEXT ("failed"))); if (CORBA::is_nil(poa_manager_2.in())) return 1; CORBA::String_var poa_manager_2_name = poa_manager_2->get_id (); if (verbose) ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Implicitly created POAManager's ID: [%C]\n"), poa_manager_2_name.in())); if (ACE_OS::strlen(poa_manager_2_name.in()) == 0) return 1; if (verbose) ACE_DEBUG ((LM_DEBUG, ACE_TEXT("List POAManagers: "))); pretest = fail; PortableServer::POAManagerFactory::POAManagerSeq_var managers = poa_manager_factory->list (); VERIFY_CONDITION (managers->length () == 3); if (verbose) ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"), (pretest == fail) ? ACE_TEXT ("passed") : ACE_TEXT ("failed"))); PortableServer::POAManager_var root_poa_manager = root_poa->the_POAManager(); for (CORBA::ULong i = 0; i < managers->length(); ++i) { CORBA::String_var name = managers[i]->get_id (); if (verbose) ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Validate listed POAManager [%C]: "), name.in())); pretest = fail; const PortableServer::POAManager_ptr tmp_pm = managers[i]; if ((ACE_OS::strcmp (name.in (), "RootPOAManager") == 0 && tmp_pm == root_poa_manager.in ()) || (ACE_OS::strcmp (name.in (), "POAManager1") == 0 && tmp_pm == poa_manager_1.in ()) || (ACE_OS::strcmp (name.in (), poa_manager_2_name.in ()) == 0 && tmp_pm == poa_manager_2.in ())) { if (verbose) ACE_DEBUG ((LM_DEBUG, ACE_TEXT("passed\n"))); continue; } else { if (verbose) ACE_DEBUG ((LM_DEBUG, ACE_TEXT("failed\n"))); fail++; } } } { // Find a specific POAManager. if (verbose) ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Find a POAManager: "))); pretest = fail; PortableServer::POAManager_var manager = poa_manager_factory->find ("POAManager1"); CORBA::String_var name = manager->get_id (); VERIFY_CONDITION ((ACE_OS::strcmp (name.in (), "POAManager1") == 0 && manager.in () == poa_manager_1.in ())); if (verbose) ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"), (pretest == fail) ? ACE_TEXT ("passed") : ACE_TEXT ("failed"))); } // Create a child poa that associates with the explicitly // created POAManager. if (verbose) ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Create A POA with explicit POAManager: "))); pretest = fail; PortableServer::POA_var child_poa = root_poa->create_POA ("childPOA", poa_manager_1.in (), policies); poa_manager_1->activate (); root_poa->destroy (1, 1); orb->destroy (); if (verbose) ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("passed\n"))); } catch (const CORBA::Exception& ex) { fail++; if (verbose) ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("failed\n"))); ex._tao_print_exception ("Exception caught"); } ACE_DEBUG ((LM_DEBUG, ACE_TEXT("POAManagerFactory %s\n"), (pretest == fail) ? ACE_TEXT ("succeeded") : ACE_TEXT ("failed"))); 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(); }
//----------------------------------------------------------------------------- ORBHelper::ORBHelper() : threadManager_mp(0), orbRunYet_m(false) { //create a new ACE thread manager threadManager_mp = ACE_Thread_Manager::instance(); //CORBA naming service corbaloc ACE_CString nameService; //get NameService Reference nameService += acscommon::NAMING_SERVICE_NAME; nameService +="=corbaloc::"; nameService += ACSPorts::getIP(); nameService += ":"; nameService += ACSPorts::getNamingServicePort().c_str(); nameService += "/"; nameService += acscommon::NAMING_SERVICE_NAME; // initialize ORB int argc = 5; char* argv[] = { "", "-ORBInitRef", (char *)nameService.c_str(), "-ORBDottedDecimalAddresses", "1"}; //initialize the ORB orb_mp = CORBA::ORB_init(argc, argv, ""); //ensure it's a real reference ACE_ASSERT(!CORBA::is_nil(orb_mp)); //get the Root POA CORBA::Object_var poaObject = orb_mp->resolve_initial_references("RootPOA"); //ensure it's a real reference ACE_ASSERT(!CORBA::is_nil(poaObject.in())); //narrow the Root POA PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(poaObject.in()); //ensure it's a real reference ACE_ASSERT(!CORBA::is_nil(rootPOA.in())); //get the POA manager PortableServer::POAManager_var poaManager = rootPOA->the_POAManager(); //ensure it's a real reference ACE_ASSERT(!CORBA::is_nil(poaManager.in())); //finally activate the POA manager to start processing incoming and //outgoing calls poaManager->activate(); //spawn a separate thread to start the ORB in ACE_ASSERT(threadManager_mp!=0); threadManager_mp->spawn(ACE_THR_FUNC(ORBHelper::runOrbThread), static_cast<void *>(this)); //block until the ORB thread has really started! while(orbRunYet_m==false) { ACE_OS::sleep(1); } ACE_OS::sleep(1); }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { DANCE_DISABLE_TRACE (); int retval = 0; try { DAnCE::Logger_Service * dlf = ACE_Dynamic_Service<DAnCE::Logger_Service>::instance ("DAnCE_Logger"); if (dlf) { dlf->init (argc, argv); } DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE, DLINFO ACE_TEXT("SHS_Deamon - initializing ORB\n"))); CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE, DLINFO ACE_TEXT("SHS_Deamon - initializing module instance\n"))); TAO::Utils::ORB_Destroyer safe_orb (orb); CORBA::Object_var tmp = orb->resolve_initial_references ("NameService"); CosNaming::NamingContext_var domain_nc = CosNaming::NamingContext::_narrow (tmp); if (CORBA::is_nil (domain_nc.in ())) { ACE_ERROR ((LM_EMERGENCY, "SHS_Daemon - Unable to register with the"\ " CORBA Naming Service\n")); return -1; } CORBA::Object_var poa_obj = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_obj.in ()); PortableServer::POAManager_var mgr = poa->the_POAManager (); PortableServer::POA_var persistent_poa; TAO::Utils::PolicyList_Destroyer policies (2); policies.length (2); try { DANCE_DEBUG (DANCE_LOG_TRACE, (LM_TRACE, DLINFO ACE_TEXT("SHS_Deamon - ") ACE_TEXT("before creating the \"SHS\" POA.\n"))); policies[0] = poa->create_id_assignment_policy ( PortableServer::USER_ID); policies[1] = poa->create_lifespan_policy ( PortableServer::PERSISTENT); persistent_poa = poa->create_POA ("SHS", mgr.in(), policies); } catch (const PortableServer::POA::AdapterAlreadyExists &) { persistent_poa = poa->find_POA ("Managers", 0); } DAnCE::SHS_Daemon_i *shs_daemon (0); ACE_NEW_RETURN (shs_daemon, DAnCE::SHS_Daemon_i (orb.in ()), 0); PortableServer::ServantBase_var safe_servant (shs_daemon); PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId ("SHS_Daemon"); persistent_poa->activate_object_with_id (oid, shs_daemon); CORBA::Object_var shs_obj = persistent_poa->id_to_reference (oid.in ()); CORBA::String_var shs_ior = orb->object_to_string (shs_obj.in ()); DAnCE::Utility::write_IOR (ACE_TEXT ("SHS_Daemon.ior"), shs_ior.in ()); CosNaming::Name name (1); name.length (1); name[0].id = "DAnCE.SystemHealthDaemon"; domain_nc->rebind (name, shs_obj.in ()); mgr->activate (); orb->run (); DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE, DLINFO ACE_TEXT("SHS_Daemon - destroying ORB\n"))); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("SHS_Daemon"); retval = -1; } catch (...) { DANCE_ERROR (DANCE_LOG_TERMINAL_ERROR, (LM_ERROR, "SHS_Daemon - Error: Unknown exception.\n")); retval = -1; } return retval; }