InterpreterMonitor.h
Go to the documentation of this file.
1 
20 #ifndef INTERPRETERMONITOR_H_D3F21429
21 #define INTERPRETERMONITOR_H_D3F21429
22 
23 #include "uscxml/Common.h"
24 #include "uscxml/messages/Event.h"
27 
28 #include <mutex>
29 
30 #define USCXML_MONITOR_CATCH(callback) \
31 catch (Event e) { LOG(USCXML_ERROR) << "Syntax error when calling " #callback " on monitors: " << std::endl << e << std::endl; } \
32 catch (std::bad_weak_ptr e) { LOG(USCXML_ERROR) << "Unclean shutdown " << std::endl; } \
33 catch (...) { LOG(USCXML_ERROR) << "An exception occurred when calling " #callback " on monitors"; } \
34 if (_state == USCXML_DESTROYED) { throw std::bad_weak_ptr(); }
35 
36 #define USCXML_MONITOR_CALLBACK(callbacks, function) { \
37 Interpreter inptr = _callbacks->getInterpreter(); \
38 for (auto callback : callbacks) { callback->function(inptr); } }
39 
40 #define USCXML_MONITOR_CALLBACK1(callbacks, function, arg1) { \
41 Interpreter inptr = _callbacks->getInterpreter(); \
42 for (auto callback : callbacks) { callback->function(inptr, arg1); } }
43 
44 #define USCXML_MONITOR_CALLBACK2(callbacks, function, arg1, arg2) { \
45 Interpreter inptr = _callbacks->getInterpreter(); \
46 for (auto callback : callbacks) { callback->function(inptr, arg1, arg2); } }
47 
48 // forward declare
49 namespace XERCESC_NS {
50 class DOMElement;
51 }
52 
53 namespace uscxml {
54 
55 class Interpreter;
56 
57 class USCXML_API InterpreterMonitor {
58 public:
59  InterpreterMonitor() : _copyToInvokers(false) {
60  _logger = Logger::getDefault();
61  }
62  InterpreterMonitor(Logger logger) : _copyToInvokers(false), _logger(logger) {}
63  virtual ~InterpreterMonitor() {}
64 
65  virtual void beforeProcessingEvent(Interpreter& interpreter, const Event& event) {}
66  virtual void beforeMicroStep(Interpreter& interpreter) {}
67 
68  virtual void beforeExitingState(Interpreter& interpreter, const XERCESC_NS::DOMElement* state) {}
69  virtual void afterExitingState(Interpreter& interpreter, const XERCESC_NS::DOMElement* state) {}
70 
71  virtual void beforeExecutingContent(Interpreter& interpreter, const XERCESC_NS::DOMElement* execContent) {}
72  virtual void afterExecutingContent(Interpreter& interpreter, const XERCESC_NS::DOMElement* execContent) {}
73 
74  virtual void beforeUninvoking(Interpreter& interpreter, const XERCESC_NS::DOMElement* invokeElem, const std::string& invokeid) {}
75  virtual void afterUninvoking(Interpreter& interpreter, const XERCESC_NS::DOMElement* invokeElem, const std::string& invokeid) {}
76 
77  virtual void beforeTakingTransition(Interpreter& interpreter, const XERCESC_NS::DOMElement* transition) {}
78  virtual void afterTakingTransition(Interpreter& interpreter, const XERCESC_NS::DOMElement* transition) {}
79 
80  virtual void beforeEnteringState(Interpreter& interpreter, const XERCESC_NS::DOMElement* state) {}
81  virtual void afterEnteringState(Interpreter& interpreter, const XERCESC_NS::DOMElement* state) {}
82 
83  virtual void beforeInvoking(Interpreter& interpreter, const XERCESC_NS::DOMElement* invokeElem, const std::string& invokeid) {}
84  virtual void afterInvoking(Interpreter& interpreter, const XERCESC_NS::DOMElement* invokeElem, const std::string& invokeid) {}
85 
86  virtual void afterMicroStep(Interpreter& interpreter) {}
87  virtual void onStableConfiguration(Interpreter& interpreter) {}
88 
89  virtual void beforeCompletion(Interpreter& interpreter) {}
90  virtual void afterCompletion(Interpreter& interpreter) {}
91 
92  virtual void reportIssue(Interpreter& interpreter, const InterpreterIssue& issue) {}
93 
94  void copyToInvokers(bool copy) {
95  _copyToInvokers = copy;
96  }
97 
98  bool copyToInvokers() {
99  return _copyToInvokers;
100  }
101 
102 protected:
103  bool _copyToInvokers;
104  Logger _logger;
105 };
106 
108 public:
109  StateTransitionMonitor(std::string prefix = "") : _logPrefix(prefix) {}
110  virtual ~StateTransitionMonitor() {}
111 
112  virtual void beforeTakingTransition(Interpreter& interpreter, const XERCESC_NS::DOMElement* transition);
113  virtual void beforeExecutingContent(Interpreter& interpreter, const XERCESC_NS::DOMElement* element);
114  virtual void onStableConfiguration(Interpreter& interpreter);
115  virtual void beforeProcessingEvent(Interpreter& interpreter, const uscxml::Event& event);
116  virtual void beforeExitingState(Interpreter& interpreter, const XERCESC_NS::DOMElement* state);
117  virtual void beforeEnteringState(Interpreter& interpreter, const XERCESC_NS::DOMElement* state);
118  virtual void beforeMicroStep(Interpreter& interpreter);
119 
120 protected:
121  static std::recursive_mutex _mutex;
122  std::string _logPrefix;
123 };
124 
125 }
126 
127 #endif /* end of include guard: INTERPRETERMONITOR_H_D3F21429 */
Definition: Breakpoint.cpp:26
Definition: InterpreterMonitor.h:57
Identify and report syntactic and semantic problems with a SCXML state-charts.
Definition: InterpreterIssue.h:41
Identifies some common problems with SCXML documents.
Central class to interpret and process SCXML documents.
Definition: Interpreter.h:79
Definition: Event.h:94
Definition: Breakpoint.h:30
Definition: InterpreterMonitor.h:107
Definition: Logging.h:69