Moved DebugEnabler and name from Module to Plugin, made name mandatory.

Added API and command to reload configuration of a single plugin.


git-svn-id: http://voip.null.ro/svn/yate@4203 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2011-03-23 16:26:25 +00:00
parent dfc831f65e
commit 8e61c980ee
23 changed files with 101 additions and 59 deletions

View File

@ -934,14 +934,12 @@ const char* Module::messageName(int id)
Module::Module(const char* name, const char* type, bool earlyInit) Module::Module(const char* name, const char* type, bool earlyInit)
: Plugin(name,earlyInit), Mutex(true,"Module"), : Plugin(name,earlyInit), Mutex(true,"Module"),
m_init(false), m_relays(0), m_name(name), m_type(type), m_changed(0) m_init(false), m_relays(0), m_type(type), m_changed(0)
{ {
debugName(m_name);
} }
Module::~Module() Module::~Module()
{ {
debugName(0);
} }
void* Module::getObject(const String& name) const void* Module::getObject(const String& name) const
@ -1052,7 +1050,7 @@ void Module::msgTimer(Message& msg)
{ {
if (m_changed && (msg.msgTime() > m_changed)) { if (m_changed && (msg.msgTime() > m_changed)) {
Message* m = new Message("module.update"); Message* m = new Message("module.update");
m->addParam("module",m_name); m->addParam("module",name());
m_changed = 0; m_changed = 0;
genUpdate(*m); genUpdate(*m);
Engine::enqueue(m); Engine::enqueue(m);
@ -1113,7 +1111,7 @@ void Module::msgStatus(Message& msg)
void Module::statusModule(String& str) void Module::statusModule(String& str)
{ {
str.append("name=",",") << m_name; str.append("name=",",") << name();
if (m_type) if (m_type)
str << ",type=" << m_type; str << ",type=" << m_type;
} }
@ -1132,7 +1130,7 @@ void Module::genUpdate(Message& msg)
bool Module::received(Message &msg, int id) bool Module::received(Message &msg, int id)
{ {
if (!m_name) if (name().null())
return false; return false;
switch (id) { switch (id) {
@ -1148,7 +1146,7 @@ bool Module::received(Message &msg, int id)
String dest = msg.getValue("module"); String dest = msg.getValue("module");
if (id == Status) { if (id == Status) {
if (dest == m_name) { if (dest == name()) {
msgStatus(msg); msgStatus(msg);
return true; return true;
} }
@ -1166,7 +1164,7 @@ bool Module::received(Message &msg, int id)
bool Module::setDebug(Message& msg, const String& target) bool Module::setDebug(Message& msg, const String& target)
{ {
if (target != m_name) if (target != name())
return false; return false;
String str = msg.getValue("line"); String str = msg.getValue("line");
@ -1186,7 +1184,7 @@ bool Module::setDebug(Message& msg, const String& target)
str >> dbg; str >> dbg;
debugEnabled(dbg); debugEnabled(dbg);
} }
msg.retValue() << "Module " << m_name msg.retValue() << "Module " << name()
<< " debug " << (debugEnabled() ? "on" : "off") << " debug " << (debugEnabled() ? "on" : "off")
<< " level " << debugLevel(); << " level " << debugLevel();
if (m_filter) if (m_filter)

View File

@ -463,6 +463,12 @@ void EngineCommand::doCompletion(Message &msg, const String& partLine, const Str
completeOne(msg.retValue(),*s,partWord); completeOne(msg.retValue(),*s,partWord);
} }
} }
else if (partLine == "reload") {
for (ObjList* l = plugins.skipNull(); l; l = l->skipNext()) {
const Plugin* p = static_cast<const Plugin*>(l->get());
completeOne(msg.retValue(),p->name(),partWord);
}
}
} }
bool EngineCommand::received(Message &msg) bool EngineCommand::received(Message &msg)
@ -1451,6 +1457,28 @@ void Engine::init()
s_init = true; s_init = true;
} }
bool Engine::init(const String& name)
{
if (exiting() || !s_self)
return false;
if (name.null() || name == "*" || name == "all") {
s_init = true;
return true;
}
Output("Initializing plugin '%s'",name.c_str());
Message msg("engine.init",0,true);
msg.addParam("plugin",name);
if (nodeName())
msg.addParam("nodename",nodeName());
bool ok = s_self->m_dispatcher.dispatch(msg);
Plugin* p = static_cast<Plugin*>(plugins[name]);
if (p) {
p->initialize();
ok = true;
}
return ok;
}
bool Engine::install(MessageHandler* handler) bool Engine::install(MessageHandler* handler)
{ {
return s_self ? s_self->m_dispatcher.install(handler) : false; return s_self ? s_self->m_dispatcher.install(handler) : false;

View File

@ -24,17 +24,11 @@
using namespace TelEngine; using namespace TelEngine;
Plugin::Plugin()
: m_early(false)
{
Debug(DebugAll,"Plugin::Plugin() [%p]",this);
Engine::Register(this);
}
Plugin::Plugin(const char* name, bool earlyInit) Plugin::Plugin(const char* name, bool earlyInit)
: m_early(earlyInit) : m_name(name), m_early(earlyInit)
{ {
Debug(DebugAll,"Plugin::Plugin(\"%s\",%s) [%p]",name,String::boolText(earlyInit),this); Debug(DebugAll,"Plugin::Plugin(\"%s\",%s) [%p]",name,String::boolText(earlyInit),this);
debugName(m_name);
Engine::Register(this); Engine::Register(this);
} }
@ -42,6 +36,7 @@ Plugin::~Plugin()
{ {
Debugger debug("Plugin::~Plugin()"," [%p]",this); Debugger debug("Plugin::~Plugin()"," [%p]",this);
Engine::Register(this,false); Engine::Register(this,false);
debugName(0);
} }
void* Plugin::getObject(const String& name) const void* Plugin::getObject(const String& name) const

View File

@ -360,7 +360,7 @@ bool AmrDecoder::pushData(unsigned long& tStamp)
// Plugin and translator factory // Plugin and translator factory
AmrPlugin::AmrPlugin() AmrPlugin::AmrPlugin()
: TranslatorFactory("amr-nb") : Plugin("amrnbcodec"), TranslatorFactory("amr-nb")
{ {
Output("Loaded module AMR-NB codec - based on 3GPP code"); Output("Loaded module AMR-NB codec - based on 3GPP code");
const FormatInfo* f = FormatRepository::addFormat("amr",0,20000); const FormatInfo* f = FormatRepository::addFormat("amr",0,20000);

View File

@ -608,7 +608,8 @@ bool CmdHandler::received(Message &msg, int id)
} }
CallGenPlugin::CallGenPlugin() CallGenPlugin::CallGenPlugin()
: m_first(true) : Plugin("callgen"),
m_first(true)
{ {
Output("Loaded module Call Generator"); Output("Loaded module Call Generator");
} }

View File

@ -679,7 +679,8 @@ bool AttachHandler::received(Message &msg)
AlsaPlugin::AlsaPlugin() AlsaPlugin::AlsaPlugin()
: m_handler(0) : Plugin("alsachan"),
m_handler(0)
{ {
Output("Loaded module AlsaChan"); Output("Loaded module AlsaChan");
} }

View File

@ -666,7 +666,8 @@ bool AttachHandler::received(Message &msg)
OssPlugin::OssPlugin() OssPlugin::OssPlugin()
: m_handler(0) : Plugin("osschan"),
m_handler(0)
{ {
Output("Loaded module OssChan"); Output("Loaded module OssChan");
} }

View File

@ -1741,7 +1741,8 @@ ExtListener* ExtListener::build(const char* name, const NamedList& sect)
ExtModulePlugin::ExtModulePlugin() ExtModulePlugin::ExtModulePlugin()
: m_handler(0) : Plugin("extmodule"),
m_handler(0)
{ {
Output("Loaded module ExtModule"); Output("Loaded module ExtModule");
} }

View File

@ -132,7 +132,7 @@ unsigned long GsmCodec::Consume(const DataBlock& data, unsigned long tStamp, uns
} }
GsmPlugin::GsmPlugin() GsmPlugin::GsmPlugin()
: TranslatorFactory("gsm") : Plugin("gsmcodec"), TranslatorFactory("gsm")
{ {
Output("Loaded module GSM - based on libgsm-%d.%d.%d",GSM_MAJOR,GSM_MINOR,GSM_PATCHLEVEL); Output("Loaded module GSM - based on libgsm-%d.%d.%d",GSM_MAJOR,GSM_MINOR,GSM_PATCHLEVEL);
const FormatInfo* f = FormatRepository::addFormat("gsm",33,20000); const FormatInfo* f = FormatRepository::addFormat("gsm",33,20000);

View File

@ -187,7 +187,8 @@ unsigned long iLBCCodec::Consume(const DataBlock& data, unsigned long tStamp, un
} }
iLBCPlugin::iLBCPlugin() iLBCPlugin::iLBCPlugin()
: m_ilbc20(0), m_ilbc30(0) : Plugin("ilbccodec"),
m_ilbc20(0), m_ilbc30(0)
{ {
Output("Loaded module iLBC - based on iLBC library"); Output("Loaded module iLBC - based on iLBC library");
const FormatInfo* f = FormatRepository::addFormat("ilbc20",NO_OF_BYTES_20MS,20000); const FormatInfo* f = FormatRepository::addFormat("ilbc20",NO_OF_BYTES_20MS,20000);

View File

@ -410,7 +410,8 @@ bool StatusHandler::received(Message &msg)
MOHPlugin::MOHPlugin() MOHPlugin::MOHPlugin()
: m_handler(0) : Plugin("moh"),
m_handler(0)
{ {
Output("Loaded module MOH"); Output("Loaded module MOH");
} }

View File

@ -144,7 +144,8 @@ void HookHandler::dispatched(const Message& msg, bool handled)
MsgSniff::MsgSniff() MsgSniff::MsgSniff()
: m_first(true) : Plugin("msgsniff"),
m_first(true)
{ {
Output("Loaded module MsgSniffer"); Output("Loaded module MsgSniffer");
} }

View File

@ -667,7 +667,8 @@ private:
}; };
RegexRoutePlugin::RegexRoutePlugin() RegexRoutePlugin::RegexRoutePlugin()
: m_preroute(0), m_route(0), m_first(true) : Plugin("regexroute"),
m_preroute(0), m_route(0), m_first(true)
{ {
Output("Loaded module RegexRoute"); Output("Loaded module RegexRoute");
} }

View File

@ -110,7 +110,7 @@ static const CommandInfo s_cmdInfo[] =
{ "drop", "{chan|*|all} [reason]", s_dall, "Drops one or all active calls" }, { "drop", "{chan|*|all} [reason]", s_dall, "Drops one or all active calls" },
{ "call", "chan target", 0, "Execute an outgoing call" }, { "call", "chan target", 0, "Execute an outgoing call" },
{ "control", "chan [operation] [param=val] [param=...]", 0, "Apply arbitrary control operations to a channel or entity" }, { "control", "chan [operation] [param=val] [param=...]", 0, "Apply arbitrary control operations to a channel or entity" },
{ "reload", 0, 0, "Reloads module configuration files" }, { "reload", "[plugin]", 0, "Reloads module configuration files" },
{ "restart", "[now]", s_rnow, "Restarts the engine if executing supervised" }, { "restart", "[now]", s_rnow, "Restarts the engine if executing supervised" },
{ "stop", "[exitcode]", 0, "Stops the engine with optionally provided exit code" }, { "stop", "[exitcode]", 0, "Stops the engine with optionally provided exit code" },
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
@ -1206,8 +1206,9 @@ bool Connection::processLine(const char *line)
#endif #endif
else if (str.startSkip("reload")) else if (str.startSkip("reload"))
{ {
str.trimSpaces();
writeStr(m_machine ? "%%=reload\r\n" : "Reinitializing...\r\n"); writeStr(m_machine ? "%%=reload\r\n" : "Reinitializing...\r\n");
Engine::init(); Engine::init(str);
} }
else if (str.startSkip("restart")) else if (str.startSkip("restart"))
{ {
@ -1328,7 +1329,8 @@ void RHook::dispatched(const Message& msg, bool handled)
RManager::RManager() RManager::RManager()
: m_first(true) : Plugin("rmanager"),
m_first(true)
{ {
Output("Loaded module RManager"); Output("Loaded module RManager");
Debugger::setIntOut(dbg_remote_func); Debugger::setIntOut(dbg_remote_func);

View File

@ -249,7 +249,8 @@ bool StartHandler::received(Message &msg)
AccFilePlugin::AccFilePlugin() AccFilePlugin::AccFilePlugin()
: m_first(true) : Plugin("accfile"),
m_first(true)
{ {
Output("Loaded module Accounts from file"); Output("Loaded module Accounts from file");
} }

View File

@ -75,7 +75,7 @@ public:
virtual bool received(Message& msg); virtual bool received(Message& msg);
}; };
class CallCountersPlugin : public Plugin, public String class CallCountersPlugin : public Plugin
{ {
public: public:
CallCountersPlugin(); CallCountersPlugin();
@ -192,7 +192,7 @@ bool RouteHandler::received(Message& msg)
bool StatusHandler::received(Message &msg) bool StatusHandler::received(Message &msg)
{ {
const String* sel = msg.getParam("module"); const String* sel = msg.getParam("module");
if (!TelEngine::null(sel) && (*sel != __plugin)) if (!TelEngine::null(sel) && (*sel != __plugin.name()))
return false; return false;
String st("name=callcounters,type=misc,format=Context|Count"); String st("name=callcounters,type=misc,format=Context|Count");
s_mutex.lock(); s_mutex.lock();
@ -221,8 +221,8 @@ bool CommandHandler::received(Message &msg)
String* tmp = msg.getParam("partline"); String* tmp = msg.getParam("partline");
if (tmp && (*tmp == "status")) { if (tmp && (*tmp == "status")) {
tmp = msg.getParam("partword"); tmp = msg.getParam("partword");
if (!tmp || tmp->null() || __plugin.startsWith(*tmp)) if (!tmp || tmp->null() || __plugin.name().startsWith(*tmp))
msg.retValue().append(__plugin,"\t"); msg.retValue().append(__plugin.name(),"\t");
} }
} }
return false; return false;
@ -230,7 +230,7 @@ bool CommandHandler::received(Message &msg)
CallCountersPlugin::CallCountersPlugin() CallCountersPlugin::CallCountersPlugin()
: String("callcounters") : Plugin("callcounters")
{ {
Output("Loaded module CallCounters"); Output("Loaded module CallCounters");
} }
@ -242,7 +242,7 @@ CallCountersPlugin::~CallCountersPlugin()
void CallCountersPlugin::initialize() void CallCountersPlugin::initialize()
{ {
Configuration cfg(Engine::configFile(c_str())); Configuration cfg(Engine::configFile(name().c_str()));
s_allCounters = cfg.getBoolValue("general","allcounters",false); s_allCounters = cfg.getBoolValue("general","allcounters",false);
// tracked parameter, direction and priorities cannot be reloaded // tracked parameter, direction and priorities cannot be reloaded
if (s_paramName.null()) { if (s_paramName.null()) {

View File

@ -102,7 +102,7 @@ bool CpuNotify::received(Message& msg)
*/ */
CongestionModule::CongestionModule() CongestionModule::CongestionModule()
: Module("CongestionModule","misc"), m_init(false), m_monitorsBlocker(false,s_mutexName) : Module("ccongestion","misc"), m_init(false), m_monitorsBlocker(false,s_mutexName)
{ {
Output("Loaded module CCongestion"); Output("Loaded module CCongestion");
} }

View File

@ -716,7 +716,7 @@ bool QueryHandler::received(Message& msg)
*/ */
CpuModule::CpuModule() CpuModule::CpuModule()
: Module("CpuModule","misc",true), m_init(false) : Module("cpuload","misc",true), m_init(false)
{ {
Output("Loaded module Cpu"); Output("Loaded module Cpu");
m_updater = new CpuUpdater(); m_updater = new CpuUpdater();

View File

@ -322,7 +322,8 @@ bool StatusHandler::received(Message &msg)
} }
RegfilePlugin::RegfilePlugin() RegfilePlugin::RegfilePlugin()
: m_init(false) : Plugin("regfile"),
m_init(false)
{ {
Output("Loaded module Registration from file"); Output("Loaded module Registration from file");
} }

View File

@ -1980,7 +1980,7 @@ TdmConsumer::~TdmConsumer()
String TdmModule::s_statusCmd[StatusCmdCount] = {"spans","channels","all"}; String TdmModule::s_statusCmd[StatusCmdCount] = {"spans","channels","all"};
TdmModule::TdmModule() TdmModule::TdmModule()
: Module("Tdm","misc",true), : Module("tdmcard","misc",true),
m_init(false), m_init(false),
m_count(0), m_count(0),
m_active(0) m_active(0)

View File

@ -256,7 +256,7 @@ unsigned long SpeexCodec::Consume(const DataBlock& data, unsigned long tStamp, u
} }
SpeexPlugin::SpeexPlugin() SpeexPlugin::SpeexPlugin()
: TranslatorFactory("speex") : Plugin("speexcodec"), TranslatorFactory("speex")
{ {
int major, minor, micro; int major, minor, micro;
speex_lib_ctl(SPEEX_LIB_GET_MAJOR_VERSION, &major); speex_lib_ctl(SPEEX_LIB_GET_MAJOR_VERSION, &major);

View File

@ -676,7 +676,7 @@ private:
*</pre> *</pre>
* @short Plugin support * @short Plugin support
*/ */
class YATE_API Plugin : public GenObject class YATE_API Plugin : public GenObject, public DebugEnabler
{ {
public: public:
/** /**
@ -686,12 +686,6 @@ public:
*/ */
explicit Plugin(const char* name, bool earlyInit = false); explicit Plugin(const char* name, bool earlyInit = false);
/**
* Creates a new Plugin container.
* Alternate constructor which is also the default.
*/
Plugin();
/** /**
* Destroys the plugin. * Destroys the plugin.
* The destructor must never be called directly - the Loader will do it * The destructor must never be called directly - the Loader will do it
@ -699,6 +693,13 @@ public:
*/ */
virtual ~Plugin(); virtual ~Plugin();
/**
* Get a string representation of this object
* @return Name of the plugin
*/
virtual const String& toString() const
{ return m_name; }
/** /**
* Get a pointer to a derived class given that class name * Get a pointer to a derived class given that class name
* @param name Name of the class we are asking for * @param name Name of the class we are asking for
@ -718,6 +719,13 @@ public:
virtual bool isBusy() const virtual bool isBusy() const
{ return false; } { return false; }
/**
* Retrieve the name of the plugin
* @return The plugin's name as String
*/
inline const String& name() const
{ return m_name; }
/** /**
* Check if the module is to be initialized early * Check if the module is to be initialized early
* @return True if the module should be initialized before regular ones * @return True if the module should be initialized before regular ones
@ -726,6 +734,8 @@ public:
{ return m_early; } { return m_early; }
private: private:
Plugin(); // no default constructor please
String m_name;
bool m_early; bool m_early;
}; };
@ -1001,6 +1011,13 @@ public:
*/ */
static void init(); static void init();
/**
* Reinitialize one plugin
* @param name Name of the plugin to initialize, emplty, "*" or "all" to initialize all
* @return True if plugin(s) were reinitialized
*/
static bool init(const String& name);
/** /**
* Stop the engine and the entire program * Stop the engine and the entire program
* @param code Return code of the program * @param code Return code of the program

View File

@ -1315,13 +1315,12 @@ private:
* Module is a descendent of Plugin specialized in implementing modules * Module is a descendent of Plugin specialized in implementing modules
* @short A Plugin that implements a module * @short A Plugin that implements a module
*/ */
class YATE_API Module : public Plugin, public Mutex, public MessageReceiver, public DebugEnabler class YATE_API Module : public Plugin, public Mutex, public MessageReceiver
{ {
YNOCOPY(Module); // no automatic copies please YNOCOPY(Module); // no automatic copies please
private: private:
bool m_init; bool m_init;
int m_relays; int m_relays;
String m_name;
String m_type; String m_type;
Regexp m_filter; Regexp m_filter;
u_int64_t m_changed; u_int64_t m_changed;
@ -1335,13 +1334,6 @@ public:
*/ */
virtual void* getObject(const String& name) const; virtual void* getObject(const String& name) const;
/**
* Retrieve the name of the module
* @return The module's name as String
*/
inline const String& name() const
{ return m_name; }
/** /**
* Retrieve the type of the module * Retrieve the type of the module
* @return The module's type as String * @return The module's type as String