/* 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 
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;
        }
}
Example #3
0
static PyObject *
pyorbit_poa_deactivate_object(PyCORBA_Object *self, PyObject *args)
{
    CORBA_Environment ev;
    PortableServer_ObjectId *id;
    Py_ssize_t id_length;
    id = (PortableServer_ObjectId *)CORBA_sequence_CORBA_octet__alloc();
    id->_release = CORBA_FALSE;
    if (!PyArg_ParseTuple(args, "s#:POA.deactivate_object",
			  &id->_buffer, &id_length)) {
	CORBA_free(id);
	return NULL;
    }
    id->_length = id_length;
    id->_length++; /* account for nul termination */

    CORBA_exception_init(&ev);
    PortableServer_POA_deactivate_object((PortableServer_POA)self->objref,
					 id, &ev);
    CORBA_free(id);
    if (pyorbit_check_ex(&ev))
	return NULL;

    Py_INCREF(Py_None);
    return Py_None;
}
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);
}
static void
impl_Wise2HSP_HSPmanagerFactory__destroy(impl_POA_Wise2HSP_HSPmanagerFactory *servant, CORBA_Environment *ev)
{
  PortableServer_ObjectId *objid;
  
  objid = PortableServer_POA_servant_to_id(servant->poa, servant, ev);
  PortableServer_POA_deactivate_object(servant->poa, objid, ev);
  CORBA_free(objid);
  
  POA_Wise2HSP_HSPmanagerFactory__fini((PortableServer_Servant)servant, ev);
  g_free(servant);
}
static void
do_window_close(GtkWidget *widget, gpointer _servant)
{
	CORBA_Environment ev;
	PortableServer_ObjectId *objid;
	impl_POA_GNOME_FileManagerWindow *servant = _servant;
	
	CORBA_exception_init(&ev);
	objid = PortableServer_POA_servant_to_id (servant->poa, _servant, &ev);
	PortableServer_POA_deactivate_object (servant->poa, objid, &ev);
	CORBA_free(objid);
	POA_GNOME_FileManagerWindow__fini(_servant, &ev);
	
	g_free(servant);
	CORBA_exception_free(&ev);
}
Example #7
0
static void
test_activate_deactivate (PortableServer_POA poa, CORBA_Environment * ev)
{
   impl_POA_Test *newservant;
   PortableServer_ObjectId *objid;

   newservant = g_new0(impl_POA_Test, 1);
   newservant->servant.vepv = &impl_Test_vepv;

   POA_Test__init((PortableServer_Servant) newservant, ev);

   objid = PortableServer_POA_activate_object(poa, newservant, ev);
   g_assert (!ORBIT_EX (ev));

   PortableServer_POA_deactivate_object (poa, objid, ev);
   g_assert (!ORBIT_EX (ev));

   CORBA_free(objid);
}
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;
}
Example #9
0
int
main (int argc, char *argv[])
{
	PortableServer_ObjectId *objid;
	PortableServer_POA poa;
	GOptionContext *ctx;
	GOptionGroup *goption_group;
	GError *error = NULL;
        GMainLoop *loop;

	CORBA_Environment ev;
	CORBA_ORB orb;
	GSList *reg_env = NULL;

	signal (SIGINT, do_exit);
	signal (SIGTERM, do_exit);

        g_thread_init (NULL);

	CORBA_exception_init (&ev);
	orb = bonobo_activation_init (argc, argv);

	g_set_prgname ("bonobo-activation-empty-server");
	ctx = g_option_context_new (NULL);
	goption_group = bonobo_activation_get_goption_group ();
	g_option_context_set_main_group (ctx, goption_group);
	if (!g_option_context_parse (ctx, &argc, &argv, &error)) {
		g_printerr ("%s\n", error->message);
		g_error_free (error);
		exit (1);
	}
	g_option_context_free (ctx);

	POA_Empty__init (&poa_empty_servant, &ev);

	poa = (PortableServer_POA)
		CORBA_ORB_resolve_initial_references (orb, "RootPOA", &ev);
	objid = PortableServer_POA_activate_object (poa, &poa_empty_servant, &ev);

	empty_client = PortableServer_POA_servant_to_reference (poa,
								&poa_empty_servant,
								&ev);
	if (!empty_client) {
		printf ("Cannot get objref\n");
		return 1;
	}

#ifndef G_OS_WIN32
	reg_env = bonobo_activation_registration_env_set (
			reg_env, "DISPLAY", getenv ("DISPLAY"));
	reg_env = bonobo_activation_registration_env_set (
			reg_env, "SESSION_MANAGER", getenv ("SESSION_MANAGER"));
	reg_env = bonobo_activation_registration_env_set (
			reg_env, "AUDIODEV", getenv ("AUDIODEV"));
#endif
	reg_env = bonobo_activation_registration_env_set (
			reg_env, "LANG", getenv ("LANG"));

        /*
         * NB. It is imperative to register the server that is being
         * requested last - or we can still race in the activation daemon.
         */
	bonobo_activation_register_active_server ("OAFIID:Empty2:19991025", empty_client, reg_env);
        g_usleep (500000); /* 1/2 sec */
	bonobo_activation_register_active_server ("OAFIID:Empty:19991025", empty_client, reg_env);

	bonobo_activation_registration_env_free (reg_env);

	PortableServer_POAManager_activate
		(PortableServer_POA__get_the_POAManager (poa, &ev), &ev);

        /* run the CORBA main loop for a couple of seconds then quit */
        loop = g_main_loop_new (NULL, FALSE);
        g_timeout_add (1000, (GSourceFunc) g_main_loop_quit, loop);
        g_main_loop_run (loop);

	bonobo_activation_active_server_unregister ("OAFIID:Empty:19991025", empty_client);
	bonobo_activation_active_server_unregister ("OAFIID:Empty2:19991025", empty_client);

	PortableServer_POA_deactivate_object (poa, objid, &ev);

	return 0;
}