Browse code

DSM: pass DSMSession along & save a dynamic_cast

Stefan Sayer authored on 06/07/2010 17:54:05
Showing 9 changed files
... ...
@@ -93,7 +93,7 @@ void DSMCall::onInvite(const AmSipRequest& req) {
93 93
   bool run_session_invite = engine.onInvite(req, this);
94 94
 
95 95
   if (run_invite_event) {
96
-    if (!engine.init(this, startDiagName, DSMCondition::Invite))
96
+    if (!engine.init(this, this, startDiagName, DSMCondition::Invite))
97 97
       run_session_invite =false;
98 98
 
99 99
     if (checkVar(DSM_CONNECT_SESSION, DSM_CONNECT_SESSION_FALSE)) {
... ...
@@ -120,7 +120,7 @@ void DSMCall::onOutgoingInvite(const string& headers) {
120 120
   bool run_session_invite = engine.onInvite(req, this);
121 121
 
122 122
   if (run_invite_event) {
123
-    if (!engine.init(this, startDiagName, DSMCondition::Invite))
123
+    if (!engine.init(this, this, startDiagName, DSMCondition::Invite))
124 124
       run_session_invite =false;
125 125
 
126 126
     if (checkVar(DSM_CONNECT_SESSION, DSM_CONNECT_SESSION_FALSE)) {
... ...
@@ -146,7 +146,7 @@ void DSMCall::onOutgoingInvite(const string& headers) {
146 146
   params["reason"] = reply.reason;
147 147
   params["has_body"] = reply.body.empty() ?
148 148
     "false" : "true";
149
-  engine.runEvent(this, DSMCondition::Ringing, &params);
149
+  engine.runEvent(this, this, DSMCondition::Ringing, &params);
150 150
   // todo: local ringbacktone
151 151
 }
152 152
 
... ...
@@ -156,7 +156,7 @@ void DSMCall::onEarlySessionStart(const AmSipReply& reply) {
156 156
   params["reason"] = reply.reason;
157 157
   params["has_body"] = reply.body.empty() ?
158 158
     "false" : "true";
159
-  engine.runEvent(this, DSMCondition::EarlySession, &params);
159
+  engine.runEvent(this, this, DSMCondition::EarlySession, &params);
160 160
 
161 161
   if (checkVar(DSM_CONNECT_EARLY_SESSION, DSM_CONNECT_EARLY_SESSION_FALSE)) {
162 162
     DBG("call does not connect early session\n");
... ...
@@ -192,7 +192,7 @@ void DSMCall::onSessionStart(const AmSipReply& rep)
192 192
 }
193 193
 
194 194
 void DSMCall::startSession(){
195
-  engine.init(this, startDiagName, DSMCondition::SessionStart);
195
+  engine.init(this, this, startDiagName, DSMCondition::SessionStart);
196 196
 
197 197
   setReceiving(true);
198 198
 
... ...
@@ -232,7 +232,7 @@ void DSMCall::onDtmf(int event, int duration_msec) {
232 232
   map<string, string> params;
233 233
   params["key"] = int2str(event);
234 234
   params["duration"] = int2str(duration_msec);
235
-  engine.runEvent(this, DSMCondition::Key, &params);
235
+  engine.runEvent(this, this, DSMCondition::Key, &params);
236 236
 }
237 237
 
238 238
 void DSMCall::onBye(const AmSipRequest& req)
... ...
@@ -241,13 +241,13 @@ void DSMCall::onBye(const AmSipRequest& req)
241 241
   map<string, string> params;
242 242
   params["headers"] = req.hdrs;
243 243
  
244
-  engine.runEvent(this, DSMCondition::Hangup, &params);
244
+  engine.runEvent(this, this, DSMCondition::Hangup, &params);
245 245
 }
246 246
 
247 247
 void DSMCall::onCancel() {
248 248
   DBG("onCancel\n");
249 249
   if (dlg.getStatus() < AmSipDialog::Connected) 
250
-    engine.runEvent(this, DSMCondition::Hangup, NULL);
250
+    engine.runEvent(this, this, DSMCondition::Hangup, NULL);
251 251
   else {
252 252
     DBG("ignoring onCancel event in established dialog\n");
253 253
   }
... ...
@@ -272,7 +272,7 @@ void DSMCall::onSipRequest(const AmSipRequest& req) {
272 272
     DSMSipRequest* sip_req = new DSMSipRequest(&req);
273 273
     avar[DSM_AVAR_REQUEST] = AmArg(sip_req);
274 274
     
275
-    engine.runEvent(this, DSMCondition::SipRequest, &params);
275
+    engine.runEvent(this, this, DSMCondition::SipRequest, &params);
276 276
 
277 277
     delete sip_req;
278 278
     avar.erase(DSM_AVAR_REQUEST);
... ...
@@ -306,7 +306,7 @@ void DSMCall::onSipReply(const AmSipReply& reply, int old_dlg_status) {
306 306
     DSMSipReply* dsm_reply = new DSMSipReply(&reply);
307 307
     avar[DSM_AVAR_REPLY] = AmArg(dsm_reply);
308 308
     
309
-    engine.runEvent(this, DSMCondition::SipReply, &params);
309
+    engine.runEvent(this, this, DSMCondition::SipReply, &params);
310 310
 
311 311
     delete dsm_reply;
312 312
     avar.erase(DSM_AVAR_REPLY);
... ...
@@ -327,7 +327,7 @@ void DSMCall::onSipReply(const AmSipReply& reply, int old_dlg_status) {
327 327
     map<string, string> params;
328 328
     params["code"] = int2str(reply.code);
329 329
     params["reason"] = reply.reason;
330
-    engine.runEvent(this, DSMCondition::FailedCall, &params);    
330
+    engine.runEvent(this, this, DSMCondition::FailedCall, &params);
331 331
     setStopped();
332 332
   }
333 333
 }
... ...
@@ -338,7 +338,7 @@ void DSMCall::process(AmEvent* event)
338 338
   if (event->event_id == DSM_EVENT_ID) {
339 339
     DSMEvent* dsm_event = dynamic_cast<DSMEvent*>(event);
340 340
     if (dsm_event) {      
341
-      engine.runEvent(this, DSMCondition::DSMEvent, &dsm_event->params);
341
+      engine.runEvent(this, this, DSMCondition::DSMEvent, &dsm_event->params);
342 342
       return;
343 343
     }
344 344
   
... ...
@@ -350,7 +350,7 @@ void DSMCall::process(AmEvent* event)
350 350
       (audio_event->event_id == AmAudioEvent::noAudio))){
351 351
     map<string, string> params;
352 352
     params["type"] = audio_event->event_id == AmAudioEvent::cleared?"cleared":"noAudio";
353
-    engine.runEvent(this, DSMCondition::NoAudio, &params);
353
+    engine.runEvent(this, this, DSMCondition::NoAudio, &params);
354 354
     return;
355 355
   }
356 356
 
... ...
@@ -359,14 +359,14 @@ void DSMCall::process(AmEvent* event)
359 359
     int timer_id = plugin_event->data.get(0).asInt();
360 360
     map<string, string> params;
361 361
     params["id"] = int2str(timer_id);
362
-    engine.runEvent(this, DSMCondition::Timer, &params);
362
+    engine.runEvent(this, this, DSMCondition::Timer, &params);
363 363
   }
364 364
 
365 365
   AmPlaylistSeparatorEvent* sep_ev = dynamic_cast<AmPlaylistSeparatorEvent*>(event);
366 366
   if (sep_ev) {
367 367
     map<string, string> params;
368 368
     params["id"] = int2str(sep_ev->event_id);
369
-    engine.runEvent(this, DSMCondition::PlaylistSeparator, &params);
369
+    engine.runEvent(this, this, DSMCondition::PlaylistSeparator, &params);
370 370
   }
371 371
 
372 372
   // todo: give modules the possibility to define/process events
... ...
@@ -389,7 +389,7 @@ void DSMCall::process(AmEvent* event)
389 389
       // save reference to full parameters
390 390
       avar[DSM_AVAR_JSONRPCRESPONEDATA] = AmArg(&resp_ev->response.data);
391 391
 
392
-      engine.runEvent(this, DSMCondition::JsonRpcResponse, &params);
392
+      engine.runEvent(this, this, DSMCondition::JsonRpcResponse, &params);
393 393
 
394 394
       avar.erase(DSM_AVAR_JSONRPCRESPONEDATA);
395 395
       return;
... ...
@@ -412,7 +412,7 @@ void DSMCall::process(AmEvent* event)
412 412
       // save reference to full parameters
413 413
       avar[DSM_AVAR_JSONRPCREQUESTDATA] = AmArg(&req_ev->params);
414 414
 
415
-      engine.runEvent(this, DSMCondition::JsonRpcRequest, &params);
415
+      engine.runEvent(this, this, DSMCondition::JsonRpcRequest, &params);
416 416
 
417 417
       avar.erase(DSM_AVAR_JSONRPCREQUESTDATA);
418 418
       return;
... ...
@@ -613,7 +613,7 @@ void DSMCall::onOtherBye(const AmSipRequest& req) {
613 613
 
614 614
   map<string, string> params;
615 615
   params["hdrs"] = req.hdrs; // todo: optimization - make this configurable
616
-  engine.runEvent(this, DSMCondition::B2BOtherBye, &params);
616
+  engine.runEvent(this, this, DSMCondition::B2BOtherBye, &params);
617 617
 }
618 618
 
619 619
 bool DSMCall::onOtherReply(const AmSipReply& reply) {
... ...
@@ -625,7 +625,7 @@ bool DSMCall::onOtherReply(const AmSipReply& reply) {
625 625
   params["reason"] = reply.reason;
626 626
   params["hdrs"] = reply.hdrs; // todo: optimization - make this configurable
627 627
 
628
-  engine.runEvent(this, DSMCondition::B2BOtherReply, &params);
628
+  engine.runEvent(this, this, DSMCondition::B2BOtherReply, &params);
629 629
 
630 630
   return false;
631 631
 }
... ...
@@ -352,7 +352,7 @@ EXEC_ACTION_START(SCStopAction) {
352 352
 
353 353
 #define DEF_SCModActionExec(clsname)				\
354 354
 								\
355
-  bool clsname::execute(AmSession* sess,			\
355
+  bool clsname::execute(AmSession* sess, DSMSession* sc_sess,	\
356 356
 			DSMCondition::EventType event,		\
357 357
 			map<string,string>* event_params) {	\
358 358
     return true;						\
... ...
@@ -110,7 +110,7 @@ class SCDIAction
110 110
   bool get_res;
111 111
  public:
112 112
   SCDIAction(const string& arg, bool get_res);
113
-  bool execute(AmSession* sess,
113
+  bool execute(AmSession* sess, DSMSession* sc_sess,
114 114
 	       DSMCondition::EventType event,
115 115
 	       map<string,string>* event_params);
116 116
 };									
... ...
@@ -96,7 +96,7 @@ class SCStrArgAction
96 96
   : public SCStrArgAction {						\
97 97
   public:								\
98 98
   CL_Name(const string& arg) : SCStrArgAction(arg) { }			\
99
-    bool execute(AmSession* sess,					\
99
+    bool execute(AmSession* sess, DSMSession* sc_sess,			\
100 100
 		 DSMCondition::EventType event,				\
101 101
 		 map<string,string>* event_params);			\
102 102
   };									\
... ...
@@ -107,7 +107,7 @@ class SCStrArgAction
107 107
   : public SCStrArgAction {						\
108 108
   public:								\
109 109
   CL_Name(const string& arg) : SCStrArgAction(arg) { }			\
110
-    bool execute(AmSession* sess,					\
110
+    bool execute(AmSession* sess, DSMSession* sc_sess,			\
111 111
 		 DSMCondition::EventType event,				\
112 112
 		 map<string,string>* event_params);			\
113 113
     SEAction getSEAction(std::string&);					\
... ...
@@ -120,7 +120,7 @@ class SCStrArgAction
120 120
     string par2;							\
121 121
   public:								\
122 122
     CL_Name(const string& arg);						\
123
-    bool execute(AmSession* sess,					\
123
+    bool execute(AmSession* sess, DSMSession* sc_sess,			\
124 124
 		 DSMCondition::EventType event,				\
125 125
 		 map<string,string>* event_params);			\
126 126
   };									\
... ...
@@ -195,25 +195,17 @@ class SCStrArgAction
195 195
   }									\
196 196
   
197 197
 
198
-#define GET_SCSESSION()					       \
199
-  DSMSession* sc_sess = dynamic_cast<DSMSession*>(sess);       \
200
-  if (!sc_sess) {					       \
201
-    ERROR("wrong session type\n");			       \
202
-    return false;					       \
203
-  }
204
-
205
-
206 198
 #define EXEC_ACTION_START(act_name)					\
207
-  bool act_name::execute(AmSession* sess,				\
199
+  bool act_name::execute(AmSession* sess, DSMSession* sc_sess,		\
208 200
 			 DSMCondition::EventType event,			\
209
-			 map<string,string>* event_params) {		\
210
-  GET_SCSESSION();							
201
+			 map<string,string>* event_params) {
202
+
211 203
 
212 204
 #define EXEC_ACTION_END				\
213 205
   return false;					\
214 206
   }
215 207
 
216
-#define EXEC_ACTION_STOP				\
208
+#define EXEC_ACTION_STOP			\
217 209
   return false;
218 210
 
219 211
 string resolveVars(const string s, AmSession* sess,
... ...
@@ -241,39 +233,19 @@ void splitCmd(const string& from_str,
241 233
     						\
242 234
   public:					\
243 235
     						\
244
-  cond_name(const string& arg, bool inv)			\
245
-    : arg(arg), inv(inv) { }					\
246
-    bool match(AmSession* sess, DSMCondition::EventType event,	\
247
-	       map<string,string>* event_params);		\
248
-  };								\
236
+  cond_name(const string& arg, bool inv)				\
237
+    : arg(arg), inv(inv) { }						\
238
+    bool match(AmSession* sess, DSMSession* sc_sess, DSMCondition::EventType event, \
239
+	       map<string,string>* event_params);			\
240
+  };
249 241
   
250 242
 
251 243
 #define MATCH_CONDITION_START(cond_clsname)				\
252
-  bool cond_clsname::match(AmSession* sess, DSMCondition::EventType event, \
253
-			   map<string,string>* event_params) {		\
254
-  GET_SCSESSION();
255
-
256
-#define MATCH_CONDITION_END }			
257
-
258
-
259
-#define GET_SCSESSION()					       \
260
-  DSMSession* sc_sess = dynamic_cast<DSMSession*>(sess);       \
261
-  if (!sc_sess) {					       \
262
-    ERROR("wrong session type\n");			       \
263
-    return false;					       \
264
-  }
265
-
266
-
267
-#define EXEC_ACTION_START(act_name)					\
268
-  bool act_name::execute(AmSession* sess,				\
269
-			 DSMCondition::EventType event,			\
270
-			 map<string,string>* event_params) {		\
271
-    GET_SCSESSION();							
272
-
273
-#define EXEC_ACTION_END				\
274
-  return false;					\
275
-  }
244
+  bool cond_clsname::match(AmSession* sess, DSMSession* sc_sess,	\
245
+			   DSMCondition::EventType event,		\
246
+			   map<string,string>* event_params) {
276 247
 
248
+#define MATCH_CONDITION_END }
277 249
 
278 250
 #define DECLARE_MODULE(mod_cls_name)			\
279 251
   class mod_cls_name					\
... ...
@@ -221,12 +221,12 @@ bool DSMStateEngine::onInvite(const AmSipRequest& req, DSMSession* sess) {
221 221
 
222 222
 bool DSMStateEngine::runactions(vector<DSMAction*>::iterator from, 
223 223
 				vector<DSMAction*>::iterator to, 
224
-				AmSession* sess,  DSMCondition::EventType event,
224
+				AmSession* sess,  DSMSession* sc_sess, DSMCondition::EventType event,
225 225
 				map<string,string>* event_params,  bool& is_consumed) {
226 226
 //   DBG("running %zd actions\n", to - from);
227 227
   for (vector<DSMAction*>::iterator it=from; it != to; it++) {
228 228
     DBG("executing '%s'\n", (*it)->name.c_str()); 
229
-    if ((*it)->execute(sess, event, event_params)) {
229
+    if ((*it)->execute(sess, sc_sess, event, event_params)) {
230 230
       string se_modifier;
231 231
       switch ((*it)->getSEAction(se_modifier)) {
232 232
       case DSMAction::Repost: 
... ...
@@ -234,17 +234,17 @@ bool DSMStateEngine::runactions(vector<DSMAction*>::iterator from,
234 234
 	break;
235 235
       case DSMAction::Jump: 
236 236
 	DBG("jumping %s\n", se_modifier.c_str());
237
-	if (jumpDiag(se_modifier, sess, event, event_params)) {
237
+	if (jumpDiag(se_modifier, sess, sc_sess, event, event_params)) {
238 238
 	  // is_consumed = false; 
239 239
 	  return true;  
240 240
 	} break;
241 241
       case DSMAction::Call: 
242
-	if (callDiag(se_modifier, sess, event, event_params))  {
242
+	if (callDiag(se_modifier, sess, sc_sess, event, event_params))  {
243 243
 	  // is_consumed = false; 
244 244
 	  return true;   
245 245
 	} break;
246 246
       case DSMAction::Return: 
247
-	if (returnDiag(sess)) {  
247
+	if (returnDiag(sess, sc_sess)) {
248 248
 	  //is_consumed = false;
249 249
 	  return true; 
250 250
 	} break;
... ...
@@ -266,11 +266,12 @@ void DSMStateEngine::addModules(vector<DSMModule*> modules) {
266 266
     mods.push_back(*it);
267 267
 }
268 268
 
269
-bool DSMStateEngine::init(AmSession* sess, const string& startDiagram, 
269
+bool DSMStateEngine::init(AmSession* sess, DSMSession* sc_sess,
270
+			  const string& startDiagram,
270 271
 			  DSMCondition::EventType init_event) {
271 272
 
272 273
   try {
273
-    if (!jumpDiag(startDiagram, sess, init_event, NULL)) {
274
+    if (!jumpDiag(startDiagram, sess, sc_sess, init_event, NULL)) {
274 275
       ERROR("initializing with start diag '%s'\n",
275 276
 	    startDiagram.c_str());
276 277
       return false;
... ...
@@ -278,24 +279,24 @@ bool DSMStateEngine::init(AmSession* sess, const string& startDiagram,
278 279
   } catch (DSMException& e) {
279 280
     DBG("Exception type '%s' occured while initializing! Run init event as exception...\n", 
280 281
 	e.params["type"].c_str());
281
-    runEvent(sess, init_event, &e.params, true);
282
+    runEvent(sess, sc_sess, init_event, &e.params, true);
282 283
     return true;
283 284
     
284 285
   }
285 286
 
286 287
   DBG("run init event...\n");
287
-  runEvent(sess, init_event, NULL);
288
+  runEvent(sess, sc_sess, init_event, NULL);
288 289
   return true;
289 290
 }
290 291
 
291
-bool DSMCondition::_match(AmSession* sess, 
292
+bool DSMCondition::_match(AmSession* sess, DSMSession* sc_sess,
292 293
 		      DSMCondition::EventType event,
293 294
 		      map<string,string>* event_params) {
294 295
   // or xor
295
-  return invert?(!match(sess,event,event_params)):match(sess,event,event_params);
296
+  return invert?(!match(sess,sc_sess,event,event_params)):match(sess, sc_sess, event, event_params);
296 297
 }
297 298
 
298
-bool DSMCondition::match(AmSession* sess, 
299
+bool DSMCondition::match(AmSession* sess, DSMSession* sc_sess,
299 300
 		      DSMCondition::EventType event,
300 301
 		      map<string,string>* event_params) {
301 302
 
... ...
@@ -316,7 +317,7 @@ bool DSMCondition::match(AmSession* sess,
316 317
   return true;
317 318
 }
318 319
 
319
-void DSMStateEngine::runEvent(AmSession* sess,
320
+void DSMStateEngine::runEvent(AmSession* sess, DSMSession* sc_sess,
320 321
 			      DSMCondition::EventType event,
321 322
 			      map<string,string>* event_params,
322 323
 			      bool run_exception) {
... ...
@@ -342,7 +343,7 @@ void DSMStateEngine::runEvent(AmSession* sess,
342 343
 	
343 344
 	vector<DSMCondition*>::iterator con=tr->precond.begin();
344 345
 	while (con!=tr->precond.end()) {
345
-	  if (!(*con)->_match(sess, active_event, active_params))
346
+	  if (!(*con)->_match(sess, sc_sess, active_event, active_params))
346 347
 	    break;
347 348
 	  con++;
348 349
 	}
... ...
@@ -366,7 +367,7 @@ void DSMStateEngine::runEvent(AmSession* sess,
366 367
 		current->post_actions.size(), current->name.c_str());
367 368
 	    if (runactions(current->post_actions.begin(), 
368 369
 			   current->post_actions.end(), 
369
-			   sess, active_event, active_params, is_consumed)) {
370
+			   sess, sc_sess, active_event, active_params, is_consumed)) {
370 371
 	      break;
371 372
 	    }
372 373
 	  }
... ...
@@ -377,7 +378,7 @@ void DSMStateEngine::runEvent(AmSession* sess,
377 378
 		tr->actions.size(), tr->name.c_str());
378 379
 	    if (runactions(tr->actions.begin(), 
379 380
 			   tr->actions.end(), 
380
-			   sess, active_event, active_params, is_consumed)) {
381
+			   sess, sc_sess, active_event, active_params, is_consumed)) {
381 382
 	      break;
382 383
 	    }
383 384
 	  }
... ...
@@ -412,7 +413,7 @@ void DSMStateEngine::runEvent(AmSession* sess,
412 413
 		current->pre_actions.size(), current->name.c_str());
413 414
 	    if (runactions(current->pre_actions.begin(), 
414 415
 			   current->pre_actions.end(), 
415
-			   sess, active_event, active_params, is_consumed)) {
416
+			   sess, sc_sess, active_event, active_params, is_consumed)) {
416 417
 	      break;
417 418
 	    }
418 419
 	  }
... ...
@@ -433,7 +434,7 @@ void DSMStateEngine::runEvent(AmSession* sess,
433 434
   } while (!is_consumed);
434 435
 }
435 436
 
436
-bool DSMStateEngine::callDiag(const string& diag_name, AmSession* sess, 
437
+bool DSMStateEngine::callDiag(const string& diag_name, AmSession* sess, DSMSession* sc_sess,
437 438
 			   DSMCondition::EventType event,
438 439
 			   map<string,string>* event_params) {
439 440
   if (!current || !current_diag) {
... ...
@@ -441,10 +442,10 @@ bool DSMStateEngine::callDiag(const string& diag_name, AmSession* sess,
441 442
     return false;
442 443
   }
443 444
   stack.push_back(std::make_pair(current_diag, current));
444
-  return jumpDiag(diag_name, sess, event, event_params);
445
+  return jumpDiag(diag_name, sess, sc_sess, event, event_params);
445 446
 }
446 447
 
447
-bool DSMStateEngine::jumpDiag(const string& diag_name, AmSession* sess,
448
+bool DSMStateEngine::jumpDiag(const string& diag_name, AmSession* sess, DSMSession* sc_sess,
448 449
 			   DSMCondition::EventType event,
449 450
 			   map<string,string>* event_params) {
450 451
   for (vector<DSMStateDiagram*>::iterator it=
... ...
@@ -478,7 +479,7 @@ bool DSMStateEngine::jumpDiag(const string& diag_name, AmSession* sess,
478 479
       is_finished = true;
479 480
       runactions(current->pre_actions.begin(), 
480 481
 		 current->pre_actions.end(), 
481
-		 sess, event, event_params, is_finished); 
482
+		 sess, sc_sess, event, event_params, is_finished); 
482 483
 
483 484
       return true;
484 485
     }
... ...
@@ -487,7 +488,7 @@ bool DSMStateEngine::jumpDiag(const string& diag_name, AmSession* sess,
487 488
   return false;
488 489
 }
489 490
 
490
-bool DSMStateEngine::returnDiag(AmSession* sess) {
491
+bool DSMStateEngine::returnDiag(AmSession* sess, DSMSession* sc_sess) {
491 492
   if (stack.empty()) {
492 493
     ERROR("returning from empty stack\n");
493 494
     return false;
... ...
@@ -87,6 +87,7 @@ class DSMCondition
87 87
 
88 88
     JsonRpcResponse,
89 89
     JsonRpcRequest
90
+
90 91
   };
91 92
 
92 93
   bool invert; 
... ...
@@ -97,10 +98,10 @@ class DSMCondition
97 98
   EventType type;
98 99
   map<string, string> params;
99 100
 
100
-  bool _match(AmSession* sess, DSMCondition::EventType event,
101
+  bool _match(AmSession* sess, DSMSession* sc_sess, DSMCondition::EventType event,
101 102
 	      map<string,string>* event_params);
102 103
 
103
-  virtual bool match(AmSession* sess, DSMCondition::EventType event,
104
+  virtual bool match(AmSession* sess, DSMSession* sc_sess, DSMCondition::EventType event,
104 105
 		     map<string,string>* event_params);
105 106
 };
106 107
 
... ...
@@ -120,7 +121,7 @@ class DSMAction
120 121
   virtual ~DSMAction() { /* DBG("dest action\n"); */ }
121 122
 
122 123
   /** @return whether state engine is to be modified (via getSEAction) */
123
-  virtual bool execute(AmSession* sess, DSMCondition::EventType event,	\
124
+  virtual bool execute(AmSession* sess, DSMSession* sc_sess, DSMCondition::EventType event, \
124 125
 		       map<string,string>* event_params) = 0;
125 126
 
126 127
   /** @return state engine modification */
... ...
@@ -210,14 +211,16 @@ class DSMStateEngine {
210 211
 
211 212
   vector<pair<DSMStateDiagram*, State*> > stack;
212 213
 
213
-  bool callDiag(const string& diag_name, AmSession* sess, DSMCondition::EventType event,
214
-			   map<string,string>* event_params);
215
-  bool jumpDiag(const string& diag_name, AmSession* sess, DSMCondition::EventType event,
216
-			   map<string,string>* event_params);
217
-  bool returnDiag(AmSession* sess);
214
+  bool callDiag(const string& diag_name, AmSession* sess, DSMSession* sc_sess, 
215
+		DSMCondition::EventType event,
216
+		map<string,string>* event_params);
217
+  bool jumpDiag(const string& diag_name, AmSession* sess, DSMSession* sc_sess,
218
+		DSMCondition::EventType event,
219
+		map<string,string>* event_params);
220
+  bool returnDiag(AmSession* sess, DSMSession* sc_sess);
218 221
   bool runactions(vector<DSMAction*>::iterator from, 
219 222
 		  vector<DSMAction*>::iterator to, 
220
-		  AmSession* sess, DSMCondition::EventType event,
223
+		  AmSession* sess, DSMSession* sc_sess, DSMCondition::EventType event,
221 224
 		  map<string,string>* event_params,  bool& is_consumed);
222 225
 
223 226
   vector<DSMModule*> mods;
... ...
@@ -229,10 +232,11 @@ class DSMStateEngine {
229 232
   void addDiagram(DSMStateDiagram* diag); 
230 233
   void addModules(vector<DSMModule*> modules);
231 234
 
232
-  bool init(AmSession* sess, const string& startDiagram,
235
+  bool init(AmSession* sess, DSMSession* sc_sess,
236
+	    const string& startDiagram,
233 237
 	    DSMCondition::EventType init_event);
234 238
 
235
-  void runEvent(AmSession* sess,
239
+  void runEvent(AmSession* sess, DSMSession* sc_sess,
236 240
 		DSMCondition::EventType event,
237 241
 		map<string,string>* event_params,
238 242
 		bool run_exception = false);
... ...
@@ -60,13 +60,6 @@ bool DLGModule::onInvite(const AmSipRequest& req, DSMSession* sess) {
60 60
   return true;
61 61
 }
62 62
 
63
-#define GET_SCSESSION()					 \
64
-  DSMSession* sc_sess = dynamic_cast<DSMSession*>(sess); \
65
-  if (!sc_sess) {					 \
66
-    ERROR("wrong session type\n");			 \
67
-    return false;					 \
68
-  }
69
-
70 63
 // todo: convert errors to exceptions
71 64
 void replyRequest(DSMSession* sc_sess, AmSession* sess, 
72 65
 		  EventParamT* event_params,
... ...
@@ -73,10 +73,9 @@ DSMCondition* MonitoringModule::getCondition(const string& from_str) {
73 73
 }
74 74
 
75 75
 CONST_ACTION_2P(MonLogAction, ',', true);
76
-bool MonLogAction::execute(AmSession* sess, 
76
+bool MonLogAction::execute(AmSession* sess, DSMSession* sc_sess,
77 77
 			   DSMCondition::EventType event,
78 78
 			   map<string,string>* event_params) {
79
-  GET_SCSESSION();
80 79
 
81 80
   string prop = resolveVars(par1, sess, sc_sess, event_params);
82 81
   string val  = resolveVars(par2, sess, sc_sess, event_params);
... ...
@@ -87,10 +86,9 @@ bool MonLogAction::execute(AmSession* sess,
87 86
 }
88 87
 
89 88
 CONST_ACTION_2P(MonLogAddAction, ',', true);
90
-bool MonLogAddAction::execute(AmSession* sess, 
89
+bool MonLogAddAction::execute(AmSession* sess,  DSMSession* sc_sess,
91 90
 			   DSMCondition::EventType event,
92 91
 			   map<string,string>* event_params) {
93
-  GET_SCSESSION();
94 92
 
95 93
   string prop = resolveVars(par1, sess, sc_sess, event_params);
96 94
   string val  = resolveVars(par2, sess, sc_sess, event_params);
... ...
@@ -100,11 +98,9 @@ bool MonLogAddAction::execute(AmSession* sess,
100 98
   return false;
101 99
 }
102 100
 
103
-bool MonLogVarsAction::execute(AmSession* sess, 
101
+bool MonLogVarsAction::execute(AmSession* sess,   DSMSession* sc_sess,
104 102
 			       DSMCondition::EventType event,
105 103
 			       map<string,string>* event_params) {
106
-  GET_SCSESSION();
107
-
108 104
   AmArg di_args,ret;
109 105
   di_args.push(AmArg(sess->getLocalTag().c_str()));
110 106
 
... ...
@@ -67,7 +67,7 @@ class SCPyPyAction
67 67
     PyObject* py_func;
68 68
  public:				
69 69
     SCPyPyAction(const string& arg);
70
-    bool execute(AmSession* sess,	
70
+    bool execute(AmSession* sess, DSMSession* sc_sess,
71 71
 		 DSMCondition::EventType event,	
72 72
 		 map<string,string>* event_params);
73 73
 };
... ...
@@ -79,7 +79,7 @@ class PyPyCondition
79 79
  public:
80 80
   
81 81
   PyPyCondition(const string& arg);
82
-  bool match(AmSession* sess, DSMCondition::EventType event,
82
+  bool match(AmSession* sess, DSMSession* sc_sess, DSMCondition::EventType event,
83 83
 	     map<string,string>* event_params);
84 84
 };
85 85