Removing an entry from proxyObjectFactory
Christian Perez <[email protected]> Thu, 20 Feb 2003 18:22:27 +0100
| Newsgroups | gmane.comp.corba.omniorb.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello, We would like to dynamically be able to load/unload code into a server. It appears to work fine except for the management of proxyObjectFactory. The proxyObjectFactory global variables in the IDL generated files correctly register themself thanks to their constructor. However, there is no destructor. When such a code is unloaded from the memory, the list of registered proxyObjectFactory is incorrect because it contains dangling pointers. A solution is to implement the destructor of proxyObjectFactory. Hence, proxyObjectFactory are going to be correctly removed. In attachement, you'll find such an implementation of proxyFactory.cc derived from omniORB3 (location src/lib/omniORB2/orbcore/proxyFactory.cc). This implementation is based on the used of the map of the C++ STL. As the proxyObjectFactory API is the same in omniORB4, the same modification should work. It would be very nice if such a patch can be applied to omniORB. Best regards, Christian Pérez -- Research scientist - PARIS Project - IRISA/INRIA http://www.irisa.fr/paris/
proxyFactory-fix.cc
(text/plain, 1.4 KB)
#include <omniORB3/CORBA.h>
#ifdef HAS_pch
#pragma hdrstop
#endif
#include <omniORB3/proxyFactory.h>
#include <map>
typedef map<const char*, proxyObjectFactory*> ofl_t;
// We used a pointer because we do not know how to control
// the initialization of global variables.
static ofl_t *_ofl;
proxyObjectFactory::~proxyObjectFactory() { _ofl->erase(pd_repoId); }
proxyObjectFactory::proxyObjectFactory(const char* repoId)
{
// The first time such an object is build, it has to
// initialize the _ofl object. So, we are ablt to control
// the order of initialization./
if (_ofl == 0) {
_ofl = new ofl_t();
}
OMNIORB_ASSERT(repoId);
pd_repoId = CORBA::string_dup(repoId);
// This code could be concurrently called with a lookup.
// It should be protected with a mutex
ofl_t::iterator it = _ofl->find(pd_repoId);
if (it != _ofl->end() ) {
it->second = this;
if( omniORB::trace(15) )
omniORB::logf("Replaced proxyObjectFactory for %s.", repoId);
} else {
(*_ofl)[repoId] = this;
}
}
void
proxyObjectFactory::shutdown()
{
_ofl->clear();
}
proxyObjectFactory*
proxyObjectFactory::lookup(const char* repoId)
{
// This code has should be concurrently called with an constructor.
// It should be protected with mutex
OMNIORB_ASSERT(repoId);
ofl_t::iterator it = _ofl->find(repoId);
if ( it != _ofl->end() )
return it->second;
else
return 0;
}