RSB  0.7.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Event.cpp
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of the RSB project
4  *
5  * Copyright (C) 2010 by Sebastian Wrede <swrede at techfak dot uni-bielefeld dot de>
6  *
7  * This file may be licensed under the terms of the
8  * GNU Lesser General Public License Version 3 (the ``LGPL''),
9  * or (at your option) any later version.
10  *
11  * Software distributed under the License is distributed
12  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13  * express or implied. See the LGPL for the specific language
14  * governing rights and limitations.
15  *
16  * You should have received a copy of the LGPL along with this
17  * program. If not, go to http://www.gnu.org/licenses/lgpl.html
18  * or write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  * The development of this software was supported by:
22  * CoR-Lab, Research Institute for Cognition and Robotics
23  * Bielefeld University
24  *
25  * ============================================================ */
26 
27 #include "Event.h"
28 
29 #include <ostream>
30 
31 #include <boost/format.hpp>
32 
33 #include <rsc/runtime/ContainerIO.h>
34 #include <rsc/misc/IllegalStateException.h>
35 
36 #include "EventId.h"
37 #include "MetaData.h"
38 #include "Scope.h"
39 
40 using namespace std;
41 using namespace boost;
42 
43 namespace rsb {
44 
45 class Event::Impl {
46 public:
49 
51 
52  // is this a single type, a hierarchy or a set?
53  std::string type;
54 
55  std::string method;
56 
57  std::set<EventId> causes;
58 
60 };
61 
62 Event::Event() :
63  d(new Impl()) {
64  d->scope.reset(new Scope);
65 }
66 
67 Event::Event(const Event& event) :
68  d(new Impl(*event.d)) {
69 
70 }
71 
72 Event::Event(ScopePtr scope, boost::shared_ptr<void> payload,
73  const string& type, const string& method) :
74  d(new Impl()) {
75  d->scope = scope;
76  d->content = payload;
77  d->type = type;
78  d->method = method;
79 }
80 
81 Event::Event(Scope scope, boost::shared_ptr<void> payload, const string& type,
82  const string& method) :
83  d(new Impl()) {
84  d->scope.reset(new Scope(scope));
85  d->content = payload;
86  d->type = type;
87  d->method = method;
88 }
89 
91 }
92 
93 string Event::getClassName() const {
94  return "Event";
95 }
96 
97 void Event::printContents(ostream& stream) const {
98  stream << "id = ";
99  if (d->id) {
100  stream << d->id;
101  } else {
102  stream << "UNSPECIFIED";
103  }
104  stream << ", type = " << d->type << ", scope = ";
105  if (d->scope) {
106  stream << *d->scope;
107  } else {
108  stream << "UNSPECIFIED";
109  }
110  stream << ", metaData = " << d->metaData << ", method = " << d->method;
111  stream << ", causes = " << d->causes;
112 }
113 
114 boost::uint64_t Event::getSequenceNumber() const {
115  return getEventId().getSequenceNumber();
116 }
117 
118 rsc::misc::UUID Event::getId() const {
119  return getEventId().getAsUUID();
120 }
121 
123  if (!d->id) {
124  throw rsc::misc::IllegalStateException(
125  "The event does not contain id information.");
126  }
127  return *d->id;
128 }
129 
130 void Event::setEventId(const rsc::misc::UUID& senderId,
131  const boost::uint32_t& sequenceNumber) {
132  d->id.reset(new EventId(senderId, sequenceNumber));
133  d->metaData.setSenderId(senderId);
134 }
135 
137  d->scope = s;
138 }
139 
140 void Event::setScope(const Scope& s) {
141  d->scope = ScopePtr(new Scope(s));
142 }
143 
145  return d->scope;
146 }
147 
149  return *d->scope;
150 }
151 
153  d->content = data;
154 }
155 
157  return d->content;
158 }
159 
160 string Event::getType() const {
161  return d->type;
162 }
163 
164 void Event::setType(const string& t) {
165  d->type = t;
166 }
167 
168 bool Event::addCause(const EventId& id) {
169  return d->causes.insert(id).second;
170 }
171 
172 bool Event::removeCause(const EventId& id) {
173  return d->causes.erase(id) > 0;
174 }
175 
176 bool Event::isCause(const EventId& id) const {
177  return d->causes.count(id) > 0;
178 }
179 
180 set<EventId> Event::getCauses() const {
181  return d->causes;
182 }
183 
184 string Event::getMethod() const {
185  return d->method;
186 }
187 
188 void Event::setMethod(const string& method) {
189  d->method = method;
190 }
191 
193  return d->metaData;
194 }
195 
197  return d->metaData;
198 }
199 
200 void Event::setMetaData(const MetaData& metaData) {
201  d->metaData = metaData;
202 }
203 
204 }