2005-01-21 00:50:25 +00:00
|
|
|
/**
|
|
|
|
* callgen.cpp
|
|
|
|
* This file is part of the YATE Project http://YATE.null.ro
|
|
|
|
*
|
|
|
|
* Call Generator
|
|
|
|
*
|
|
|
|
* Yet Another Telephony Engine - a fully featured software PBX and IVR
|
2005-04-29 22:05:07 +00:00
|
|
|
* Copyright (C) 2004, 2005 Null Team
|
2005-01-21 00:50:25 +00:00
|
|
|
*
|
|
|
|
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
2005-03-18 18:16:59 +00:00
|
|
|
#include <yatephone.h>
|
2005-01-21 00:50:25 +00:00
|
|
|
|
2005-01-21 16:35:35 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2005-01-21 00:50:25 +00:00
|
|
|
using namespace TelEngine;
|
|
|
|
|
2005-04-28 17:40:41 +00:00
|
|
|
static Mutex s_mutex(true);
|
|
|
|
static ObjList s_calls;
|
2005-01-21 00:50:25 +00:00
|
|
|
static Configuration s_cfg;
|
2005-01-21 16:35:35 +00:00
|
|
|
static bool s_runs = false;
|
2005-01-21 00:50:25 +00:00
|
|
|
static int s_total = 0;
|
|
|
|
static int s_current = 0;
|
2005-01-21 20:34:10 +00:00
|
|
|
static int s_ringing = 0;
|
2005-01-21 16:35:35 +00:00
|
|
|
static int s_answers = 0;
|
|
|
|
|
|
|
|
static int s_numcalls = 0;
|
2005-01-21 00:50:25 +00:00
|
|
|
|
2005-01-21 20:34:10 +00:00
|
|
|
static const char s_help[] = "callgen {start|stop|drop|pause|resume|single|info|load|save|set paramname[=value]}";
|
|
|
|
|
2005-04-28 17:40:41 +00:00
|
|
|
class GenConnection : public CallEndpoint
|
2005-01-21 00:50:25 +00:00
|
|
|
{
|
|
|
|
public:
|
2005-04-28 17:40:41 +00:00
|
|
|
GenConnection(unsigned int lifetime, const String& callto);
|
2005-01-21 00:50:25 +00:00
|
|
|
~GenConnection();
|
|
|
|
virtual void disconnected(bool final, const char *reason);
|
|
|
|
void ringing();
|
|
|
|
void answered();
|
|
|
|
void hangup();
|
2005-01-21 20:34:10 +00:00
|
|
|
void makeSource();
|
2005-04-28 17:40:41 +00:00
|
|
|
inline const String& status() const
|
|
|
|
{ return m_status; }
|
2005-01-21 22:24:54 +00:00
|
|
|
inline const String& party() const
|
|
|
|
{ return m_callto; }
|
2005-04-28 17:40:41 +00:00
|
|
|
inline void setTarget(const char *target = 0)
|
|
|
|
{ m_target = target; }
|
|
|
|
inline const String& getTarget() const
|
|
|
|
{ return m_target; }
|
2005-04-29 22:05:07 +00:00
|
|
|
inline bool oldAge(u_int64_t now) const
|
2005-04-28 17:40:41 +00:00
|
|
|
{ return now > m_finish; }
|
|
|
|
static GenConnection* find(const String& id);
|
2005-01-21 20:34:10 +00:00
|
|
|
static bool oneCall(String* target = 0);
|
2005-01-21 00:50:25 +00:00
|
|
|
private:
|
2005-04-28 17:40:41 +00:00
|
|
|
String m_status;
|
2005-01-21 22:24:54 +00:00
|
|
|
String m_callto;
|
2005-04-28 17:40:41 +00:00
|
|
|
String m_target;
|
2005-04-29 22:05:07 +00:00
|
|
|
u_int64_t m_finish;
|
2005-01-21 16:35:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class GenThread : public Thread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GenThread()
|
|
|
|
: Thread("CallGen")
|
|
|
|
{ }
|
|
|
|
virtual void run();
|
2005-01-21 00:50:25 +00:00
|
|
|
};
|
|
|
|
|
2005-04-28 17:40:41 +00:00
|
|
|
class CleanThread : public Thread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CleanThread()
|
|
|
|
: Thread("GenCleaner")
|
|
|
|
{ }
|
|
|
|
virtual void run();
|
|
|
|
};
|
|
|
|
|
|
|
|
class ConnHandler : public MessageReceiver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum {
|
|
|
|
Ringing,
|
|
|
|
Answered,
|
|
|
|
Execute,
|
|
|
|
Drop,
|
|
|
|
};
|
|
|
|
virtual bool received(Message &msg, int id);
|
|
|
|
};
|
|
|
|
|
2005-01-21 00:50:25 +00:00
|
|
|
class CmdHandler : public MessageReceiver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum {
|
|
|
|
Drop,
|
|
|
|
Status,
|
|
|
|
Command,
|
|
|
|
Help
|
|
|
|
};
|
|
|
|
virtual bool received(Message &msg, int id);
|
2005-01-21 16:35:35 +00:00
|
|
|
bool doCommand(String& line, String& rval);
|
2005-01-21 00:50:25 +00:00
|
|
|
};
|
|
|
|
|
2005-04-28 17:40:41 +00:00
|
|
|
class CallGenPlugin : public Plugin
|
2005-01-21 00:50:25 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CallGenPlugin();
|
|
|
|
virtual ~CallGenPlugin();
|
|
|
|
virtual void initialize();
|
|
|
|
private:
|
|
|
|
bool m_first;
|
|
|
|
};
|
|
|
|
|
2005-04-28 17:40:41 +00:00
|
|
|
GenConnection::GenConnection(unsigned int lifetime, const String& callto)
|
|
|
|
: m_callto(callto)
|
2005-01-21 00:50:25 +00:00
|
|
|
{
|
2005-04-28 17:40:41 +00:00
|
|
|
if (!lifetime)
|
|
|
|
lifetime = 60000;
|
|
|
|
if (lifetime < 100)
|
|
|
|
lifetime = 100;
|
2005-04-29 22:05:07 +00:00
|
|
|
m_finish = Time::now() + ((u_int64_t)lifetime * 1000);
|
2005-04-28 17:40:41 +00:00
|
|
|
m_status = "calling";
|
|
|
|
s_mutex.lock();
|
|
|
|
s_calls.append(this);
|
|
|
|
m_id << "callgen/" << ++s_total;
|
2005-01-21 16:35:35 +00:00
|
|
|
++s_current;
|
2005-04-28 17:40:41 +00:00
|
|
|
s_mutex.unlock();
|
|
|
|
Output("Generating %u ms call %s to: %s",lifetime,m_id.c_str(),m_callto.c_str());
|
2005-01-21 00:50:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GenConnection::~GenConnection()
|
|
|
|
{
|
2005-04-28 17:40:41 +00:00
|
|
|
if (!Engine::exiting())
|
|
|
|
Output("Ending %s generated call %s to: %s",
|
|
|
|
m_status.c_str(),m_id.c_str(),m_callto.c_str());
|
|
|
|
m_status = "destroyed";
|
|
|
|
s_mutex.lock();
|
|
|
|
s_calls.remove(this,false);
|
2005-01-21 16:35:35 +00:00
|
|
|
--s_current;
|
2005-04-28 17:40:41 +00:00
|
|
|
s_mutex.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
GenConnection* GenConnection::find(const String& id)
|
|
|
|
{
|
|
|
|
ObjList* l = s_calls.find(id);
|
|
|
|
return l ? static_cast<GenConnection*>(l->get()) : 0;
|
2005-01-21 00:50:25 +00:00
|
|
|
}
|
|
|
|
|
2005-01-21 20:34:10 +00:00
|
|
|
bool GenConnection::oneCall(String* target)
|
2005-01-21 16:35:35 +00:00
|
|
|
{
|
|
|
|
Message m("call.route");
|
|
|
|
m.addParam("driver","callgen");
|
2005-01-21 20:40:58 +00:00
|
|
|
m.addParam("caller",s_cfg.getValue("parameters","caller","yate"));
|
|
|
|
String callto(s_cfg.getValue("parameters","callto"));
|
2005-01-21 20:34:10 +00:00
|
|
|
if (callto.null()) {
|
2005-01-21 20:40:58 +00:00
|
|
|
String called(s_cfg.getValue("parameters","called"));
|
2005-04-28 17:40:41 +00:00
|
|
|
if (called.null())
|
|
|
|
return false;
|
2005-01-21 20:34:10 +00:00
|
|
|
if (target)
|
|
|
|
*target = called;
|
|
|
|
m.addParam("called",called);
|
|
|
|
if (!Engine::dispatch(m) || m.retValue().null()) {
|
|
|
|
Debug("CallGen",DebugInfo,"No route to call '%s'",called.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
callto = m.retValue();
|
|
|
|
m.retValue().clear();
|
|
|
|
}
|
|
|
|
if (target) {
|
|
|
|
if (*target)
|
|
|
|
*target << " ";
|
|
|
|
*target << callto;
|
2005-01-21 16:35:35 +00:00
|
|
|
}
|
|
|
|
m = "call.execute";
|
2005-01-21 20:34:10 +00:00
|
|
|
m.addParam("callto",callto);
|
2005-04-28 17:40:41 +00:00
|
|
|
unsigned int lifetime = s_cfg.getIntValue("parameters","maxlife");
|
|
|
|
if (lifetime) {
|
|
|
|
int minlife = s_cfg.getIntValue("parameters","minlife");
|
|
|
|
if (minlife)
|
2005-05-10 11:52:48 +00:00
|
|
|
lifetime -= (int)(((lifetime - minlife) * (int64_t)::random()) / RAND_MAX);
|
2005-04-28 17:40:41 +00:00
|
|
|
}
|
|
|
|
GenConnection* conn = new GenConnection(lifetime,callto);
|
2005-01-21 16:35:35 +00:00
|
|
|
m.addParam("id",conn->id());
|
|
|
|
m.userData(conn);
|
|
|
|
if (Engine::dispatch(m)) {
|
|
|
|
conn->setTarget(m.getValue("targetid"));
|
2005-04-28 17:40:41 +00:00
|
|
|
if (conn->getTarget().null()) {
|
2005-01-21 16:35:35 +00:00
|
|
|
Debug(DebugInfo,"Answering now generated call %s [%p] because we have no targetid",
|
|
|
|
conn->id().c_str(),conn);
|
|
|
|
conn->answered();
|
|
|
|
}
|
|
|
|
conn->deref();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Debug("CallGen",DebugInfo,"Rejecting '%s' unconnected to '%s'",
|
2005-01-21 20:34:10 +00:00
|
|
|
conn->id().c_str(),callto.c_str());
|
2005-01-21 16:35:35 +00:00
|
|
|
conn->destruct();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-01-21 00:50:25 +00:00
|
|
|
void GenConnection::disconnected(bool final, const char *reason)
|
|
|
|
{
|
2005-04-28 17:40:41 +00:00
|
|
|
Debug("CallGen",DebugInfo,"Disconnected '%s' reason '%s' [%p]",m_id.c_str(),reason,this);
|
2005-01-21 22:24:54 +00:00
|
|
|
m_status = "disconnected";
|
2005-01-21 00:50:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GenConnection::ringing()
|
|
|
|
{
|
2005-04-28 17:40:41 +00:00
|
|
|
Debug("CallGen",DebugInfo,"Ringing '%s' [%p]",m_id.c_str(),this);
|
2005-01-21 22:24:54 +00:00
|
|
|
m_status = "ringing";
|
2005-01-21 20:34:10 +00:00
|
|
|
s_mutex.lock();
|
|
|
|
++s_ringing;
|
2005-01-21 20:40:58 +00:00
|
|
|
bool media =s_cfg.getBoolValue("parameters","earlymedia",true);
|
2005-01-21 20:34:10 +00:00
|
|
|
s_mutex.unlock();
|
|
|
|
if (media)
|
|
|
|
makeSource();
|
2005-01-21 00:50:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GenConnection::answered()
|
|
|
|
{
|
2005-04-28 17:40:41 +00:00
|
|
|
Debug("CallGen",DebugInfo,"Answered '%s' [%p]",m_id.c_str(),this);
|
2005-01-21 22:24:54 +00:00
|
|
|
m_status = "answered";
|
2005-01-21 16:35:35 +00:00
|
|
|
s_mutex.lock();
|
|
|
|
++s_answers;
|
|
|
|
s_mutex.unlock();
|
2005-01-21 20:34:10 +00:00
|
|
|
makeSource();
|
2005-01-21 00:50:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GenConnection::hangup()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-01-21 20:34:10 +00:00
|
|
|
void GenConnection::makeSource()
|
|
|
|
{
|
|
|
|
if (getSource())
|
|
|
|
return;
|
|
|
|
s_mutex.lock();
|
2005-01-21 20:40:58 +00:00
|
|
|
String src(s_cfg.getValue("parameters","source"));
|
2005-01-21 20:34:10 +00:00
|
|
|
s_mutex.unlock();
|
|
|
|
if (src) {
|
|
|
|
Message m("chan.attach");
|
2005-04-28 17:40:41 +00:00
|
|
|
m.addParam("id",m_id);
|
2005-01-21 20:34:10 +00:00
|
|
|
m.addParam("source",src);
|
|
|
|
m.userData(this);
|
|
|
|
Engine::dispatch(m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-28 17:40:41 +00:00
|
|
|
bool ConnHandler::received(Message &msg, int id)
|
|
|
|
{
|
|
|
|
String callid(msg.getValue("targetid"));
|
|
|
|
if (!callid.startsWith("callgen/",false))
|
|
|
|
return false;
|
|
|
|
GenConnection *conn = GenConnection::find(callid);
|
|
|
|
if (!conn) {
|
|
|
|
Debug(DebugInfo,"Target '%s' was not found in list",callid.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
String text(msg.getValue("text"));
|
|
|
|
switch (id) {
|
|
|
|
case Answered:
|
|
|
|
conn->answered();
|
|
|
|
break;
|
|
|
|
case Ringing:
|
|
|
|
conn->ringing();
|
|
|
|
break;
|
|
|
|
case Execute:
|
|
|
|
break;
|
|
|
|
case Drop:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-01-21 16:35:35 +00:00
|
|
|
void GenThread::run()
|
|
|
|
{
|
2005-04-28 17:40:41 +00:00
|
|
|
Debug("CallGen",DebugInfo,"GenThread::run() [%p]",this);
|
|
|
|
int tonext = 10000;
|
|
|
|
while (!Engine::exiting()) {
|
2005-05-10 11:52:48 +00:00
|
|
|
Thread::usleep(tonext);
|
2005-04-28 17:40:41 +00:00
|
|
|
tonext = 10000;
|
2005-01-21 20:34:10 +00:00
|
|
|
Lock lock(s_mutex);
|
2005-01-21 20:40:58 +00:00
|
|
|
int maxcalls = s_cfg.getIntValue("parameters","maxcalls",5);
|
2005-01-21 20:34:10 +00:00
|
|
|
if (!s_runs || (s_current >= maxcalls) || (s_numcalls <= 0))
|
2005-01-21 16:35:35 +00:00
|
|
|
continue;
|
|
|
|
--s_numcalls;
|
2005-04-28 17:40:41 +00:00
|
|
|
tonext = s_cfg.getIntValue("parameters","avgdelay",1000);
|
2005-01-21 20:34:10 +00:00
|
|
|
lock.drop();
|
2005-01-21 16:35:35 +00:00
|
|
|
GenConnection::oneCall();
|
2005-05-10 11:52:48 +00:00
|
|
|
tonext = (int)(((int64_t)::random() * tonext * 2000) / RAND_MAX);
|
2005-04-28 17:40:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CleanThread::run()
|
|
|
|
{
|
|
|
|
Debug("CallGen",DebugInfo,"CleanThread::run() [%p]",this);
|
|
|
|
while (!Engine::exiting()) {
|
2005-05-10 11:52:48 +00:00
|
|
|
Thread::usleep(100000);
|
2005-04-28 17:40:41 +00:00
|
|
|
Lock lock(s_mutex);
|
|
|
|
Time t;
|
|
|
|
ObjList* l = &s_calls;
|
|
|
|
while (l) {
|
|
|
|
GenConnection* c = static_cast<GenConnection*>(l->get());
|
|
|
|
if (c && c->oldAge(t)) {
|
|
|
|
c->destruct();
|
|
|
|
if (c != l->get())
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
l = l->next();
|
|
|
|
}
|
2005-01-21 16:35:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CmdHandler::doCommand(String& line, String& rval)
|
2005-01-21 00:50:25 +00:00
|
|
|
{
|
|
|
|
if (line.startSkip("set")) {
|
2005-01-21 16:35:35 +00:00
|
|
|
int q = line.find('=');
|
2005-01-21 20:34:10 +00:00
|
|
|
s_mutex.lock();
|
2005-01-21 16:35:35 +00:00
|
|
|
if (q >= 0) {
|
|
|
|
String val = line.substr(q+1).trimBlanks();
|
|
|
|
line = line.substr(0,q).trimBlanks().toLower();
|
2005-01-21 20:40:58 +00:00
|
|
|
s_cfg.setValue("parameters",line,val.c_str());
|
2005-01-21 16:35:35 +00:00
|
|
|
rval << "Set '" << line << "' to '" << val << "'";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
line.toLower();
|
2005-01-21 20:40:58 +00:00
|
|
|
rval << "Value of '" << line << "' is '" << s_cfg.getValue("parameters",line) << "'";
|
2005-01-21 16:35:35 +00:00
|
|
|
}
|
2005-01-21 20:34:10 +00:00
|
|
|
s_mutex.unlock();
|
2005-01-21 00:50:25 +00:00
|
|
|
}
|
|
|
|
else if (line == "info") {
|
2005-01-21 20:34:10 +00:00
|
|
|
s_mutex.lock();
|
2005-01-21 16:35:35 +00:00
|
|
|
rval << "Made " << s_total << " calls, "
|
2005-01-21 20:34:10 +00:00
|
|
|
<< s_ringing << " ring, "
|
2005-01-21 16:35:35 +00:00
|
|
|
<< s_answers << " answered, "
|
|
|
|
<< s_current << " running";
|
|
|
|
if (s_runs)
|
|
|
|
rval << ", " << s_numcalls << " to go";
|
2005-01-21 20:34:10 +00:00
|
|
|
s_mutex.unlock();
|
2005-01-21 00:50:25 +00:00
|
|
|
}
|
|
|
|
else if (line == "start") {
|
2005-01-21 20:34:10 +00:00
|
|
|
s_mutex.lock();
|
2005-01-21 20:40:58 +00:00
|
|
|
s_numcalls = s_cfg.getIntValue("parameters","numcalls",100);
|
2005-01-21 16:35:35 +00:00
|
|
|
rval << "Generating " << s_numcalls << " new calls";
|
|
|
|
s_runs = true;
|
2005-01-21 20:34:10 +00:00
|
|
|
s_mutex.unlock();
|
2005-01-21 00:50:25 +00:00
|
|
|
}
|
|
|
|
else if (line == "stop") {
|
2005-01-21 20:34:10 +00:00
|
|
|
s_mutex.lock();
|
2005-01-21 16:35:35 +00:00
|
|
|
s_runs = false;
|
|
|
|
s_numcalls = 0;
|
2005-01-21 20:34:10 +00:00
|
|
|
s_mutex.unlock();
|
2005-04-28 17:40:41 +00:00
|
|
|
s_calls.clear();
|
2005-01-21 16:35:35 +00:00
|
|
|
rval << "Stopping generator and clearing calls";
|
2005-01-21 00:50:25 +00:00
|
|
|
}
|
2005-01-21 20:34:10 +00:00
|
|
|
else if (line == "drop") {
|
|
|
|
s_mutex.lock();
|
|
|
|
bool tmp = s_runs;
|
|
|
|
s_runs = false;
|
|
|
|
s_mutex.unlock();
|
2005-04-28 17:40:41 +00:00
|
|
|
s_calls.clear();
|
2005-01-21 20:34:10 +00:00
|
|
|
s_runs = tmp;
|
|
|
|
rval << "Clearing calls and continuing";
|
|
|
|
}
|
2005-01-21 00:50:25 +00:00
|
|
|
else if (line == "pause") {
|
2005-01-21 16:35:35 +00:00
|
|
|
s_runs = false;
|
|
|
|
rval << "No longer generating new calls";
|
|
|
|
}
|
|
|
|
else if (line == "resume") {
|
2005-01-21 20:34:10 +00:00
|
|
|
s_mutex.lock();
|
2005-01-21 16:35:35 +00:00
|
|
|
rval << "Resumed generating new calls, " << s_numcalls << " to go";
|
|
|
|
s_runs = true;
|
2005-01-21 20:34:10 +00:00
|
|
|
s_mutex.unlock();
|
2005-01-21 00:50:25 +00:00
|
|
|
}
|
|
|
|
else if (line == "single") {
|
2005-01-21 20:34:10 +00:00
|
|
|
String dest;
|
|
|
|
if (GenConnection::oneCall(&dest))
|
|
|
|
rval << "Calling " << dest;
|
|
|
|
else {
|
2005-01-21 16:35:35 +00:00
|
|
|
rval << "Failed to start call";
|
2005-01-21 20:34:10 +00:00
|
|
|
if (dest)
|
|
|
|
rval << " to " << dest;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (line == "load") {
|
|
|
|
s_mutex.lock();
|
|
|
|
s_cfg.load();
|
|
|
|
rval << "Loaded config from " << s_cfg;
|
|
|
|
s_mutex.unlock();
|
|
|
|
}
|
|
|
|
else if (line == "save") {
|
|
|
|
s_mutex.lock();
|
|
|
|
if (s_cfg.getBoolValue("general","cansave",true)) {
|
|
|
|
s_cfg.save();
|
|
|
|
rval << "Saved config to " << s_cfg;
|
|
|
|
}
|
|
|
|
else
|
2005-01-21 20:40:58 +00:00
|
|
|
rval << "Saving is disabled from config file";
|
2005-01-21 20:34:10 +00:00
|
|
|
s_mutex.unlock();
|
2005-01-21 00:50:25 +00:00
|
|
|
}
|
2005-01-21 20:34:10 +00:00
|
|
|
else if (line.null() || (line == "help") || (line == "?"))
|
|
|
|
rval << "Usage: " << s_help;
|
2005-01-21 00:50:25 +00:00
|
|
|
else
|
|
|
|
return false;
|
2005-01-21 16:35:35 +00:00
|
|
|
rval << "\n";
|
2005-01-21 00:50:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CmdHandler::received(Message &msg, int id)
|
|
|
|
{
|
|
|
|
String tmp;
|
|
|
|
switch (id) {
|
2005-01-21 22:24:54 +00:00
|
|
|
case Status:
|
2005-01-21 00:50:25 +00:00
|
|
|
tmp = msg.getValue("module");
|
|
|
|
if (tmp.null() || (tmp == "callgen")) {
|
2005-01-21 22:24:54 +00:00
|
|
|
s_mutex.lock();
|
|
|
|
msg.retValue() << "name=callgen,type=varchans,format=Status|Callto"
|
|
|
|
<< ";total=" << s_total
|
2005-01-21 20:34:10 +00:00
|
|
|
<< ",ring=" << s_ringing
|
2005-01-21 22:24:54 +00:00
|
|
|
<< ",answered=" << s_answers
|
|
|
|
<< ",chans=" << s_current << ";";
|
|
|
|
ObjList *l = &s_calls;
|
|
|
|
bool first = true;
|
|
|
|
for (; l; l=l->next()) {
|
|
|
|
GenConnection *c = static_cast<GenConnection *>(l->get());
|
|
|
|
if (c) {
|
|
|
|
if (first)
|
|
|
|
first = false;
|
|
|
|
else
|
|
|
|
msg.retValue() << ",";
|
|
|
|
msg.retValue() << c->id() << "=" << c->status() << "|" << c->party();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
msg.retValue() << "\n";
|
|
|
|
s_mutex.unlock();
|
2005-01-21 00:50:25 +00:00
|
|
|
if (tmp)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
2005-01-21 22:24:54 +00:00
|
|
|
case Command:
|
2005-01-21 00:50:25 +00:00
|
|
|
tmp = msg.getValue("line");
|
|
|
|
if (tmp.startSkip("callgen"))
|
2005-01-21 16:35:35 +00:00
|
|
|
return doCommand(tmp,msg.retValue());
|
2005-01-21 00:50:25 +00:00
|
|
|
break;
|
|
|
|
case Help:
|
|
|
|
tmp = msg.getValue("line");
|
|
|
|
if (tmp.null() || (tmp == "callgen")) {
|
2005-01-21 20:34:10 +00:00
|
|
|
msg.retValue() << " " << s_help << "\n";
|
2005-01-21 00:50:25 +00:00
|
|
|
if (tmp)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CallGenPlugin::CallGenPlugin()
|
2005-04-28 17:40:41 +00:00
|
|
|
: m_first(true)
|
2005-01-21 00:50:25 +00:00
|
|
|
{
|
|
|
|
Output("Loaded module Call Generator");
|
|
|
|
}
|
|
|
|
|
|
|
|
CallGenPlugin::~CallGenPlugin()
|
|
|
|
{
|
2005-04-28 17:40:41 +00:00
|
|
|
Output("Unloading module Call Generator, clearing %u calls",s_calls.count());
|
|
|
|
s_mutex.lock();
|
|
|
|
s_runs = false;
|
|
|
|
s_calls.clear();
|
|
|
|
s_mutex.unlock();
|
2005-01-21 00:50:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CallGenPlugin::initialize()
|
|
|
|
{
|
|
|
|
Output("Initializing module Call Generator");
|
2005-04-28 17:40:41 +00:00
|
|
|
s_mutex.lock();
|
2005-01-21 00:50:25 +00:00
|
|
|
s_cfg = Engine::configFile("callgen");
|
|
|
|
s_cfg.load();
|
2005-04-28 17:40:41 +00:00
|
|
|
s_mutex.unlock();
|
2005-01-21 00:50:25 +00:00
|
|
|
if (m_first) {
|
|
|
|
m_first = false;
|
2005-01-21 16:35:35 +00:00
|
|
|
|
2005-04-28 17:40:41 +00:00
|
|
|
ConnHandler* coh = new ConnHandler;
|
|
|
|
Engine::install(new MessageRelay("call.ringing",coh,ConnHandler::Ringing));
|
|
|
|
Engine::install(new MessageRelay("call.answered",coh,ConnHandler::Answered));
|
|
|
|
Engine::install(new MessageRelay("call.execute",coh,ConnHandler::Execute));
|
|
|
|
Engine::install(new MessageRelay("call.drop",coh,ConnHandler::Drop));
|
|
|
|
|
2005-01-21 00:50:25 +00:00
|
|
|
CmdHandler* cmh = new CmdHandler;
|
|
|
|
Engine::install(new MessageRelay("engine.status",cmh,CmdHandler::Status));
|
|
|
|
Engine::install(new MessageRelay("engine.command",cmh,CmdHandler::Command));
|
|
|
|
Engine::install(new MessageRelay("engine.help",cmh,CmdHandler::Help));
|
2005-01-21 16:35:35 +00:00
|
|
|
|
2005-04-28 17:40:41 +00:00
|
|
|
CleanThread* cln = new CleanThread;
|
|
|
|
if (!cln->startup()) {
|
|
|
|
Debug(DebugGoOn,"Failed to start call generator cleaner thread");
|
|
|
|
delete cln;
|
|
|
|
return;
|
|
|
|
}
|
2005-01-21 16:35:35 +00:00
|
|
|
GenThread* gen = new GenThread;
|
|
|
|
if (!gen->startup()) {
|
|
|
|
Debug(DebugGoOn,"Failed to start call generator thread");
|
|
|
|
delete gen;
|
|
|
|
}
|
2005-01-21 00:50:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-28 17:40:41 +00:00
|
|
|
INIT_PLUGIN(CallGenPlugin);
|
|
|
|
|
2005-01-21 00:50:25 +00:00
|
|
|
/* vi: set ts=8 sw=4 sts=4 noet: */
|