Browse code

b/f:dsm: execute actions after callFSM

e.g. callFSM(callsub);
log(3, "hello, back here");

thanks to Oz Oseghale for reporting

Stefan Sayer authored on 13/02/2014 17:10:08
Showing 3 changed files
... ...
@@ -262,13 +262,13 @@ bool DSMStateEngine::runactions(vector<DSMElement*>::iterator from,
262 262
 	  break;
263 263
 	case DSMAction::Call:
264 264
 	  DBG("calling %s\n", se_modifier.c_str());
265
-	  if (callDiag(se_modifier, sess, sc_sess, event, event_params))  {
265
+	  if (callDiag(se_modifier, sess, sc_sess, event, event_params, it+1, to))  {
266 266
 	    // is_consumed = false; 
267 267
 	    return true;   
268 268
 	  } 
269 269
 	  break;
270 270
 	case DSMAction::Return: 
271
-	  if (returnDiag(sess, sc_sess)) {
271
+	  if (returnDiag(sess, sc_sess, event, event_params)) {
272 272
 	    //is_consumed = false;
273 273
 	    return true; 
274 274
 	  }
... ...
@@ -632,13 +632,17 @@ void DSMStateEngine::runEvent(AmSession* sess, DSMSession* sc_sess,
632 632
 }
633 633
 
634 634
 bool DSMStateEngine::callDiag(const string& diag_name, AmSession* sess, DSMSession* sc_sess,
635
-			   DSMCondition::EventType event,
636
-			   map<string,string>* event_params) {
635
+			      DSMCondition::EventType event,
636
+			      map<string,string>* event_params,
637
+			      vector<DSMElement*>::iterator actions_from, vector<DSMElement*>::iterator actions_to) {
637 638
   if (!current || !current_diag) {
638 639
     ERROR("no current diag to push\n");
639 640
     return false;
640 641
   }
641
-  stack.push_back(std::make_pair(current_diag, current));
642
+  stack.push_back(DSMStackElement(current_diag, current));
643
+  for (vector<DSMElement*>::iterator it = actions_from; it != actions_to; it++)
644
+    stack.back().actions.push_back(*it);
645
+
642 646
   return jumpDiag(diag_name, sess, sc_sess, event, event_params);
643 647
 }
644 648
 
... ...
@@ -685,15 +689,23 @@ bool DSMStateEngine::jumpDiag(const string& diag_name, AmSession* sess, DSMSessi
685 689
   return false;
686 690
 }
687 691
 
688
-bool DSMStateEngine::returnDiag(AmSession* sess, DSMSession* sc_sess) {
692
+bool DSMStateEngine::returnDiag(AmSession* sess, DSMSession* sc_sess,
693
+				DSMCondition::EventType event, map<string,string>* event_params) {
689 694
   if (stack.empty()) {
690 695
     ERROR("returning from empty stack\n");
691 696
     return false;
692 697
   }
693
-  current_diag = stack.back().first;
694
-  current = stack.back().second;
698
+  current_diag = stack.back().diag;
699
+  current = stack.back().state;
700
+  vector<DSMElement*> actions = stack.back().actions;
695 701
   stack.pop_back();
696 702
 
703
+  bool is_consumed; //?
704
+  DBG("executing %zd action elements from stack\n", actions.size());
705
+  if (actions.size()) {
706
+    runactions(actions.begin(), actions.end(), sess, sc_sess, event, event_params, is_consumed);
707
+  }
708
+
697 709
   MONITORING_LOG2(sess->getLocalTag().c_str(), 
698 710
 		  "dsm_diag", current_diag->getName().c_str(),
699 711
 		  "dsm_state", current->name.c_str());
... ...
@@ -255,20 +255,35 @@ class DSMException {
255 255
   map<string, string> params;    
256 256
 };
257 257
 
258
+struct DSMStackElement {
259
+  DSMStateDiagram* diag;
260
+  State* state;
261
+  vector<DSMElement*> actions;
262
+
263
+  DSMStackElement(DSMStateDiagram* diag, State* state)
264
+  : diag(diag), state(state) { }
265
+
266
+  DSMStackElement(DSMStateDiagram* diag, State* state, const vector<DSMElement*>& actions)
267
+  : diag(diag), state(state), actions(actions) { }
268
+
269
+};
270
+
258 271
 class DSMStateEngine {
259 272
   State* current;
260 273
   DSMStateDiagram* current_diag;
261 274
   vector<DSMStateDiagram*> diags;
262 275
 
263
-  vector<pair<DSMStateDiagram*, State*> > stack;
276
+  //  vector<pair<DSMStateDiagram*, State*> > stack;
277
+  vector<DSMStackElement> stack;
264 278
 
265 279
   bool callDiag(const string& diag_name, AmSession* sess, DSMSession* sc_sess, 
266 280
 		DSMCondition::EventType event,
267
-		map<string,string>* event_params);
281
+		map<string,string>* event_params,
282
+		vector<DSMElement*>::iterator actions_from, vector<DSMElement*>::iterator actions_to);
268 283
   bool jumpDiag(const string& diag_name, AmSession* sess, DSMSession* sc_sess,
269 284
 		DSMCondition::EventType event,
270 285
 		map<string,string>* event_params);
271
-  bool returnDiag(AmSession* sess, DSMSession* sc_sess);
286
+  bool returnDiag(AmSession* sess, DSMSession* sc_sess, DSMCondition::EventType event, map<string,string>* event_params);
272 287
   bool runactions(vector<DSMElement*>::iterator from, 
273 288
 		  vector<DSMElement*>::iterator to, 
274 289
 		  AmSession* sess, DSMSession* sc_sess, DSMCondition::EventType event,
... ...
@@ -71,7 +71,7 @@ DSM flow
71 71
 
72 72
  -- call/jump/return sub-FSM
73 73
  jumpFSM(name)
74
- callFSM(name)
74
+ callFSM(name)   - note that actions after callFSM may have the event & event params of the sub-FSM  
75 75
  returnFSM()
76 76
 
77 77
  stop(<send bye>)