2011-06-16 17:59:26 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
2011-07-05 16:29:07 -04:00
|
|
|
#include <set>
|
2011-06-16 17:59:26 -04:00
|
|
|
#include <vector>
|
|
|
|
#include <retroshare/rsplugin.h>
|
2011-07-05 16:29:07 -04:00
|
|
|
#include <pqi/p3cfgmgr.h>
|
2011-06-16 17:59:26 -04:00
|
|
|
|
|
|
|
class p3ConfigMgr ;
|
|
|
|
class p3ServiceServer ;
|
2011-07-09 20:41:39 -04:00
|
|
|
class p3LinkMgr ;
|
2011-06-16 17:59:26 -04:00
|
|
|
|
2012-02-18 15:29:03 -05:00
|
|
|
class PluginInfo
|
2011-07-05 16:29:07 -04:00
|
|
|
{
|
2012-02-18 15:29:03 -05:00
|
|
|
public:
|
|
|
|
RsPlugin *plugin ;
|
|
|
|
std::string info_string ;
|
|
|
|
std::string file_hash ;
|
|
|
|
std::string file_name ;
|
|
|
|
uint32_t status ;
|
2011-07-05 16:29:07 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class RsPluginManager: public RsPluginHandler, public p3Config
|
2011-06-16 17:59:26 -04:00
|
|
|
{
|
|
|
|
public:
|
2011-07-05 16:29:07 -04:00
|
|
|
RsPluginManager() ;
|
2011-06-16 17:59:26 -04:00
|
|
|
virtual ~RsPluginManager() {}
|
|
|
|
|
2011-07-05 16:29:07 -04:00
|
|
|
// ------------ Derived from RsPluginHandler ----------------//
|
|
|
|
//
|
2011-06-16 17:59:26 -04:00
|
|
|
virtual int nbPlugins() const { return _plugins.size() ; }
|
2011-07-05 16:29:07 -04:00
|
|
|
virtual RsPlugin *plugin(int i) { return _plugins[i].plugin ; }
|
2011-06-17 15:59:01 -04:00
|
|
|
virtual const std::vector<std::string>& getPluginDirectories() const { return _plugin_directories ; }
|
2011-07-05 16:29:07 -04:00
|
|
|
virtual void getPluginStatus(int i, uint32_t& status,std::string& file_name, std::string& hash,std::string& error_string) const ;
|
|
|
|
virtual void enablePlugin(const std::string& hash) ;
|
|
|
|
virtual void disablePlugin(const std::string& hash) ;
|
2011-06-16 17:59:26 -04:00
|
|
|
|
|
|
|
virtual void slowTickPlugins(time_t sec) ;
|
|
|
|
virtual const std::string& getLocalCacheDir() const ;
|
|
|
|
virtual const std::string& getRemoteCacheDir() const ;
|
|
|
|
virtual ftServer *getFileServer() const ;
|
2011-07-09 20:41:39 -04:00
|
|
|
virtual p3LinkMgr *getLinkMgr() const ;
|
2011-06-16 17:59:26 -04:00
|
|
|
|
2012-02-18 09:55:50 -05:00
|
|
|
virtual void allowAllPlugins(bool b) ;
|
|
|
|
virtual bool getAllowAllPlugins() const ;
|
|
|
|
|
2011-07-05 16:29:07 -04:00
|
|
|
// ---------------- Derived from p3Config -------------------//
|
|
|
|
//
|
|
|
|
bool saveList(bool& cleanup, std::list<RsItem*>& list) ;
|
|
|
|
bool loadList(std::list<RsItem*>& list) ;
|
|
|
|
virtual RsSerialiser* setupSerialiser() ;
|
|
|
|
|
|
|
|
// -------------------- Own members -------------------------//
|
|
|
|
//
|
|
|
|
virtual void addConfigurations(p3ConfigMgr *cfgMgr) ;
|
|
|
|
virtual void loadConfiguration() ;
|
|
|
|
|
2011-10-08 13:47:36 -04:00
|
|
|
/*!
|
|
|
|
* sets interfaces for all loaded plugins
|
|
|
|
* @param interfaces
|
|
|
|
*/
|
|
|
|
void setInterfaces(RsPlugInInterfaces& interfaces);
|
2011-06-16 17:59:26 -04:00
|
|
|
static void setPluginEntrySymbol(const std::string& s) { _plugin_entry_symbol = s ; }
|
|
|
|
static bool acceptablePluginName(const std::string& s) ;
|
|
|
|
static void setCacheDirectories(const std::string& local,const std::string& remote) ;
|
|
|
|
static void setFileServer(ftServer *ft) { _ftserver = ft ; }
|
2011-07-09 20:41:39 -04:00
|
|
|
static void setLinkMgr(p3LinkMgr *cm) { _linkmgr = cm ; }
|
2011-06-16 17:59:26 -04:00
|
|
|
|
2011-12-22 15:17:59 -05:00
|
|
|
// Normal plugin loading system. Parses through the plugin directories and loads
|
|
|
|
// dso libraries, checks for the hash, and loads/rejects plugins according to
|
|
|
|
// the user's choice.
|
|
|
|
//
|
2011-06-16 17:59:26 -04:00
|
|
|
void loadPlugins(const std::vector<std::string>& plugin_directories) ;
|
|
|
|
|
2011-12-22 15:17:59 -05:00
|
|
|
// Explicit function to load a plugin programatically.
|
|
|
|
// No hash-checking is performed (there's no DSO file to hash!)
|
|
|
|
// Mostly convenient for insering plugins in development.
|
|
|
|
//
|
|
|
|
void loadPlugins(const std::vector<RsPlugin*>& explicit_plugin_entries) ;
|
|
|
|
|
2011-06-16 17:59:26 -04:00
|
|
|
void registerCacheServices() ;
|
|
|
|
void registerClientServices(p3ServiceServer *pqih) ;
|
2011-12-22 15:17:59 -05:00
|
|
|
|
2011-06-16 17:59:26 -04:00
|
|
|
private:
|
2011-12-22 15:17:59 -05:00
|
|
|
bool loadPlugin(RsPlugin *) ;
|
2011-06-16 17:59:26 -04:00
|
|
|
bool loadPlugin(const std::string& shared_library_name) ;
|
2011-07-05 16:29:07 -04:00
|
|
|
std::string hashPlugin(const std::string& shared_library_name) ;
|
2011-06-16 17:59:26 -04:00
|
|
|
|
2011-07-05 16:29:07 -04:00
|
|
|
std::vector<PluginInfo> _plugins ;
|
|
|
|
std::set<std::string> _accepted_hashes ;
|
2012-02-18 09:55:50 -05:00
|
|
|
bool _allow_all_plugins ;
|
2011-06-16 17:59:26 -04:00
|
|
|
|
|
|
|
static std::string _plugin_entry_symbol ;
|
|
|
|
static std::string _remote_cache_dir ;
|
|
|
|
static std::string _local_cache_dir ;
|
|
|
|
static ftServer *_ftserver ;
|
2011-07-09 20:41:39 -04:00
|
|
|
static p3LinkMgr *_linkmgr ;
|
2011-06-17 15:59:01 -04:00
|
|
|
|
|
|
|
static std::vector<std::string> _plugin_directories ;
|
2011-06-16 17:59:26 -04:00
|
|
|
};
|
|
|
|
|