/* * This file is a part of Winix * and is not publicly distributed * * Copyright (c) 2008-2010, Tomasz Sowa * All rights reserved. * */ #include #include #include "plugin.h" #include "pluginmsg.h" #include "misc.h" void Plugin::UnloadPlugins() { size_t i; slots.clear(); for(i=0 ; i & plugins) { for(size_t i=0 ; i(info.p1); plugins.push_back(item); current_plugin = old_current_plugin; } void Plugin::LoadPlugin(const wchar_t * filename) { AssignString(filename, afilename); LoadPlugin(afilename.c_str()); } void Plugin::LoadPlugin(const std::wstring & filename) { LoadPlugin(filename.c_str()); } bool Plugin::HasPlugin(const wchar_t * name) { if( *name == 0 ) return false; for(size_t i=0 ; isecond.index; info.plugin_id = current_plugin; if( request && request->session && current_plugin != -1 ) info.plugin_data_base = request->session->plugin_data.Get(current_plugin); else info.plugin_data_base = 0; if( !slot->second.is_running ) { if( config->log_plugin_call ) log << log1 << "Plugin: calling plugin id: " << slot->second.index << ", message: " << message << logend; 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; if( config->log_plugin_call ) log << log1 << "Plugin: returning from plugin id: " << slot->second.index << ", message: " << message << logend; } else { log << log1 << "Plugin: id: " << slot->second.index << ", message: " << message << ", recurrences are not allowed" << logend; } } void Plugin::Call(int message, void * p1_, void * p2_, long l1_, long l2_) { // how many plugins return 'false' and 'true' // we are using local variables because Call() method can be called // from a plugin too (one Call() can execute another Call()) int ret_false_loc = 0; int ret_true_loc = 0; int old_current_plugin = current_plugin; Slots::iterator i = slots.lower_bound(message); for( ; i!=slots.end() && i->first==message ; ++i ) { info.Clear(); info.p1 = p1_; info.p2 = p2_; info.l1 = l1_; info.l2 = l2_; Call(message, i); if( info.res ) ++ret_true_loc; else ++ret_false_loc; } current_plugin = old_current_plugin; ret_false = ret_false_loc; ret_true = ret_true_loc; } void Plugin::Call(int message) { Call(message, 0, 0, 0, 0); } void Plugin::Call(int message, void * p1_) { Call(message, p1_, 0, 0, 0); } void Plugin::Call(int message, void * p1_, void * p2_) { Call(message, p1_, p2_, 0, 0); } void Plugin::Call(int message, long l1_) { Call(message, 0, 0, l1_, 0); } void Plugin::Call(int message, long l1_, long l2_) { Call(message, 0, 0, l1_, l2_); } void Plugin::Call(int message, void * p1_, long l1_) { Call(message, p1_, 0, l1_, 0); } void Plugin::Call(int message, void * p1_, long l1_, long l2_) { Call(message, p1_, 0, l1_, l2_); } void Plugin::Call(int message, void * p1_, void * p2_, long l1_) { Call(message, p1_, p2_, l1_, 0); } size_t Plugin::Size() { return plugins.size(); } int Plugin::True() { return ret_true; } int Plugin::False() { return ret_false; } void Plugin::Assign(int message, Fun1 fun1) { Slot s; if( current_plugin == -1 ) return; s.fun1 = fun1; s.index = current_plugin; slots.insert( std::make_pair(message, s) ); log << log3 << "Plugin: added function for message: " << message << ", plugin index: " << s.index << logend; } void Plugin::Assign(int message, Fun2 fun2) { Slot s; if( current_plugin == -1 ) return; s.fun2 = fun2; s.index = current_plugin; slots.insert( std::make_pair(message, s) ); log << log3 << "Plugin: added function for message: " << message << ", plugin index: " << s.index << logend; }