DSM: pass DSMSession along & save a dynamic_cast

sayer/1.4-spce2.6
Stefan Sayer 16 years ago
parent c2169502d1
commit 21265b0fc3

@ -93,7 +93,7 @@ void DSMCall::onInvite(const AmSipRequest& req) {
bool run_session_invite = engine.onInvite(req, this);
if (run_invite_event) {
if (!engine.init(this, startDiagName, DSMCondition::Invite))
if (!engine.init(this, this, startDiagName, DSMCondition::Invite))
run_session_invite =false;
if (checkVar(DSM_CONNECT_SESSION, DSM_CONNECT_SESSION_FALSE)) {
@ -120,7 +120,7 @@ void DSMCall::onOutgoingInvite(const string& headers) {
bool run_session_invite = engine.onInvite(req, this);
if (run_invite_event) {
if (!engine.init(this, startDiagName, DSMCondition::Invite))
if (!engine.init(this, this, startDiagName, DSMCondition::Invite))
run_session_invite =false;
if (checkVar(DSM_CONNECT_SESSION, DSM_CONNECT_SESSION_FALSE)) {
@ -146,7 +146,7 @@ void DSMCall::onOutgoingInvite(const string& headers) {
params["reason"] = reply.reason;
params["has_body"] = reply.body.empty() ?
"false" : "true";
engine.runEvent(this, DSMCondition::Ringing, &params);
engine.runEvent(this, this, DSMCondition::Ringing, &params);
// todo: local ringbacktone
}
@ -156,7 +156,7 @@ void DSMCall::onEarlySessionStart(const AmSipReply& reply) {
params["reason"] = reply.reason;
params["has_body"] = reply.body.empty() ?
"false" : "true";
engine.runEvent(this, DSMCondition::EarlySession, &params);
engine.runEvent(this, this, DSMCondition::EarlySession, &params);
if (checkVar(DSM_CONNECT_EARLY_SESSION, DSM_CONNECT_EARLY_SESSION_FALSE)) {
DBG("call does not connect early session\n");
@ -192,7 +192,7 @@ void DSMCall::onSessionStart(const AmSipReply& rep)
}
void DSMCall::startSession(){
engine.init(this, startDiagName, DSMCondition::SessionStart);
engine.init(this, this, startDiagName, DSMCondition::SessionStart);
setReceiving(true);
@ -232,7 +232,7 @@ void DSMCall::onDtmf(int event, int duration_msec) {
map<string, string> params;
params["key"] = int2str(event);
params["duration"] = int2str(duration_msec);
engine.runEvent(this, DSMCondition::Key, &params);
engine.runEvent(this, this, DSMCondition::Key, &params);
}
void DSMCall::onBye(const AmSipRequest& req)
@ -241,13 +241,13 @@ void DSMCall::onBye(const AmSipRequest& req)
map<string, string> params;
params["headers"] = req.hdrs;
engine.runEvent(this, DSMCondition::Hangup, &params);
engine.runEvent(this, this, DSMCondition::Hangup, &params);
}
void DSMCall::onCancel() {
DBG("onCancel\n");
if (dlg.getStatus() < AmSipDialog::Connected)
engine.runEvent(this, DSMCondition::Hangup, NULL);
engine.runEvent(this, this, DSMCondition::Hangup, NULL);
else {
DBG("ignoring onCancel event in established dialog\n");
}
@ -272,7 +272,7 @@ void DSMCall::onSipRequest(const AmSipRequest& req) {
DSMSipRequest* sip_req = new DSMSipRequest(&req);
avar[DSM_AVAR_REQUEST] = AmArg(sip_req);
engine.runEvent(this, DSMCondition::SipRequest, &params);
engine.runEvent(this, this, DSMCondition::SipRequest, &params);
delete sip_req;
avar.erase(DSM_AVAR_REQUEST);
@ -306,7 +306,7 @@ void DSMCall::onSipReply(const AmSipReply& reply, int old_dlg_status) {
DSMSipReply* dsm_reply = new DSMSipReply(&reply);
avar[DSM_AVAR_REPLY] = AmArg(dsm_reply);
engine.runEvent(this, DSMCondition::SipReply, &params);
engine.runEvent(this, this, DSMCondition::SipReply, &params);
delete dsm_reply;
avar.erase(DSM_AVAR_REPLY);
@ -327,7 +327,7 @@ void DSMCall::onSipReply(const AmSipReply& reply, int old_dlg_status) {
map<string, string> params;
params["code"] = int2str(reply.code);
params["reason"] = reply.reason;
engine.runEvent(this, DSMCondition::FailedCall, &params);
engine.runEvent(this, this, DSMCondition::FailedCall, &params);
setStopped();
}
}
@ -338,7 +338,7 @@ void DSMCall::process(AmEvent* event)
if (event->event_id == DSM_EVENT_ID) {
DSMEvent* dsm_event = dynamic_cast<DSMEvent*>(event);
if (dsm_event) {
engine.runEvent(this, DSMCondition::DSMEvent, &dsm_event->params);
engine.runEvent(this, this, DSMCondition::DSMEvent, &dsm_event->params);
return;
}
@ -350,7 +350,7 @@ void DSMCall::process(AmEvent* event)
(audio_event->event_id == AmAudioEvent::noAudio))){
map<string, string> params;
params["type"] = audio_event->event_id == AmAudioEvent::cleared?"cleared":"noAudio";
engine.runEvent(this, DSMCondition::NoAudio, &params);
engine.runEvent(this, this, DSMCondition::NoAudio, &params);
return;
}
@ -359,14 +359,14 @@ void DSMCall::process(AmEvent* event)
int timer_id = plugin_event->data.get(0).asInt();
map<string, string> params;
params["id"] = int2str(timer_id);
engine.runEvent(this, DSMCondition::Timer, &params);
engine.runEvent(this, this, DSMCondition::Timer, &params);
}
AmPlaylistSeparatorEvent* sep_ev = dynamic_cast<AmPlaylistSeparatorEvent*>(event);
if (sep_ev) {
map<string, string> params;
params["id"] = int2str(sep_ev->event_id);
engine.runEvent(this, DSMCondition::PlaylistSeparator, &params);
engine.runEvent(this, this, DSMCondition::PlaylistSeparator, &params);
}
// todo: give modules the possibility to define/process events
@ -389,7 +389,7 @@ void DSMCall::process(AmEvent* event)
// save reference to full parameters
avar[DSM_AVAR_JSONRPCRESPONEDATA] = AmArg(&resp_ev->response.data);
engine.runEvent(this, DSMCondition::JsonRpcResponse, &params);
engine.runEvent(this, this, DSMCondition::JsonRpcResponse, &params);
avar.erase(DSM_AVAR_JSONRPCRESPONEDATA);
return;
@ -412,7 +412,7 @@ void DSMCall::process(AmEvent* event)
// save reference to full parameters
avar[DSM_AVAR_JSONRPCREQUESTDATA] = AmArg(&req_ev->params);
engine.runEvent(this, DSMCondition::JsonRpcRequest, &params);
engine.runEvent(this, this, DSMCondition::JsonRpcRequest, &params);
avar.erase(DSM_AVAR_JSONRPCREQUESTDATA);
return;
@ -613,7 +613,7 @@ void DSMCall::onOtherBye(const AmSipRequest& req) {
map<string, string> params;
params["hdrs"] = req.hdrs; // todo: optimization - make this configurable
engine.runEvent(this, DSMCondition::B2BOtherBye, &params);
engine.runEvent(this, this, DSMCondition::B2BOtherBye, &params);
}
bool DSMCall::onOtherReply(const AmSipReply& reply) {
@ -625,7 +625,7 @@ bool DSMCall::onOtherReply(const AmSipReply& reply) {
params["reason"] = reply.reason;
params["hdrs"] = reply.hdrs; // todo: optimization - make this configurable
engine.runEvent(this, DSMCondition::B2BOtherReply, &params);
engine.runEvent(this, this, DSMCondition::B2BOtherReply, &params);
return false;
}

@ -352,7 +352,7 @@ EXEC_ACTION_START(SCStopAction) {
#define DEF_SCModActionExec(clsname) \
\
bool clsname::execute(AmSession* sess, \
bool clsname::execute(AmSession* sess, DSMSession* sc_sess, \
DSMCondition::EventType event, \
map<string,string>* event_params) { \
return true; \

@ -110,7 +110,7 @@ class SCDIAction
bool get_res;
public:
SCDIAction(const string& arg, bool get_res);
bool execute(AmSession* sess,
bool execute(AmSession* sess, DSMSession* sc_sess,
DSMCondition::EventType event,
map<string,string>* event_params);
};

@ -96,7 +96,7 @@ class SCStrArgAction
: public SCStrArgAction { \
public: \
CL_Name(const string& arg) : SCStrArgAction(arg) { } \
bool execute(AmSession* sess, \
bool execute(AmSession* sess, DSMSession* sc_sess, \
DSMCondition::EventType event, \
map<string,string>* event_params); \
}; \
@ -107,7 +107,7 @@ class SCStrArgAction
: public SCStrArgAction { \
public: \
CL_Name(const string& arg) : SCStrArgAction(arg) { } \
bool execute(AmSession* sess, \
bool execute(AmSession* sess, DSMSession* sc_sess, \
DSMCondition::EventType event, \
map<string,string>* event_params); \
SEAction getSEAction(std::string&); \
@ -120,7 +120,7 @@ class SCStrArgAction
string par2; \
public: \
CL_Name(const string& arg); \
bool execute(AmSession* sess, \
bool execute(AmSession* sess, DSMSession* sc_sess, \
DSMCondition::EventType event, \
map<string,string>* event_params); \
}; \
@ -195,25 +195,17 @@ class SCStrArgAction
} \
#define GET_SCSESSION() \
DSMSession* sc_sess = dynamic_cast<DSMSession*>(sess); \
if (!sc_sess) { \
ERROR("wrong session type\n"); \
return false; \
}
#define EXEC_ACTION_START(act_name) \
bool act_name::execute(AmSession* sess, \
bool act_name::execute(AmSession* sess, DSMSession* sc_sess, \
DSMCondition::EventType event, \
map<string,string>* event_params) { \
GET_SCSESSION();
map<string,string>* event_params) {
#define EXEC_ACTION_END \
return false; \
}
#define EXEC_ACTION_STOP \
#define EXEC_ACTION_STOP \
return false;
string resolveVars(const string s, AmSession* sess,
@ -241,39 +233,19 @@ void splitCmd(const string& from_str,
\
public: \
\
cond_name(const string& arg, bool inv) \
: arg(arg), inv(inv) { } \
bool match(AmSession* sess, DSMCondition::EventType event, \
map<string,string>* event_params); \
}; \
cond_name(const string& arg, bool inv) \
: arg(arg), inv(inv) { } \
bool match(AmSession* sess, DSMSession* sc_sess, DSMCondition::EventType event, \
map<string,string>* event_params); \
};
#define MATCH_CONDITION_START(cond_clsname) \
bool cond_clsname::match(AmSession* sess, DSMCondition::EventType event, \
map<string,string>* event_params) { \
GET_SCSESSION();
#define MATCH_CONDITION_END }
#define GET_SCSESSION() \
DSMSession* sc_sess = dynamic_cast<DSMSession*>(sess); \
if (!sc_sess) { \
ERROR("wrong session type\n"); \
return false; \
}
#define EXEC_ACTION_START(act_name) \
bool act_name::execute(AmSession* sess, \
DSMCondition::EventType event, \
map<string,string>* event_params) { \
GET_SCSESSION();
#define EXEC_ACTION_END \
return false; \
}
bool cond_clsname::match(AmSession* sess, DSMSession* sc_sess, \
DSMCondition::EventType event, \
map<string,string>* event_params) {
#define MATCH_CONDITION_END }
#define DECLARE_MODULE(mod_cls_name) \
class mod_cls_name \

@ -221,12 +221,12 @@ bool DSMStateEngine::onInvite(const AmSipRequest& req, DSMSession* sess) {
bool DSMStateEngine::runactions(vector<DSMAction*>::iterator from,
vector<DSMAction*>::iterator to,
AmSession* sess, DSMCondition::EventType event,
AmSession* sess, DSMSession* sc_sess, DSMCondition::EventType event,
map<string,string>* event_params, bool& is_consumed) {
// DBG("running %zd actions\n", to - from);
for (vector<DSMAction*>::iterator it=from; it != to; it++) {
DBG("executing '%s'\n", (*it)->name.c_str());
if ((*it)->execute(sess, event, event_params)) {
if ((*it)->execute(sess, sc_sess, event, event_params)) {
string se_modifier;
switch ((*it)->getSEAction(se_modifier)) {
case DSMAction::Repost:
@ -234,17 +234,17 @@ bool DSMStateEngine::runactions(vector<DSMAction*>::iterator from,
break;
case DSMAction::Jump:
DBG("jumping %s\n", se_modifier.c_str());
if (jumpDiag(se_modifier, sess, event, event_params)) {
if (jumpDiag(se_modifier, sess, sc_sess, event, event_params)) {
// is_consumed = false;
return true;
} break;
case DSMAction::Call:
if (callDiag(se_modifier, sess, event, event_params)) {
if (callDiag(se_modifier, sess, sc_sess, event, event_params)) {
// is_consumed = false;
return true;
} break;
case DSMAction::Return:
if (returnDiag(sess)) {
if (returnDiag(sess, sc_sess)) {
//is_consumed = false;
return true;
} break;
@ -266,11 +266,12 @@ void DSMStateEngine::addModules(vector<DSMModule*> modules) {
mods.push_back(*it);
}
bool DSMStateEngine::init(AmSession* sess, const string& startDiagram,
bool DSMStateEngine::init(AmSession* sess, DSMSession* sc_sess,
const string& startDiagram,
DSMCondition::EventType init_event) {
try {
if (!jumpDiag(startDiagram, sess, init_event, NULL)) {
if (!jumpDiag(startDiagram, sess, sc_sess, init_event, NULL)) {
ERROR("initializing with start diag '%s'\n",
startDiagram.c_str());
return false;
@ -278,24 +279,24 @@ bool DSMStateEngine::init(AmSession* sess, const string& startDiagram,
} catch (DSMException& e) {
DBG("Exception type '%s' occured while initializing! Run init event as exception...\n",
e.params["type"].c_str());
runEvent(sess, init_event, &e.params, true);
runEvent(sess, sc_sess, init_event, &e.params, true);
return true;
}
DBG("run init event...\n");
runEvent(sess, init_event, NULL);
runEvent(sess, sc_sess, init_event, NULL);
return true;
}
bool DSMCondition::_match(AmSession* sess,
bool DSMCondition::_match(AmSession* sess, DSMSession* sc_sess,
DSMCondition::EventType event,
map<string,string>* event_params) {
// or xor
return invert?(!match(sess,event,event_params)):match(sess,event,event_params);
return invert?(!match(sess,sc_sess,event,event_params)):match(sess, sc_sess, event, event_params);
}
bool DSMCondition::match(AmSession* sess,
bool DSMCondition::match(AmSession* sess, DSMSession* sc_sess,
DSMCondition::EventType event,
map<string,string>* event_params) {
@ -316,7 +317,7 @@ bool DSMCondition::match(AmSession* sess,
return true;
}
void DSMStateEngine::runEvent(AmSession* sess,
void DSMStateEngine::runEvent(AmSession* sess, DSMSession* sc_sess,
DSMCondition::EventType event,
map<string,string>* event_params,
bool run_exception) {
@ -342,7 +343,7 @@ void DSMStateEngine::runEvent(AmSession* sess,
vector<DSMCondition*>::iterator con=tr->precond.begin();
while (con!=tr->precond.end()) {
if (!(*con)->_match(sess, active_event, active_params))
if (!(*con)->_match(sess, sc_sess, active_event, active_params))
break;
con++;
}
@ -366,7 +367,7 @@ void DSMStateEngine::runEvent(AmSession* sess,
current->post_actions.size(), current->name.c_str());
if (runactions(current->post_actions.begin(),
current->post_actions.end(),
sess, active_event, active_params, is_consumed)) {
sess, sc_sess, active_event, active_params, is_consumed)) {
break;
}
}
@ -377,7 +378,7 @@ void DSMStateEngine::runEvent(AmSession* sess,
tr->actions.size(), tr->name.c_str());
if (runactions(tr->actions.begin(),
tr->actions.end(),
sess, active_event, active_params, is_consumed)) {
sess, sc_sess, active_event, active_params, is_consumed)) {
break;
}
}
@ -412,7 +413,7 @@ void DSMStateEngine::runEvent(AmSession* sess,
current->pre_actions.size(), current->name.c_str());
if (runactions(current->pre_actions.begin(),
current->pre_actions.end(),
sess, active_event, active_params, is_consumed)) {
sess, sc_sess, active_event, active_params, is_consumed)) {
break;
}
}
@ -433,7 +434,7 @@ void DSMStateEngine::runEvent(AmSession* sess,
} while (!is_consumed);
}
bool DSMStateEngine::callDiag(const string& diag_name, AmSession* sess,
bool DSMStateEngine::callDiag(const string& diag_name, AmSession* sess, DSMSession* sc_sess,
DSMCondition::EventType event,
map<string,string>* event_params) {
if (!current || !current_diag) {
@ -441,10 +442,10 @@ bool DSMStateEngine::callDiag(const string& diag_name, AmSession* sess,
return false;
}
stack.push_back(std::make_pair(current_diag, current));
return jumpDiag(diag_name, sess, event, event_params);
return jumpDiag(diag_name, sess, sc_sess, event, event_params);
}
bool DSMStateEngine::jumpDiag(const string& diag_name, AmSession* sess,
bool DSMStateEngine::jumpDiag(const string& diag_name, AmSession* sess, DSMSession* sc_sess,
DSMCondition::EventType event,
map<string,string>* event_params) {
for (vector<DSMStateDiagram*>::iterator it=
@ -478,7 +479,7 @@ bool DSMStateEngine::jumpDiag(const string& diag_name, AmSession* sess,
is_finished = true;
runactions(current->pre_actions.begin(),
current->pre_actions.end(),
sess, event, event_params, is_finished);
sess, sc_sess, event, event_params, is_finished);
return true;
}
@ -487,7 +488,7 @@ bool DSMStateEngine::jumpDiag(const string& diag_name, AmSession* sess,
return false;
}
bool DSMStateEngine::returnDiag(AmSession* sess) {
bool DSMStateEngine::returnDiag(AmSession* sess, DSMSession* sc_sess) {
if (stack.empty()) {
ERROR("returning from empty stack\n");
return false;

@ -87,6 +87,7 @@ class DSMCondition
JsonRpcResponse,
JsonRpcRequest
};
bool invert;
@ -97,10 +98,10 @@ class DSMCondition
EventType type;
map<string, string> params;
bool _match(AmSession* sess, DSMCondition::EventType event,
bool _match(AmSession* sess, DSMSession* sc_sess, DSMCondition::EventType event,
map<string,string>* event_params);
virtual bool match(AmSession* sess, DSMCondition::EventType event,
virtual bool match(AmSession* sess, DSMSession* sc_sess, DSMCondition::EventType event,
map<string,string>* event_params);
};
@ -120,7 +121,7 @@ class DSMAction
virtual ~DSMAction() { /* DBG("dest action\n"); */ }
/** @return whether state engine is to be modified (via getSEAction) */
virtual bool execute(AmSession* sess, DSMCondition::EventType event, \
virtual bool execute(AmSession* sess, DSMSession* sc_sess, DSMCondition::EventType event, \
map<string,string>* event_params) = 0;
/** @return state engine modification */
@ -210,14 +211,16 @@ class DSMStateEngine {
vector<pair<DSMStateDiagram*, State*> > stack;
bool callDiag(const string& diag_name, AmSession* sess, DSMCondition::EventType event,
map<string,string>* event_params);
bool jumpDiag(const string& diag_name, AmSession* sess, DSMCondition::EventType event,
map<string,string>* event_params);
bool returnDiag(AmSession* sess);
bool callDiag(const string& diag_name, AmSession* sess, DSMSession* sc_sess,
DSMCondition::EventType event,
map<string,string>* event_params);
bool jumpDiag(const string& diag_name, AmSession* sess, DSMSession* sc_sess,
DSMCondition::EventType event,
map<string,string>* event_params);
bool returnDiag(AmSession* sess, DSMSession* sc_sess);
bool runactions(vector<DSMAction*>::iterator from,
vector<DSMAction*>::iterator to,
AmSession* sess, DSMCondition::EventType event,
AmSession* sess, DSMSession* sc_sess, DSMCondition::EventType event,
map<string,string>* event_params, bool& is_consumed);
vector<DSMModule*> mods;
@ -229,10 +232,11 @@ class DSMStateEngine {
void addDiagram(DSMStateDiagram* diag);
void addModules(vector<DSMModule*> modules);
bool init(AmSession* sess, const string& startDiagram,
bool init(AmSession* sess, DSMSession* sc_sess,
const string& startDiagram,
DSMCondition::EventType init_event);
void runEvent(AmSession* sess,
void runEvent(AmSession* sess, DSMSession* sc_sess,
DSMCondition::EventType event,
map<string,string>* event_params,
bool run_exception = false);

@ -60,13 +60,6 @@ bool DLGModule::onInvite(const AmSipRequest& req, DSMSession* sess) {
return true;
}
#define GET_SCSESSION() \
DSMSession* sc_sess = dynamic_cast<DSMSession*>(sess); \
if (!sc_sess) { \
ERROR("wrong session type\n"); \
return false; \
}
// todo: convert errors to exceptions
void replyRequest(DSMSession* sc_sess, AmSession* sess,
EventParamT* event_params,

@ -73,10 +73,9 @@ DSMCondition* MonitoringModule::getCondition(const string& from_str) {
}
CONST_ACTION_2P(MonLogAction, ',', true);
bool MonLogAction::execute(AmSession* sess,
bool MonLogAction::execute(AmSession* sess, DSMSession* sc_sess,
DSMCondition::EventType event,
map<string,string>* event_params) {
GET_SCSESSION();
string prop = resolveVars(par1, sess, sc_sess, event_params);
string val = resolveVars(par2, sess, sc_sess, event_params);
@ -87,10 +86,9 @@ bool MonLogAction::execute(AmSession* sess,
}
CONST_ACTION_2P(MonLogAddAction, ',', true);
bool MonLogAddAction::execute(AmSession* sess,
bool MonLogAddAction::execute(AmSession* sess, DSMSession* sc_sess,
DSMCondition::EventType event,
map<string,string>* event_params) {
GET_SCSESSION();
string prop = resolveVars(par1, sess, sc_sess, event_params);
string val = resolveVars(par2, sess, sc_sess, event_params);
@ -100,11 +98,9 @@ bool MonLogAddAction::execute(AmSession* sess,
return false;
}
bool MonLogVarsAction::execute(AmSession* sess,
bool MonLogVarsAction::execute(AmSession* sess, DSMSession* sc_sess,
DSMCondition::EventType event,
map<string,string>* event_params) {
GET_SCSESSION();
AmArg di_args,ret;
di_args.push(AmArg(sess->getLocalTag().c_str()));

@ -67,7 +67,7 @@ class SCPyPyAction
PyObject* py_func;
public:
SCPyPyAction(const string& arg);
bool execute(AmSession* sess,
bool execute(AmSession* sess, DSMSession* sc_sess,
DSMCondition::EventType event,
map<string,string>* event_params);
};
@ -79,7 +79,7 @@ class PyPyCondition
public:
PyPyCondition(const string& arg);
bool match(AmSession* sess, DSMCondition::EventType event,
bool match(AmSession* sess, DSMSession* sc_sess, DSMCondition::EventType event,
map<string,string>* event_params);
};

Loading…
Cancel
Save