From 22ba41b066b6622f74f041fac29a2a774157f7ee Mon Sep 17 00:00:00 2001 From: Stefan Sayer Date: Fri, 30 Apr 2010 01:45:55 +0000 Subject: [PATCH] for outgoing calls, ringing/early/failed events. git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@1864 8eb893ce-cfd4-0310-b710-fb5ebe64c474 --- apps/dsm/DSMCall.cpp | 52 ++++++++++++++++++++++++++++++++++++++ apps/dsm/DSMCall.h | 3 +++ apps/dsm/DSMCoreModule.cpp | 9 +++++++ apps/dsm/DSMSession.h | 6 +++++ apps/dsm/DSMStateEngine.h | 3 +++ doc/dsm/dsm_syntax.txt | 12 ++++++--- 6 files changed, 82 insertions(+), 3 deletions(-) diff --git a/apps/dsm/DSMCall.cpp b/apps/dsm/DSMCall.cpp index 84fbcd86..67a479e9 100644 --- a/apps/dsm/DSMCall.cpp +++ b/apps/dsm/DSMCall.cpp @@ -94,6 +94,14 @@ void DSMCall::onInvite(const AmSipRequest& req) { DBG("session choose to not connect media\n"); run_session_invite = false; // don't accept audio } + + if (checkVar(DSM_ACCEPT_EARLY_SESSION, DSM_ACCEPT_EARLY_SESSION_FALSE)) { + DBG("session choose to not accept early session\n"); + accept_early_session = false; + } else { + accept_early_session = true; + } + } if (run_session_invite) @@ -124,6 +132,35 @@ void DSMCall::onOutgoingInvite(const string& headers) { } } +void DSMCall::onRinging(const AmSipReply& reply) { + map params; + params["code"] = int2str(reply.code); + params["reason"] = reply.reason; + params["has_body"] = reply.body.empty() ? + "false" : "true"; + engine.runEvent(this, DSMCondition::Ringing, ¶ms); + // todo: local ringbacktone +} + +void DSMCall::onEarlySessionStart(const AmSipReply& reply) { + map params; + params["code"] = int2str(reply.code); + params["reason"] = reply.reason; + params["has_body"] = reply.body.empty() ? + "false" : "true"; + engine.runEvent(this, DSMCondition::EarlySession, ¶ms); + + if (checkVar(DSM_CONNECT_EARLY_SESSION, DSM_CONNECT_EARLY_SESSION_FALSE)) { + DBG("call does not connect early session\n"); + } else { + if (!getInput()) + setInput(&playlist); + + if (!getOutput()) + setOutput(&playlist); + } +} + void DSMCall::onSessionStart(const AmSipRequest& req) { if (process_sessionstart) { @@ -208,6 +245,21 @@ void DSMCall::onCancel() { } } +void DSMCall::onSipReply(const AmSipReply& reply, int old_dlg_status) { + AmB2BCallerSession::onSipReply(reply,old_dlg_status); + + if ((old_dlg_status < AmSipDialog::Connected) && + (dlg.getStatus() == AmSipDialog::Disconnected)) { + DBG("Outbound call failed with reply %d %s.\n", + reply.code, reply.reason.c_str()); + map params; + params["code"] = int2str(reply.code); + params["reason"] = reply.reason; + engine.runEvent(this, DSMCondition::FailedCall, ¶ms); + setStopped(); + } +} + void DSMCall::process(AmEvent* event) { diff --git a/apps/dsm/DSMCall.h b/apps/dsm/DSMCall.h index d3d47fde..2a92b3af 100644 --- a/apps/dsm/DSMCall.h +++ b/apps/dsm/DSMCall.h @@ -73,6 +73,8 @@ public: void onInvite(const AmSipRequest& req); void onOutgoingInvite(const string& headers); + void onRinging(const AmSipReply& reply); + void onEarlySessionStart(const AmSipReply& reply); void onSessionStart(const AmSipRequest& req); void onSessionStart(const AmSipReply& rep); void startSession(); @@ -80,6 +82,7 @@ public: void onBye(const AmSipRequest& req); void onDtmf(int event, int duration_msec); + void onSipReply(const AmSipReply& reply, int old_dlg_status); void process(AmEvent* event); UACAuthCred* getCredentials(); diff --git a/apps/dsm/DSMCoreModule.cpp b/apps/dsm/DSMCoreModule.cpp index 140f1518..a07017db 100644 --- a/apps/dsm/DSMCoreModule.cpp +++ b/apps/dsm/DSMCoreModule.cpp @@ -151,6 +151,15 @@ DSMCondition* DSMCoreModule::getCondition(const string& from_str) { if (cmd == "sessionStart") return new TestDSMCondition(params, DSMCondition::SessionStart); + if (cmd == "ringing") + return new TestDSMCondition(params, DSMCondition::Ringing); + + if (cmd == "early") + return new TestDSMCondition(params, DSMCondition::EarlySession); + + if (cmd == "failed") + return new TestDSMCondition(params, DSMCondition::FailedCall); + if (cmd == "B2B.otherReply") return new TestDSMCondition(params, DSMCondition::B2BOtherReply); diff --git a/apps/dsm/DSMSession.h b/apps/dsm/DSMSession.h index 3d6268ff..aa9cc04f 100644 --- a/apps/dsm/DSMSession.h +++ b/apps/dsm/DSMSession.h @@ -46,6 +46,12 @@ using std::map; #define DSM_CONNECT_SESSION "connect_session" // todo: rethink these names #define DSM_CONNECT_SESSION_FALSE "0" +#define DSM_ACCEPT_EARLY_SESSION "accept_early_session" // todo: rethink these names +#define DSM_ACCEPT_EARLY_SESSION_FALSE "0" + +#define DSM_CONNECT_EARLY_SESSION "connect_early_session" // todo: rethink these names +#define DSM_CONNECT_EARLY_SESSION_FALSE "0" + #define DSM_ERRNO_FILE "file" #define DSM_ERRNO_UNKNOWN_ARG "arg" #define DSM_ERRNO_SCRIPT "script" diff --git a/apps/dsm/DSMStateEngine.h b/apps/dsm/DSMStateEngine.h index e8932ea7..c5751d25 100644 --- a/apps/dsm/DSMStateEngine.h +++ b/apps/dsm/DSMStateEngine.h @@ -59,6 +59,9 @@ class DSMCondition Any, Invite, SessionStart, + Ringing, + EarlySession, + FailedCall, Key, Timer, diff --git a/doc/dsm/dsm_syntax.txt b/doc/dsm/dsm_syntax.txt index 6f6be43c..353d6d47 100644 --- a/doc/dsm/dsm_syntax.txt +++ b/doc/dsm/dsm_syntax.txt @@ -198,9 +198,15 @@ conditions: -- bye received: hangup - -- execution is invite (with run_invite_event): - invite - -- execution is start of session (with run_invite_event, otherwise its always true): + -- event is invite (only with run_invite_event): + invite + -- event is ringing, 180 (only with run_invite_event): + ringing + -- event is early session, 183 (only with run_invite_event): + early + -- event is failed call (only with run_invite_event): + failed + -- event is start of session (with run_invite_event, otherwise its always true): sessionStart B2B.otherReply