2009-11-13 21:40:11 +01:00
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
* This file is a part of Winix
|
2014-10-04 20:04:03 +02:00
|
|
|
* and is distributed under the 2-Clause BSD licence.
|
|
|
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2018-11-21 12:03:53 +01:00
|
|
|
* Copyright (c) 2008-2018, Tomasz Sowa
|
2009-11-13 21:40:11 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2014-10-04 20:04:03 +02:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2009-11-13 21:40:11 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <dlfcn.h>
|
2010-10-11 22:42:49 +02:00
|
|
|
#include <string.h>
|
2009-11-13 21:40:11 +01:00
|
|
|
#include "plugin.h"
|
2010-11-21 01:19:17 +01:00
|
|
|
#include "misc.h"
|
2018-11-21 12:03:53 +01:00
|
|
|
#include "system.h"
|
|
|
|
#include "sessionmanager.h"
|
|
|
|
#include "functions/functions.h"
|
|
|
|
#include "templates/templates.h"
|
2018-11-21 18:51:15 +01:00
|
|
|
#include "winixrequest.h"
|
|
|
|
|
2009-11-13 21:40:11 +01:00
|
|
|
|
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
namespace Winix
|
|
|
|
{
|
|
|
|
|
2009-11-13 21:40:11 +01:00
|
|
|
|
2018-11-21 18:51:15 +01:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* PluginInfo
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
void PluginInfo::set_dependency_for(WinixBase * winix_base)
|
|
|
|
{
|
|
|
|
plugin->SetDependencyFor(winix_base);
|
|
|
|
}
|
|
|
|
|
2019-01-02 12:33:19 +01:00
|
|
|
void PluginInfo::set_dependency_for(WinixBase & winix_base)
|
|
|
|
{
|
|
|
|
set_dependency_for(&winix_base);
|
|
|
|
}
|
|
|
|
|
2021-06-16 18:07:44 +02:00
|
|
|
void PluginInfo::set_dependency_for(WinixModelDeprecated * winix_model)
|
2019-01-02 12:33:19 +01:00
|
|
|
{
|
|
|
|
plugin->SetDependencyFor(winix_model);
|
2021-02-24 01:19:47 +01:00
|
|
|
|
|
|
|
//model_connector = winix_model->get_model_connector();
|
|
|
|
// CHECKME what about model_connector here?
|
2019-01-02 12:33:19 +01:00
|
|
|
}
|
|
|
|
|
2021-06-16 18:07:44 +02:00
|
|
|
void PluginInfo::set_dependency_for(WinixModelDeprecated & winix_model)
|
2019-01-02 12:33:19 +01:00
|
|
|
{
|
|
|
|
set_dependency_for(&winix_model);
|
|
|
|
}
|
|
|
|
|
2018-11-21 18:51:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Plugin
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-11-13 21:40:11 +01:00
|
|
|
|
|
|
|
void Plugin::UnloadPlugins()
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
slots.clear();
|
|
|
|
|
|
|
|
for(i=0 ; i<plugins.size() ; ++i)
|
2010-07-27 22:41:56 +02:00
|
|
|
dlclose(plugins[i].handle);
|
2009-11-13 21:40:11 +01:00
|
|
|
|
|
|
|
plugins.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Plugin::Plugin()
|
|
|
|
{
|
2011-01-20 19:37:51 +01:00
|
|
|
current_plugin = -1;
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2018-11-21 12:03:53 +01:00
|
|
|
db = nullptr;
|
|
|
|
cur = nullptr;
|
|
|
|
system = nullptr;
|
|
|
|
functions = nullptr;
|
|
|
|
templates = nullptr;
|
|
|
|
session_manager = nullptr;
|
2018-11-21 18:51:15 +01:00
|
|
|
winix_request = nullptr;
|
2009-11-13 21:40:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Plugin::~Plugin()
|
|
|
|
{
|
|
|
|
UnloadPlugins();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
void Plugin::SetDb(Db * pdb)
|
|
|
|
{
|
|
|
|
db = pdb;
|
|
|
|
}
|
|
|
|
|
2018-11-21 12:03:53 +01:00
|
|
|
//void Plugin::SetConfig(Config * pconfig)
|
|
|
|
//{
|
|
|
|
// config = pconfig;
|
|
|
|
//}
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
void Plugin::SetCur(Cur * pcur)
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
cur = pcur;
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Plugin::SetSystem(System * psystem)
|
|
|
|
{
|
|
|
|
system = psystem;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Plugin::SetFunctions(Functions * pfunctions)
|
|
|
|
{
|
|
|
|
functions = pfunctions;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Plugin::SetTemplates(Templates * ptemplates)
|
|
|
|
{
|
|
|
|
templates = ptemplates;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-21 12:03:53 +01:00
|
|
|
//void Plugin::SetSynchro(Synchro * psynchro)
|
|
|
|
//{
|
|
|
|
// synchro = psynchro;
|
|
|
|
//}
|
2010-12-06 01:25:46 +01:00
|
|
|
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
void Plugin::SetSessionManager(SessionManager * psession_manager)
|
|
|
|
{
|
|
|
|
session_manager = psession_manager;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-21 18:51:15 +01:00
|
|
|
void Plugin::SetWinixRequest(WinixRequest * winix_request)
|
2018-11-21 12:03:53 +01:00
|
|
|
{
|
2018-11-21 18:51:15 +01:00
|
|
|
this->winix_request = winix_request;
|
2018-11-21 12:03:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-23 22:52:25 +01:00
|
|
|
|
2012-04-28 22:57:57 +02:00
|
|
|
void Plugin::Lock()
|
|
|
|
{
|
|
|
|
if( synchro )
|
|
|
|
synchro->Lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Plugin::Unlock()
|
|
|
|
{
|
|
|
|
if( synchro )
|
|
|
|
synchro->Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-11-23 22:52:25 +01:00
|
|
|
|
2018-11-21 12:03:53 +01:00
|
|
|
bool Plugin::SetDependency(PluginInfo & info)
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
|
|
|
// for safety we call a plugin function only when all our pointers are not null
|
2018-11-21 18:51:15 +01:00
|
|
|
bool res = (db && config && cur && system && functions && templates && synchro && session_manager && winix_request);
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
if( !res )
|
2012-04-28 22:57:57 +02:00
|
|
|
{
|
2010-08-10 18:12:50 +02:00
|
|
|
log << log1 << "Plugin: cannot call a function - some of the winix pointers are null" << logend;
|
2012-04-28 22:57:57 +02:00
|
|
|
}
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
info.db = db;
|
|
|
|
info.config = config;
|
2011-01-23 15:15:30 +01:00
|
|
|
info.cur = cur;
|
2010-08-10 18:12:50 +02:00
|
|
|
info.system = system;
|
|
|
|
info.functions = functions;
|
|
|
|
info.templates = templates;
|
2010-12-06 01:25:46 +01:00
|
|
|
info.synchro = synchro;
|
2010-08-10 18:12:50 +02:00
|
|
|
info.session_manager = session_manager;
|
2018-11-21 12:03:53 +01:00
|
|
|
info.plugin = this;
|
2018-11-21 18:51:15 +01:00
|
|
|
|
2021-04-09 17:50:58 +02:00
|
|
|
/*
|
|
|
|
* FIXME
|
|
|
|
* if we call a message from a different thread then a different model connector is needed
|
|
|
|
* (each thread should have its own model connector)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
info.model_connector = system->get_model_connector();
|
|
|
|
|
2018-11-21 12:03:53 +01:00
|
|
|
info.log.SetDependency(&log);
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-01-02 12:33:19 +01:00
|
|
|
|
2018-11-21 18:51:15 +01:00
|
|
|
void Plugin::SetDependencyFor(WinixBase * winix_base)
|
|
|
|
{
|
|
|
|
winix_base->set_dependency(winix_request);
|
|
|
|
}
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2021-06-16 18:07:44 +02:00
|
|
|
void Plugin::SetDependencyFor(WinixModelDeprecated * winix_model)
|
2019-01-02 12:33:19 +01:00
|
|
|
{
|
|
|
|
winix_model->set_dependency(winix_request);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
void Plugin::LoadPlugins(const std::wstring & plugins_dir, const std::vector<std::wstring> & plugins)
|
2009-11-13 21:40:11 +01:00
|
|
|
{
|
2010-08-18 00:32:47 +02:00
|
|
|
for(size_t i=0 ; i<plugins.size() ; ++i)
|
|
|
|
{
|
|
|
|
if( !plugins[i].empty() && plugins[i][0] == '/' )
|
|
|
|
{
|
|
|
|
LoadPlugin(plugins[i]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
temp_path = plugins_dir;
|
|
|
|
temp_path += '/';
|
|
|
|
temp_path += plugins[i];
|
2010-08-18 01:48:42 +02:00
|
|
|
LoadPlugin(temp_path);
|
2010-08-18 00:32:47 +02:00
|
|
|
}
|
|
|
|
}
|
2009-11-13 21:40:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-09 22:44:56 +02:00
|
|
|
// we don't have to use Lock() here because plugins are read
|
2012-04-28 22:57:57 +02:00
|
|
|
// before threads are started
|
2014-10-09 22:44:56 +02:00
|
|
|
void * Plugin::LoadInitFun(const wchar_t * filename, Fun1 & fun_init)
|
2009-11-13 21:40:11 +01:00
|
|
|
{
|
2014-10-09 22:44:56 +02:00
|
|
|
char file[WINIX_OS_PATH_SIZE];
|
|
|
|
|
2021-05-21 00:41:27 +02:00
|
|
|
if( !wide_to_utf8(filename, file, WINIX_OS_PATH_SIZE) )
|
2014-10-09 22:44:56 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
void * p = dlopen(file, RTLD_NOW | RTLD_LOCAL);
|
2009-11-13 21:40:11 +01:00
|
|
|
|
|
|
|
if( !p )
|
|
|
|
{
|
2010-08-10 18:12:50 +02:00
|
|
|
log << log1 << "Plugin: cannot load a plugin: \"" << filename << "\"" << logend;
|
|
|
|
log << log1 << "Plugin: dlerror: " << dlerror() << logend;
|
2010-07-27 22:41:56 +02:00
|
|
|
return 0;
|
2009-11-13 21:40:11 +01:00
|
|
|
}
|
|
|
|
|
2014-02-12 18:21:42 +01:00
|
|
|
fun_init = (Fun1)dlsym(p, "Init");
|
2009-11-13 21:40:11 +01:00
|
|
|
|
2010-07-27 22:41:56 +02:00
|
|
|
if( !fun_init )
|
2009-11-13 21:40:11 +01:00
|
|
|
{
|
2010-07-27 22:41:56 +02:00
|
|
|
log << log1 << "Plugin: cannot load a plugin: " << filename
|
|
|
|
<< " (there is no Init() function)" << logend;
|
|
|
|
|
2009-11-13 21:40:11 +01:00
|
|
|
dlclose(p);
|
2010-07-27 22:41:56 +02:00
|
|
|
return 0;
|
2009-11-13 21:40:11 +01:00
|
|
|
}
|
2010-05-04 23:58:22 +02:00
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
log << log2 << "Plugin: plugin loaded"
|
2010-07-27 22:41:56 +02:00
|
|
|
<< ", file: " << filename
|
|
|
|
<< ", index: " << plugins.size() << logend;
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-09 22:44:56 +02:00
|
|
|
void Plugin::LoadPlugin(const wchar_t * filename)
|
2010-07-27 22:41:56 +02:00
|
|
|
{
|
|
|
|
Fun1 fun_init;
|
|
|
|
void * plugin_handle;
|
|
|
|
int old_current_plugin;
|
2011-01-24 00:23:24 +01:00
|
|
|
PluginInfo info;
|
2010-07-27 22:41:56 +02:00
|
|
|
|
2018-11-21 12:03:53 +01:00
|
|
|
if( !SetDependency(info) )
|
2010-08-10 18:12:50 +02:00
|
|
|
return;
|
|
|
|
|
2010-07-27 22:41:56 +02:00
|
|
|
if( !(plugin_handle = LoadInitFun(filename, fun_init)) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
info.Clear();
|
|
|
|
old_current_plugin = current_plugin;
|
|
|
|
current_plugin = (int)plugins.size();
|
|
|
|
info.plugin_id = current_plugin;
|
|
|
|
|
|
|
|
fun_init(info);
|
|
|
|
|
|
|
|
PluginsItem item;
|
|
|
|
item.handle = plugin_handle;
|
2010-11-21 01:19:17 +01:00
|
|
|
item.plugin_name = reinterpret_cast<const wchar_t *>(info.p1);
|
2010-05-04 23:58:22 +02:00
|
|
|
|
2010-07-27 22:41:56 +02:00
|
|
|
plugins.push_back(item);
|
2010-05-04 23:58:22 +02:00
|
|
|
|
2010-07-27 22:41:56 +02:00
|
|
|
current_plugin = old_current_plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
void Plugin::LoadPlugin(const std::wstring & filename)
|
|
|
|
{
|
|
|
|
LoadPlugin(filename.c_str());
|
|
|
|
}
|
|
|
|
|
2010-07-27 22:41:56 +02:00
|
|
|
|
2014-10-09 22:44:56 +02:00
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
bool Plugin::HasPlugin(const wchar_t * name)
|
2010-10-11 22:42:49 +02:00
|
|
|
{
|
|
|
|
if( *name == 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for(size_t i=0 ; i<plugins.size() ; ++i)
|
|
|
|
{
|
2010-11-21 01:19:17 +01:00
|
|
|
if( plugins[i].plugin_name && Equal(plugins[i].plugin_name, name) )
|
2010-10-11 22:42:49 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
bool Plugin::HasPlugin(const std::wstring & name)
|
2010-10-11 22:42:49 +02:00
|
|
|
{
|
|
|
|
return HasPlugin(name.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-13 08:08:34 +02:00
|
|
|
bool Plugin::HasMessage(int message)
|
|
|
|
{
|
|
|
|
return (slots.find(message) != slots.end());
|
|
|
|
}
|
|
|
|
|
2010-10-11 22:42:49 +02:00
|
|
|
|
2012-03-17 06:11:23 +01:00
|
|
|
void Plugin::Call(Session * ses, int message, Slots::iterator & slot, PluginInfo & info)
|
2010-07-27 22:41:56 +02:00
|
|
|
{
|
2018-11-21 12:03:53 +01:00
|
|
|
if( !SetDependency(info) )
|
2010-08-10 18:12:50 +02:00
|
|
|
return;
|
|
|
|
|
2010-07-27 22:41:56 +02:00
|
|
|
current_plugin = slot->second.index;
|
|
|
|
info.plugin_id = current_plugin;
|
2012-03-17 06:11:23 +01:00
|
|
|
info.session = ses;
|
2010-07-27 22:41:56 +02:00
|
|
|
|
2012-03-17 06:11:23 +01:00
|
|
|
if( current_plugin != -1 && ses )
|
|
|
|
info.plugin_data_base = ses->plugin_data.Get(current_plugin);
|
2010-07-27 22:41:56 +02:00
|
|
|
else
|
|
|
|
info.plugin_data_base = 0;
|
|
|
|
|
|
|
|
if( !slot->second.is_running )
|
2009-11-13 21:40:11 +01:00
|
|
|
{
|
2010-11-23 22:52:25 +01:00
|
|
|
if( config->log_plugin_call )
|
2012-04-28 22:57:57 +02:00
|
|
|
{
|
2011-01-05 22:24:11 +01:00
|
|
|
log << log1 << "Plugin: calling plugin id: " << slot->second.index << ", message: " << message << logend;
|
2012-04-28 22:57:57 +02:00
|
|
|
}
|
2010-11-23 22:52:25 +01:00
|
|
|
|
2010-07-27 22:41:56 +02:00
|
|
|
slot->second.is_running = true;
|
|
|
|
|
|
|
|
if( slot->second.fun1 )
|
|
|
|
slot->second.fun1(info);
|
|
|
|
|
|
|
|
if( slot->second.fun2 )
|
|
|
|
slot->second.fun2();
|
|
|
|
|
|
|
|
slot->second.is_running = false;
|
2010-11-23 22:52:25 +01:00
|
|
|
|
|
|
|
if( config->log_plugin_call )
|
2012-04-28 22:57:57 +02:00
|
|
|
{
|
2012-03-14 21:25:30 +01:00
|
|
|
log << log1 << "Plugin: returning from plugin id: " << slot->second.index << ", message: " << message
|
|
|
|
<< ", result: " << (info.res? "true" : "false") << logend;
|
2012-04-28 22:57:57 +02:00
|
|
|
}
|
2010-11-23 22:52:25 +01:00
|
|
|
|
2009-11-13 21:40:11 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-27 22:41:56 +02:00
|
|
|
log << log1 << "Plugin: id: " << slot->second.index
|
|
|
|
<< ", message: " << message
|
|
|
|
<< ", recurrences are not allowed" << logend;
|
2009-11-13 21:40:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-20 19:37:51 +01:00
|
|
|
|
2012-04-22 15:30:07 +02:00
|
|
|
PluginRes Plugin::Call(Session * ses, int message, void * p1_, void * p2_, long l1_, long l2_)
|
2009-11-13 21:40:11 +01:00
|
|
|
{
|
2012-04-22 15:30:07 +02:00
|
|
|
PluginRes res;
|
2011-01-20 19:37:51 +01:00
|
|
|
int old_current_plugin = current_plugin;
|
2011-01-24 00:23:24 +01:00
|
|
|
PluginInfo info;
|
2011-01-20 19:37:51 +01:00
|
|
|
|
2009-11-13 21:40:11 +01:00
|
|
|
Slots::iterator i = slots.lower_bound(message);
|
2010-05-04 23:58:22 +02:00
|
|
|
|
2009-11-13 21:40:11 +01:00
|
|
|
for( ; i!=slots.end() && i->first==message ; ++i )
|
|
|
|
{
|
2010-07-27 22:41:56 +02:00
|
|
|
info.Clear();
|
|
|
|
info.p1 = p1_;
|
|
|
|
info.p2 = p2_;
|
|
|
|
info.l1 = l1_;
|
|
|
|
info.l2 = l2_;
|
|
|
|
|
2012-03-17 06:11:23 +01:00
|
|
|
Call(ses, message, i, info);
|
2011-01-20 19:37:51 +01:00
|
|
|
|
|
|
|
if( info.res )
|
2012-04-22 15:30:07 +02:00
|
|
|
++res.res_true;
|
2011-01-20 19:37:51 +01:00
|
|
|
else
|
2012-04-22 15:30:07 +02:00
|
|
|
++res.res_false;
|
2009-11-13 21:40:11 +01:00
|
|
|
}
|
|
|
|
|
2010-05-04 23:58:22 +02:00
|
|
|
current_plugin = old_current_plugin;
|
2012-04-22 15:30:07 +02:00
|
|
|
|
|
|
|
return res;
|
2010-07-27 22:41:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-22 15:30:07 +02:00
|
|
|
PluginRes Plugin::Call(int message)
|
2010-07-27 22:41:56 +02:00
|
|
|
{
|
2012-04-22 15:30:07 +02:00
|
|
|
return Call(cur->session, message, 0, 0, 0, 0);
|
2010-07-27 22:41:56 +02:00
|
|
|
}
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2012-04-22 15:30:07 +02:00
|
|
|
PluginRes Plugin::Call(int message, void * p1_)
|
2010-07-27 22:41:56 +02:00
|
|
|
{
|
2012-04-22 15:30:07 +02:00
|
|
|
return Call(cur->session, message, p1_, 0, 0, 0);
|
2010-07-27 22:41:56 +02:00
|
|
|
}
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2012-04-22 15:30:07 +02:00
|
|
|
PluginRes Plugin::Call(int message, void * p1_, void * p2_)
|
2010-07-27 22:41:56 +02:00
|
|
|
{
|
2012-04-22 15:30:07 +02:00
|
|
|
return Call(cur->session, message, p1_, p2_, 0, 0);
|
2010-07-27 22:41:56 +02:00
|
|
|
}
|
2010-05-04 23:58:22 +02:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2012-04-22 15:30:07 +02:00
|
|
|
PluginRes Plugin::Call(int message, long l1_)
|
2010-07-27 22:41:56 +02:00
|
|
|
{
|
2012-04-22 15:30:07 +02:00
|
|
|
return Call(cur->session, message, 0, 0, l1_, 0);
|
2009-11-13 21:40:11 +01:00
|
|
|
}
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2012-04-22 15:30:07 +02:00
|
|
|
PluginRes Plugin::Call(int message, long l1_, long l2_)
|
2010-07-27 22:41:56 +02:00
|
|
|
{
|
2012-04-22 15:30:07 +02:00
|
|
|
return Call(cur->session, message, 0, 0, l1_, l2_);
|
2010-07-27 22:41:56 +02:00
|
|
|
}
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2012-04-22 15:30:07 +02:00
|
|
|
PluginRes Plugin::Call(int message, void * p1_, long l1_)
|
2010-07-27 22:41:56 +02:00
|
|
|
{
|
2012-04-22 15:30:07 +02:00
|
|
|
return Call(cur->session, message, p1_, 0, l1_, 0);
|
2010-07-27 22:41:56 +02:00
|
|
|
}
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2012-04-22 15:30:07 +02:00
|
|
|
PluginRes Plugin::Call(int message, void * p1_, long l1_, long l2_)
|
2010-07-27 22:41:56 +02:00
|
|
|
{
|
2012-04-22 15:30:07 +02:00
|
|
|
return Call(cur->session, message, p1_, 0, l1_, l2_);
|
2010-07-27 22:41:56 +02:00
|
|
|
}
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2012-04-22 15:30:07 +02:00
|
|
|
PluginRes Plugin::Call(int message, void * p1_, void * p2_, long l1_)
|
2010-07-27 22:41:56 +02:00
|
|
|
{
|
2012-04-22 15:30:07 +02:00
|
|
|
return Call(cur->session, message, p1_, p2_, l1_, 0);
|
2010-07-27 22:41:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 06:11:23 +01:00
|
|
|
|
2012-04-22 15:30:07 +02:00
|
|
|
PluginRes Plugin::Call(Session * ses, int message)
|
2012-03-17 06:11:23 +01:00
|
|
|
{
|
2012-04-22 15:30:07 +02:00
|
|
|
return Call(ses, message, 0, 0, 0, 0);
|
2012-03-17 06:11:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-22 15:30:07 +02:00
|
|
|
PluginRes Plugin::Call(Session * ses, int message, void * p1_)
|
2012-03-17 06:11:23 +01:00
|
|
|
{
|
2012-04-22 15:30:07 +02:00
|
|
|
return Call(ses, message, p1_, 0, 0, 0);
|
2012-03-17 06:11:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-22 15:30:07 +02:00
|
|
|
PluginRes Plugin::Call(Session * ses, int message, void * p1_, void * p2_)
|
2012-03-17 06:11:23 +01:00
|
|
|
{
|
2012-04-22 15:30:07 +02:00
|
|
|
return Call(ses, message, p1_, p2_, 0, 0);
|
2012-03-17 06:11:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-22 15:30:07 +02:00
|
|
|
PluginRes Plugin::Call(Session * ses, int message, long l1_)
|
2012-03-17 06:11:23 +01:00
|
|
|
{
|
2012-04-22 15:30:07 +02:00
|
|
|
return Call(ses, message, 0, 0, l1_, 0);
|
2012-03-17 06:11:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-22 15:30:07 +02:00
|
|
|
PluginRes Plugin::Call(Session * ses, int message, long l1_, long l2_)
|
2012-03-17 06:11:23 +01:00
|
|
|
{
|
2012-04-22 15:30:07 +02:00
|
|
|
return Call(ses, message, 0, 0, l1_, l2_);
|
2012-03-17 06:11:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-22 15:30:07 +02:00
|
|
|
PluginRes Plugin::Call(Session * ses, int message, void * p1_, long l1_)
|
2012-03-17 06:11:23 +01:00
|
|
|
{
|
2012-04-22 15:30:07 +02:00
|
|
|
return Call(ses, message, p1_, 0, l1_, 0);
|
2012-03-17 06:11:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-22 15:30:07 +02:00
|
|
|
PluginRes Plugin::Call(Session * ses, int message, void * p1_, long l1_, long l2_)
|
2012-03-17 06:11:23 +01:00
|
|
|
{
|
2012-04-22 15:30:07 +02:00
|
|
|
return Call(ses, message, p1_, 0, l1_, l2_);
|
2012-03-17 06:11:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-22 15:30:07 +02:00
|
|
|
PluginRes Plugin::Call(Session * ses, int message, void * p1_, void * p2_, long l1_)
|
2012-03-17 06:11:23 +01:00
|
|
|
{
|
2012-04-22 15:30:07 +02:00
|
|
|
return Call(ses, message, p1_, p2_, l1_, 0);
|
2012-03-17 06:11:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-05-04 23:58:22 +02:00
|
|
|
size_t Plugin::Size()
|
|
|
|
{
|
|
|
|
return plugins.size();
|
|
|
|
}
|
2009-11-13 21:40:11 +01:00
|
|
|
|
|
|
|
|
2012-04-22 15:30:07 +02:00
|
|
|
/*
|
2012-04-28 22:57:57 +02:00
|
|
|
!! IMPROVE ME
|
|
|
|
Assign() can work only if other threads are not started
|
|
|
|
we can add some barrier/flag so when other threads starts
|
|
|
|
then we cannot use Assign() method
|
2012-04-22 15:30:07 +02:00
|
|
|
*/
|
2010-07-27 22:41:56 +02:00
|
|
|
void Plugin::Assign(int message, Fun1 fun1)
|
2009-11-13 21:40:11 +01:00
|
|
|
{
|
2010-07-27 22:41:56 +02:00
|
|
|
Slot s;
|
2010-05-04 23:58:22 +02:00
|
|
|
|
2010-11-23 22:52:25 +01:00
|
|
|
if( current_plugin == -1 )
|
|
|
|
return;
|
|
|
|
|
2010-07-27 22:41:56 +02:00
|
|
|
s.fun1 = fun1;
|
2010-05-04 23:58:22 +02:00
|
|
|
s.index = current_plugin;
|
|
|
|
|
|
|
|
slots.insert( std::make_pair(message, s) );
|
2010-07-27 22:41:56 +02:00
|
|
|
log << log3 << "Plugin: added function for message: " << message << ", plugin index: " << s.index << logend;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Plugin::Assign(int message, Fun2 fun2)
|
|
|
|
{
|
|
|
|
Slot s;
|
2010-05-04 23:58:22 +02:00
|
|
|
|
2010-11-23 22:52:25 +01:00
|
|
|
if( current_plugin == -1 )
|
|
|
|
return;
|
|
|
|
|
2010-07-27 22:41:56 +02:00
|
|
|
s.fun2 = fun2;
|
|
|
|
s.index = current_plugin;
|
|
|
|
|
|
|
|
slots.insert( std::make_pair(message, s) );
|
2010-05-04 23:58:22 +02:00
|
|
|
log << log3 << "Plugin: added function for message: " << message << ", plugin index: " << s.index << logend;
|
2009-11-13 21:40:11 +01:00
|
|
|
}
|
2010-07-27 22:41:56 +02:00
|
|
|
|
2011-06-27 23:38:19 +02:00
|
|
|
|
|
|
|
const Plugin::Plugins * Plugin::GetPlugins()
|
|
|
|
{
|
|
|
|
return &plugins;
|
|
|
|
}
|
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
|
2018-11-21 18:51:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
} // namespace Winix
|
|
|
|
|