Added capability for plugins to request early init order.
git-svn-id: http://yate.null.ro/svn/yate/trunk@1496 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
710adaeafd
commit
6063d1b43e
|
@ -762,8 +762,8 @@ const char* Module::messageName(int id)
|
|||
return lookup(id,s_messages);
|
||||
}
|
||||
|
||||
Module::Module(const char* name, const char* type)
|
||||
: Plugin(name), Mutex(true),
|
||||
Module::Module(const char* name, const char* type, bool earlyInit)
|
||||
: Plugin(name,earlyInit), Mutex(true),
|
||||
m_init(false), m_relays(0), m_name(name), m_type(type), m_changed(0)
|
||||
{
|
||||
debugName(m_name);
|
||||
|
|
|
@ -149,6 +149,7 @@ int Engine::s_haltcode = -1;
|
|||
int EnginePrivate::count = 0;
|
||||
static bool s_init = false;
|
||||
static bool s_dynplugin = false;
|
||||
static Engine::PluginMode s_loadMode = Engine::LoadFail;
|
||||
static int s_maxworkers = 10;
|
||||
static bool s_debug = true;
|
||||
|
||||
|
@ -167,10 +168,12 @@ class SLib : public GenObject
|
|||
public:
|
||||
virtual ~SLib();
|
||||
static SLib* load(const char* file, bool local);
|
||||
inline const String& file() const
|
||||
{ return m_file; }
|
||||
private:
|
||||
SLib(HMODULE handle, const char* file);
|
||||
const char* m_file;
|
||||
HMODULE m_handle;
|
||||
String m_file;
|
||||
};
|
||||
|
||||
class EngineSuperHandler : public MessageHandler
|
||||
|
@ -483,8 +486,9 @@ static int supervise(void)
|
|||
}
|
||||
#endif /* _WINDOWS */
|
||||
|
||||
|
||||
SLib::SLib(HMODULE handle, const char* file)
|
||||
: m_handle(handle)
|
||||
: m_handle(handle), m_file(file)
|
||||
{
|
||||
DDebug(DebugAll,"SLib::SLib(%p,'%s') [%p]",handle,file,this);
|
||||
checkPoint();
|
||||
|
@ -548,6 +552,7 @@ SLib* SLib::load(const char* file, bool local)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Engine::Engine()
|
||||
{
|
||||
DDebug(DebugAll,"Engine::Engine() [%p]",this);
|
||||
|
@ -795,7 +800,12 @@ bool Engine::Register(const Plugin* plugin, bool reg)
|
|||
if (reg) {
|
||||
if (p)
|
||||
return false;
|
||||
p = plugins.append(plugin);
|
||||
if (plugin->earlyInit()) {
|
||||
s_loadMode = LoadEarly;
|
||||
p = plugins.insert(plugin);
|
||||
}
|
||||
else
|
||||
p = plugins.append(plugin);
|
||||
p->setDelete(s_dynplugin);
|
||||
}
|
||||
else if (p)
|
||||
|
@ -806,15 +816,32 @@ bool Engine::Register(const Plugin* plugin, bool reg)
|
|||
bool Engine::loadPlugin(const char* file, bool local)
|
||||
{
|
||||
s_dynplugin = false;
|
||||
s_loadMode = Engine::LoadLate;
|
||||
SLib *lib = SLib::load(file,local);
|
||||
s_dynplugin = true;
|
||||
if (lib) {
|
||||
m_libs.append(lib);
|
||||
switch (s_loadMode) {
|
||||
case LoadFail:
|
||||
delete lib;
|
||||
return false;
|
||||
case LoadEarly:
|
||||
// load early - unload late
|
||||
m_libs.append(lib);
|
||||
break;
|
||||
default:
|
||||
m_libs.insert(lib);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Engine::pluginMode(PluginMode mode)
|
||||
{
|
||||
s_loadMode = mode;
|
||||
}
|
||||
|
||||
bool Engine::loadPluginDir(const String& relPath)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
|
|
|
@ -25,14 +25,16 @@
|
|||
using namespace TelEngine;
|
||||
|
||||
Plugin::Plugin()
|
||||
: m_early(false)
|
||||
{
|
||||
Debug(DebugAll,"Plugin::Plugin() [%p]",this);
|
||||
Engine::Register(this);
|
||||
}
|
||||
|
||||
Plugin::Plugin(const char* name)
|
||||
Plugin::Plugin(const char* name, bool earlyInit)
|
||||
: m_early(earlyInit)
|
||||
{
|
||||
Debug(DebugAll,"Plugin::Plugin(\"%s\") [%p]",name,this);
|
||||
Debug(DebugAll,"Plugin::Plugin(\"%s\",%s) [%p]",name,String::boolText(earlyInit),this);
|
||||
Engine::Register(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -88,17 +88,24 @@ class CdrFilePlugin : public Plugin
|
|||
{
|
||||
public:
|
||||
CdrFilePlugin();
|
||||
~CdrFilePlugin();
|
||||
virtual void initialize();
|
||||
private:
|
||||
CdrFileHandler *m_handler;
|
||||
};
|
||||
|
||||
CdrFilePlugin::CdrFilePlugin()
|
||||
: m_handler(0)
|
||||
: Plugin("cdrfile",true),
|
||||
m_handler(0)
|
||||
{
|
||||
Output("Loaded module CdrFile");
|
||||
}
|
||||
|
||||
CdrFilePlugin::~CdrFilePlugin()
|
||||
{
|
||||
Output("Unloading module CdrFile");
|
||||
}
|
||||
|
||||
void CdrFilePlugin::initialize()
|
||||
{
|
||||
Output("Initializing module CdrFile");
|
||||
|
|
|
@ -338,15 +338,15 @@ bool MyHandler::received(Message& msg)
|
|||
}
|
||||
|
||||
MyModule::MyModule()
|
||||
: Module ("mysqldb","database"),m_init(false)
|
||||
: Module ("mysqldb","database",true),m_init(false)
|
||||
{
|
||||
Output("Loaded module MySQL based on %s",mysql_get_client_info());
|
||||
}
|
||||
|
||||
MyModule::~MyModule()
|
||||
{
|
||||
Output("Unloading module MySQL");
|
||||
s_conns.clear();
|
||||
Output("Unloaded module MySQL");
|
||||
}
|
||||
|
||||
void MyModule::statusParams(String& str)
|
||||
|
|
|
@ -337,7 +337,7 @@ bool PgHandler::received(Message& msg)
|
|||
}
|
||||
|
||||
PgModule::PgModule()
|
||||
: Module ("pgsqldb","database"),m_init(false)
|
||||
: Module ("pgsqldb","database",true),m_init(false)
|
||||
{
|
||||
Output("Loaded module PostgreSQL");
|
||||
}
|
||||
|
|
31
yatengine.h
31
yatengine.h
|
@ -633,8 +633,9 @@ public:
|
|||
/**
|
||||
* Creates a new Plugin container.
|
||||
* @param name the undecorated name of the library that contains the plugin
|
||||
* @param earlyInit True to initialize the plugin early
|
||||
*/
|
||||
Plugin(const char* name);
|
||||
Plugin(const char* name, bool earlyInit = false);
|
||||
|
||||
/**
|
||||
* Creates a new Plugin container.
|
||||
|
@ -667,6 +668,16 @@ public:
|
|||
*/
|
||||
virtual bool isBusy() const
|
||||
{ return false; }
|
||||
|
||||
/**
|
||||
* Check if the module is to be initialized early
|
||||
* @return True if the module should be initialized before regular ones
|
||||
*/
|
||||
bool earlyInit() const
|
||||
{ return m_early; }
|
||||
|
||||
private:
|
||||
bool m_early;
|
||||
};
|
||||
|
||||
#if 0 /* for documentation generator */
|
||||
|
@ -699,6 +710,18 @@ public:
|
|||
Server = 3,
|
||||
};
|
||||
|
||||
/**
|
||||
* Plugin load and initialization modes.
|
||||
* Default is LoadLate that initailizes the plugin after others.
|
||||
* LoadEarly will move the plugin to the front of the init order.
|
||||
* LoadFail causes the plugin to be unloaded.
|
||||
*/
|
||||
enum PluginMode {
|
||||
LoadFail = 0,
|
||||
LoadLate,
|
||||
LoadEarly
|
||||
};
|
||||
|
||||
/**
|
||||
* Main entry point to be called directly from a wrapper program
|
||||
* @param argc Argument count
|
||||
|
@ -935,6 +958,12 @@ public:
|
|||
*/
|
||||
bool loadPluginDir(const String& relPath);
|
||||
|
||||
/**
|
||||
* Set the load and init mode of the currently loading @ref Plugin
|
||||
* @param mode Load and init mode, default LoadLate
|
||||
*/
|
||||
static void pluginMode(PluginMode mode);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Destroys the engine and everything. You must not call it directly,
|
||||
|
|
|
@ -1315,8 +1315,9 @@ protected:
|
|||
* Constructor
|
||||
* @param name Plugin name of this driver
|
||||
* @param type Type of the driver: "misc", "route", etc.
|
||||
* @param earlyInit True to attempt to initialize module before others
|
||||
*/
|
||||
Module(const char* name, const char* type = 0);
|
||||
Module(const char* name, const char* type = 0, bool earlyInit = false);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
|
|
Loading…
Reference in New Issue