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:
parent
dfc831f65e
commit
8e61c980ee
|
@ -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)
|
||||
|
|
|
@ -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<const Plugin*>(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<Plugin*>(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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -679,7 +679,8 @@ bool AttachHandler::received(Message &msg)
|
|||
|
||||
|
||||
AlsaPlugin::AlsaPlugin()
|
||||
: m_handler(0)
|
||||
: Plugin("alsachan"),
|
||||
m_handler(0)
|
||||
{
|
||||
Output("Loaded module AlsaChan");
|
||||
}
|
||||
|
|
|
@ -666,7 +666,8 @@ bool AttachHandler::received(Message &msg)
|
|||
|
||||
|
||||
OssPlugin::OssPlugin()
|
||||
: m_handler(0)
|
||||
: Plugin("osschan"),
|
||||
m_handler(0)
|
||||
{
|
||||
Output("Loaded module OssChan");
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -410,7 +410,8 @@ bool StatusHandler::received(Message &msg)
|
|||
|
||||
|
||||
MOHPlugin::MOHPlugin()
|
||||
: m_handler(0)
|
||||
: Plugin("moh"),
|
||||
m_handler(0)
|
||||
{
|
||||
Output("Loaded module MOH");
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
33
yatengine.h
33
yatengine.h
|
@ -676,7 +676,7 @@ private:
|
|||
*</pre>
|
||||
* @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
|
||||
|
|
10
yatephone.h
10
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
|
||||
|
|
Loading…
Reference in New Issue