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; }
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 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 { 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[]) { 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; }
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; }