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  explicit 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  operator std::string() {
113  std::stringstream ss;
114  ss << *this;
115  return ss.str();
116  }
117 
118  typedef std::multimap<std::string, Data> params_t;
119  typedef std::map<std::string, Data> namelist_t;
120 
121  static bool getParam(const params_t& params, const std::string& name, Data& target) {
122  if (params.find(name) != params.end()) {
123  target = params.find(name)->second;
124  return true;
125  }
126  return false;
127  }
128 
129  static bool getParam(const params_t& params, const std::string& name, std::list<Data>& target) {
130  if (params.find(name) != params.end()) {
131  std::pair<params_t::const_iterator, params_t::const_iterator> rangeIter = params.equal_range(name);
132  while(rangeIter.first != rangeIter.second) {
133  target.push_back(rangeIter.first->second);
134  rangeIter.first++;
135  }
136  return true;
137  }
138  return false;
139  }
140 
141  template <typename T> static bool getParam(const params_t& params, const std::string& name, T& target) {
142  if (params.find(name) != params.end()) {
143  target = strTo<T>(params.find(name)->second.atom);
144  return true;
145  }
146  return false;
147  }
148 
149  static bool getParam(const params_t& params, const std::string& name, bool& target) {
150  if (params.find(name) != params.end()) {
151  target = true;
152  if (iequals(params.find(name)->second.atom, "false")) {
153  target = false;
154  } else if(iequals(params.find(name)->second.atom, "off")) {
155  target = false;
156  } else if(iequals(params.find(name)->second.atom, "no")) {
157  target = false;
158  } else if(iequals(params.find(name)->second.atom, "0")) {
159  target = false;
160  }
161  return true;
162  }
163  return false;
164  }
165 
166  template <typename T> static bool getParam(const params_t& params, const std::string& name, std::list<T>& target) {
167  if (params.find(name) != params.end()) {
168  std::pair<params_t::const_iterator, params_t::const_iterator> rangeIter = params.equal_range(name);
169  while(rangeIter.first != rangeIter.second) {
170  target.push_back(strTo<T>(rangeIter.first->second.atom));
171  rangeIter.first++;
172  }
173  return true;
174  }
175  return false;
176  }
177 
178  std::string raw;
179  std::string name;
180  Type eventType;
181  std::string origin;
182  std::string origintype;
183  std::string sendid;
184  bool hideSendId; // sendid is assumed to be undef with some ecma tests
185  std::string invokeid;
186  Data data;
187  std::map<std::string, Data> namelist;
188  std::multimap<std::string, Data> params;
189  std::string uuid; // the sendid is not necessarily unique!
190 
191  friend USCXML_API std::ostream& operator<< (std::ostream& os, const Event& event);
192 };
193 
194 USCXML_API std::ostream& operator<< (std::ostream& os, const Event& event);
195 
196 
197 class USCXML_API ErrorEvent : public Event {
198 public:
199  ErrorEvent() : Event() {}
200  ErrorEvent(const std::string& msg) : Event("error.platform") {
201  data.compound["msg"] = Data(msg, Data::VERBATIM);
202  }
203 };
204 
205 }
206 
207 
208 
209 #endif /* end of include guard: EVENT_H_6174D929 */
Definition: Breakpoint.cpp:26
Definition: Event.h:197
Definition: Event.h:84
Definition: Data.h:43