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_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 PersistentServantBase::create_user_persistent_POA(const char* POAname) { Object_var poaObj = orb_->resolve_initial_references("RootPOA"); PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(poaObj.in()); PortableServer::POAManager_var poaManager = rootPOA->the_POAManager(); poaManager->activate(); PolicyList policyList; policyList.length(2); policyList[0] = rootPOA->create_lifespan_policy(PortableServer::PERSISTENT); policyList[1] = rootPOA->create_id_assignment_policy(PortableServer::USER_ID); defaultPOA_ = rootPOA->create_POA( POAname, poaManager, policyList ); }
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); }
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 ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); if (parse_args (argc, argv) != 0) { return 1; } CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); ORB_Task worker (orb.in ()); worker.activate (THR_NEW_LWP | THR_JOINABLE, 1); PortableServer::POA_var rootPOA = PortableServer::POA::_narrow (object.in ()); PortableServer::POAManager_var poa_manager = rootPOA->the_POAManager (); CORBA::PolicyList policies (5); policies.length (5); // Lifespan policy policies[0] = rootPOA->create_lifespan_policy (PortableServer::PERSISTENT); // Servant Retention Policy policies[1] = rootPOA->create_servant_retention_policy (PortableServer::RETAIN ); // ID Assignment Policy policies[2] = rootPOA->create_id_assignment_policy (PortableServer::USER_ID ); // Request Processing Policy policies[3] = rootPOA->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY ); // Threading policy policies[4] = rootPOA->create_thread_policy (PortableServer::ORB_CTRL_MODEL); if (server_notify_delay > 0) { ACE_OS::sleep (server_notify_delay); ACE_DEBUG ((LM_DEBUG, "(%P|%t)ServerB Now register with IMR \n")); } PortableServer::POA_var poa_a = rootPOA->create_POA ("poaB", poa_manager.in (), policies ); for (CORBA::ULong i = 0; i < policies.length (); ++i) { CORBA::Policy_ptr policy = policies[i]; policy->destroy (); } Test_Dummy_i* dummy = new Test_Dummy_i(); PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId ("Server_B"); poa_a->activate_object_with_id (oid.in (), dummy); CORBA::Object_var dummy_obj = poa_a->id_to_reference(oid.in()); CORBA::String_var ior = orb->object_to_string (dummy_obj.in ()); poa_manager->activate (); // Output the IOR to the <ior_output_file> FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: %s", ior_output_file), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); worker.wait (); rootPOA->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception &ex) { ex._tao_print_exception ("Exception caught by serverB:"); 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 ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); if (parse_args (argc, argv) != 0) return 1; CORBA::Object_var poa_object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var rootPOA = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = rootPOA->the_POAManager (); // Policies for the firstPOA to be created. CORBA::PolicyList policies (5); policies.length (5); // Lifespan policy policies[0] = rootPOA->create_lifespan_policy (PortableServer::PERSISTENT ); // Servant Retention Policy policies[1] = rootPOA->create_servant_retention_policy (PortableServer::RETAIN ); // ID Assignment Policy policies[2] = rootPOA->create_id_assignment_policy (PortableServer::USER_ID ); // Request Processing Policy policies[3] = rootPOA->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY ); // Threading policy policies[4] = rootPOA->create_thread_policy (PortableServer::ORB_CTRL_MODEL ); PortableServer::POA_var demoPOA = rootPOA->create_POA ("HelloWorldServer", poa_manager.in (), policies ); for (CORBA::ULong i = 0; i < policies.length (); ++i) { CORBA::Policy_ptr policy = policies[i]; policy->destroy (); } // Create object for shutdown commanded by client. { // create the object Demo_HelloWorld_i * hello = new Demo_HelloWorld_i(orb.in()); // Get the Object ID. PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId ("shutdown"); demoPOA->activate_object_with_id (oid.in (), hello); // Create an object reference. CORBA::Object_var myhello = demoPOA->id_to_reference(oid.in()); // Put the object reference as an IOR string ofstream out(ACE_TEXT_ALWAYS_CHAR (shutdown_ior_output_file)); CORBA::String_var ior = orb->object_to_string (myhello.in ()); out << ior.in(); // save the reference into a file out.close(); } // Create object to handle client sayHello requests. { // create the object Demo_HelloWorld_i * hello = new Demo_HelloWorld_i(orb.in()); // Get the Object ID. PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId ("hello"); demoPOA->activate_object_with_id (oid.in (), hello); // Create an object reference. CORBA::Object_var myhello = demoPOA->id_to_reference(oid.in()); // Put the object reference as an IOR string ofstream out(ACE_TEXT_ALWAYS_CHAR (ior_output_file)); CORBA::String_var ior = orb->object_to_string (myhello.in ()); out << ior.in(); // save the reference into a file out.close(); } ////////////////////////////////////////////////////////////////////////////////////////////////// poa_manager->activate (); std::cout << ior_output_file << " is ready " << std::endl; orb->run (); // Destroy the POA, waiting until the destruction terminates rootPOA->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception &e) { std::cerr << "Unexpected exception: " << e << std::endl; return 1; } 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 poa = PortableServer::POA::_narrow (obj.in ()); // Get POA manager PortableServer::POAManager_var poa_mgr = poa->the_POAManager (); // Create a policy list. We use persistent objects with // user-assigned IDs, and explicit activation. CORBA::PolicyList policy_list; policy_list.length (3); policy_list[0] = poa->create_lifespan_policy ( PortableServer::TRANSIENT // REVISIT ); policy_list[1] = poa->create_id_assignment_policy ( PortableServer::USER_ID ); policy_list[2] = poa->create_implicit_activation_policy ( PortableServer::NO_IMPLICIT_ACTIVATION ); // Create a POA for the controller. PortableServer::POA_var ctrl_poa = poa->create_POA ("CtrlPOA", poa_mgr.in (), policy_list); policy_list.length (5); policy_list[3] = poa->create_request_processing_policy ( PortableServer::USE_SERVANT_MANAGER ); policy_list[4] = poa->create_servant_retention_policy ( PortableServer::NON_RETAIN ); // Create a POA for the devices. PortableServer::POA_var dev_poa = ctrl_poa->create_POA ("DevPOA", poa_mgr.in (), policy_list); // Create a controller and set static m_ctrl member // for thermostats and thermometers. Controller_impl ctrl_servant (dev_poa.in (), "/tmp/CCS_assets"); Thermometer_impl::m_ctrl = &ctrl_servant; obj = ctrl_servant._this (); // Write a reference for the controller to stdout. CORBA::String_var str = orb->object_to_string (obj.in ()); std::cout << str.in () << std::endl << std::endl; // Instantiate the servant locator for devices. PortableServer::ServantManager_var locator = new DeviceLocator_impl (&ctrl_servant); // Set servant locator. dev_poa->set_servant_manager (locator.in ()); // Activate the POA manager. poa_mgr->activate (); // Accept requests orb->run (); } catch (const CORBA::Exception & e) { std::cerr << "Uncaught CORBA exception: " << e << std::endl; return 1; } catch (...) { assert (0); // Uncaught exception, dump core } return 0; }
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; }
bool ServiceOptions::bindServiceObject(CORBA::ORB_ptr orb, CORBA::Object_ptr object, PortableServer::Servant p_servant, const char* objName, bool rebind) { if(is_set("with-naming")) { CosNaming::Name name; name.length(1); name[0].id=CORBA::string_dup(objName); name[0].kind=CORBA::string_dup(""); CORBA::Object_var obj ; try { obj = orb->resolve_initial_references("NameService"); }catch(const CORBA::ORB::InvalidName& ex){ std::cerr << argv()[0] << ": can't resolve `NameService'" << std::endl; return false; } CosNaming::NamingContext_var nc; try { nc = CosNaming::NamingContext::_narrow(obj.in()); }catch(const CORBA::SystemException& ex){ std::cerr << argv()[0] << ": can't narrow naming service" << std::endl; return false; } try { if(rebind){ nc->rebind(name,object); }else{ try{ nc->bind(name,object); }catch(const CosNaming::NamingContext::AlreadyBound&){ std::cerr<<argv()[0]<<":can't bind "<<objName<<" (AlreadyBound)"<< std::endl; return false; } } }catch(const CosNaming::NamingContext::CannotProceed&){ std::cerr<<argv()[0]<<": can't bind "<<objName<<" (CannotProceed)"<< std::endl; return false; }catch(const CosNaming::NamingContext::InvalidName&){ std::cerr<<argv()[0]<<":can't bind "<<objName<<" (InvalidName)"<< std::endl; return false; } std::cout<<argv()[0]<<": binding completed successfully"<<std::endl; } CORBA::String_var ior ; try { ior = orb->object_to_string(object); }catch(const CORBA::SystemException& ex){ #ifdef CORBA_SYSTEM_EXCEPTION_IS_STREAMBLE std::cerr << ex << std::endl; #else std::cerr << "CORBA::SystemException" << std::endl; #endif return false; } const char* fname = get_ior_fname(objName); if (fname!=NULL && strcmp(fname,"")!=0) { std::ofstream ofs (fname); if (ofs.bad()) { std::cerr << argv()[0] << ": can't open file " << fname << std::endl; perror(argv()[0]); return false; } ofs << ior.in(); ofs.close(); } if (is_set("ior-stdout")) { std::cout << ior << std::flush; } #ifdef ORBACUS CORBA::Object_var bmgrObj = orb->resolve_initial_references("BootManager"); OB::BootManager_var bootManager = OB::BootManager::_narrow(bmgrObj); PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId(objName); bootManager -> add_binding(oid.in(),object); #elif defined(OMNIORB) PortableServer::POA_var objPOA = p_servant->_default_POA(); CORBA::String_var objPOAName = objPOA->the_name(); if (strcmp(objPOAName.in(),"omniINSPOA")!=0) { CORBA::Object_var insPOAObj = orb->resolve_initial_references("omniINSPOA"); PortableServer::POA_var insPOA = PortableServer::POA::_narrow(insPOAObj); PortableServer::POAManager_var insPOAManager=insPOA->the_POAManager(); insPOAManager->activate(); PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId(objName); insPOA->activate_object_with_id(oid.in(),p_servant); } #elif defined(RSSH_TAO) #ifdef TAO_HAVE_IORTABLE_ADAPTER CORBA::Object_var table = orb->resolve_initial_references ("IORTable"); IORTable::Table_var adapter = IORTable::Table::_narrow (table.in()); if (CORBA::is_nil(adapter.in())) { cerr<<argv()[0]<<": nil IORTable reference"<<endl; } else { adapter->bind (objName, ior.in ()); } #else ACE_CString ins(objName); if (orb->_tao_add_to_IOR_table(ins,object)!=0) { return false; } #endif #elif defined(MICO) // create persistent POA with name as service name if we have no one. PortableServer::POA_var objPOA = p_servant->_default_POA(); CORBA::String_var objPOAName = objPOA->the_name(); std::cerr << "existent OBJPOAName=" << objPOAName.in() << std::endl; std::cerr << "objName=" << objName << std::endl; if (strcmp(objPOAName.in(),objName)!=0) { CORBA::Object_var rootPOAObj = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(rootPOAObj); CORBA::PolicyList pl; pl.length (2); pl[0] = rootPOA->create_lifespan_policy (PortableServer::PERSISTENT); pl[1] = rootPOA->create_id_assignment_policy (PortableServer::USER_ID); PortableServer::POA_var objPOA = rootPOA->create_POA(objName, PortableServer::POAManager::_nil (), pl); PortableServer::POAManager_var objPOAManager = objPOA->the_POAManager (); PortableServer::ObjectId_var objId = PortableServer::string_to_ObjectId (objName); objPOA->activate_object_with_id (objId.in(), p_servant); objPOAManager->activate(); }else{ //PortbaobjPOA } #endif return true; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { CORBA::ORB_var orb; try { // Initialize orb orb = CORBA::ORB_init (argc, argv); // Get reference to Root POA. CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (obj.in ()); // Get POA manager PortableServer::POAManager_var poa_mgr = poa->the_POAManager (); // Create a policy list. We use persistent objects with // user-assigned IDs, and explicit activation. CORBA::PolicyList policy_list; policy_list.length (6); policy_list[0] = poa->create_lifespan_policy ( PortableServer::TRANSIENT // REVISIT ); policy_list[1] = poa->create_id_assignment_policy ( PortableServer::USER_ID ); policy_list[2] = poa->create_implicit_activation_policy ( PortableServer::NO_IMPLICIT_ACTIVATION ); policy_list[3] = poa->create_request_processing_policy ( PortableServer::USE_SERVANT_MANAGER ); policy_list[4] = poa->create_servant_retention_policy ( PortableServer::NON_RETAIN ); policy_list[5] = poa->create_thread_policy ( PortableServer::SINGLE_THREAD_MODEL ); // Create a POA for all CCS elements. PortableServer::POA_var ccs_poa = poa->create_POA ("CCS_POA", poa_mgr.in (), policy_list); // Create a controller and set static m_ctrl member // for thermostats and thermometers. Controller_impl ctrl_servant (ccs_poa.in (), "/tmp/CCS_assets"); Thermometer_impl::m_ctrl = &ctrl_servant; // Create a reference for the controller and // create the corresponding CORBA object. PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId (Controller_oid); CORBA::Object_var ctrl = ccs_poa->create_reference_with_id ( oid.in (), "IDL:acme.com/CCS/Controller:1.0" ); // Get reference to initial naming context. CosNaming::NamingContext_var inc = resolve_init<CosNaming::NamingContext> ( orb.in (), "NameService" ); // Attempt to create CCS context. CosNaming::Name n; n.length (1); n[0].id = CORBA::string_dup ("CCS"); try { CosNaming::NamingContext_var nc = inc->bind_new_context (n); } catch (const CosNaming::NamingContext::AlreadyBound &) { // Fine, CCS context already exists. } // Force binding of controller reference to make // sure it is always up-to-date. n.length (2); n[1].id = CORBA::string_dup ("Controller"); inc->rebind (n, ctrl.in ()); // Instantiate the servant locator for devices. PortableServer::ServantManager_var locator = new DeviceLocator_impl (&ctrl_servant); // Set servant locator. ccs_poa->set_servant_manager (locator.in ()); // Activate the POA manager. poa_mgr->activate (); // Accept requests orb->run (); } catch (const CORBA::Exception & e) { std::cerr << "Uncaught CORBA exception: " << e << std::endl; return 1; } catch (...) { assert (0); // Uncaught exception, dump core } 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 run(CORBA::ORB_ptr orb, int /* argc */, char* argv[]) { // // Resolve Root POA // CORBA::Object_var poaObj = orb -> resolve_initial_references("RootPOA"); PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(poaObj); // // Create Persistent POA // CORBA::PolicyList pl; pl.length (4); pl[0] = rootPOA->create_lifespan_policy(PortableServer::PERSISTENT); pl[1] = rootPOA->create_id_assignment_policy(PortableServer::USER_ID); pl[2] = rootPOA->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL); pl[3] = rootPOA->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION); // // Get a reference to the POA manager // PortableServer::POAManager_var manager = rootPOA -> the_POAManager(); // // Create Persistent POA // PortableServer::POA_var stapoa = rootPOA->create_POA ("stapoa",manager,pl) ; // // Resolve the BootManager and register the server // CORBA::Object_var obj = orb -> resolve_initial_references("BootManager"); OB::BootManager_var bootManager = OB::BootManager::_narrow(obj); // // Create implementation object // Hello_impl* helloImpl = new Hello_impl(stapoa); PortableServer::ServantBase_var servant = helloImpl; PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId("Hello"); stapoa->activate_object_with_id(oid, servant); Hello_var hello = helloImpl -> _this(); // // add binding to BootManager // bootManager -> add_binding(oid, hello); // // Save reference // CORBA::String_var s = orb -> object_to_string(hello); const char* refFile = "Hello.ref"; ofstream out(refFile); if(out.fail()) { cerr << argv[0] << ": can't open `" << refFile << "': " << strerror(errno) << endl; return EXIT_FAILURE; } out << s << endl; out.close(); // // Run implementation // manager -> activate(); orb -> run(); return EXIT_SUCCESS; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); if (parse_args (argc, argv) != 0) { return 1; } CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var rootPOA = PortableServer::POA::_narrow (object.in ()); PortableServer::POAManager_var poa_manager = rootPOA->the_POAManager (); CORBA::PolicyList policies (5); policies.length (5); // Lifespan policy policies[0] = rootPOA->create_lifespan_policy (PortableServer::PERSISTENT); // Servant Retention Policy policies[1] = rootPOA->create_servant_retention_policy (PortableServer::RETAIN ); // ID Assignment Policy policies[2] = rootPOA->create_id_assignment_policy (PortableServer::USER_ID ); // Request Processing Policy policies[3] = rootPOA->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY ); // Threading policy policies[4] = rootPOA->create_thread_policy (PortableServer::ORB_CTRL_MODEL); PortableServer::POA_var poa_a = rootPOA->create_POA ("poaA", poa_manager.in (), policies ); PortableServer::POA_var poa_c = rootPOA->create_POA ("poaC", poa_manager.in (), policies ); for (CORBA::ULong i = 0; i < policies.length (); ++i) { CORBA::Policy_ptr policy = policies[i]; policy->destroy (); } Test_Time_i* time = new Test_Time_i(); PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId ("Server_A"); poa_a->activate_object_with_id (oid.in (), time); CORBA::Object_var time_obj = poa_a->id_to_reference(oid.in()); CORBA::String_var ior = orb->object_to_string (time_obj.in ()); poa_manager->activate (); FILE *output_file = ACE_OS::fopen (pid_file, ACE_TEXT ("w")); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Cannot open output file for writing IOR: %s\n"), pid_file), 1); int pid = static_cast<int> (ACE_OS::getpid ()); ACE_OS::fprintf (output_file, "%d\n", pid); ACE_OS::fclose (output_file); orb->run (); rootPOA->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception &ex) { ex._tao_print_exception (ACE_TEXT ("server:")); return 1; } return 0; }
int EC::run (int argc, ACE_TCHAR* argv[]) { TAO_EC_Default_Factory::init_svcs (); try { // First parse our command line options if (this->parse_args(argc, argv) != 0) { return -1; } // ORB initialization boiler plate... CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var rootpoa = PortableServer::POA::_narrow (object.in ()); PortableServer::POAManager_var root_poa_manager = rootpoa->the_POAManager (); // Create persistent POA CORBA::PolicyList policies (2); policies.length (2); policies[0] = rootpoa->create_id_assignment_policy (PortableServer::USER_ID); policies[1] = rootpoa->create_lifespan_policy (PortableServer::PERSISTENT); ACE_CString poaname = "POA"; PortableServer::POA_var child_poa_ = rootpoa->create_POA (poaname.c_str (), root_poa_manager.in (), policies); // Create a local event channel and register it with the RootPOA. TAO_EC_Event_Channel_Attributes attributes (rootpoa.in (), rootpoa.in ()); attributes.consumer_reconnect = 1; attributes.supplier_reconnect = 1; TAO_EC_Event_Channel ec_impl (attributes); ec_impl.activate (); PortableServer::ObjectId_var ecId = PortableServer::string_to_ObjectId(ACE_TEXT_ALWAYS_CHAR(ecname)); child_poa_->activate_object_with_id(ecId.in(), &ec_impl); CORBA::Object_var ec_obj = child_poa_->id_to_reference(ecId.in()); RtecEventChannelAdmin::EventChannel_var ec = RtecEventChannelAdmin::EventChannel::_narrow(ec_obj.in()); // Find the Naming Service. object = orb->resolve_initial_references("NameService"); CosNaming::NamingContextExt_var naming_context = CosNaming::NamingContextExt::_narrow(object.in()); // Create a name. CosNaming::Name name; name.length (1); name[0].id = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(ecname)); name[0].kind = CORBA::string_dup (""); // Register with the name server naming_context->rebind (name, ec.in ()); root_poa_manager->activate (); // Wait for events, using work_pending()/perform_work() may help // or using another thread, this example is too simple for that. orb->run (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("EC::run"); return 1; } return 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[]) { 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; }