From 2c6a2b4ee7ea551ccfff4598ef4c196857e49e50 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 18 Feb 2012 20:29:03 +0000 Subject: [PATCH] improved plugin management to allow services to be used, and config pages to be added git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4960 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/plugins/pluginmanager.cc | 19 ++++++++++++++++--- libretroshare/src/plugins/pluginmanager.h | 13 +++++++------ libretroshare/src/plugins/rspqiservice.h | 5 +++-- libretroshare/src/retroshare/rsplugin.h | 4 ++-- .../src/gui/settings/rsettingswin.cpp | 2 +- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/libretroshare/src/plugins/pluginmanager.cc b/libretroshare/src/plugins/pluginmanager.cc index 8c0366693..39a880160 100644 --- a/libretroshare/src/plugins/pluginmanager.cc +++ b/libretroshare/src/plugins/pluginmanager.cc @@ -198,6 +198,7 @@ bool RsPluginManager::loadPlugin(const std::string& plugin_name) PluginInfo pf ; pf.plugin = NULL ; pf.file_name = plugin_name ; + pf.info_string = "" ; std::cerr << " -> hashing." << std::endl; uint64_t size ; @@ -232,9 +233,10 @@ bool RsPluginManager::loadPlugin(const std::string& plugin_name) if(handle == NULL) { - std::cerr << " Cannot open plugin: " << dlerror() << std::endl ; + const char *val = dlerror() ; + std::cerr << " Cannot open plugin: " << val << std::endl ; pinfo.status = PLUGIN_STATUS_DLOPEN_ERROR ; - pinfo.info_string = dlerror() ; + pinfo.info_string = val ; return false ; } @@ -331,7 +333,13 @@ void RsPluginManager::addConfigurations(p3ConfigMgr *ConfigMgr) for(uint32_t i=0;i<_plugins.size();++i) if(_plugins[i].plugin != NULL && _plugins[i].plugin->configurationFileName().length() > 0) { - ConfigMgr->addConfiguration(_plugins[i].plugin->configurationFileName(), _plugins[i].plugin->rs_cache_service()); + if( _plugins[i].plugin->rs_cache_service() != NULL) + ConfigMgr->addConfiguration(_plugins[i].plugin->configurationFileName(), _plugins[i].plugin->rs_cache_service()); + else if(_plugins[i].plugin->rs_pqi_service() != NULL) + ConfigMgr->addConfiguration(_plugins[i].plugin->configurationFileName(), _plugins[i].plugin->rs_pqi_service()); + else + continue ; + std::cerr << " Added configuration for plugin " << _plugins[i].plugin->getPluginName() << ", with file " << _plugins[i].plugin->configurationFileName() << std::endl; } } @@ -401,3 +409,8 @@ RsCacheService::RsCacheService(uint16_t service_type,uint32_t config_type,uint32 { } +RsPQIService::RsPQIService(uint16_t service_type,uint32_t config_type,uint32_t tick_delay_in_seconds, RsPluginHandler* pgHandler) + : p3Service(service_type),p3Config(config_type) +{ +} + diff --git a/libretroshare/src/plugins/pluginmanager.h b/libretroshare/src/plugins/pluginmanager.h index 8d9cf922a..2735727ac 100644 --- a/libretroshare/src/plugins/pluginmanager.h +++ b/libretroshare/src/plugins/pluginmanager.h @@ -10,13 +10,14 @@ class p3ConfigMgr ; class p3ServiceServer ; class p3LinkMgr ; -struct PluginInfo +class PluginInfo { - RsPlugin *plugin ; - std::string info_string ; - std::string file_hash ; - std::string file_name ; - uint32_t status ; + public: + RsPlugin *plugin ; + std::string info_string ; + std::string file_hash ; + std::string file_name ; + uint32_t status ; }; class RsPluginManager: public RsPluginHandler, public p3Config diff --git a/libretroshare/src/plugins/rspqiservice.h b/libretroshare/src/plugins/rspqiservice.h index 00a3d2948..b92925538 100644 --- a/libretroshare/src/plugins/rspqiservice.h +++ b/libretroshare/src/plugins/rspqiservice.h @@ -1,17 +1,18 @@ #pragma once +#include "services/p3service.h" #include "plugins/pluginmanager.h" // The following class abstracts the construction of a peer-to-peer service. The user only has to // supply RS with a type ID. If the ID is already in use, RS will complain. // -class RsPQIService: public p3Config +class RsPQIService: public p3Service, public p3Config { public: RsPQIService(uint16_t type,uint32_t config_type,uint32_t tick_delay_in_seconds, RsPluginHandler* pgHandler) ; uint32_t tickDelay() const { return _tick_delay_in_seconds ; } - virtual void tick() {} + virtual int tick() = 0 ; // Functions from p3config // diff --git a/libretroshare/src/retroshare/rsplugin.h b/libretroshare/src/retroshare/rsplugin.h index 59fc115e7..9de9ccb4d 100644 --- a/libretroshare/src/retroshare/rsplugin.h +++ b/libretroshare/src/retroshare/rsplugin.h @@ -46,7 +46,7 @@ class QApplication; class RsCacheService ; class ftServer ; class ConfigPage ; -class pqiService ; +class RsPQIService ; // Used for the status of plugins. // @@ -78,7 +78,7 @@ class RsPlugin { public: virtual RsCacheService *rs_cache_service() const { return NULL ; } - virtual pqiService *rs_pqi_service() const { return NULL ; } + virtual RsPQIService *rs_pqi_service() const { return NULL ; } virtual uint16_t rs_service_id() const { return 0 ; } virtual MainPage *qt_page() const { return NULL ; } diff --git a/retroshare-gui/src/gui/settings/rsettingswin.cpp b/retroshare-gui/src/gui/settings/rsettingswin.cpp index 43e8dc848..d36857d72 100644 --- a/retroshare-gui/src/gui/settings/rsettingswin.cpp +++ b/retroshare-gui/src/gui/settings/rsettingswin.cpp @@ -127,7 +127,7 @@ RSettingsWin::initStackedWidget() RsPlugin *pl = rsPlugins->plugin(i) ; if(pl->qt_config_page() != NULL) - stackedWidget->addWidget(pl->qt_config_page()) ; + addPage(pl->qt_config_page()) ; } // make the first page the default.