int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // Initialize the ORB first. CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); int result = parse_args (argc, argv); if (result != 0) return result; // Obtain the RootPOA. CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); // Get the POA_var object from Object_var. PortableServer::POA_var root_poa = PortableServer::POA::_narrow (obj.in ()); // Get the POAManager of the RootPOA. PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); // Policies for the firstPOA to be created. CORBA::PolicyList policies (3); policies.length (3); // Id Assignment Policy policies[0] = root_poa->create_id_assignment_policy (PortableServer::USER_ID); // Lifespan policy policies[1] = root_poa->create_lifespan_policy (PortableServer::PERSISTENT); // Threading policy policies[2] = root_poa->create_thread_policy (PortableServer::ORB_CTRL_MODEL); // Create the firstPOA under the RootPOA. ACE_CString name = "firstPOA"; PortableServer::POA_var first_poa = root_poa->create_POA (name.c_str (), poa_manager.in (), policies); policies[2]->destroy (); // Threading policy policies[2] = root_poa->create_thread_policy (PortableServer::SINGLE_THREAD_MODEL); // Create the secondPOA under the firstPOA. name = "secondPOA"; PortableServer::POA_var second_poa = first_poa->create_POA (name.c_str (), poa_manager.in (), policies); // Creation of POAs is over. Destroy the Policy objects. for (CORBA::ULong i = 0; i < policies.length (); ++i) { policies[i]->destroy (); } // Create two Objects of Class test_i (defined in // ./../GenericServant/test_i.h) Create one object at RootPOA // and the other at firstPOA. test_i first_servant (orb.in (), root_poa.in ()); test_i second_servant (orb.in (), first_poa.in ()); // Do "activate_object" to activate the first_servant object. It // returns ObjectId for that object. Operation Used : // ObjectId activate_object(in Servant p_servant) // raises (ServantAlreadyActive, WrongPolicy); PortableServer::ObjectId_var first_oid = root_poa->activate_object (&first_servant); // Get Object Reference for the first_servant object. test_var first_test = first_servant._this (); // Get ObjectId for object secondtest and use that ObjectId to // activate the second_servant object. // Operation Used : // void activate_object_with_id(in ObjectId oid, in Servant p_servant) // raises (ObjectAlreadyActive, ServantAlreadyActive, WrongPolicy); PortableServer::ObjectId_var second_oid = PortableServer::string_to_ObjectId ("second test"); first_poa->activate_object_with_id (second_oid.in (), &second_servant); // Get Object reference for second_servant object. test_var second_test = second_servant._this (); // Get ObjectId for the string thirdPOA Create the object reference // for thirdPOA using that ObjectId. Operation Used : // Object create_reference_with_id (in ObjectId oid, in CORBA::RepositoryId intf ); // This operation creates an object reference that encapsulates the // specified Object Id and interface repository Id values. /* PortableServer::ObjectId_var third_oid = PortableServer::string_to_ObjectId ("thirdtest"); */ // This will test how the POA handles a user given ID PortableServer::ObjectId_var third_oid = PortableServer::string_to_ObjectId ("third test"); third_oid[5] = (CORBA::Octet) '\0'; CORBA::Object_var third_test = second_poa->create_reference_with_id (third_oid.in (), "IDL:test:1.0"); // Stringyfy all the object references and print them out. CORBA::String_var first_ior = orb->object_to_string (first_test.in ()); CORBA::String_var second_ior = orb->object_to_string (second_test.in ()); CORBA::String_var third_ior = orb->object_to_string (third_test.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n%C\n%C\n", first_ior.in (), second_ior.in (), third_ior.in ())); int write_result = write_iors_to_file (first_ior.in (), second_ior.in (), third_ior.in ()); if (write_result != 0) return write_result; // Activate third servant using its ObjectID. test_i third_servant (orb.in (), second_poa.in ()); second_poa->activate_object_with_id (third_oid.in (), &third_servant); poa_manager->activate (); orb->run (); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught"); return -1; } return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // Initialize the ORB first. CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); int result = parse_args (argc, argv); if (result != 0) return result; // Obtain the RootPOA. CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); // Get the POA_var object from Object_var. PortableServer::POA_var root_poa = PortableServer::POA::_narrow (obj.in ()); // Get the POAManager of the RootPOA. PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); Adapter_Activator adapter_activator (poa_manager.in (), orb.in ()); root_poa->the_activator (&adapter_activator); PortableServer::POA_var first_poa; PortableServer::POA_var second_poa; { // Policies for the firstPOA to be created. CORBA::PolicyList &policies = adapter_activator.first_poa_policies_; policies.length (4); // Id Assignment Policy policies[0] = root_poa->create_id_assignment_policy (PortableServer::SYSTEM_ID); // Lifespan policy policies[1] = root_poa->create_lifespan_policy (PortableServer::PERSISTENT); // Request Processing policy policies[2] = root_poa->create_request_processing_policy (PortableServer::USE_DEFAULT_SERVANT); // Id Uniqueness policies[3] = root_poa->create_id_uniqueness_policy (PortableServer::MULTIPLE_ID); // Create the firstPOA under the RootPOA. first_poa = root_poa->create_POA ("firstPOA", poa_manager.in (), policies); } { // Policies for the secondPOA to be created. CORBA::PolicyList &policies = adapter_activator.second_poa_policies_; policies.length (2); // Id Assignment Policy policies[0] = root_poa->create_id_assignment_policy (PortableServer::USER_ID); // Lifespan policy policies[1] = root_poa->create_lifespan_policy (PortableServer::PERSISTENT); // Create the secondPOA under the firstPOA. second_poa = first_poa->create_POA ("secondPOA", poa_manager.in (), policies); } // Create a servant. reference_counted_test_i first_servant (orb.in (), root_poa.in ()); PortableServer::ObjectId_var first_oid = root_poa->activate_object (&first_servant); // Get Object Reference for the first_servant object. test_var first_test = first_servant._this (); CORBA::Object_var second_test = first_poa->create_reference ("IDL:test:1.0"); PortableServer::ObjectId_var third_oid = PortableServer::string_to_ObjectId ("third test"); CORBA::Object_var third_test = second_poa->create_reference_with_id (third_oid.in (), "IDL:test:1.0"); // Stringyfy all the object references and print them out. CORBA::String_var first_ior = orb->object_to_string (first_test.in ()); CORBA::String_var second_ior = orb->object_to_string (second_test.in ()); CORBA::String_var third_ior = orb->object_to_string (third_test.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n%C\n%C\n", first_ior.in (), second_ior.in (), third_ior.in ())); int write_result = write_iors_to_file (first_ior.in (), second_ior.in (), third_ior.in ()); if (write_result != 0) return write_result; first_poa->destroy (1, 1); poa_manager->activate (); orb->run (); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught"); return -1; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { // Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); int result = parse_args (argc, argv); if (result != 0) return result; // Obtain the RootPOA. CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); // Narrow the Object reference to a POA reference PortableServer::POA_var root_poa = PortableServer::POA::_narrow (obj.in ()); // Get the POAManager of RootPOA PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); CORBA::PolicyList policies (4); policies.length (4); // ID Assignment Policy policies[0] = root_poa->create_id_assignment_policy (PortableServer::USER_ID); // Lifespan Policy policies[1] = root_poa->create_lifespan_policy (PortableServer::PERSISTENT); // Request Processing Policy policies[2] = root_poa->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER); PortableServer::POA_var first_poa; { // Servant Retention Policy policies[3] = root_poa->create_servant_retention_policy (PortableServer::RETAIN); ACE_CString name = "firstPOA"; // Create firstPOA as the child of RootPOA with the above policies // firstPOA will use SERVANT_ACTIVATOR because of RETAIN policy. first_poa = root_poa->create_POA (name.c_str (), poa_manager.in (), policies); } PortableServer::POA_var second_poa; { // Servant Retention Policy policies[3] = root_poa->create_servant_retention_policy (PortableServer::NON_RETAIN); ACE_CString name = "secondPOA"; // Create secondPOA as child of RootPOA with the above policies // secondPOA will use a SERVANT_LOCATOR because of NON_RETAIN // policy. second_poa = root_poa->create_POA (name.c_str (), poa_manager.in (), policies); } // Destroy the policy objects as they have been passed to // create_POA and no longer needed. for (CORBA::ULong i = 0; i < policies.length (); ++i) { CORBA::Policy_ptr policy = policies[i]; policy->destroy (); } // Allocate the servant activator. ServantActivator activator (orb.in ()); // Set ServantActivator object as the servant_manager of // firstPOA. first_poa->set_servant_manager (&activator); // For the code above, we're using the CORBA 3.0 servant manager // semantics supported by TAO. For CORBA 2.x ORBs you'd need to // use the following code in place of the previous line: // // PortableServer::ServantManager_var servant_activator = // activator->_this (); // // first_poa->set_servant_manager (servant_activator.in (), //); // Create a reference with user created ID in firstPOA which uses // the ServantActivator. PortableServer::ObjectId_var first_test_oid = PortableServer::string_to_ObjectId ("first test"); CORBA::Object_var first_test = first_poa->create_reference_with_id (first_test_oid.in (), "IDL:test:1.0"); // Allocate the servant locator. ServantLocator locator (orb.in ()); // Set ServantLocator object as the servant Manager of // secondPOA. second_poa->set_servant_manager (&locator); // For the code above, we're using the CORBA 3.0 servant manager // semantics supported by TAO. For CORBA 2.x ORBs you'd need to // use the following code in place of the previous line: // // PortableServer::ServantManager_var servant_locator = // locator->_this (); // // second_poa->set_servant_manager (servant_locator.in (), //); // Try to create a reference with user created ID in second_poa // which uses ServantLocator. PortableServer::ObjectId_var second_test_oid = PortableServer::string_to_ObjectId ("second test"); CORBA::Object_var second_test = second_poa->create_reference_with_id (second_test_oid.in (), "IDL:test:1.0"); // Invoke object_to_string on the references created in firstPOA and // secondPOA. CORBA::String_var first_test_ior = orb->object_to_string (first_test.in ()); CORBA::String_var second_test_ior = orb->object_to_string (second_test.in ()); // Print the ior's of first_test and second_test. ACE_DEBUG((LM_DEBUG,"Cs\n%C\n", first_test_ior.in (), second_test_ior.in ())); int write_result = write_iors_to_file (first_test_ior.in (), second_test_ior.in ()); if (write_result != 0) return write_result; // Set the poa_manager state to active, ready to process requests. poa_manager->activate (); // Run the ORB. orb->run (); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught in main"); return -1; } return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // Initialize the ORB first. CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); int result = parse_args (argc, argv); if (result != 0) return result; // Obtain the RootPOA. CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); // Get the POA_var object from Object_var. PortableServer::POA_var root_poa = PortableServer::POA::_narrow (obj.in ()); // Get the POAManager of the RootPOA. PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); // Create a servant. reference_counted_test_i *servant = 0; ACE_NEW_RETURN (servant, reference_counted_test_i (orb.in (), root_poa.in ()), -1); // Get Object Reference for the servant object. test_var test = servant->_this (); // This means that the ownership of <servant> now belongs to // the POA. servant->_remove_ref (); // Stringyfy all the object references and print them out. CORBA::String_var ior = orb->object_to_string (test.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", ior.in ())); int write_result = write_iors_to_file (ior.in ()); if (write_result != 0) return write_result; poa_manager->activate (); orb->run (); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught"); return -1; } return 0; }
int Server_Task::svc (void) { try { CORBA::Object_var poa_object = this->sorb_->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); if (CORBA::is_nil (root_poa.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); CORBA::PolicyList policies (4); policies.length (4); // ID Assignment Policy policies[0] = root_poa->create_id_assignment_policy (PortableServer::USER_ID); // Lifespan Policy policies[1] = root_poa->create_lifespan_policy (PortableServer::PERSISTENT); // Request Processing Policy policies[2] = root_poa->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER); PortableServer::POA_var first_poa; { // Servant Retention Policy policies[3] = root_poa->create_servant_retention_policy (PortableServer::RETAIN); ACE_CString name = "firstPOA"; // Create firstPOA as the child of RootPOA with the above policies // firstPOA will use SERVANT_ACTIVATOR because of RETAIN policy. first_poa = root_poa->create_POA (name.c_str (), poa_manager.in (), policies); } // Destroy the policy objects as they have been passed to // create_POA and no longer needed. for (CORBA::ULong i = 0; i < policies.length (); ++i) { CORBA::Policy_ptr policy = policies[i]; policy->destroy (); } // Allocate the servant activator. ServantActivator activator (this->sorb_.in (), ACE_Thread::self ()); // Set ServantActivator object as the servant_manager of // firstPOA. first_poa->set_servant_manager (&activator); // Create a reference with user created ID in firstPOA which uses // the ServantActivator. PortableServer::ObjectId_var first_test_oid = PortableServer::string_to_ObjectId ("first test"); CORBA::Object_var first_test = first_poa->create_reference_with_id (first_test_oid.in (), "IDL:test:1.0"); // Invoke object_to_string on the references created in firstPOA CORBA::String_var first_test_ior = this->sorb_->object_to_string (first_test.in ()); // Print the ior's of first_test. ACE_DEBUG((LM_DEBUG,"<%C>\n", first_test_ior.in ())); int write_result = write_iors_to_file (first_test_ior.in ()); if (write_result != 0) return write_result; // Set the poa_manager state to active, ready to process requests. poa_manager->activate (); this->me_.signal (); // Run the ORB. this->sorb_->run (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
int Task::svc (void) { try { CORBA::Object_var object = this->orb_->resolve_initial_references ("RTORB"); RTCORBA::RTORB_var rt_orb = RTCORBA::RTORB::_narrow (object.in ()); object = this->orb_->resolve_initial_references ("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (object.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); CORBA::PolicyList policies; int result = get_priority_bands ("server", bands_file, rt_orb.in (), policies, debug); if (result != 0) return result; result = get_priority_lanes ("server", lanes_file, rt_orb.in (), stacksize, static_threads, dynamic_threads, allow_request_buffering, max_buffered_requests, max_request_buffer_size, allow_borrowing, policies, debug); if (result != 0) return result; CORBA::Policy_var priority_model_policy = rt_orb->create_priority_model_policy (RTCORBA::CLIENT_PROPAGATED, 0); // Implicit_activation policy. CORBA::Policy_var implicit_activation_policy = root_poa->create_implicit_activation_policy (PortableServer::IMPLICIT_ACTIVATION); policies.length (policies.length () + 1); policies[policies.length () - 1] = priority_model_policy; policies.length (policies.length () + 1); policies[policies.length () - 1] = implicit_activation_policy; PortableServer::POA_var poa = root_poa->create_POA ("child", poa_manager.in (), policies); test_i *servant = 0; ACE_NEW_THROW_EX (servant, test_i (this->orb_.in (), poa.in ()), CORBA::NO_MEMORY ()); PortableServer::ServantBase_var safe_servant (servant); PortableServer::ObjectId_var id = poa->activate_object (servant); CORBA::Object_var object_act = poa->id_to_reference (id.in ()); test_var test = test::_narrow (object_act.in ()); write_iors_to_file (test.in (), this->orb_.in (), ior); poa_manager->activate (); this->orb_->run (); this->orb_->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught"); return -1; } return 0; }