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; }
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 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 ); }
// Implementation skeleton constructor Stock_StockBroker_i::Stock_StockBroker_i (CORBA::ORB_ptr orb, Stock::StockDistributor_ptr dist, const char *stock_name) : orb_ (CORBA::ORB::_duplicate (orb)), quoter_ (Stock::StockQuoter::_nil()), consumer_ (0), distributor_ (Stock::StockDistributor::_duplicate (dist)) { // Get a reference to the <RTORB>. CORBA::Object_var obj = orb->resolve_initial_references ("RTORB"); RTCORBA::RTORB_var rt_orb = RTCORBA::RTORB::_narrow (obj.in ()); // Create a <CORBA::PolicyList> for the child POA. TAO::Utils::PolicyList_Destroyer consumer_policies (1); consumer_policies.length (1); // Create a <CLIENT_PROPAGATED> priority model policy. consumer_policies[0] = rt_orb->create_priority_model_policy (RTCORBA::CLIENT_PROPAGATED, Stock::Priority_Mapping::MEDIUM); PortableServer::POA_var poa = this->_default_POA (); PortableServer::POAManager_var poa_mgr = poa->the_POAManager (); // Create a child POA with CLIENT_PROPAGATED policies. The name of // the POA will be <StockNameConsumer_POA>. Instances of the // Stock_StockNameConsumer_i will be activated under this POA. PortableServer::POA_var child_poa = poa->create_POA ("StockNameConsumer_POA", poa_mgr. in(), consumer_policies); // Narrow the POA to a <RTPortableServer::POA>. RTPortableServer::POA_var rt_poa = RTPortableServer::POA::_narrow (child_poa.in ()); // Create and activate the <consumer_>. this->consumer_ = new Stock_StockNameConsumer_i (*this, stock_name); PortableServer::ServantBase_var nameconsumer_owner_transfer = this->consumer_; rt_poa->activate_object (this->consumer_); }
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; }
// Implementation skeleton constructor StockDistributorHome_i::StockDistributorHome_i (CORBA::ORB_ptr orb) : orb_ (CORBA::ORB::_duplicate (orb)), rt_poa_ (RTPortableServer::POA::_nil ()), dist_id_ (0) { // Register this class as a signal handler to catch keyboard interrupts. if (orb_->orb_core ()->reactor ()->register_handler (SIGINT, this) == -1) ACE_DEBUG ((LM_DEBUG, "ERROR: Failed to register as a signal handler: %p\n", "register_handler\n")); // Register the necessary factories and mappings with the specified // <orb>. If we neglect to perform these registrations then the app // will not execute. Stock::StockNames_init *stockname_factory = new Stock::StockNames_init; orb_->register_value_factory (stockname_factory->tao_repository_id (), stockname_factory); Stock::Cookie_init *cookie_factory = new Stock::Cookie_init; this->orb_->register_value_factory (cookie_factory->tao_repository_id (), cookie_factory); Stock::Priority_Mapping::register_mapping (orb_.in ()); // Get a reference to the <RTORB>. CORBA::Object_var obj = orb_->resolve_initial_references ("RTORB"); RTCORBA::RTORB_var rt_orb = RTCORBA::RTORB::_narrow (obj.in ()); TAO::Utils::PolicyList_Destroyer policies (2); policies.length (2); // Create a <SERVER_DECLARED> priority model policy. policies[0] = rt_orb->create_priority_model_policy (RTCORBA::SERVER_DECLARED, Stock::Priority_Mapping::VERY_LOW); // Create a threadpool with lanes for the distributor. Since the brokers // will have various priorities, create a lane for each priority. RTCORBA::ThreadpoolLanes lanes (5); lanes.length (5); for (CORBA::ULong i = 0; i < lanes.length (); ++i) { lanes[i].lane_priority = static_cast<RTCORBA::Priority> (i); lanes[i].static_threads = 5; lanes[i].dynamic_threads = 0; } RTCORBA::ThreadpoolId threadpool_id = rt_orb->create_threadpool_with_lanes (1024*1024, lanes, false, false, 0, 0); policies[1] = rt_orb->create_threadpool_policy (threadpool_id); PortableServer::POA_var poa = this->_default_POA (); PortableServer::POAManager_var poa_mgr = poa->the_POAManager (); // Create a child POA with <SERVER_DECLARED> policies. The name of // the POA will be <StockDistributor_POA>. Any instances of the // StockDistributor_i created via the create() method will be // activated under this POA. PortableServer::POA_var child_poa = poa->create_POA ("StockDistributor_POA", poa_mgr.in (), policies); // Narrow the POA to a RT POA, and cache the reference this->rt_poa_ = RTPortableServer::POA::_narrow (child_poa.in ()); // Create the initial distributor reference this->create_distributor (); }
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; }
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 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 naming_obj = orb->resolve_initial_references ("NameService"); CosNaming::NamingContext_var naming_context = CosNaming::NamingContext::_narrow(naming_obj.in()); CosNaming::Name name; name.length (1); name[0].id = CORBA::string_dup("MyEventChannel"); CORBA::Object_var ecObj = naming_context->resolve(name); CosNotifyChannelAdmin::EventChannel_var ec = CosNotifyChannelAdmin::EventChannel::_narrow(ecObj.in()); CosNotifyChannelAdmin::AdminID adminid; CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = CosNotifyChannelAdmin::AND_OP; CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin = ec->new_for_consumers(ifgop, adminid); CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_object.in()); CORBA::Object_var rtorb_obj = orb->resolve_initial_references ("RTORB"); RTCORBA::RTORB_var rt_orb = RTCORBA::RTORB::_narrow (rtorb_obj.in ()); // Create an RT POA with a lane at the given priority. CORBA::Policy_var priority_model_policy = rt_orb->create_priority_model_policy (RTCORBA::CLIENT_PROPAGATED, DEFAULT_PRIORITY); RTCORBA::ThreadpoolLanes lanes (2); lanes.length (2); lanes[0].lane_priority = LOW_PRIORITY; lanes[0].static_threads = 2; lanes[0].dynamic_threads = 0; lanes[1].lane_priority = HIGH_PRIORITY; lanes[1].static_threads = 2; lanes[1].dynamic_threads = 0; // Create a thread-pool. CORBA::ULong stacksize = 0; CORBA::Boolean allow_request_buffering = 0; CORBA::ULong max_buffered_requests = 0; CORBA::ULong max_request_buffer_size = 0; CORBA::Boolean allow_borrowing = 0; // Create the thread-pool. RTCORBA::ThreadpoolId threadpool_id = rt_orb->create_threadpool_with_lanes (stacksize, lanes, allow_borrowing, allow_request_buffering, max_buffered_requests, max_request_buffer_size); // Create a thread-pool policy. CORBA::Policy_var lanes_policy = rt_orb->create_threadpool_policy (threadpool_id); CORBA::PolicyList poa_policy_list(2); poa_policy_list.length (2); poa_policy_list[0] = priority_model_policy; poa_policy_list[1] = lanes_policy; PortableServer::POAManager_var poa_manager = poa->the_POAManager (); PortableServer::POA_var rt_poa = poa->create_POA ("RT POA", poa_manager.in (), poa_policy_list); PortableServer::Servant_var<StructuredEventConsumer_i> servant = new StructuredEventConsumer_i(orb.in()); PortableServer::ObjectId_var objectId = rt_poa->activate_object (servant.in()); CORBA::Object_var consumer_obj = rt_poa->id_to_reference (objectId.in ()); CosNotifyComm::StructuredPushConsumer_var consumer = CosNotifyComm::StructuredPushConsumer::_narrow (consumer_obj.in ()); NotifyExt::ThreadPoolLanesParams tpl_params; tpl_params.priority_model = NotifyExt::CLIENT_PROPAGATED; tpl_params.server_priority = DEFAULT_PRIORITY; tpl_params.stacksize = 0; tpl_params.allow_borrowing = 0; tpl_params.allow_request_buffering = 0; tpl_params.max_buffered_requests = 0; tpl_params.max_request_buffer_size = 0; tpl_params.lanes.length (2); tpl_params.lanes[0].lane_priority = LOW_PRIORITY; tpl_params.lanes[0].static_threads = 2; tpl_params.lanes[0].dynamic_threads = 0; tpl_params.lanes[1].lane_priority = HIGH_PRIORITY; tpl_params.lanes[1].static_threads = 2; tpl_params.lanes[1].dynamic_threads = 0; CosNotification::QoSProperties qos; qos.length(1); qos[0].name = CORBA::string_dup (NotifyExt::ThreadPoolLanes); qos[0].value <<= tpl_params; consumer_admin->set_qos(qos); CORBA::Object_var current_obj = orb->resolve_initial_references ("RTCurrent"); RTCORBA::Current_var current = RTCORBA::Current::_narrow (current_obj.in ()); current->the_priority(HIGH_PRIORITY); CosNotifyChannelAdmin::ProxyID consumeradmin_proxy_id; CosNotifyChannelAdmin::ProxySupplier_var proxy_supplier = consumer_admin->obtain_notification_push_supplier( CosNotifyChannelAdmin::STRUCTURED_EVENT, consumeradmin_proxy_id); CosNotifyChannelAdmin::StructuredProxyPushSupplier_var supplier_proxy; supplier_proxy = CosNotifyChannelAdmin::StructuredProxyPushSupplier:: _narrow(proxy_supplier.in()); supplier_proxy->connect_structured_push_consumer(consumer.in()); CosNotification::EventTypeSeq added (1); CosNotification::EventTypeSeq removed (1); added.length (1); removed.length (1); added[0].domain_name = CORBA::string_dup ("OCI_TAO"); added[0].type_name = CORBA::string_dup ("examples"); removed[0].domain_name = CORBA::string_dup ("*"); removed[0].type_name = CORBA::string_dup ("*"); supplier_proxy->subscription_change(added, removed); poa_manager->activate(); // Write a file to let the run_test.pl script know we are ready. std::ofstream iorFile( ACE_TEXT_ALWAYS_CHAR(output_file) ); iorFile << "Ready" << std::endl; iorFile.close(); orb->run(); } catch(const CORBA::Exception& ex) { std::cerr << "Caught exception: " << ex << std::endl; return 1; } return 0; }
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 { // 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[]) { 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 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[]) { 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 main(int argc, char* argv[]) { // // Signals staff // signal(SIGINT, handler); // signal(SIGTERM, handler); // signal(SIGKILL, handler); // Print the welcome message printWelcome(); // // Check TIDNaming arguments // /* * Note: this TIDNaming special arguments may be passed to ORB * initialization with no problems. Any unknown argument will be ignored * by ORB, so no change is needed for argv. */ const char * persistence_dir = ""; int max_binding_iterators = 40; const char * ior_file = ""; for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "--help") == 0) { printUsage(argv[0]); _exit(0); } if (strcmp(argv[i], "--version") == 0) { cerr << "TIDNaming C++ version " << TIDNaming::st_version << endl; _exit(0); } if (strcmp(argv[i], "--persistence-dir") == 0) { if (i == argc - 1) { cerr << "Error: --persistence-dir specified but no path given" << endl; printUsage(argv[0]); _exit(-1); } persistence_dir = argv[i+1]; } if (strcmp(argv[i], "--max_binding_iterators") == 0) { char* ptr; long laux; laux = strtol(argv[i+1], &ptr, 10); max_binding_iterators = laux; } if (strcmp(argv[i], "--ior") == 0) { if (i == argc - 1) { cerr << "Error: --ior specified but no file name given" << endl; printUsage(argv[0]); _exit(-1); } ior_file = argv[i+1]; } } DMSG("Executing in debug mode, a lot of messages will be "\ "printed to stderr"); DMSG_P("Using '", persistence_dir, "' as persistence directory"); DMSG_P("Using '", ior_file, "' as ior output file"); char * port = strdup("2809"); char * ssl_port = strdup(""); bool port_given = false; bool ssl_port_given = false; bool ssl_config = false; try { // // Start TIDThread library // TIDThr::init(); // // Check for -ORB_iiop_orb_port to set NameService default // int new_argc = argc + 2; char * new_argv[new_argc]; for (int i = 1; i < argc; i++) { new_argv[i] = argv[i]; // No strdup is needed if (strcmp(argv[i], "-ORB_iiop_orb_port") == 0) { port_given = true; free(port); port = strdup(argv[i+1]); } if (strcmp(argv[i], "-ORB_ssl_port") == 0) { ssl_port_given = true; // util?? free(ssl_port); ssl_port = strdup(argv[i+1]); } if (strcmp(argv[i], "-ORB_ssl_private_key") == 0) { for (int j = 1; j < argc; j++) { if (strcmp(argv[j], "-ORB_ssl_certificate") == 0) { ssl_config = true; break; } } } } new_argv[new_argc - 2] = "-ORB_iiop_orb_port"; new_argv[new_argc - 1] = port; int orb_argc = port_given ? argc : new_argc; char ** orb_argv = port_given ? argv : new_argv; // // ORB initialization // my_global_orb = CORBA::ORB_init(orb_argc, orb_argv); // Get internal ORB TIDorb::core::TIDORB* m_orb = dynamic_cast<TIDorb::core::TIDORB*> (CORBA::ORB::_duplicate(my_global_orb)); // // Getting RootPOA & Manager references // CORBA::Object_var poa_obj = my_global_orb->resolve_initial_references("RootPOA"); PortableServer::POA_ptr rootPOA = PortableServer::POA::_narrow(poa_obj); PortableServer::POAManager_var manager = rootPOA->the_POAManager(); // // NamingContexts POA creation // CORBA::PolicyList policies; policies.length(4); policies[0] = rootPOA->create_servant_retention_policy(PortableServer::RETAIN); policies[1] = rootPOA->create_request_processing_policy( PortableServer::USE_SERVANT_MANAGER); policies[2] = rootPOA->create_id_assignment_policy(PortableServer::USER_ID); policies[3] = rootPOA->create_lifespan_policy(PortableServer::PERSISTENT); PortableServer::POA_var namingContextsPOA = rootPOA->create_POA("namingContextsPOA", manager, policies); PortableServer::POAManager_var namingContextsManager = namingContextsPOA->the_POAManager(); // // BindingIterators POA creation // CORBA::PolicyList bindingIterators_policies; bindingIterators_policies.length(2); bindingIterators_policies[0] = rootPOA->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL); bindingIterators_policies[1] = rootPOA->create_id_assignment_policy(PortableServer::USER_ID); PortableServer::POA_var bindingIteratorsPOA = namingContextsPOA->create_POA("bindingIteratorsPOA", namingContextsManager, bindingIterators_policies); // // Creates and sets a new ServantManager // TIDNaming::ServantManagerNSImpl* servant_manager = new TIDNaming::ServantManagerNSImpl(my_global_orb, bindingIteratorsPOA, max_binding_iterators); namingContextsPOA->set_servant_manager(servant_manager); // Creates the reference to the "root.ctx". Dont create it // This fragment of code is not needed anymore. It creates the // initial reference to root naming context, now created from // PersistenceManager class. /* PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId("root.ctx"); // Change to "NameService" CORBA::Object_var obj = namingContextsPOA->create_reference_with_id(oid,"IDL:omg.org/CosNaming/NamingContextExt:1.0"); */ // Manager activation (ORB/POA staff) manager->activate(); namingContextsManager->activate(); // // Check if has persistence // if (strcmp(persistence_dir, "") != 0) { if (m_orb->trace != NULL){ TIDorb::util::StringBuffer msg; msg << "Using '" << persistence_dir << "' as persistence directory"; m_orb->print_trace(TIDorb::util::TR_USER, msg.str().data()); } // // Recover the persistent data // try { TIDNaming::NamingContextFileIOFactory::init(persistence_dir); } catch (TIDNaming::NamingContextFileIOFactory::InvalidPathException & e) { if (m_orb->trace != NULL) { TIDorb::util::StringBuffer msg; msg << "Error: cannot initialize persistence directory '"; msg << e.path << "'"; m_orb->print_trace(TIDorb::util::TR_ERROR, msg.str().data()); } printUsage(argv[0]); _exit(-1); } loadPersistence(namingContextsPOA.inout(), bindingIteratorsPOA.inout(), ior_file); } else { // // Start without persistent data // try { TIDNaming::NamingContextNullIOFactory::init(); } catch (...) { printUsage(argv[0]); _exit(-1); } if (m_orb->trace != NULL) m_orb->print_trace(TIDorb::util::TR_USER, "No root context found. Initializing a new one... "); CosNaming::NamingContext_var root_nc = createNamingContextReference(namingContextsPOA, NamingInternals::RootNamingContextOID); // Get ssl system assigned port if (ssl_config && (!ssl_port_given)) { TIDorb::portable::Stub* stub_obj = dynamic_cast<TIDorb::portable::Stub*> ((CORBA::Object*)root_nc); TIDorb::core::ObjectDelegateImpl* obj_delegate = dynamic_cast<TIDorb::core::ObjectDelegateImpl*> (stub_obj->_get_delegate()); TIDorb::core::iop::IOR* ior = obj_delegate->getReference(); SSLIOP::SSL* _ssl = ior->get_SSL(); free(ssl_port); ssl_port = (char*)malloc(6); sprintf(ssl_port, "%d", _ssl->port); } registerNameService(my_global_orb, root_nc, ior_file); if (m_orb->trace != NULL) m_orb->print_trace(TIDorb::util::TR_DEBUG, "Done"); } // // Run the ORB loop forever // TIDorb::util::StringBuffer msg; msg << "Serving at port " << port << "... " << endl; if (ssl_config) { msg.seekp(0, ios::beg); msg << "Serving at SSL port " << ssl_port << "... " << endl; } if (m_orb->trace != NULL) m_orb->print_trace(TIDorb::util::TR_USER, msg.str().data()); cerr << msg.str().data(); my_global_orb->run(); my_global_orb->destroy(); } catch (const CORBA::INITIALIZE & ex) { cerr << "ERROR: cannot initialize Naming Service at port "; if (ssl_config) cerr << ssl_port; else cerr << port; cerr << " due to: " << ex << endl; } catch (const CORBA::Exception& ex) { cerr << "ERROR: Naming Server Exception: " << ex << endl << flush; exit (1); } catch (...) { cerr << "ERROR: unexpected exception raised" << endl << flush; exit (1); } free(port); free(ssl_port); }
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; }