Added test module to delay arbitrary messages.

Fixed building of test modules.


git-svn-id: http://yate.null.ro/svn/yate/trunk@4664 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2011-10-31 15:09:51 +00:00
parent dbb3e70ac8
commit 6b9da6a725
3 changed files with 129 additions and 4 deletions

View File

@ -1,6 +1,9 @@
# Makefile
# This file holds the make rules for the Telephony Engine test cases
# override DEBUG at compile time to enable full debug or remove it all
DEBUG :=
CXX := @CXX@ -Wall
SED := sed
DEFS :=
@ -12,13 +15,13 @@ MODFLAGS:= @MODULE_LDFLAGS@
MODSTRIP:= @MODULE_SYMBOLS@
MKDEPS := ../../config.status
PROGS = randcall.yate
PROGS = randcall.yate msgdelay.yate
LIBS =
OBJS =
LOCALFLAGS =
LOCALLIBS =
COMPILE = $(CXX) $(DEFS) $(INCLUDES) $(CFLAGS)
COMPILE = $(CXX) $(DEFS) $(DEBUG) $(INCLUDES) $(CFLAGS)
LINK = $(CXX) $(LDFLAGS)
MODLINK = $(CXX) $(MODFLAGS) $(MODSTRIP) $(LDFLAGS)
MODCOMP = $(COMPILE) $(MODFLAGS) $(MODSTRIP) $(LDFLAGS)
@ -29,9 +32,18 @@ exec_prefix = @exec_prefix@
# include optional local make rules
-include YateLocal.mak
.PHONY: all
.PHONY: all debug ddebug xdebug
all: $(LIBS) $(PROGS)
debug:
$(MAKE) all DEBUG=-g3 MODSTRIP=
ddebug:
$(MAKE) all DEBUG='-g3 -DDEBUG' MODSTRIP=
xdebug:
$(MAKE) all DEBUG='-g3 -DXDEBUG' MODSTRIP=
.PHONY: strip
strip: all
strip --strip-debug --discard-locals $(PROGS)

112
modules/test/msgdelay.cpp Normal file
View File

@ -0,0 +1,112 @@
/*
* msgdelay.cpp
* This file is part of the YATE Project http://YATE.null.ro
*
* An arbitrary message delayer
*
* Yet Another Telephony Engine - a fully featured software PBX and IVR
* Copyright (C) 2011 Null Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <yatengine.h>
using namespace TelEngine;
namespace { // anonymous
class DelayHandler : public MessageHandler
{
public:
DelayHandler(int prio) : MessageHandler(0,prio) { }
virtual bool received(Message &msg);
};
class MsgDelay : public Plugin
{
public:
MsgDelay();
virtual ~MsgDelay();
virtual void initialize();
bool unload();
private:
DelayHandler* m_handler;
};
INIT_PLUGIN(MsgDelay);
UNLOAD_PLUGIN(unloadNow)
{
if (unloadNow)
return __plugin.unload();
return true;
}
bool DelayHandler::received(Message &msg)
{
NamedString* p = msg.getParam(YSTRING("message_delay"));
if (!p)
return false;
int ms = p->toInteger();
// make sure we don't get here again
msg.clearParam(p);
if (ms > 0) {
// delay maximum 10s
if (ms > 10000)
ms = 10000;
Debug(DebugAll,"Delaying '%s' by %d ms in thread '%s'",msg.safe(),ms,Thread::currentName());
Thread::msleep(ms);
}
return false;
};
MsgDelay::MsgDelay()
: Plugin("msgdelay","misc"),
m_handler(0)
{
Output("Loaded module MsgDelay");
}
MsgDelay::~MsgDelay()
{
Output("Unloading module MsgDelay");
}
bool MsgDelay::unload()
{
if (m_handler) {
Engine::uninstall(m_handler);
TelEngine::destruct(m_handler);
}
return true;
}
void MsgDelay::initialize()
{
if (!m_handler) {
int prio = Engine::config().getIntValue("general","msgdelay",50);
if (prio > 0) {
Output("Initializing module MsgDelay priority %d",prio);
m_handler = new DelayHandler(prio);
Engine::install(m_handler);
}
}
}
}; // anonymous namespace
/* vi: set ts=8 sw=4 sts=4 noet: */

View File

@ -125,7 +125,8 @@ void RouteThread::run()
}
RandPlugin::RandPlugin()
: m_thread(0)
: Plugin("randplugin","misc"),
m_thread(0)
{
Output("Loaded random call generator");
}