Added proper shutdown of the plugins with remove of the service and dlcose of the plugin handle.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8493 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2015-06-16 14:20:59 +00:00
parent bfab3622ec
commit 5f4e465a09
8 changed files with 49 additions and 19 deletions

View File

@ -174,7 +174,7 @@ void RsPluginManager::loadPlugins(const std::vector<std::string>& plugin_directo
saveConfiguration();
}
void RsPluginManager::stopPlugins()
void RsPluginManager::stopPlugins(p3ServiceServer *pqih)
{
std::cerr << " Stopping plugins." << std::endl;
@ -182,16 +182,21 @@ void RsPluginManager::stopPlugins()
{
if (_plugins[i].plugin != NULL)
{
p3Service *service = _plugins[i].plugin->p3_service();
if (service)
{
pqih->removeService(service);
}
_plugins[i].plugin->stop();
// delete _plugins[i].plugin;
// _plugins[i].plugin = NULL;
delete _plugins[i].plugin;
_plugins[i].plugin = NULL;
}
if (_plugins[i].handle)
{
dlclose(_plugins[i].handle);
_plugins[i].handle = NULL;
}
// Causes a crash
// if (_plugins[i].handle)
// {
// dlclose(_plugins[i].handle);
// _plugins[i].handle = NULL;
// }
}
}

View File

@ -98,7 +98,7 @@ class RsPluginManager: public RsPluginHandler, public p3Config
//
void loadPlugins(const std::vector<RsPlugin*>& explicit_plugin_entries) ;
void stopPlugins();
void stopPlugins(p3ServiceServer *pqih);
void registerCacheServices() ;
void registerClientServices(p3ServiceServer *pqih) ;

View File

@ -84,6 +84,31 @@ int p3ServiceServer::addService(pqiService *ts, bool defaultOn)
return 1;
}
int p3ServiceServer::removeService(pqiService *ts)
{
RsStackMutex stack(srvMtx); /********* LOCKED *********/
#ifdef SERVICE_DEBUG
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, "p3ServiceServer::removeService()");
#endif
RsServiceInfo info = ts->getServiceInfo();
// This doesn't need to be in Mutex.
mServiceControl->deregisterService(info.mServiceType);
std::map<uint32_t, pqiService *>::iterator it = services.find(info.mServiceType);
if (it == services.end())
{
std::cerr << "p3ServiceServer::removeService(): Service not found with id " << info.mServiceType << "!" << std::endl;
return -1;
}
services.erase(it);
return 1;
}
bool p3ServiceServer::recvItem(RsRawItem *item)
{
RsStackMutex stack(srvMtx); /********* LOCKED *********/

View File

@ -109,6 +109,7 @@ public:
p3ServiceServer(pqiPublisher *pub, p3ServiceControl *ctrl);
int addService(pqiService *, bool defaultOn);
int removeService(pqiService *);
bool recvItem(RsRawItem *);
bool sendItem(RsRawItem *);

View File

@ -121,6 +121,9 @@ public:
class RsPlugin
{
public:
RsPlugin() {}
virtual ~RsPlugin() {}
//
//================================ Services ==================================//
//

View File

@ -83,7 +83,7 @@ void RsServer::rsGlobalShutDown()
ConfigFinalSave(); // save configuration before exit
mPluginsManager->stopPlugins();
mPluginsManager->stopPlugins(pqih);
mNetMgr->shutdown(); /* Handles UPnP */

View File

@ -44,11 +44,9 @@ extern "C" {
#ifdef WIN32
__declspec(dllexport)
#endif
void *RETROSHARE_PLUGIN_provide()
RsPlugin *RETROSHARE_PLUGIN_provide()
{
static FeedReaderPlugin *p = new FeedReaderPlugin();
return (void*)p;
return new FeedReaderPlugin();
}
// This symbol contains the svn revision number grabbed from the executable.

View File

@ -51,11 +51,9 @@ extern "C" {
// - always respect the C linkage convention
// - always return an object of type RsPlugin*
//
void *RETROSHARE_PLUGIN_provide()
RsPlugin *RETROSHARE_PLUGIN_provide()
{
static VOIPPlugin *p = new VOIPPlugin() ;
return (void*)p ;
return new VOIPPlugin() ;
}
// This symbol contains the svn revision number grabbed from the executable.