2018-05-28 22:28:51 +02:00
/*******************************************************************************
* libretroshare / src / retroshare : rsplugin . h *
* *
* libretroshare : retroshare core library *
* *
* Copyright 2011 - 2011 by Cyril Soler < csoler @ users . sourceforge . net > *
* *
* This program is free software : you can redistribute it and / or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation , either version 3 of the *
* License , or ( at your option ) any later version . *
* *
* This program is distributed in the hope that it will be useful , *
* but WITHOUT ANY WARRANTY ; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the *
* GNU Lesser General Public License for more details . *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program . If not , see < https : //www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2011-06-17 08:30:12 +00:00
# pragma once
2018-10-07 01:34:05 +02:00
# include "util/rstime.h"
2013-12-15 19:35:14 +00:00
# include <string.h>
2011-06-17 08:30:12 +00:00
# include <stdint.h>
# include <string>
2011-06-17 19:59:01 +00:00
# include <vector>
2011-10-08 17:47:36 +00:00
# include "retroshare/rspeers.h"
# include "retroshare/rsfiles.h"
2015-01-14 23:26:51 +00:00
# include "retroshare/rsversion.h"
2014-08-25 21:07:07 +00:00
# include "util/rsinitedptr.h"
2019-05-02 16:23:46 +02:00
# include "retroshare/rsdisc.h"
2011-06-17 08:30:12 +00:00
class RsPluginHandler ;
extern RsPluginHandler * rsPlugins ;
class p3Service ;
2014-04-20 14:20:13 +00:00
class RsServiceControl ;
2015-10-04 23:14:49 -04:00
class RsReputations ;
2013-12-15 19:35:14 +00:00
class RsTurtle ;
2015-11-28 18:02:57 -05:00
class RsGxsTunnelService ;
2013-12-15 19:35:14 +00:00
class RsDht ;
class RsMsgs ;
2014-11-23 23:24:41 +00:00
class RsGxsForums ;
class RsGxsChannels ;
2014-01-10 20:27:51 +00:00
class RsNotify ;
2015-12-15 19:56:49 +01:00
class RsServiceControl ;
2011-07-10 00:41:39 +00:00
class p3LinkMgr ;
2011-06-17 08:30:12 +00:00
class MainPage ;
class QIcon ;
2011-07-05 20:29:07 +00:00
class QString ;
2012-09-04 21:59:49 +00:00
class QDialog ;
2011-07-05 20:29:07 +00:00
class QWidget ;
2011-11-17 21:17:24 +00:00
class QTranslator ;
class QApplication ;
2011-06-17 08:30:12 +00:00
class RsCacheService ;
class ftServer ;
2012-02-18 14:55:50 +00:00
class ConfigPage ;
2012-02-18 20:29:03 +00:00
class RsPQIService ;
2012-02-21 21:53:25 +00:00
class RsAutoUpdatePage ;
2012-10-21 21:38:55 +00:00
class SoundEvents ;
2013-01-08 22:07:52 +00:00
class FeedNotify ;
2015-05-26 15:19:57 +00:00
class ToasterNotify ;
2014-01-02 00:56:46 +00:00
class ChatWidget ;
class ChatWidgetHolder ;
2014-08-25 21:07:07 +00:00
// for gxs based plugins
2018-10-05 01:55:18 +02:00
struct RsIdentity ;
2014-08-25 21:07:07 +00:00
class RsNxsNetMgr ;
class RsGxsIdExchange ;
class RsGcxs ;
class PgpAuxUtils ;
class p3Config ;
2011-06-17 08:30:12 +00:00
2015-12-15 19:56:49 +01:00
namespace resource_api
{
class ResourceRouter ;
class StateTokenServer ;
}
2012-09-09 13:59:21 +00:00
// Plugin API version. Not used yet, but will be in the future the
// main value that decides for compatibility.
//
# define RS_PLUGIN_API_VERSION 0x000101
2011-07-05 20:29:07 +00:00
// Used for the status of plugins.
//
# define PLUGIN_STATUS_NO_STATUS 0x0000
2012-09-09 13:59:21 +00:00
# define PLUGIN_STATUS_REJECTED_HASH 0x0001
2011-07-05 20:29:07 +00:00
# define PLUGIN_STATUS_DLOPEN_ERROR 0x0002
# define PLUGIN_STATUS_MISSING_SYMBOL 0x0003
# define PLUGIN_STATUS_NULL_PLUGIN 0x0004
# define PLUGIN_STATUS_LOADED 0x0005
2012-09-09 13:59:21 +00:00
# define PLUGIN_STATUS_WRONG_API 0x0006
# define PLUGIN_STATUS_MISSING_API 0x0007
# define PLUGIN_STATUS_MISSING_SVN 0x0008
2011-07-05 20:29:07 +00:00
2011-10-08 17:47:36 +00:00
class RsPluginHandler ;
/*!
*
* convenience class to store gui interfaces
*
*/
class RsPlugInInterfaces {
public :
2014-08-25 21:07:07 +00:00
RsUtil : : inited_ptr < RsPeers > mPeers ;
RsUtil : : inited_ptr < RsFiles > mFiles ;
RsUtil : : inited_ptr < RsMsgs > mMsgs ;
RsUtil : : inited_ptr < RsTurtle > mTurtle ;
RsUtil : : inited_ptr < RsDisc > mDisc ;
RsUtil : : inited_ptr < RsDht > mDht ;
RsUtil : : inited_ptr < RsNotify > mNotify ;
2015-12-15 19:56:49 +01:00
RsUtil : : inited_ptr < RsServiceControl > mServiceControl ;
RsUtil : : inited_ptr < RsPluginHandler > mPluginHandler ;
2011-10-08 17:47:36 +00:00
2014-08-25 21:07:07 +00:00
// gxs
std : : string mGxsDir ;
RsUtil : : inited_ptr < RsIdentity > mIdentity ;
RsUtil : : inited_ptr < RsNxsNetMgr > mRsNxsNetMgr ;
RsUtil : : inited_ptr < RsGxsIdExchange > mGxsIdService ;
RsUtil : : inited_ptr < RsGcxs > mGxsCirlces ;
RsUtil : : inited_ptr < PgpAuxUtils > mPgpAuxUtils ;
2014-11-23 23:24:41 +00:00
RsUtil : : inited_ptr < RsGxsForums > mGxsForums ;
RsUtil : : inited_ptr < RsGxsChannels > mGxsChannels ;
2015-11-28 18:02:57 -05:00
RsUtil : : inited_ptr < RsGxsTunnelService > mGxsTunnels ;
2015-10-04 23:14:49 -04:00
RsUtil : : inited_ptr < RsReputations > mReputations ;
2011-10-08 17:47:36 +00:00
} ;
2011-06-17 08:30:12 +00:00
class RsPlugin
{
public :
2015-06-16 14:20:59 +00:00
RsPlugin ( ) { }
virtual ~ RsPlugin ( ) { }
2012-02-21 21:53:25 +00:00
//
//================================ Services ==================================//
//
// Cache service. Use this for providing cache-based services, such as channels, forums.
2013-01-08 22:07:52 +00:00
// Example plugin: LinksCloud
2012-02-21 21:53:25 +00:00
//
2013-01-08 22:07:52 +00:00
virtual RsCacheService * rs_cache_service ( ) const { return NULL ; }
2012-02-21 21:53:25 +00:00
// Peer-to-Peer service. Use this for providing a service based to friend to friend
2013-01-08 22:07:52 +00:00
// exchange of data, such as chat, messages, etc.
2012-02-21 21:53:25 +00:00
// Example plugin: VOIP
//
2014-08-25 21:07:07 +00:00
//virtual RsPQIService *rs_pqi_service() const { return NULL ; }
// gxs netservice is not a RsPQIService
// so have two fns which result in the same gxs netservice to be returned
virtual p3Service * p3_service ( ) const { return NULL ; }
virtual p3Config * p3_config ( ) const { return NULL ; }
2011-06-17 08:30:12 +00:00
virtual uint16_t rs_service_id ( ) const { return 0 ; }
2011-07-05 20:29:07 +00:00
2015-12-15 19:56:49 +01:00
// creates a new resource api handler object. ownership is transferred to the caller.
// the caller should supply a statetokenserver, and keep it valid until destruction
// the plugin should return a entry point name. this is to make the entry point name independent from file names
2016-01-12 21:10:11 -05:00
virtual resource_api : : ResourceRouter * new_resource_api_handler ( const RsPlugInInterfaces & /* ifaces */ , resource_api : : StateTokenServer * /* sts */ , std : : string & /*entrypoint*/ ) const { return 0 ; }
2015-12-15 19:56:49 +01:00
2012-08-02 13:17:53 +00:00
// Shutdown
virtual void stop ( ) { }
2012-02-21 21:53:25 +00:00
// Filename used for saving the specific plugin configuration. Both RsCacheService and RsPQIService
// derive from p3Config, which means that the service provided by the plugin can load/save its own
// config by deriving loadList() and saveList() from p3Config.
//
2014-04-20 14:20:13 +00:00
virtual std : : string configurationFileName ( ) const
{
std : : cerr < < " (EE) Plugin configuration file name requested in non overloaded method! Plugin code should derive configurationFileName() method! " < < std : : endl ;
return std : : string ( ) ;
}
2012-02-21 21:53:25 +00:00
//
//=================================== GUI ====================================//
//
// Derive the following methods to provide GUI additions to RetroShare's GUI.
//
// Main page: like Transfers, Channels, Forums, etc.
//
virtual MainPage * qt_page ( ) const { return NULL ; } // The page itself
virtual QIcon * qt_icon ( ) const { return NULL ; } // the page icon. Todo: put icon as virtual in MainPage
virtual QWidget * qt_config_panel ( ) const { return NULL ; } // Config panel, to appear config->plugins->[]->
2012-09-04 21:59:49 +00:00
virtual QDialog * qt_about_page ( ) const { return NULL ; } // About/Help button in plugin entry will show this up
2012-02-21 21:53:25 +00:00
virtual ConfigPage * qt_config_page ( ) const { return NULL ; } // Config tab to add in config panel.
virtual RsAutoUpdatePage * qt_transfers_tab ( ) const { return NULL ; } // Tab to add in transfers, after turtle statistics.
virtual std : : string qt_transfers_tab_name ( ) const { return " Tab " ; } // Tab name
2012-10-21 21:38:55 +00:00
virtual void qt_sound_events ( SoundEvents & /*events*/ ) const { } // Sound events
2012-02-18 14:55:50 +00:00
2014-01-02 00:56:46 +00:00
// Provide buttons for the ChatWidget
virtual ChatWidgetHolder * qt_get_chat_widget_holder ( ChatWidget */ * chatWidget */ ) const { return NULL ; }
2012-02-25 12:17:36 +00:00
2015-06-28 10:11:47 +00:00
virtual std : : string qt_stylesheet ( ) { return " " ; }
2012-10-12 18:44:02 +00:00
virtual QTranslator * qt_translator ( QApplication * /* app */ , const QString & /* languageCode */ , const QString & /* externalDir */ ) const { return NULL ; }
2011-06-17 08:30:12 +00:00
2013-01-08 22:07:52 +00:00
//
//================================== Notify ==================================//
//
virtual FeedNotify * qt_feedNotify ( ) { return NULL ; }
2015-05-26 15:19:57 +00:00
virtual ToasterNotify * qt_toasterNotify ( ) { return NULL ; }
2013-01-08 22:07:52 +00:00
//
2012-02-21 21:53:25 +00:00
//========================== Plugin Description ==============================//
2013-01-08 22:07:52 +00:00
//
2012-02-21 21:53:25 +00:00
// All these items appear in the config->plugins tab, as a description of the plugin.
//
2018-09-12 00:33:29 +02:00
uint32_t getSvnRevision ( ) const { return 0 ; } // This is read from libretroshare/retroshare/rsversion.h
2012-09-04 21:59:49 +00:00
2011-06-17 08:30:12 +00:00
virtual std : : string getShortPluginDescription ( ) const = 0 ;
virtual std : : string getPluginName ( ) const = 0 ;
2015-01-14 23:26:51 +00:00
virtual void getPluginVersion ( int & major , int & minor , int & build , int & svn_rev ) const = 0 ;
2015-06-14 17:45:26 +00:00
virtual void getLibraries ( std : : list < RsLibraryInfo > & /*libraries*/ ) { }
2012-02-21 21:53:25 +00:00
2013-01-08 22:07:52 +00:00
//
2012-02-21 21:53:25 +00:00
//========================== Plugin Interface ================================//
2013-01-08 22:07:52 +00:00
//
2012-02-21 21:53:25 +00:00
// Use these methods to access main objects from RetroShare.
//
2011-11-17 21:17:24 +00:00
virtual void setInterfaces ( RsPlugInInterfaces & interfaces ) = 0 ;
2012-02-21 21:53:25 +00:00
virtual void setPlugInHandler ( RsPluginHandler * pgHandler ) = 0 ;
2011-06-17 08:30:12 +00:00
} ;
class RsPluginHandler
{
public :
// Returns the number of loaded plugins.
//
virtual int nbPlugins ( ) const = 0 ;
virtual RsPlugin * plugin ( int i ) = 0 ;
2011-06-17 19:59:01 +00:00
virtual const std : : vector < std : : string > & getPluginDirectories ( ) const = 0 ;
2014-03-17 20:56:06 +00:00
virtual void getPluginStatus ( int i , uint32_t & status , std : : string & file_name , RsFileHash & file_hash , uint32_t & svn_revision , std : : string & error_string ) const = 0 ;
virtual void enablePlugin ( const RsFileHash & hash ) = 0 ;
virtual void disablePlugin ( const RsFileHash & hash ) = 0 ;
2011-06-17 19:59:01 +00:00
2012-02-18 14:55:50 +00:00
virtual void allowAllPlugins ( bool b ) = 0 ;
virtual bool getAllowAllPlugins ( ) const = 0 ;
2018-10-07 01:34:05 +02:00
virtual void slowTickPlugins ( rstime_t sec ) = 0 ;
2011-06-17 08:30:12 +00:00
virtual const std : : string & getLocalCacheDir ( ) const = 0 ;
2014-04-20 14:20:13 +00:00
virtual const std : : string & getRemoteCacheDir ( ) const = 0 ;
virtual RsServiceControl * getServiceControl ( ) const = 0 ;
2011-06-17 08:30:12 +00:00
} ;