MIRA
Event.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Redistribution and modification of this code is strictly prohibited.
9  *
10  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
11  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
12  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
13  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14  *
15  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
16  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
18  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
19  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
20  */
21 
30 #ifndef _MIRA_EVENT_H_
31 #define _MIRA_EVENT_H_
32 
33 #include <string>
34 #include <list>
35 #include <map>
36 
37 #include <boost/shared_ptr.hpp>
38 
40 
41 #include <python/JSON2Python.h>
42 
43 #include <sm/TransitionTarget.h>
44 
45 namespace mira { namespace sm {
46 
48 
49 class Event
50 {
51 public:
52 
53  Event() :
54  delay(0),
55  canceled(false)
56  {}
57 
58  Event(const std::string& n) :
59  name(n),
60  delay(0),
61  canceled(false)
62  {}
63 
64  Event(const std::string& n, const std::string& i) :
65  name(n),
66  id(i),
67  delay(0),
68  canceled(false)
69  {}
70 
71  Event(const std::string& n, const boost::python::object& d) :
72  name(n),
73  data(d),
74  delay(0),
75  canceled(false)
76  {}
77 
79 
80  template<typename Reflector>
81  void reflectRead(Reflector& r)
82  {
83  r.member("Name", name, "");
84  r.member("ID", id, "");
86  std::string dataStr = json::write(v);
87  r.member("Data", dataStr, "");
88  r.member("Delay", delay, "");
89  r.member("Canceled", canceled, "");
90  }
91 
92  template<typename Reflector>
93  void reflectWrite(Reflector& r)
94  {
95  r.member("Name", name, "");
96  r.member("ID", id, "");
97  std::string dataStr;
98  r.member("Data", dataStr, "");
99  json::Value v;
100  json::read(dataStr, v);
101  data = python::from_json(v);
102  r.member("Delay", delay, "");
103  r.member("Canceled", canceled, "");
104  }
105 
106 public:
107 
108  std::string name;
109  std::string id;
110  std::string target;
111  boost::python::object data;
114  bool canceled;
115 
116 };
117 
119 
120 }} // namespace
121 
122 #endif
void write(const Value &value, std::ostream &ioStream, bool formatted=false, int precision=-1)
uint64_t uint64
std::string id
Definition: Event.h:109
Event()
Definition: Event.h:53
#define MIRA_SPLIT_REFLECT_MEMBER
void read(const std::string &s, Value &oValue)
boost::python::object data
Definition: Event.h:111
std::string name
Definition: Event.h:108
std::string target
Definition: Event.h:110
Event(const std::string &n)
Definition: Event.h:58
boost::python::object from_json(const json::Value &j)
Time invocationTime
Definition: Event.h:113
uint64 delay
Definition: Event.h:112
json_spirit::mValue Value
MIRA_SPLIT_REFLECT_MEMBER void reflectRead(Reflector &r)
Definition: Event.h:81
Definition: Event.h:49
json::Value to_json(boost::python::object o)
TODO Add description.
Event(const std::string &n, const std::string &i)
Definition: Event.h:64
bool canceled
Definition: Event.h:114
void reflectWrite(Reflector &r)
Definition: Event.h:93
Event(const std::string &n, const boost::python::object &d)
Definition: Event.h:71