moved timers API into AmSession

app level timers can now be used easily with the AmSession functions:
 setTimer(int id, unsigned timeout)
 removeTimer(int id)
 removeTimers()
 timersSupported()
sayer/1.4-spce2.6
Stefan Sayer 16 years ago
parent 0159ea10c1
commit e471726afe

@ -56,7 +56,6 @@ EXPORT_SESSION_FACTORY(AnnRecorderFactory,MOD_NAME);
string AnnRecorderFactory::AnnouncePath;
string AnnRecorderFactory::DefaultAnnounce;
bool AnnRecorderFactory::SimpleMode=false;
AmDynInvokeFactory* AnnRecorderFactory::user_timer_fact = NULL;
AmDynInvokeFactory* AnnRecorderFactory::message_storage_fact = NULL;
const char* MsgStrError(int e) {
@ -106,8 +105,7 @@ int AnnRecorderFactory::onLoad()
AM_PROMPT_END(prompts, cfg, MOD_NAME);
user_timer_fact = AmPlugIn::instance()->getFactory4Di("user_timer");
if(!user_timer_fact) {
if (!AmSession::timersSupported()) {
ERROR("sorry, could not load user_timer from session_timer plug-in\n");
return -1;
}
@ -253,12 +251,6 @@ AnnRecorderDialog::AnnRecorderDialog(const map<string, string>& params,
prompts(prompts), cred(credentials),
playlist(this)
{
user_timer = AnnRecorderFactory::user_timer_fact->getInstance();
if(!user_timer) {
ERROR("could not get a user timer reference\n");
throw AmSession::Exception(500,"could not get a timer");
}
msg_storage = AnnRecorderFactory::message_storage_fact->getInstance();
if(!msg_storage){
ERROR("could not get a message storage reference\n");
@ -319,9 +311,7 @@ void AnnRecorderDialog::onDtmf(int event, int duration_msec) {
DBG("DTMF %d, %d\n", event, duration_msec);
// remove timer
try {
AmArg di_args,ret;
di_args.push(getLocalTag().c_str());
user_timer->invoke("removeUserTimers", di_args, ret);
removeTimers();
} catch(...) {
ERROR("Exception caught calling mod api\n");
}
@ -434,22 +424,14 @@ void AnnRecorderDialog::process(AmEvent* event)
if ((pl_ev->event_id == SEP_MSG_BEGIN) &&
(S_WAIT_START == state)) {
// start timer
AmArg di_args,ret;
di_args.push(TIMERID_START_TIMER);
di_args.push(START_RECORDING_TIMEOUT); // in seconds
di_args.push(getLocalTag().c_str());
user_timer->invoke("setTimer", di_args, ret);
setTimer(TIMERID_START_TIMER, START_RECORDING_TIMEOUT);
return;
}
if ((pl_ev->event_id == SEP_CONFIRM_BEGIN) &&
(S_CONFIRM == state)) {
// start timer
AmArg di_args,ret;
di_args.push(TIMERID_CONFIRM_TIMER);
di_args.push(CONFIRM_RECORDING_TIMEOUT); // in seconds
di_args.push(getLocalTag().c_str());
user_timer->invoke("setTimer", di_args, ret);
setTimer(TIMERID_CONFIRM_TIMER, CONFIRM_RECORDING_TIMEOUT);
return;
}
return;

@ -65,7 +65,6 @@ class AnnRecorderFactory: public AmSessionFactory
AmPromptCollection prompts;
public:
static AmDynInvokeFactory* user_timer_fact;
static AmDynInvokeFactory* message_storage_fact;
static string AnnouncePath;
@ -95,7 +94,6 @@ class AnnRecorderDialog : public AmSession,
string msg_filename; // recorded file
AmDynInvoke* user_timer;
AmDynInvoke* msg_storage;
std::auto_ptr<UACAuthCred> cred;

@ -43,7 +43,6 @@ EXPORT_SESSION_FACTORY(AuthB2BFactory,MOD_NAME);
AuthB2BFactory::AuthB2BFactory(const string& _app_name)
: AmSessionFactory(_app_name)
// , user_timer_fact(NULL)
{
}
@ -61,31 +60,18 @@ int AuthB2BFactory::onLoad()
pwd = cfg.getParameter("pwd");
}
// user_timer_fact = AmPlugIn::instance()->getFactory4Di("user_timer");
// if(!user_timer_fact) {
// ERROR("could not load user_timer from session_timer plug-in\n");
// return -1;
// }
return 0;
}
AmSession* AuthB2BFactory::onInvite(const AmSipRequest& req)
{
// AmDynInvoke* user_timer = user_timer_fact->getInstance();
// if(!user_timer) {
// ERROR("could not get a user timer reference\n");
// throw AmSession::Exception(500,"could not get a user timer reference");
// }
return new AuthB2BDialog(); //user_timer);
return new AuthB2BDialog();
}
AuthB2BDialog::AuthB2BDialog() // AmDynInvoke* user_timer)
AuthB2BDialog::AuthB2BDialog()
: m_state(BB_Init),
//m_user_timer(user_timer),
AmB2BCallerSession()
{
@ -187,11 +173,7 @@ bool AuthB2BDialog::onOtherReply(const AmSipReply& reply)
setInOut(NULL, NULL);
// // set the call timer
// AmArg di_args,ret;
// di_args.push(TIMERID_CREDIT_TIMEOUT);
// di_args.push(m_credit); // in seconds
// di_args.push(dlg.local_tag.c_str());
// m_user_timer->invoke("setTimer", di_args, ret);
// setTimer(TIMERID_CREDIT_TIMEOUT, m_credit);
}
}
else if(reply.code == 487 && dlg.getStatus() == AmSipDialog::Pending) {

@ -35,7 +35,6 @@ using std::string;
class AuthB2BFactory: public AmSessionFactory
{
/* AmDynInvokeFactory* user_timer_fact; */
public:
AuthB2BFactory(const string& _app_name);
@ -65,11 +64,9 @@ class AuthB2BDialog : public AmB2BCallerSession
string from;
string to;
/* AmDynInvoke* m_user_timer; */
public:
AuthB2BDialog(); //AmDynInvoke* user_timer);
AuthB2BDialog();
~AuthB2BDialog();
void process(AmEvent* ev);

@ -46,8 +46,7 @@ bool CallTimerFactory::UseAppParam = true;
EXPORT_SESSION_FACTORY(CallTimerFactory,MOD_NAME);
CallTimerFactory::CallTimerFactory(const string& _app_name)
: AmSessionFactory(_app_name),
user_timer_fact(NULL)
: AmSessionFactory(_app_name)
{
}
@ -67,9 +66,8 @@ int CallTimerFactory::onLoad()
UseAppParam = (cfg.getParameter("use_app_param") == "yes");
}
user_timer_fact = AmPlugIn::instance()->getFactory4Di("user_timer");
if(!user_timer_fact) {
ERROR("could not load user_timer from session_timer plug-in\n");
if (!AmSession::timersSupported()) {
ERROR("load session_timer plug-in for timers\n");
return -1;
}
@ -80,11 +78,6 @@ int CallTimerFactory::onLoad()
AmSession* CallTimerFactory::onInvite(const AmSipRequest& req)
{
DBG(" *** creating new call timer session ***\n");
AmDynInvoke* user_timer = user_timer_fact->getInstance();
if(!user_timer) {
ERROR("could not get a user timer reference\n");
throw AmSession::Exception(500,"could not get a user timer reference");
}
string app_param = getHeader(req.hdrs, PARAM_HDR, true);
@ -107,15 +100,13 @@ AmSession* CallTimerFactory::onInvite(const AmSipRequest& req)
DBG("using call timer %d seconds\n", call_time);
return new CallTimerDialog(user_timer, call_time);
return new CallTimerDialog(call_time);
}
CallTimerDialog::CallTimerDialog(AmDynInvoke* user_timer,
unsigned int call_time)
CallTimerDialog::CallTimerDialog(unsigned int call_time)
: m_state(BB_Init),
call_time(call_time),
m_user_timer(user_timer),
AmB2BCallerSession()
{
@ -185,11 +176,7 @@ bool CallTimerDialog::onOtherReply(const AmSipReply& reply)
setInOut(NULL, NULL);
// startAccounting();
// set the call timer
AmArg di_args,ret;
di_args.push(TIMERID_CALL_TIMER);
di_args.push((int)call_time); // in seconds
di_args.push(dlg.local_tag.c_str());
m_user_timer->invoke("setTimer", di_args, ret);
setTimer(TIMERID_CALL_TIMER, call_time);
}
}
else if(reply.code == 487 && dlg.getStatus() == AmSipDialog::Pending) {

@ -36,8 +36,6 @@ using std::string;
class CallTimerFactory: public AmSessionFactory
{
public:
AmDynInvokeFactory* user_timer_fact;
static unsigned int DefaultCallTimer;
static bool UseAppParam;
@ -59,14 +57,11 @@ class CallTimerDialog : public AmB2BCallerSession
int m_state;
AmDynInvoke* m_user_timer;
unsigned int call_time;
public:
CallTimerDialog(AmDynInvoke* user_timer,
unsigned int call_time);
CallTimerDialog(unsigned int call_time);
~CallTimerDialog();
void process(AmEvent* ev);

@ -756,30 +756,13 @@ EXEC_ACTION_START(SCSetTimerAction) {
EXEC_ACTION_STOP;
}
DBG("setting timer %u with timeout %u\n", timerid, timeout);
AmDynInvokeFactory* user_timer_fact =
AmPlugIn::instance()->getFactory4Di("user_timer");
if(!user_timer_fact) {
ERROR("load sess_timer module for timers.\n");
sc_sess->SET_ERRNO(DSM_ERRNO_CONFIG);
sc_sess->SET_STRERROR("load sess_timer module for timers.\n");
EXEC_ACTION_STOP;
}
AmDynInvoke* user_timer = user_timer_fact->getInstance();
if(!user_timer) {
ERROR("load sess_timer module for timers.\n");
if (!sess->setTimer(timerid, timeout)) {
ERROR("load session_timer module for timers.\n");
sc_sess->SET_ERRNO(DSM_ERRNO_CONFIG);
sc_sess->SET_STRERROR("load sess_timer module for timers.\n");
EXEC_ACTION_STOP;
}
AmArg di_args,ret;
di_args.push((int)timerid);
di_args.push((int)timeout); // in seconds
di_args.push(sess->getLocalTag().c_str());
user_timer->invoke("setTimer", di_args, ret);
sc_sess->CLR_ERRNO;
} EXEC_ACTION_END;
@ -795,53 +778,25 @@ EXEC_ACTION_START(SCRemoveTimerAction) {
return false;
}
DBG("removing timer %u\n", timerid);
AmDynInvokeFactory* user_timer_fact =
AmPlugIn::instance()->getFactory4Di("user_timer");
if(!user_timer_fact) {
sc_sess->SET_ERRNO(DSM_ERRNO_CONFIG);
sc_sess->SET_STRERROR("load sess_timer module for timers.\n");
EXEC_ACTION_STOP;
}
AmDynInvoke* user_timer = user_timer_fact->getInstance();
if(!user_timer) {
if (!sess->removeTimer(timerid)) {
ERROR("load session_timer module for timers.\n");
sc_sess->SET_ERRNO(DSM_ERRNO_CONFIG);
sc_sess->SET_STRERROR("load sess_timer module for timers.\n");
sc_sess->SET_STRERROR("load session_timer module for timers.\n");
EXEC_ACTION_STOP;
}
AmArg di_args,ret;
di_args.push((int)timerid);
di_args.push(sess->getLocalTag().c_str());
user_timer->invoke("removeTimer", di_args, ret);
sc_sess->CLR_ERRNO;
} EXEC_ACTION_END;
EXEC_ACTION_START(SCRemoveTimersAction) {
DBG("removing timers for session %s\n", sess->getLocalTag().c_str());
AmDynInvokeFactory* user_timer_fact =
AmPlugIn::instance()->getFactory4Di("user_timer");
if(!user_timer_fact) {
ERROR("load sess_timer module for timers.\n");
if (!sess->removeTimers()) {
ERROR("load session_timer module for timers.\n");
sc_sess->SET_ERRNO(DSM_ERRNO_CONFIG);
sc_sess->SET_STRERROR("load sess_timer module for timers.\n");
EXEC_ACTION_STOP;
}
AmDynInvoke* user_timer = user_timer_fact->getInstance();
if(!user_timer) {
sc_sess->SET_ERRNO(DSM_ERRNO_CONFIG);
sc_sess->SET_STRERROR("load sess_timer module for timers.\n");
EXEC_ACTION_STOP;
}
AmArg di_args,ret;
di_args.push(sess->getLocalTag().c_str());
user_timer->invoke("removeUserTimers", di_args, ret);
sc_sess->CLR_ERRNO;
} EXEC_ACTION_END;

@ -58,9 +58,8 @@ int b2b_connectFactory::onLoad()
if (cfg.getParameter("transparent_ruri")=="true")
TransparentDestination = true;
// user_timer_fact = AmPlugIn::instance()->getFactory4Di("user_timer");
// if(!user_timer_fact) {
// ERROR("could not load user_timer from session_timer plug-in\n");
// if (!AmSession::timersSupported()) {
// ERROR("load session_timer plug-in for timers\n");
// return -1;
// }
@ -70,25 +69,18 @@ int b2b_connectFactory::onLoad()
AmSession* b2b_connectFactory::onInvite(const AmSipRequest& req)
{
// AmDynInvoke* user_timer = user_timer_fact->getInstance();
// if(!user_timer) {
// ERROR("could not get a user timer reference\n");
// throw AmSession::Exception(500,"could not get a user timer reference");
// }
string app_param = getHeader(req.hdrs, PARAM_HDR, true);
if (!app_param.length()) {
throw AmSession::Exception(500, "b2b_connect: parameters not found");
}
return new b2b_connectDialog(); //user_timer);
return new b2b_connectDialog();
}
b2b_connectDialog::b2b_connectDialog() // AmDynInvoke* user_timer)
: //m_user_timer(user_timer),
AmB2ABCallerSession()
b2b_connectDialog::b2b_connectDialog()
: AmB2ABCallerSession()
{
RTPStream()->setPlayoutType(ADAPTIVE_PLAYOUT);

@ -35,7 +35,6 @@ using std::string;
class b2b_connectFactory: public AmSessionFactory
{
/* AmDynInvokeFactory* user_timer_fact; */
public:
b2b_connectFactory(const string& _app_name);
@ -58,11 +57,9 @@ class b2b_connectDialog : public AmB2ABCallerSession
AmSipRequest invite_req;
/* AmDynInvoke* m_user_timer; */
public:
b2b_connectDialog(); //AmDynInvoke* user_timer);
b2b_connectDialog();
~b2b_connectDialog();
void onSessionStart(const AmSipRequest& req);

@ -413,24 +413,10 @@ void CallGenDialog::onSessionStart(const AmSipReply& rep) {
call_timer+=rand()%call_time_rand;
if (call_timer > 0) {
AmDynInvokeFactory* UserTimer = AmPlugIn::instance()->getFactory4Di("user_timer");
if(!UserTimer){
if (!setTimer(CALL_TIMER, call_timer)) {
ERROR("could not load user_timer from session_timer plug-in\n");
return;
}
AmDynInvoke* user_timer = UserTimer->getInstance();
if (!user_timer) {
ERROR("could not get user_timer\n");
return;
}
DBG("setting call timer to %d seconds\n", call_timer);
AmArg di_args,ret;
di_args.push(CALL_TIMER);
di_args.push(call_timer);
di_args.push(getLocalTag().c_str());
user_timer->invoke("setTimer",di_args,ret);
}
}

@ -26,7 +26,7 @@ EXPORT_SESSION_FACTORY(MyCCFactory,MOD_NAME);
string MyCCFactory::ConnectSuffix;
MyCCFactory::MyCCFactory(const string& _app_name)
: AmSessionFactory(_app_name), user_timer_fact(NULL)
: AmSessionFactory(_app_name)
{
}
@ -44,9 +44,8 @@ int MyCCFactory::onLoad()
EnterNumber = cfg.getParameter("enter_number", "/tmp/enter_number.wav");
ConnectSuffix = cfg.getParameter("connect_suffix", "@127.0.0.1");
user_timer_fact = AmPlugIn::instance()->getFactory4Di("user_timer");
if(!user_timer_fact){
ERROR("could not load user_timer from session_timer plug-in\n");
if (!AmSession::timersSupported()) {
ERROR("load session_timer plug-in for timers\n");
return -1;
}
cc_acc_fact = AmPlugIn::instance()->getFactory4Di("cc_acc");
@ -60,26 +59,21 @@ int MyCCFactory::onLoad()
AmSession* MyCCFactory::onInvite(const AmSipRequest& req)
{
AmDynInvoke* user_timer = user_timer_fact->getInstance();
if(!user_timer){
ERROR("could not get a user timer reference\n");
throw AmSession::Exception(500,"could not get a user timer reference");
}
AmDynInvoke* cc_acc = cc_acc_fact->getInstance();
if(!user_timer){
if(!cc_acc){
ERROR("could not get a cc acc reference\n");
throw AmSession::Exception(500,"could not get a cc acc reference");
}
return new MyCCDialog(cc_acc, user_timer);
return new MyCCDialog(cc_acc);
}
MyCCDialog::MyCCDialog(AmDynInvoke* cc_acc, AmDynInvoke* user_timer)
MyCCDialog::MyCCDialog(AmDynInvoke* cc_acc)
: playlist(this),
state(CC_Collecting_PIN),
cc_acc(cc_acc), user_timer(user_timer),
cc_acc(cc_acc),
AmB2BCallerSession()
{
@ -209,11 +203,7 @@ bool MyCCDialog::onOtherReply(const AmSipReply& reply) {
// detach from media processor (not in RTP path any more)
AmMediaProcessor::instance()->removeSession(this);
// set the call timer
AmArg di_args,ret;
di_args.push(TIMERID_CREDIT_TIMEOUT);
di_args.push(credit); // in seconds
di_args.push(dlg.local_tag.c_str());
user_timer->invoke("setTimer", di_args, ret);
setTimer(TIMERID_CREDIT_TIMEOUT, credit);
}
} else {
DBG("Callee final error with code %d\n",reply.code);

@ -10,7 +10,6 @@ using std::string;
class MyCCFactory: public AmSessionFactory
{
AmDynInvokeFactory* user_timer_fact;
AmDynInvokeFactory* cc_acc_fact;
public:
@ -49,11 +48,10 @@ class MyCCDialog : public AmB2BCallerSession
void stopAccounting();
struct timeval acc_start;
AmDynInvoke* user_timer;
AmDynInvoke* cc_acc;
public:
MyCCDialog(AmDynInvoke* cc_acc, AmDynInvoke* user_timer);
MyCCDialog(AmDynInvoke* cc_acc);
~MyCCDialog();
void onSessionStart(const AmSipRequest& req);

@ -174,8 +174,7 @@ void PythonScriptThread::on_stop() {
}
IvrFactory::IvrFactory(const string& _app_name)
: AmSessionFactory(_app_name),
user_timer_fact(NULL)
: AmSessionFactory(_app_name)
{
}
@ -300,14 +299,7 @@ IvrDialog* IvrFactory::newDlg(const string& name)
IvrScriptDesc& mod_desc = mod_it->second;
AmDynInvoke* user_timer = user_timer_fact->getInstance();
if(!user_timer){
ERROR("could not get a user timer reference\n");
throw AmSession::Exception(500,"could not get a user timer reference");
}
IvrDialog* dlg = new IvrDialog(user_timer);
IvrDialog* dlg = new IvrDialog();
PyObject* c_dlg = PyCObject_FromVoidPtr(dlg,NULL);
PyObject* dlg_inst = PyObject_CallMethod(mod_desc.dlg_class,"__new__","OO",
@ -425,10 +417,8 @@ bool IvrFactory::loadScript(const string& path)
*/
int IvrFactory::onLoad()
{
user_timer_fact = AmPlugIn::instance()->getFactory4Di("user_timer");
if(!user_timer_fact){
ERROR("could not load user_timer from session_timer plug-in\n");
if (!AmSession::timersSupported()) {
ERROR("load session_timer plug-in (for timers)\n");
return -1;
}
@ -575,11 +565,10 @@ AmSession* IvrFactory::onInvite(const AmSipRequest& req)
return newDlg(req.user);
}
IvrDialog::IvrDialog(AmDynInvoke* user_timer)
IvrDialog::IvrDialog()
: py_mod(NULL),
py_dlg(NULL),
playlist(this),
user_timer(user_timer)
playlist(this)
{
set_sip_relay_only(false);
}

@ -83,7 +83,6 @@ class IvrFactory: public AmSessionFactory
map<string,IvrScriptDesc> mod_reg;
AmDynInvokeFactory* user_timer_fact;
static AmSessionEventHandlerFactory* session_timer_f;
void init_python_interpreter(const string& script_path);
@ -131,10 +130,9 @@ class IvrDialog : public AmB2BCallerSession
void createCalleeSession();
public:
AmDynInvoke* user_timer;
AmPlaylist playlist;
IvrDialog(AmDynInvoke* user_timer);
IvrDialog();
~IvrDialog();
// must be called before everything else.

@ -411,13 +411,7 @@ static PyObject* IvrDialogBase_setTimer(IvrDialogBase* self, PyObject* args)
return NULL;
}
AmArg di_args,ret;
di_args.push(id);
di_args.push(interval);
di_args.push(self->p_dlg->getLocalTag().c_str());
self->p_dlg->user_timer->
invoke("setTimer", di_args, ret);
self->p_dlg->setTimer(id, interval);
Py_INCREF(Py_None);
return Py_None;
@ -436,12 +430,7 @@ static PyObject* IvrDialogBase_removeTimer(IvrDialogBase* self, PyObject* args)
return NULL;
}
AmArg di_args,ret;
di_args.push(id);
di_args.push(self->p_dlg->getLocalTag().c_str());
self->p_dlg->user_timer->
invoke("removeTimer",di_args,ret);
self->p_dlg->removeTimer(id);
Py_INCREF(Py_None);
return Py_None;
@ -452,12 +441,8 @@ static PyObject* IvrDialogBase_removeTimers(IvrDialogBase* self, PyObject* args)
{
assert(self->p_dlg);
AmArg di_args,ret;
di_args.push(self->p_dlg->getLocalTag().c_str());
self->p_dlg->removeTimers();
self->p_dlg->user_timer->
invoke("removeUserTimers",di_args,ret);
Py_INCREF(Py_None);
return Py_None;
}

@ -120,8 +120,7 @@ extern "C" {
}
PySemsFactory::PySemsFactory(const string& _app_name)
: AmSessionFactory(_app_name),
user_timer_fact(NULL)
: AmSessionFactory(_app_name)
{
}
@ -228,10 +227,9 @@ AmSession* PySemsFactory::newDlg(const string& name)
PySemsScriptDesc& mod_desc = mod_it->second;
AmDynInvoke* user_timer = user_timer_fact->getInstance();
if(!user_timer){
ERROR("could not get a user timer reference\n");
throw AmSession::Exception(500,"could not get a user timer reference");
if (!AmSession::timersSupported()) {
ERROR("load session_timer plugin for timers\n");
throw AmSession::Exception(500,SIP_REPLY_SERVER_INTERNAL_ERROR);
}
PyObject* dlg_inst = PyObject_Call(mod_desc.dlg_class,PyTuple_New(0),NULL);
@ -402,10 +400,8 @@ bool PySemsFactory::loadScript(const string& path)
*/
int PySemsFactory::onLoad()
{
user_timer_fact = AmPlugIn::instance()->getFactory4Di("user_timer");
if(!user_timer_fact){
ERROR("could not load user_timer from session_timer plug-in\n");
if (!AmSession::timersSupported()) {
ERROR("load session_timer plug-in (for timers)\n");
return -1;
}

@ -83,8 +83,6 @@ class PySemsFactory: public AmSessionFactory
map<string,PySemsScriptDesc> mod_reg;
AmDynInvokeFactory* user_timer_fact;
void init_python_interpreter(const string& script_path);
void set_sys_path(const string& script_path);
void import_py_sems_builtins();

@ -20,14 +20,7 @@
#include "PySemsB2ABDialog.h"
#include "PySemsUtils.h"
PySemsB2ABDialog::PySemsB2ABDialog()
: playlist(this),
user_timer(NULL)
{
}
PySemsB2ABDialog::PySemsB2ABDialog(AmDynInvoke* user_timer)
: playlist(this),
user_timer(user_timer)
: playlist(this)
{
}

@ -32,11 +32,9 @@ class PySemsB2ABDialog : public AmB2ABCallerSession,
public PySemsDialogBase
{
public:
AmDynInvoke* user_timer;
AmPlaylist playlist;
PySemsB2ABDialog();
PySemsB2ABDialog(AmDynInvoke* user_timer);
virtual ~PySemsB2ABDialog();
void onSessionStart(const AmSipRequest& req);

@ -21,15 +21,7 @@
#include "PySemsB2BDialog.h"
#include "PySemsUtils.h"
PySemsB2BDialog::PySemsB2BDialog()
: playlist(this),
user_timer(NULL)
{
set_sip_relay_only(false);
}
PySemsB2BDialog::PySemsB2BDialog(AmDynInvoke* user_timer)
: playlist(this),
user_timer(user_timer)
: playlist(this)
{
set_sip_relay_only(false);
}

@ -31,11 +31,9 @@ class PySemsB2BDialog : public AmB2BCallerSession,
public PySemsDialogBase
{
public:
AmDynInvoke* user_timer;
AmPlaylist playlist;
PySemsB2BDialog();
PySemsB2BDialog(AmDynInvoke* user_timer);
virtual ~PySemsB2BDialog();
void onSessionStart(const AmSipRequest& req);

@ -22,25 +22,15 @@
#include "PySemsUtils.h"
PySemsDialog::PySemsDialog()
: playlist(this),
user_timer(NULL)
: playlist(this)
{
}
PySemsDialog::PySemsDialog(AmDynInvoke* user_timer)
: playlist(this),
user_timer(user_timer)
{
}
PySemsDialog::~PySemsDialog()
{
playlist.close(false);
}
void PySemsDialog::onSessionStart(const AmSipRequest& req)
{
DBG("PySemsDialog::onSessionStart\n");

@ -34,11 +34,9 @@ class PySemsDialog : public AmSession,
{
public:
AmDynInvoke* user_timer;
AmPlaylist playlist;
PySemsDialog();
PySemsDialog(AmDynInvoke* user_timer);
virtual ~PySemsDialog();
void onSessionStart(const AmSipRequest& req);

@ -1,3 +1,3 @@
target = py_sems_lib
sources = sippy_sems_libcmodule.cpp sippy_sems_libPySemsB2ABEvent.cpp sippy_sems_libPySemsB2ABCalleeDialog.cpp sippy_sems_libAmB2ABCalleeSession.cpp sippy_sems_libPySemsB2ABDialog.cpp sippy_sems_libAmSessionAudioConnector.cpp sippy_sems_libPySemsB2BDialog.cpp sippy_sems_libPySemsDialog.cpp sippy_sems_libAmAudioFile.cpp sippy_sems_libAmAudioEvent.cpp sippy_sems_libAmEvent.cpp sippy_sems_libAmSipDialog.cpp sippy_sems_libAmSipReply.cpp sippy_sems_libAmSipRequest.cpp sippy_sems_libstring.cpp
headers = sipAPIpy_sems_lib.h sippy_sems_libPySemsB2ABEvent.h sippy_sems_libPySemsB2ABCalleeDialog.h sippy_sems_libAmB2ABCalleeSession.h sippy_sems_libPySemsB2ABDialog.h sippy_sems_libAmSessionAudioConnector.h sippy_sems_libPySemsB2BDialog.h sippy_sems_libPySemsDialog.h sippy_sems_libAmAudioFile.h sippy_sems_libAmAudioEvent.h sippy_sems_libAmEvent.h sippy_sems_libAmSipDialog.h sippy_sems_libAmSipReply.h sippy_sems_libAmSipRequest.h sippy_sems_libstring.h
headers = sipAPIpy_sems_lib.h

@ -158,9 +158,9 @@ AmSession* SBCFactory::onInvite(const AmSipRequest& req)
}
SBCDialog::SBCDialog(const SBCCallProfile& call_profile) // AmDynInvoke* user_timer)
SBCDialog::SBCDialog(const SBCCallProfile& call_profile)
: m_state(BB_Init),
m_user_timer(NULL),prepaid_acc(NULL),
prepaid_acc(NULL),
call_profile(call_profile)
{
set_sip_relay_only(false);
@ -250,7 +250,8 @@ void SBCDialog::onInvite(const AmSipRequest& req)
// get timer
if (call_profile.call_timer_enabled || call_profile.prepaid_enabled) {
if (!getUserTimer()) {
if (!timersSupported()) {
ERROR("load session_timer module for call timers\n");
throw AmSession::Exception(500, SIP_REPLY_SERVER_INTERNAL_ERROR);
}
}
@ -310,20 +311,6 @@ void SBCDialog::onInvite(const AmSipRequest& req)
connectCallee(to, ruri, true);
}
bool SBCDialog::getUserTimer() {
AmDynInvokeFactory* fact =
AmPlugIn::instance()->getFactory4Di("user_timer");
if (NULL == fact) {
ERROR("load session_timer module for call timers\n");
}
m_user_timer = fact->getInstance();
if(NULL == m_user_timer) {
ERROR("could not get a timer reference\n");
return false;
}
return true;
}
bool SBCDialog::getPrepaidInterface() {
if (call_profile.prepaid_accmodule.empty()) {
ERROR("using prepaid but empty prepaid_accmodule!\n");
@ -516,8 +503,8 @@ void SBCDialog::stopCall() {
/** @return whether successful */
bool SBCDialog::startCallTimer() {
if ((call_profile.call_timer_enabled || call_profile.prepaid_enabled) &&
(NULL == m_user_timer)) {
ERROR("internal implementation error: invalid timer reference\n");
(!AmSession::timersSupported())) {
ERROR("internal implementation error: timers not supported\n");
terminateOtherLeg();
terminateLeg();
return false;
@ -525,11 +512,7 @@ bool SBCDialog::startCallTimer() {
if (call_profile.call_timer_enabled) {
DBG("SBC: starting call timer of %u seconds\n", call_timer);
AmArg di_args,ret;
di_args.push((int)SBC_TIMER_ID_CALL_TIMER);
di_args.push((int)call_timer); // in seconds
di_args.push(getLocalTag().c_str());
m_user_timer->invoke("setTimer", di_args, ret);
setTimer(SBC_TIMER_ID_CALL_TIMER, call_timer);
}
return true;
@ -550,11 +533,7 @@ void SBCDialog::startPrepaidAccounting() {
DBG("SBC: starting prepaid timer of %d seconds\n", prepaid_credit);
{
AmArg di_args,ret;
di_args.push((int)SBC_TIMER_ID_PREPAID_TIMEOUT);
di_args.push((int)prepaid_credit); // in seconds
di_args.push(getLocalTag().c_str());
m_user_timer->invoke("setTimer", di_args, ret);
setTimer(SBC_TIMER_ID_PREPAID_TIMEOUT, prepaid_credit);
}
{

@ -43,8 +43,6 @@ using std::string;
class SBCFactory: public AmSessionFactory
{
/* AmDynInvokeFactory* user_timer_fact; */
std::map<string, SBCCallProfile> call_profiles;
std::map<string, AmConfigReader> call_profiles_configs;
@ -80,7 +78,6 @@ class SBCDialog : public AmB2BCallerSession
string callid;
unsigned int call_timer;
AmDynInvoke* m_user_timer;
// prepaid
AmDynInvoke* prepaid_acc;
@ -95,12 +92,11 @@ class SBCDialog : public AmB2BCallerSession
void startPrepaidAccounting();
void stopPrepaidAccounting();
bool getUserTimer();
bool getPrepaidInterface();
public:
SBCDialog(const SBCCallProfile& call_profile); //AmDynInvoke* user_timer);
SBCDialog(const SBCCallProfile& call_profile);
~SBCDialog();
void process(AmEvent* ev);

@ -91,7 +91,7 @@ AmSession* SSTB2BFactory::onInvite(const AmSipRequest& req)
}
SSTB2BDialog::SSTB2BDialog() // AmDynInvoke* user_timer)
SSTB2BDialog::SSTB2BDialog()
: m_state(BB_Init),
AmB2BCallerSession()

@ -37,8 +37,6 @@ using std::string;
class SSTB2BFactory: public AmSessionFactory
{
/* AmDynInvokeFactory* user_timer_fact; */
public:
SSTB2BFactory(const string& _app_name);
@ -71,12 +69,9 @@ class SSTB2BDialog : public AmB2BCallerSession
string from;
string to;
/* AmDynInvoke* m_user_timer; */
/* set<int> b2b_reinvite_cseqs; // cseqs of reinvite we sent from the middle */
public:
SSTB2BDialog(); //AmDynInvoke* user_timer);
SSTB2BDialog();
~SSTB2BDialog();
void process(AmEvent* ev);

@ -45,7 +45,7 @@
EXPORT_SESSION_FACTORY(SWPrepaidSIPFactory,MOD_NAME);
SWPrepaidSIPFactory::SWPrepaidSIPFactory(const string& _app_name)
: AmSessionFactory(_app_name), user_timer_fact(NULL)
: AmSessionFactory(_app_name)
{
}
@ -58,9 +58,8 @@ int SWPrepaidSIPFactory::onLoad()
string acc_plugin = cfg.getParameter("acc_plugin", ACC_PLUGIN);
user_timer_fact = AmPlugIn::instance()->getFactory4Di("user_timer");
if(!user_timer_fact) {
ERROR("could not load user_timer from session_timer plug-in\n");
if (!AmSession::timersSupported()) {
ERROR("load session_timer plug-in for timers\n");
return -1;
}
@ -78,25 +77,19 @@ int SWPrepaidSIPFactory::onLoad()
AmSession* SWPrepaidSIPFactory::onInvite(const AmSipRequest& req)
{
AmDynInvoke* user_timer = user_timer_fact->getInstance();
if(!user_timer) {
ERROR("could not get a user timer reference\n");
throw AmSession::Exception(500,"could not get a user timer reference");
}
AmDynInvoke* cc_acc = cc_acc_fact->getInstance();
if(!cc_acc) {
ERROR("could not get an accounting reference\n");
throw AmSession::Exception(500,"could not get an acc reference");
}
return new SWPrepaidSIPDialog(cc_acc, user_timer);
return new SWPrepaidSIPDialog(cc_acc);
}
SWPrepaidSIPDialog::SWPrepaidSIPDialog(AmDynInvoke* cc_acc, AmDynInvoke* user_timer)
SWPrepaidSIPDialog::SWPrepaidSIPDialog(AmDynInvoke* cc_acc)
: m_state(CC_Init),
m_cc_acc(cc_acc), m_user_timer(user_timer),
m_cc_acc(cc_acc),
AmB2BCallerSession()
{
@ -231,11 +224,7 @@ bool SWPrepaidSIPDialog::onOtherReply(const AmSipReply& reply)
setInOut(NULL, NULL);
// set the call timer
AmArg di_args,ret;
di_args.push(TIMERID_CREDIT_TIMEOUT);
di_args.push(m_credit); // in seconds
di_args.push(dlg.local_tag.c_str());
m_user_timer->invoke("setTimer", di_args, ret);
setTimer(TIMERID_CREDIT_TIMEOUT, m_credit);
}
}
else if(reply.code == 487 && dlg.getStatus() == AmSipDialog::Pending) {

@ -35,7 +35,6 @@ using std::string;
class SWPrepaidSIPFactory: public AmSessionFactory
{
AmDynInvokeFactory* user_timer_fact;
AmDynInvokeFactory* cc_acc_fact;
public:
@ -68,12 +67,11 @@ class SWPrepaidSIPDialog : public AmB2BCallerSession
void stopAccounting();
struct timeval m_acc_start;
AmDynInvoke* m_user_timer;
AmDynInvoke* m_cc_acc;
public:
SWPrepaidSIPDialog(AmDynInvoke* cc_acc, AmDynInvoke* user_timer);
SWPrepaidSIPDialog(AmDynInvoke* cc_acc);
~SWPrepaidSIPDialog();
void process(AmEvent* ev);

@ -76,7 +76,6 @@ string AnswerMachineFactory::RecFileExt;
string AnswerMachineFactory::AnnouncePath;
string AnswerMachineFactory::DefaultAnnounce;
int AnswerMachineFactory::MaxRecordTime;
AmDynInvokeFactory* AnswerMachineFactory::UserTimer=0;
AmDynInvokeFactory* AnswerMachineFactory::MessageStorage=0;
bool AnswerMachineFactory::SaveEmptyMsg = true;
bool AnswerMachineFactory::TryPersonalGreeting = false;
@ -452,10 +451,8 @@ int AnswerMachineFactory::onLoad()
MaxRecordTime = cfg.getParameterInt("max_record_time",DEFAULT_RECORD_TIME);
RecFileExt = cfg.getParameter("rec_file_ext",DEFAULT_AUDIO_EXT);
UserTimer = AmPlugIn::instance()->getFactory4Di("user_timer");
if(!UserTimer){
ERROR("could not load user_timer from session_timer plug-in\n");
if (!AmSession::timersSupported()) {
ERROR("load session_timer plug-in (for timers support)\n");
return -1;
}
@ -746,13 +743,6 @@ AnswerMachineDialog::AnswerMachineDialog(const string& user,
email_dict["uid"] = uid;
email_dict["did"] = did;
user_timer = AnswerMachineFactory::UserTimer->getInstance();
if(!user_timer){
ERROR("could not get a user timer reference\n");
throw AmSession::Exception(500,"could not get a "
"user timer reference");
}
if (vm_mode == MODE_BOTH || vm_mode == MODE_BOX) {
msg_storage = AnswerMachineFactory::MessageStorage->getInstance();
if(!msg_storage){
@ -790,12 +780,8 @@ void AnswerMachineDialog::process(AmEvent* event)
playlist.addToPlaylist(new AmPlaylistItem(NULL,&a_msg));
{AmArg di_args,ret;
di_args.push(RECORD_TIMER);
di_args.push(AnswerMachineFactory::MaxRecordTime);
di_args.push(getLocalTag().c_str());
setTimer(RECORD_TIMER, AnswerMachineFactory::MaxRecordTime);
user_timer->invoke("setTimer",di_args,ret);}
status = 1;
} break;

@ -80,7 +80,6 @@ public:
static string AnnouncePath;
static string DefaultAnnounce;
static int MaxRecordTime;
static AmDynInvokeFactory* UserTimer;
static AmDynInvokeFactory* MessageStorage;
static bool SaveEmptyMsg;
static bool TryPersonalGreeting;
@ -118,7 +117,6 @@ class AnswerMachineDialog : public AmSession
const EmailTemplate* tmpl;
EmailTmplDict email_dict;
AmDynInvoke* user_timer;
AmDynInvoke* msg_storage;
int status;

@ -67,7 +67,8 @@ AmSession::AmSession()
m_dtmfDetectionEnabled(true),
accept_early_session(false),
refresh_method(REFRESH_UPDATE_FB_REINV),
processing_status(SESSION_PROCESSING_EVENTS)
processing_status(SESSION_PROCESSING_EVENTS),
user_timer_ref(NULL)
#ifdef WITH_ZRTP
, zrtp_session(NULL), zrtp_audio(NULL), enable_zrtp(true)
#endif
@ -78,6 +79,7 @@ AmSession::AmSession()
{
use_local_audio[AM_AUDIO_IN] = false;
use_local_audio[AM_AUDIO_OUT] = false;
DBG("user_timer_ref = %p\n", user_timer_ref);
}
AmSession::~AmSession()
@ -1081,6 +1083,70 @@ string AmSession::advertisedIP()
return AmConfig::LocalIP; // "listen" parameter.
return set_ip;
}
// TODO: move user timers into core
void AmSession::getUserTimerInstance() {
AmDynInvokeFactory* fact =
AmPlugIn::instance()->getFactory4Di("user_timer");
if (!fact)
return;
user_timer_ref = fact->getInstance();
}
bool AmSession::timersSupported() {
return NULL != AmPlugIn::instance()->getFactory4Di("user_timer") ;
}
bool AmSession::setTimer(int timer_id, unsigned int timeout) {
if (NULL == user_timer_ref)
getUserTimerInstance();
if (NULL == user_timer_ref)
return false;
DBG("setting timer %d with timeout %u\n", timer_id, timeout);
AmArg di_args,ret;
di_args.push((int)timer_id);
di_args.push((int)timeout); // in seconds
di_args.push(getLocalTag().c_str());
user_timer_ref->invoke("setTimer", di_args, ret);
return true;
}
bool AmSession::removeTimer(int timer_id) {
if (NULL == user_timer_ref)
getUserTimerInstance();
if (NULL == user_timer_ref)
return false;
DBG("removing timer %d\n", timer_id);
AmArg di_args,ret;
di_args.push((int)timer_id);
di_args.push(getLocalTag().c_str());
user_timer_ref->invoke("removeTimer", di_args, ret);
return true;
}
bool AmSession::removeTimers() {
if (NULL == user_timer_ref)
getUserTimerInstance();
if (NULL == user_timer_ref)
return false;
DBG("removing timers\n");
AmArg di_args,ret;
di_args.push(getLocalTag().c_str());
user_timer_ref->invoke("removeTimers", di_args, ret);
return true;
}
#ifdef WITH_ZRTP
void AmSession::onZRTPEvent(zrtp_event_t event, zrtp_stream_ctx_t *stream_ctx) {

@ -148,7 +148,10 @@ private:
friend class AmSessionProcessorThread;
auto_ptr<AmRtpAudio> _rtp_str;
AmDynInvoke* user_timer_ref;
void getUserTimerInstance();
protected:
AmSdp sdp;
@ -416,6 +419,38 @@ public:
*/
void sendDtmf(int event, unsigned int duration_ms);
/* ---- general purpose application level timers ------------ */
/** check for support of timers
@return true if application level timers are supported
*/
static bool timersSupported();
/**
set a Timer
@param timer_id the ID of the timer (<0 for system timers)
@param timeout timeout in seconds
@return true on success
*/
virtual bool setTimer(int timer_id, unsigned int timeout);
/**
remove a Timer
@param timer_id the ID of the timer (<0 for system timers)
@return true on success
*/
virtual bool removeTimer(int timer_id);
/**
remove all Timers
@return true on success
Note: this doesn't clear timer events already in the
event queue
*/
virtual bool removeTimers();
/* ---------- event handlers ------------------------- */
/** DTMF event handler for apps to use*/
virtual void onDtmf(int event, int duration);

Loading…
Cancel
Save