[omniORB] Unloading DLLs and deferred object deactivation

Andrew Wilde ajw@it-innovation.soton.ac.uk
Fri Apr 4 16:24:02 2003


Hi,

I'm having some problems deactivating a servant when this servant is located inside a DLL. I read on a previous posting that is caused by the deactivation being deferred until after the DLL is freed and one way to deal with it is to create a POA for the servant and destroy it with etherialize_objects and wait_for_completion arguments set to true. I tried using this approach but I get a BAD_INV_ORDER exception when I attempt to destroy the POA suggesting I'm missing a step.  Can anybody give me any pointers as to where I'm going wrong. 

The DLL consists of two methods one to create the servant and other to destroy it. Here is the relevant code:

Header file
~~~~~~~~~~~~

extern "C" __declspec(dllexport) ModelExecutorCV_ptr getModelExecutorInstance(PortableServer::POA_ptr poa);
extern "C" __declspec(dllexport) void destroyModelExecutor();

ModelExecutor* servant;
PortableServer::POA_ptr mPOA;
PortableServer::POA_var modelExecutorPOA;
PortableServer::POAManager_var mgr;


Main file
~~~~~~~~~~

extern "C" __declspec(dllexport) ModelExecutorCV_ptr getModelExecutorInstance(PortableServer::POA_ptr poa) {

	mPOA=PortableServer::POA::_duplicate(poa);
	servant = (ModelExecutor*)new QuadraticModel();

    //create policy
	PortableServer::ImplicitActivationPolicy_var implicitActivationPolicy = mPOA->create_implicit_activation_policy(PortableServer::IMPLICIT_ACTIVATION);
	CORBA::PolicyList policy_list;
	policy_list.length(1);
	policy_list[0]= PortableServer::ImplicitActivationPolicy::_duplicate(implicitActivationPolicy);

    //create new POA
	modelExecutorPOA =mPOA->create_POA("modelExecutorPOA", PortableServer::POAManager::_nil(),policy_list);
	mgr = modelExecutorPOA->the_POAManager();	
	mgr->activate();
	implicitActivationPolicy->destroy();
	
	PortableServer::ObjectId *oid=modelExecutorPOA->activate_object(servant);
	CORBA::Object_ptr retobj=modelExecutorPOA->id_to_reference(*oid); 
	ModelExecutorCV_ptr ret=ModelExecutorCV::_narrow(retobj);
	servant->_remove_ref(); 
	
	return ret;		
}


extern "C" __declspec(dllexport) void destroyModelExecutor() {
	
	PortableServer::ObjectId *oid=modelExecutorPOA->servant_to_id(servant);	
	modelExecutorPOA->deactivate_object(*oid); 	 
	modelExecutorPOA->destroy (TRUE, TRUE);
}

Thanks in advance,

Andy

-------------------------
Andrew Wilde
IT Innovation Centre
2 Venture Road
Chilworth Science Park
Southampton, SO16 7NP, UK