changed: the way how plugins work
all your plugin functions can have signature either: void my_function(PluginInfo & info); or void my_function(); only the main Init should have: extern "C" void Init(PluginFunction & info); added: directory 'plugins' for plugins added: 'stats' plugin git-svn-id: svn://ttmath.org/publicrep/winix/trunk@624 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
115
core/plugin.h
115
core/plugin.h
@@ -21,30 +21,56 @@
|
||||
#include "plugindata.h"
|
||||
|
||||
|
||||
// plugin arguments
|
||||
struct Arg
|
||||
/*
|
||||
all your plugin functions can have signature either:
|
||||
void my_function(PluginInfo & info); or
|
||||
void my_function();
|
||||
|
||||
only the main Init should have:
|
||||
extern "C" void Init(PluginFunction & info);
|
||||
|
||||
in the Init you can add your own functions by using plugin.Assign() method
|
||||
and you can set the name of the plugin by setting info.p1 pointer
|
||||
to a string buffer (const char *)
|
||||
(this buffer will not be copied so it should not be destroyed after Init finishes)
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
struct PluginInfo
|
||||
{
|
||||
void * app; // used for some purposes
|
||||
void * app2; // used for some purposes
|
||||
void * app3; // used for some purposes
|
||||
// these variables are used for some purposes
|
||||
// depending on a hook in which they are used
|
||||
void * p1;
|
||||
void * p2;
|
||||
long l1;
|
||||
long l2;
|
||||
|
||||
// unique plugin identifier
|
||||
int plugin_id;
|
||||
|
||||
int plugin_id; // unique plugin identifier
|
||||
// pointer to the plugin session (can be null if not set by the plugin)
|
||||
// you should use WINIX_SESSION_CREATED and WINIX_SESSION_REMOVE
|
||||
// to create your plugin's session data
|
||||
PluginDataBase * plugin_data_base;
|
||||
|
||||
|
||||
PluginDataBase * plugin_data_base; // pointer to the plugin session
|
||||
|
||||
int ret_true; // how many plugins returned true
|
||||
int ret_false; // how many plugins returned false
|
||||
// function return status
|
||||
// default: false (if not set by the plugin)
|
||||
bool ret;
|
||||
|
||||
|
||||
void Clear()
|
||||
{
|
||||
app = 0;
|
||||
app2 = 0;
|
||||
app3 = 0;
|
||||
ret_true = 0;
|
||||
ret_false = 0;
|
||||
p1 = 0;
|
||||
p2 = 0;
|
||||
l1 = 0;
|
||||
l2 = 0;
|
||||
|
||||
plugin_id = -1;
|
||||
plugin_data_base = 0;
|
||||
|
||||
ret = false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -58,46 +84,73 @@ public:
|
||||
// normally: -1
|
||||
int current_plugin;
|
||||
|
||||
// Fun is a type of a function you should provide in your plugin
|
||||
typedef void (*Fun1)(PluginInfo &);
|
||||
typedef void (*Fun2)(void);
|
||||
|
||||
// !! zmienic sygnature funkcji (niech nie zwraca zadnej wartosci, bo to tylko wkurwia)
|
||||
// albo dodac jeszcze inna sygnature (niech nie pobiera zadnego argumentu)
|
||||
typedef bool (*Fun)(Arg *);
|
||||
|
||||
//typedef void (*Fun2)();
|
||||
|
||||
struct Slot
|
||||
{
|
||||
Fun fun;
|
||||
// Fun2 fun2; // dla drugiej sygnatury
|
||||
int index; // plugin index
|
||||
Fun1 fun1;
|
||||
Fun2 fun2;
|
||||
int index; // plugin index (which plugin has inserted the slot)
|
||||
bool is_running;
|
||||
|
||||
Slot()
|
||||
{
|
||||
fun1 = 0;
|
||||
fun2 = 0;
|
||||
index = -1;
|
||||
is_running = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Plugin();
|
||||
~Plugin();
|
||||
|
||||
void LoadPlugin(const char * filename);
|
||||
void LoadPlugin(const std::string & filename);
|
||||
void LoadPlugins(const std::vector<std::string> & plugins);
|
||||
|
||||
void UnloadPlugins();
|
||||
|
||||
Arg * Call(int message, void * a=0, void * a2=0, void * a3=0);
|
||||
void Call(int message);
|
||||
void Call(int message, void * p1_);
|
||||
void Call(int message, void * p1_, void * p2_);
|
||||
void Call(int message, long l1_);
|
||||
void Call(int message, long l1_, long l2_);
|
||||
void Call(int message, void * p1_, long l1_);
|
||||
void Call(int message, void * p1_, long l1_, long l2_);
|
||||
void Call(int message, void * p1_, void * p2_, long l1_);
|
||||
void Call(int message, void * p1_, void * p2_, long l1_, long l2_);
|
||||
|
||||
// how many plugins there are
|
||||
size_t Size();
|
||||
|
||||
void Assign(int message, Fun);
|
||||
|
||||
// assign a function to a message
|
||||
// you can assign more than one function to a specific message
|
||||
void Assign(int message, Fun1);
|
||||
void Assign(int message, Fun2);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
typedef std::vector<void*> Plugins;
|
||||
struct PluginsItem
|
||||
{
|
||||
void * handle;
|
||||
const char * plugin_name; // plugin name (can be null if was not set by the plugin)
|
||||
};
|
||||
|
||||
typedef std::vector<PluginsItem> Plugins;
|
||||
Plugins plugins;
|
||||
|
||||
typedef std::multimap<int, Slot> Slots;
|
||||
Slots slots;
|
||||
|
||||
Arg arg;
|
||||
|
||||
PluginInfo info;
|
||||
|
||||
void * LoadInitFun(const char * filename, Fun1 & fun_init);
|
||||
void Call(int message, Slots::iterator & slot);
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user