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(); saveConfiguration();
} }
void RsPluginManager::stopPlugins() void RsPluginManager::stopPlugins(p3ServiceServer *pqih)
{ {
std::cerr << " Stopping plugins." << std::endl; std::cerr << " Stopping plugins." << std::endl;
@ -182,16 +182,21 @@ void RsPluginManager::stopPlugins()
{ {
if (_plugins[i].plugin != NULL) if (_plugins[i].plugin != NULL)
{ {
p3Service *service = _plugins[i].plugin->p3_service();
if (service)
{
pqih->removeService(service);
}
_plugins[i].plugin->stop(); _plugins[i].plugin->stop();
// delete _plugins[i].plugin; delete _plugins[i].plugin;
// _plugins[i].plugin = NULL; _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 loadPlugins(const std::vector<RsPlugin*>& explicit_plugin_entries) ;
void stopPlugins(); void stopPlugins(p3ServiceServer *pqih);
void registerCacheServices() ; void registerCacheServices() ;
void registerClientServices(p3ServiceServer *pqih) ; void registerClientServices(p3ServiceServer *pqih) ;

View file

@ -84,6 +84,31 @@ int p3ServiceServer::addService(pqiService *ts, bool defaultOn)
return 1; 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) bool p3ServiceServer::recvItem(RsRawItem *item)
{ {
RsStackMutex stack(srvMtx); /********* LOCKED *********/ RsStackMutex stack(srvMtx); /********* LOCKED *********/

View file

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

View file

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

View file

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

View file

@ -44,11 +44,9 @@ extern "C" {
#ifdef WIN32 #ifdef WIN32
__declspec(dllexport) __declspec(dllexport)
#endif #endif
void *RETROSHARE_PLUGIN_provide() RsPlugin *RETROSHARE_PLUGIN_provide()
{ {
static FeedReaderPlugin *p = new FeedReaderPlugin(); return new FeedReaderPlugin();
return (void*)p;
} }
// This symbol contains the svn revision number grabbed from the executable. // 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 respect the C linkage convention
// - always return an object of type RsPlugin* // - always return an object of type RsPlugin*
// //
void *RETROSHARE_PLUGIN_provide() RsPlugin *RETROSHARE_PLUGIN_provide()
{ {
static VOIPPlugin *p = new VOIPPlugin() ; return new VOIPPlugin() ;
return (void*)p ;
} }
// This symbol contains the svn revision number grabbed from the executable. // This symbol contains the svn revision number grabbed from the executable.