Module: sems
Branch: rco/offer_answer
Commit: 11166ef7f074d16055dc8b1c5d97b03308dd3ec6
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=11166ef7f074d16055dc8b1c5d97b03308dd3ec6

Author: Raphael Coeffic <[email protected]>
Committer: Raphael Coeffic <[email protected]>
Date:   Wed May 18 10:45:10 2011 +0200

call engine.init() when onStart() is triggered.

---

 apps/dsm/DSMCall.cpp                     |   58 ++++++++++++++----------------
 apps/dsm/DSMCall.h                       |    1 +
 apps/dsm/DSMStateEngine.h                |    1 +
 doc/dsm/examples/183_early_establish.dsm |   38 +++++++++----------
 doc/dsm/examples/test.dsm                |   20 +++++-----
 5 files changed, 57 insertions(+), 61 deletions(-)

diff --git a/apps/dsm/DSMCall.cpp b/apps/dsm/DSMCall.cpp
index ea5e8bb..f6d73de 100644
--- a/apps/dsm/DSMCall.cpp
+++ b/apps/dsm/DSMCall.cpp
@@ -79,6 +79,11 @@ bool checkParam(const string& par_name, const string& 
par_val, map<string, strin
   return (it != params->end()) && (it->second == par_val);
 }
 
+void DSMCall::onStart()
+{
+  engine.init(this, this, startDiagName, DSMCondition::Start);
+}
+
 void DSMCall::onInvite(const AmSipRequest& req) {
   // make B2B dialogs work in onInvite as well
   invite_req = req;
@@ -92,10 +97,13 @@ void DSMCall::onInvite(const AmSipRequest& req) {
     
   bool run_session_invite = engine.onInvite(req, this);
 
-  if (!engine.init(this, this, startDiagName, DSMCondition::Invite))
-    run_session_invite =false;
+  DBG("before runEvent(this, this, DSMCondition::Invite);\n");
+  AmSipDialog::Status old_st = dlg.getStatus();
+  engine.runEvent(this, this, DSMCondition::Invite, NULL);
 
-  if (checkVar(DSM_CONNECT_SESSION, DSM_CONNECT_SESSION_FALSE)) {
+  if ( old_st != dlg.getStatus()
+       //checkVar(DSM_CONNECT_SESSION, DSM_CONNECT_SESSION_FALSE)
+      ) {
     DBG("session choose to not connect media\n");
     run_session_invite = false;     // don't accept audio 
   }    
@@ -114,30 +122,24 @@ void DSMCall::onOutgoingInvite(const string& headers) {
   // TODO: construct correct request of outgoing INVITE
   AmSipRequest req;
   req.hdrs = headers;
-  bool run_session_invite = engine.onInvite(req, this);
-
-  if (run_invite_event) {
-    if (!engine.init(this, this, startDiagName, DSMCondition::Invite))
-      run_session_invite =false;
-
-    if (checkVar(DSM_CONNECT_SESSION, DSM_CONNECT_SESSION_FALSE)) {
-      DBG("session choose to not connect media\n");
-      // TODO: set flag to not connect RTP on session start
-      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 {
-      DBG("session choose to accept early session\n");
-      accept_early_session = true;
-    }
 
+  bool run_session_invite = engine.onInvite(req, this);
+  if (checkVar(DSM_CONNECT_SESSION, DSM_CONNECT_SESSION_FALSE)) {
+    DBG("session choose to not connect media\n");
+    // TODO: set flag to not connect RTP on session start
+    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 {
+    DBG("session choose to accept early session\n");
+    accept_early_session = true;
   }
 }
 
- void DSMCall::onRinging(const AmSipReply& reply) {
+void DSMCall::onRinging(const AmSipReply& reply) {
   map<string, string> params;
   params["code"] = int2str(reply.code);
   params["reason"] = reply.reason;
@@ -148,13 +150,7 @@ void DSMCall::onOutgoingInvite(const string& headers) {
 }
 
 void DSMCall::onEarlySessionStart() {
-  // map<string, string> params;
-  // params["code"] = int2str(reply.code);
-  // params["reason"] = reply.reason;
-  // params["has_body"] = reply.body.empty() ?
-  //   "false" : "true";
-  engine.runEvent(this, this, DSMCondition::EarlySession, NULL// , &params
-                 );
+  engine.runEvent(this, this, DSMCondition::EarlySession, NULL);
 
   if (checkVar(DSM_CONNECT_EARLY_SESSION, DSM_CONNECT_EARLY_SESSION_FALSE)) {
     DBG("call does not connect early session\n");
@@ -185,8 +181,8 @@ int DSMCall::onSdpCompleted(const AmSdp& offer, const 
AmSdp& answer)
 }
 
 void DSMCall::startSession(){
-  engine.init(this, this, startDiagName, DSMCondition::SessionStart);
 
+  engine.runEvent(this, this, DSMCondition::SessionStart, NULL);
   setReceiving(true);
 
   if (!checkVar(DSM_CONNECT_SESSION, DSM_CONNECT_SESSION_FALSE)) {
diff --git a/apps/dsm/DSMCall.h b/apps/dsm/DSMCall.h
index bea7763..58e7d8f 100644
--- a/apps/dsm/DSMCall.h
+++ b/apps/dsm/DSMCall.h
@@ -71,6 +71,7 @@ public:
          UACAuthCred* credentials = NULL);
   ~DSMCall();
 
+  void onStart();
   void onInvite(const AmSipRequest& req);
   void onOutgoingInvite(const string& headers);
   void onRinging(const AmSipReply& reply);
diff --git a/apps/dsm/DSMStateEngine.h b/apps/dsm/DSMStateEngine.h
index e335109..b97e1b5 100644
--- a/apps/dsm/DSMStateEngine.h
+++ b/apps/dsm/DSMStateEngine.h
@@ -59,6 +59,7 @@ class DSMCondition
   enum EventType {
     Any,
 
+    Start,
     Invite,
     SessionStart,
     Ringing,
diff --git a/doc/dsm/examples/183_early_establish.dsm 
b/doc/dsm/examples/183_early_establish.dsm
index f0e2f18..a762cb6 100644
--- a/doc/dsm/examples/183_early_establish.dsm
+++ b/doc/dsm/examples/183_early_establish.dsm
@@ -7,24 +7,23 @@
 import(mod_dlg);
 
 initial state START ;
-transition "on invite" START - invite -> runinvite;
-
-state runinvite 
-      enter { 
+transition "on invite" START - invite / { 
        log(2, run invite!); 
-       dlg.reply(100, trying...);
        -- we don't want to have the default 200 OK reply
-       set(connect_session=0);
+       dlg.reply(100, trying...);
        setTimer(1, 2);
-};
+} -> runinvite;
 
-transition "go early" runinvite - timerTest(#id==1) / {
-        dlg.acceptInvite(183, progress);
-} -> replied_183;
+state runinvite;
 
-state replied_183;
+transition "go early" runinvite - timerTest(#id==1) -> reply_183;
+state reply_183
+      enter {
+        -- this triggers "on sess start" transition
+        dlg.acceptInvite(183, progress);
+};
 
-transition "on sess start" runinvite - earlySession -> play_early_msg;
+transition "on sess start" reply_183 - earlySession -> play_early_msg;
 state play_early_msg
       enter {
        log(2, run start!);
@@ -32,30 +31,29 @@ state play_early_msg
        playFile(wav/default_en.wav);
 };
 
-transition "play file failed" runinvite - exception; test(#type==file) / {
+transition "play file failed" play_early_msg - exception; test(#type==file) / {
         log(1, Error playing file!); 
         dlg.reply(500, server error); 
         stop 
 } -> FIN;
 
-transition "early message ended" replied_183 - noAudioTest / {
+transition "early message ended" play_early_msg - noAudioTest -> recording;
+state recording
+      enter {
         dlg.acceptInvite(200, ok);
         recordFile(/tmp/test.wav);
         setTimer(3,10);
-} -> recording;
-
-state recording;
+};
 
-transition "recording failed" replied_183 - exception; / 
+transition "recording failed" recording - exception; / 
    log(1, Error recording!); stop(true) -> FIN;
 
-transition "bye in early" (replied_183, play_early_msg, runinvite) - hangup / {
+transition "bye in early" (runinvite, reply_183, play_early_msg, recording) - 
hangup / {
        log(2, hangup event received);
         stop(false)
 } -> FIN;
 
 transition "recording timer" recording - timerTest(#id==3) / stop -> FIN;
-
 transition "bye in recording" recording - hangup / stop -> FIN;
 
 state FIN;
diff --git a/doc/dsm/examples/test.dsm b/doc/dsm/examples/test.dsm
index 3e88cee..d905607 100644
--- a/doc/dsm/examples/test.dsm
+++ b/doc/dsm/examples/test.dsm
@@ -1,24 +1,25 @@
 
-initial state START 
-       enter {
+initial state START;
+
+transition "sess start" START - sessionStart / {
          playPrompt(hello);
-         DI(user_timer, setTimer, (int)1, (int)5, @local_tag);
-         DI(user_timer, setTimer, (int)2, (int)20, @local_tag);
+         setTimer(1, 5);
+         setTimer(2, 20);
          recordFile(/tmp/test_rec.wav);
-       };
+} -> sess_started;
 
+state sess_started;
 state ADDKEY;
 state FIN;
 
-transition "start pin entry" START - / set($pin = "") -> ADDKEY;
+transition "start pin entry" sess_started - / set($pin = "") -> ADDKEY;
 
 transition "play from timer" ADDKEY - timerTest(#id == 1) /  {
           playPrompt(hello); 
           stopRecord();
           closePlaylist();
           playFile("/tmp/test_rec.wav");
-          } 
-    -> ADDKEY;
+          } -> ADDKEY;
 
 transition "add a key" ADDKEY - keyTest(#key < 10) / 
           { 
@@ -28,5 +29,4 @@ transition "add a key" ADDKEY - keyTest(#key < 10) /
 
 transition "timeout stop it" ADDKEY - timerTest(#id == 2) / stop(true) -> FIN;
 
-transition finished ADDKEY - keyTest(#key > 9) / playPrompt(entering) -> FIN;
-
+transition finished ADDKEY - keyTest(#key > 9) / playPrompt(entering) -> FIN;
\ No newline at end of file

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to