winix/core/plugin.h

110 lines
1.8 KiB
C++
Executable File

/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmsluplugin
#define headerfilecmsluplugin
#include <vector>
#include <string>
#include <map>
#include "request.h"
#include "data.h"
#include "pluginmsg.h"
#include "log.h"
#include "plugindata.h"
// plugin arguments
struct Arg
{
void * app; // used for some purposes
void * app2; // used for some purposes
void * app3; // used for some purposes
int plugin_id; // unique plugin identifier
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
void Clear()
{
app = 0;
app2 = 0;
app3 = 0;
ret_true = 0;
ret_false = 0;
plugin_data_base = 0;
}
};
class Plugin
{
public:
// index of a plugin which is called by Call() method
// normally: -1
int current_plugin;
// !! 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
};
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);
size_t Size();
void Assign(int message, Fun);
private:
typedef std::vector<void*> Plugins;
Plugins plugins;
typedef std::multimap<int, Slot> Slots;
Slots slots;
Arg arg;
};
extern Plugin plugin;
#endif