From 8e61c980ee64a3d4ecfa0150ff8e46bcb73cfa2f Mon Sep 17 00:00:00 2001 From: paulc Date: Wed, 23 Mar 2011 16:26:25 +0000 Subject: [PATCH] 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 --- engine/Channel.cpp | 16 +++++++--------- engine/Engine.cpp | 28 ++++++++++++++++++++++++++++ engine/Plugin.cpp | 11 +++-------- modules/amrnbcodec.cpp | 2 +- modules/callgen.cpp | 3 ++- modules/client/alsachan.cpp | 3 ++- modules/client/osschan.cpp | 3 ++- modules/extmodule.cpp | 3 ++- modules/gsmcodec.cpp | 2 +- modules/ilbccodec.cpp | 3 ++- modules/moh.cpp | 3 ++- modules/msgsniff.cpp | 3 ++- modules/regexroute.cpp | 3 ++- modules/rmanager.cpp | 8 +++++--- modules/server/accfile.cpp | 3 ++- modules/server/callcounters.cpp | 12 ++++++------ modules/server/ccongestion.cpp | 2 +- modules/server/cpuload.cpp | 2 +- modules/server/regfile.cpp | 3 ++- modules/server/tdmcard.cpp | 2 +- modules/speexcodec.cpp | 2 +- yatengine.h | 33 +++++++++++++++++++++++++-------- yatephone.h | 10 +--------- 23 files changed, 101 insertions(+), 59 deletions(-) diff --git a/engine/Channel.cpp b/engine/Channel.cpp index 2614acfa..571c7986 100644 --- a/engine/Channel.cpp +++ b/engine/Channel.cpp @@ -934,14 +934,12 @@ const char* Module::messageName(int id) Module::Module(const char* name, const char* type, bool earlyInit) : 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() { - debugName(0); } void* Module::getObject(const String& name) const @@ -1052,7 +1050,7 @@ void Module::msgTimer(Message& msg) { if (m_changed && (msg.msgTime() > m_changed)) { Message* m = new Message("module.update"); - m->addParam("module",m_name); + m->addParam("module",name()); m_changed = 0; genUpdate(*m); Engine::enqueue(m); @@ -1113,7 +1111,7 @@ void Module::msgStatus(Message& msg) void Module::statusModule(String& str) { - str.append("name=",",") << m_name; + str.append("name=",",") << name(); if (m_type) str << ",type=" << m_type; } @@ -1132,7 +1130,7 @@ void Module::genUpdate(Message& msg) bool Module::received(Message &msg, int id) { - if (!m_name) + if (name().null()) return false; switch (id) { @@ -1148,7 +1146,7 @@ bool Module::received(Message &msg, int id) String dest = msg.getValue("module"); if (id == Status) { - if (dest == m_name) { + if (dest == name()) { msgStatus(msg); return true; } @@ -1166,7 +1164,7 @@ bool Module::received(Message &msg, int id) bool Module::setDebug(Message& msg, const String& target) { - if (target != m_name) + if (target != name()) return false; String str = msg.getValue("line"); @@ -1186,7 +1184,7 @@ bool Module::setDebug(Message& msg, const String& target) str >> dbg; debugEnabled(dbg); } - msg.retValue() << "Module " << m_name + msg.retValue() << "Module " << name() << " debug " << (debugEnabled() ? "on" : "off") << " level " << debugLevel(); if (m_filter) diff --git a/engine/Engine.cpp b/engine/Engine.cpp index d400853e..e389aa9d 100644 --- a/engine/Engine.cpp +++ b/engine/Engine.cpp @@ -463,6 +463,12 @@ void EngineCommand::doCompletion(Message &msg, const String& partLine, const Str completeOne(msg.retValue(),*s,partWord); } } + else if (partLine == "reload") { + for (ObjList* l = plugins.skipNull(); l; l = l->skipNext()) { + const Plugin* p = static_cast(l->get()); + completeOne(msg.retValue(),p->name(),partWord); + } + } } bool EngineCommand::received(Message &msg) @@ -1451,6 +1457,28 @@ void Engine::init() 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(plugins[name]); + if (p) { + p->initialize(); + ok = true; + } + return ok; +} + bool Engine::install(MessageHandler* handler) { return s_self ? s_self->m_dispatcher.install(handler) : false; diff --git a/engine/Plugin.cpp b/engine/Plugin.cpp index 2602b1b3..d1d8373b 100644 --- a/engine/Plugin.cpp +++ b/engine/Plugin.cpp @@ -24,17 +24,11 @@ using namespace TelEngine; -Plugin::Plugin() - : m_early(false) -{ - Debug(DebugAll,"Plugin::Plugin() [%p]",this); - Engine::Register(this); -} - 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); + debugName(m_name); Engine::Register(this); } @@ -42,6 +36,7 @@ Plugin::~Plugin() { Debugger debug("Plugin::~Plugin()"," [%p]",this); Engine::Register(this,false); + debugName(0); } void* Plugin::getObject(const String& name) const diff --git a/modules/amrnbcodec.cpp b/modules/amrnbcodec.cpp index e7b0be1c..9ed0e231 100644 --- a/modules/amrnbcodec.cpp +++ b/modules/amrnbcodec.cpp @@ -360,7 +360,7 @@ bool AmrDecoder::pushData(unsigned long& tStamp) // Plugin and translator factory AmrPlugin::AmrPlugin() - : TranslatorFactory("amr-nb") + : Plugin("amrnbcodec"), TranslatorFactory("amr-nb") { Output("Loaded module AMR-NB codec - based on 3GPP code"); const FormatInfo* f = FormatRepository::addFormat("amr",0,20000); diff --git a/modules/callgen.cpp b/modules/callgen.cpp index 39934da9..972ae09c 100644 --- a/modules/callgen.cpp +++ b/modules/callgen.cpp @@ -608,7 +608,8 @@ bool CmdHandler::received(Message &msg, int id) } CallGenPlugin::CallGenPlugin() - : m_first(true) + : Plugin("callgen"), + m_first(true) { Output("Loaded module Call Generator"); } diff --git a/modules/client/alsachan.cpp b/modules/client/alsachan.cpp index 319f1863..eaadea71 100644 --- a/modules/client/alsachan.cpp +++ b/modules/client/alsachan.cpp @@ -679,7 +679,8 @@ bool AttachHandler::received(Message &msg) AlsaPlugin::AlsaPlugin() - : m_handler(0) + : Plugin("alsachan"), + m_handler(0) { Output("Loaded module AlsaChan"); } diff --git a/modules/client/osschan.cpp b/modules/client/osschan.cpp index 7b4ec087..cf82a6c2 100644 --- a/modules/client/osschan.cpp +++ b/modules/client/osschan.cpp @@ -666,7 +666,8 @@ bool AttachHandler::received(Message &msg) OssPlugin::OssPlugin() - : m_handler(0) + : Plugin("osschan"), + m_handler(0) { Output("Loaded module OssChan"); } diff --git a/modules/extmodule.cpp b/modules/extmodule.cpp index 30d48a01..1a4ad65b 100644 --- a/modules/extmodule.cpp +++ b/modules/extmodule.cpp @@ -1741,7 +1741,8 @@ ExtListener* ExtListener::build(const char* name, const NamedList& sect) ExtModulePlugin::ExtModulePlugin() - : m_handler(0) + : Plugin("extmodule"), + m_handler(0) { Output("Loaded module ExtModule"); } diff --git a/modules/gsmcodec.cpp b/modules/gsmcodec.cpp index 8ceadbb9..31053fc7 100644 --- a/modules/gsmcodec.cpp +++ b/modules/gsmcodec.cpp @@ -132,7 +132,7 @@ unsigned long GsmCodec::Consume(const DataBlock& data, unsigned long tStamp, uns } GsmPlugin::GsmPlugin() - : TranslatorFactory("gsm") + : Plugin("gsmcodec"), TranslatorFactory("gsm") { Output("Loaded module GSM - based on libgsm-%d.%d.%d",GSM_MAJOR,GSM_MINOR,GSM_PATCHLEVEL); const FormatInfo* f = FormatRepository::addFormat("gsm",33,20000); diff --git a/modules/ilbccodec.cpp b/modules/ilbccodec.cpp index 7e924ead..cac38a43 100644 --- a/modules/ilbccodec.cpp +++ b/modules/ilbccodec.cpp @@ -187,7 +187,8 @@ unsigned long iLBCCodec::Consume(const DataBlock& data, unsigned long tStamp, un } iLBCPlugin::iLBCPlugin() - : m_ilbc20(0), m_ilbc30(0) + : Plugin("ilbccodec"), + m_ilbc20(0), m_ilbc30(0) { Output("Loaded module iLBC - based on iLBC library"); const FormatInfo* f = FormatRepository::addFormat("ilbc20",NO_OF_BYTES_20MS,20000); diff --git a/modules/moh.cpp b/modules/moh.cpp index 06310e16..43c196e4 100644 --- a/modules/moh.cpp +++ b/modules/moh.cpp @@ -410,7 +410,8 @@ bool StatusHandler::received(Message &msg) MOHPlugin::MOHPlugin() - : m_handler(0) + : Plugin("moh"), + m_handler(0) { Output("Loaded module MOH"); } diff --git a/modules/msgsniff.cpp b/modules/msgsniff.cpp index 1c80067e..880e2a4c 100644 --- a/modules/msgsniff.cpp +++ b/modules/msgsniff.cpp @@ -144,7 +144,8 @@ void HookHandler::dispatched(const Message& msg, bool handled) MsgSniff::MsgSniff() - : m_first(true) + : Plugin("msgsniff"), + m_first(true) { Output("Loaded module MsgSniffer"); } diff --git a/modules/regexroute.cpp b/modules/regexroute.cpp index 509c76ab..fb01b44f 100644 --- a/modules/regexroute.cpp +++ b/modules/regexroute.cpp @@ -667,7 +667,8 @@ private: }; 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"); } diff --git a/modules/rmanager.cpp b/modules/rmanager.cpp index 15491745..b7c5e46c 100644 --- a/modules/rmanager.cpp +++ b/modules/rmanager.cpp @@ -110,7 +110,7 @@ static const CommandInfo s_cmdInfo[] = { "drop", "{chan|*|all} [reason]", s_dall, "Drops one or all active calls" }, { "call", "chan target", 0, "Execute an outgoing call" }, { "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" }, { "stop", "[exitcode]", 0, "Stops the engine with optionally provided exit code" }, { 0, 0, 0, 0 } @@ -1206,8 +1206,9 @@ bool Connection::processLine(const char *line) #endif else if (str.startSkip("reload")) { + str.trimSpaces(); writeStr(m_machine ? "%%=reload\r\n" : "Reinitializing...\r\n"); - Engine::init(); + Engine::init(str); } else if (str.startSkip("restart")) { @@ -1328,7 +1329,8 @@ void RHook::dispatched(const Message& msg, bool handled) RManager::RManager() - : m_first(true) + : Plugin("rmanager"), + m_first(true) { Output("Loaded module RManager"); Debugger::setIntOut(dbg_remote_func); diff --git a/modules/server/accfile.cpp b/modules/server/accfile.cpp index 35d71d88..4af226ef 100644 --- a/modules/server/accfile.cpp +++ b/modules/server/accfile.cpp @@ -249,7 +249,8 @@ bool StartHandler::received(Message &msg) AccFilePlugin::AccFilePlugin() - : m_first(true) + : Plugin("accfile"), + m_first(true) { Output("Loaded module Accounts from file"); } diff --git a/modules/server/callcounters.cpp b/modules/server/callcounters.cpp index 25d88f22..dac86239 100644 --- a/modules/server/callcounters.cpp +++ b/modules/server/callcounters.cpp @@ -75,7 +75,7 @@ public: virtual bool received(Message& msg); }; -class CallCountersPlugin : public Plugin, public String +class CallCountersPlugin : public Plugin { public: CallCountersPlugin(); @@ -192,7 +192,7 @@ bool RouteHandler::received(Message& msg) bool StatusHandler::received(Message &msg) { const String* sel = msg.getParam("module"); - if (!TelEngine::null(sel) && (*sel != __plugin)) + if (!TelEngine::null(sel) && (*sel != __plugin.name())) return false; String st("name=callcounters,type=misc,format=Context|Count"); s_mutex.lock(); @@ -221,8 +221,8 @@ bool CommandHandler::received(Message &msg) String* tmp = msg.getParam("partline"); if (tmp && (*tmp == "status")) { tmp = msg.getParam("partword"); - if (!tmp || tmp->null() || __plugin.startsWith(*tmp)) - msg.retValue().append(__plugin,"\t"); + if (!tmp || tmp->null() || __plugin.name().startsWith(*tmp)) + msg.retValue().append(__plugin.name(),"\t"); } } return false; @@ -230,7 +230,7 @@ bool CommandHandler::received(Message &msg) CallCountersPlugin::CallCountersPlugin() - : String("callcounters") + : Plugin("callcounters") { Output("Loaded module CallCounters"); } @@ -242,7 +242,7 @@ CallCountersPlugin::~CallCountersPlugin() void CallCountersPlugin::initialize() { - Configuration cfg(Engine::configFile(c_str())); + Configuration cfg(Engine::configFile(name().c_str())); s_allCounters = cfg.getBoolValue("general","allcounters",false); // tracked parameter, direction and priorities cannot be reloaded if (s_paramName.null()) { diff --git a/modules/server/ccongestion.cpp b/modules/server/ccongestion.cpp index 23618ef6..95d9cbed 100644 --- a/modules/server/ccongestion.cpp +++ b/modules/server/ccongestion.cpp @@ -102,7 +102,7 @@ bool CpuNotify::received(Message& msg) */ 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"); } diff --git a/modules/server/cpuload.cpp b/modules/server/cpuload.cpp index 788ecc5a..5d9c4ccb 100644 --- a/modules/server/cpuload.cpp +++ b/modules/server/cpuload.cpp @@ -716,7 +716,7 @@ bool QueryHandler::received(Message& msg) */ CpuModule::CpuModule() - : Module("CpuModule","misc",true), m_init(false) + : Module("cpuload","misc",true), m_init(false) { Output("Loaded module Cpu"); m_updater = new CpuUpdater(); diff --git a/modules/server/regfile.cpp b/modules/server/regfile.cpp index 01bb4b2c..c9bc6305 100644 --- a/modules/server/regfile.cpp +++ b/modules/server/regfile.cpp @@ -322,7 +322,8 @@ bool StatusHandler::received(Message &msg) } RegfilePlugin::RegfilePlugin() - : m_init(false) + : Plugin("regfile"), + m_init(false) { Output("Loaded module Registration from file"); } diff --git a/modules/server/tdmcard.cpp b/modules/server/tdmcard.cpp index 9d758717..078f6de6 100644 --- a/modules/server/tdmcard.cpp +++ b/modules/server/tdmcard.cpp @@ -1980,7 +1980,7 @@ TdmConsumer::~TdmConsumer() String TdmModule::s_statusCmd[StatusCmdCount] = {"spans","channels","all"}; TdmModule::TdmModule() - : Module("Tdm","misc",true), + : Module("tdmcard","misc",true), m_init(false), m_count(0), m_active(0) diff --git a/modules/speexcodec.cpp b/modules/speexcodec.cpp index 13acc402..5da77f11 100644 --- a/modules/speexcodec.cpp +++ b/modules/speexcodec.cpp @@ -256,7 +256,7 @@ unsigned long SpeexCodec::Consume(const DataBlock& data, unsigned long tStamp, u } SpeexPlugin::SpeexPlugin() - : TranslatorFactory("speex") + : Plugin("speexcodec"), TranslatorFactory("speex") { int major, minor, micro; speex_lib_ctl(SPEEX_LIB_GET_MAJOR_VERSION, &major); diff --git a/yatengine.h b/yatengine.h index 6e2ca555..ba86ddff 100644 --- a/yatengine.h +++ b/yatengine.h @@ -676,7 +676,7 @@ private: * * @short Plugin support */ -class YATE_API Plugin : public GenObject +class YATE_API Plugin : public GenObject, public DebugEnabler { public: /** @@ -686,12 +686,6 @@ public: */ explicit Plugin(const char* name, bool earlyInit = false); - /** - * Creates a new Plugin container. - * Alternate constructor which is also the default. - */ - Plugin(); - /** * Destroys the plugin. * The destructor must never be called directly - the Loader will do it @@ -699,6 +693,13 @@ public: */ 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 * @param name Name of the class we are asking for @@ -718,6 +719,13 @@ public: virtual bool isBusy() const { 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 * @return True if the module should be initialized before regular ones @@ -726,6 +734,8 @@ public: { return m_early; } private: + Plugin(); // no default constructor please + String m_name; bool m_early; }; @@ -807,7 +817,7 @@ public: Client = 3, ClientProxy = 4, }; - + enum CallAccept { Accept = 0, Partial = 1, @@ -1001,6 +1011,13 @@ public: */ 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 * @param code Return code of the program diff --git a/yatephone.h b/yatephone.h index 00737b6a..4d36abe5 100644 --- a/yatephone.h +++ b/yatephone.h @@ -1315,13 +1315,12 @@ private: * Module is a descendent of Plugin specialized in implementing modules * @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 private: bool m_init; int m_relays; - String m_name; String m_type; Regexp m_filter; u_int64_t m_changed; @@ -1335,13 +1334,6 @@ public: */ 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 * @return The module's type as String