Event.h
Go to the documentation of this file.
1 
20 #ifndef EVENT_H_6174D929
21 #define EVENT_H_6174D929
22 
23 #include "uscxml/messages/Data.h"
24 #include "uscxml/util/UUID.h"
25 
26 #define ERROR_PLATFORM_THROW(msg) \
27  ErrorEvent e; \
28  e.name = "error.platform"; \
29  e.data.compound["cause"] = Data(msg, Data::VERBATIM); \
30  throw e; \
31 
32 #define ERROR_EXECUTION(identifier, cause) \
33  uscxml::ErrorEvent identifier; \
34  identifier.data.compound["cause"] = uscxml::Data(cause, uscxml::Data::VERBATIM); \
35  identifier.name = "error.execution"; \
36  identifier.eventType = uscxml::Event::PLATFORM;
37 
38 #define ERROR_EXECUTION2(identifier, cause, node) \
39  uscxml::ErrorEvent identifier; \
40  identifier.data.compound["cause"] = uscxml::Data(cause, uscxml::Data::VERBATIM); \
41  identifier.name = "error.execution"; \
42  identifier.data.compound["xpath"] = uscxml::Data(DOMUtils::xPathForNode(node), uscxml::Data::VERBATIM); \
43  identifier.eventType = uscxml::Event::PLATFORM;
44 
45 #define ERROR_COMMUNICATION(identifier, cause) \
46  uscxml::ErrorEvent identifier; \
47  identifier.data.compound["cause"] = uscxml::Data(cause, uscxml::Data::VERBATIM); \
48  identifier.name = "error.communication"; \
49  identifier.eventType = uscxml::Event::PLATFORM;
50 
51 #define ERROR_COMMUNICATION2(identifier, cause, node) \
52  uscxml::ErrorEvent identifier; \
53  identifier.data.compound["cause"] = uscxml::Data(cause, uscxml::Data::VERBATIM); \
54  identifier.name = "error.communication"; \
55  identifier.data.compound["xpath"] = uscxml::Data(DOMUtils::xPathForNode(node), uscxml::Data::VERBATIM); \
56  identifier.eventType = uscxml::Event::PLATFORM;
57 
58 #define ERROR_EXECUTION_THROW(cause) \
59 {\
60  ERROR_EXECUTION(exc, cause); \
61  throw exc;\
62 }
63 
64 #define ERROR_EXECUTION_THROW2(cause, node) \
65 {\
66  ERROR_EXECUTION2(exc, cause, node); \
67  throw exc;\
68 }
69 
70 #define ERROR_COMMUNICATION_THROW(cause) \
71 {\
72  ERROR_COMMUNICATION(exc, cause); \
73  throw exc;\
74 }
75 
76 #define ERROR_COMMUNICATION_THROW2(cause, node) \
77 {\
78  ERROR_COMMUNICATION(exc, cause, node); \
79  throw exc;\
80 }
81 
82 namespace uscxml {
83 
84 class USCXML_API Event {
85 public:
86  enum Type {
87  INTERNAL = 1,
88  EXTERNAL = 2,
89  PLATFORM = 3
90  };
91 
92  Event() : eventType(INTERNAL), hideSendId(false), uuid(UUID::getUUID()) {}
93  Event(const std::string& name, Type type = INTERNAL) : name(name), eventType(type), hideSendId(false) {}
94  bool operator< (const Event& other) const {
95  return this < &other;
96  }
97 
98  bool operator==(const Event& other) const {
99  return (this->name == other.name &&
100  this->sendid == other.sendid &&
101  this->invokeid == other.invokeid &&
102  this->data == other.data);
103  }
104  bool operator!=(const Event& other) const {
105  return !(*this == other);
106  }
107 
108  operator bool() {
109  return name.size() > 0;
110  }
111 
112  typedef std::multimap<std::string, Data> params_t;
113  typedef std::map<std::string, Data> namelist_t;
114 
115  static bool getParam(const params_t& params, const std::string& name, Data& target) {
116  if (params.find(name) != params.end()) {
117  target = params.find(name)->second;
118  return true;
119  }
120  return false;
121  }
122 
123  static bool getParam(const params_t& params, const std::string& name, std::list<Data>& target) {
124  if (params.find(name) != params.end()) {
125  std::pair<params_t::const_iterator, params_t::const_iterator> rangeIter = params.equal_range(name);
126  while(rangeIter.first != rangeIter.second) {
127  target.push_back(rangeIter.first->second);
128  rangeIter.first++;
129  }
130  return true;
131  }
132  return false;
133  }
134 
135  template <typename T> static bool getParam(const params_t& params, const std::string& name, T& target) {
136  if (params.find(name) != params.end()) {
137  target = strTo<T>(params.find(name)->second.atom);
138  return true;
139  }
140  return false;
141  }
142 
143  static bool getParam(const params_t& params, const std::string& name, bool& target) {
144  if (params.find(name) != params.end()) {
145  target = true;
146  if (iequals(params.find(name)->second.atom, "false")) {
147  target = false;
148  } else if(iequals(params.find(name)->second.atom, "off")) {
149  target = false;
150  } else if(iequals(params.find(name)->second.atom, "no")) {
151  target = false;
152  } else if(iequals(params.find(name)->second.atom, "0")) {
153  target = false;
154  }
155  return true;
156  }
157  return false;
158  }
159 
160  template <typename T> static bool getParam(const params_t& params, const std::string& name, std::list<T>& target) {
161  if (params.find(name) != params.end()) {
162  std::pair<params_t::const_iterator, params_t::const_iterator> rangeIter = params.equal_range(name);
163  while(rangeIter.first != rangeIter.second) {
164  target.push_back(strTo<T>(rangeIter.first->second.atom));
165  rangeIter.first++;
166  }
167  return true;
168  }
169  return false;
170  }
171 
172  std::string raw;
173  std::string name;
174  Type eventType;
175  std::string origin;
176  std::string origintype;
177  std::string sendid;
178  bool hideSendId; // sendid is assumed to be undef with some ecma tests
179  std::string invokeid;
180  Data data;
181  std::map<std::string, Data> namelist;
182  std::multimap<std::string, Data> params;
183  std::string uuid; // the sendid is not necessarily unique!
184 
185  friend USCXML_API std::ostream& operator<< (std::ostream& os, const Event& event);
186 };
187 
188 USCXML_API std::ostream& operator<< (std::ostream& os, const Event& event);
189 
190 
191 class USCXML_API ErrorEvent : public Event {
192 public:
193  ErrorEvent() : Event() {}
194  ErrorEvent(const std::string& msg) : Event("error.platform") {
195  data.compound["msg"] = msg;
196  }
197 };
198 
199 }
200 
201 
202 
203 #endif /* end of include guard: EVENT_H_6174D929 */
Definition: InterpreterIssue.cpp:33
Definition: Event.h:191
Definition: Event.h:84
Definition: Data.h:44