static void server_cleanup (CORBA_ORB orb, PortableServer_POA poa, CORBA_Object ref, CORBA_Environment *ev) { PortableServer_ObjectId *objid = NULL; objid = PortableServer_POA_reference_to_id (poa, ref, ev); if (etk_raised_exception(ev)) return; PortableServer_POA_deactivate_object (poa, objid, ev); if (etk_raised_exception(ev)) return; PortableServer_POA_destroy (poa, TRUE, FALSE, ev); if (etk_raised_exception(ev)) return; CORBA_free (objid); CORBA_Object_release ((CORBA_Object) poa, ev); if (etk_raised_exception(ev)) return; CORBA_Object_release (ref, ev); if (etk_raised_exception(ev)) return; if (orb != CORBA_OBJECT_NIL) { CORBA_ORB_destroy(orb, ev); if (etk_raised_exception(ev)) return; } }
/* Releases @servant object and finally destroys @orb. If error * occures @ev points to exception object on return. */ static void server_cleanup (CORBA_ORB orb, PortableServer_POA poa, CORBA_Object ref, CORBA_Environment *ev) { PortableServer_ObjectId *objid = NULL; objid = PortableServer_POA_reference_to_id (poa, ref, ev); if (etk_raised_exception(ev)) return; /* Servant: deactivatoin - will invoke __fini destructor */ PortableServer_POA_deactivate_object (poa, objid, ev); if (etk_raised_exception(ev)) return; PortableServer_POA_destroy (poa, TRUE, FALSE, ev); if (etk_raised_exception(ev)) return; CORBA_free (objid); CORBA_Object_release ((CORBA_Object) poa, ev); if (etk_raised_exception(ev)) return; CORBA_Object_release (ref, ev); if (etk_raised_exception(ev)) return; /* ORB: tear down the ORB */ if (orb != CORBA_OBJECT_NIL) { /* going to destroy orb.. */ CORBA_ORB_destroy(orb, ev); if (etk_raised_exception(ev)) return; } }
static void test_activation (void) { CORBA_Environment env; PortableServer_POA poa; GSList *objids = NULL, *l; int i; fprintf (stderr, "Testing object activation...\n"); CORBA_exception_init (&env); POA_Test__init (&test_servant, &env); poa = create_mult_id_poa (&env); g_assert (env._major == CORBA_NO_EXCEPTION); g_timer_reset (timer); for (i = 0; i < 1000; i++) { PortableServer_ObjectId *objid; objid = PortableServer_POA_activate_object (poa, &test_servant, &env); g_assert (env._major == CORBA_NO_EXCEPTION); objids = g_slist_append (objids, objid); } elapsed_time = g_timer_elapsed (timer, NULL); bogomark += elapsed_time; fprintf (stderr, " activation : %g(ms)\n", elapsed_time); g_timer_reset (timer); for (l = objids; l; l = l->next) { PortableServer_POA_deactivate_object (poa, l->data, &env); g_assert (env._major == CORBA_NO_EXCEPTION); } elapsed_time = g_timer_elapsed (timer, NULL); bogomark += elapsed_time; fprintf (stderr, " de-activation : %g(ms)\n", elapsed_time); for (l = objids; l; l = l->next) CORBA_free (l->data); g_slist_free (objids); POA_Test__fini (&test_servant, &env); PortableServer_POA_destroy (poa, CORBA_FALSE, CORBA_FALSE, &env); g_assert (env._major == CORBA_NO_EXCEPTION); CORBA_Object_release ((CORBA_Object) poa, &env); g_assert (env._major == CORBA_NO_EXCEPTION); CORBA_exception_free (&env); }
int main (int argc, char **argv) { CORBA_Environment ev[1]; PortableServer_POA rootpoa, poa; CORBA_exception_init (ev); orb = CORBA_ORB_init (&argc, argv, "", ev); rootpoa = (PortableServer_POA) CORBA_ORB_resolve_initial_references (orb, "RootPOA", ev); g_assert (ev->_major == CORBA_NO_EXCEPTION); { poa = ORBit_POA_new_from (orb, rootpoa, "Foo", NULL, ev); g_assert (ev->_major == CORBA_NO_EXCEPTION); PortableServer_POA_destroy (poa, FALSE, FALSE, ev); CORBA_Object_release ((CORBA_Object) poa, ev); } CORBA_Object_release ((CORBA_Object) rootpoa, ev); CORBA_ORB_destroy (orb, ev); g_assert (ev->_major == CORBA_NO_EXCEPTION); CORBA_Object_release ((CORBA_Object) orb, ev); g_assert (ev->_major == CORBA_NO_EXCEPTION); CORBA_exception_free (ev); fprintf (stderr, "PASS: test-poa\n"); return 0; }
poatest poatest_run (PortableServer_POA rootpoa, PortableServer_POAManager rootpoa_mgr) { CORBA_Environment ev; poatest poatest_obj; CORBA_PolicyList *poa_policies; PortableServer_ObjectId *objid; CORBA_exception_init (&ev); /* * Create child POA with USER_ID Id Assignment and PERSISTENT lifespan policy. */ poa_policies = CORBA_PolicyList__alloc (); poa_policies->_maximum = 2; poa_policies->_length = 2; poa_policies->_buffer = CORBA_PolicyList_allocbuf (2); CORBA_sequence_set_release (poa_policies, CORBA_TRUE); poa_policies->_buffer[0] = (CORBA_Policy) PortableServer_POA_create_id_assignment_policy ( rootpoa, PortableServer_USER_ID, &ev); poa_policies->_buffer[1] = (CORBA_Policy) PortableServer_POA_create_lifespan_policy ( rootpoa, PortableServer_PERSISTENT, &ev); child_poa = PortableServer_POA_create_POA (rootpoa, "User Id and Persistent POA", rootpoa_mgr, poa_policies, &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("create_POA : ", &ev); return CORBA_OBJECT_NIL; } /* * Initialise the servant. */ POA_poatest__init (&poatest_servant, &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("POA_poatest__init : ", &ev); return CORBA_OBJECT_NIL; } /* * Set up the ObjectId. */ objid = PortableServer_string_to_ObjectId ("Test Id", &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("string_to_ObjectId : ", &ev); return CORBA_OBJECT_NIL; } /* * Activate object with user assigned Id. */ PortableServer_POA_activate_object_with_id (child_poa, objid, &poatest_servant, &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("activate_object_with_id : ", &ev); return CORBA_OBJECT_NIL; } /* * Get reference for object. */ poatest_obj = PortableServer_POA_servant_to_reference (child_poa, &poatest_servant, &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("servant_to_reference : ", &ev); return CORBA_OBJECT_NIL; } /* * Deactivate object and destroy POA */ PortableServer_POA_deactivate_object(child_poa, objid, &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("deactivate_object : ", &ev); return CORBA_OBJECT_NIL; } PortableServer_POA_destroy (child_poa, CORBA_FALSE, CORBA_FALSE, &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("POA_destroy : ", &ev); return CORBA_OBJECT_NIL; } /* * Re-create POA and re-activate the object. */ child_poa = PortableServer_POA_create_POA (rootpoa, "User Id and Persistent POA", rootpoa_mgr, poa_policies, &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("create_POA : ", &ev); return CORBA_OBJECT_NIL; } PortableServer_POA_activate_object_with_id (child_poa, objid, &poatest_servant, &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("activate_object_with_id : ", &ev); return CORBA_OBJECT_NIL; } /* * Reference should still be valid. */ CORBA_free (objid); CORBA_Policy_destroy (poa_policies->_buffer[0], &ev); CORBA_Policy_destroy (poa_policies->_buffer[1], &ev); CORBA_free (poa_policies); /* * Activate the POAManager. POA will now accept requests */ PortableServer_POAManager_activate( rootpoa_mgr, &ev ); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("POAManager_activate : ", &ev); return CORBA_OBJECT_NIL; } return poatest_obj; }