RSB  0.7.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EventIdConverter.cpp
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of the RSB TimeSync project.
4  *
5  * Copyright (C) 2012 by Johannes Wienke <jwienke 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 "EventIdConverter.h"
28 
29 #include <map>
30 #include <vector>
31 
32 #include "../EventId.h"
33 #include "rsb/protocol/EventId.pb.h"
35 #include "SerializationException.h"
36 
37 using namespace std;
38 
39 namespace rsb {
40 namespace converter {
41 
42 EventIdConverter::EventIdConverter() :
43  Converter<string>("dummy", RSB_TYPE_TAG(EventId)), converter(
44  new ProtocolBufferConverter<protocol::EventId>) {
45 }
46 
48 }
49 
51  return converter->getWireSchema();
52 }
53 
55  return "EventIdConverter";
56 }
57 
58 string EventIdConverter::serialize(const AnnotatedData& data, string& wire) {
59 
60  if (data.first != getDataType()) {
62  "Called with unsupported data type " + data.first);
63  }
64 
65  boost::shared_ptr<EventId> eventId = boost::static_pointer_cast<EventId>(
66  data.second);
67 
68  boost::shared_ptr<protocol::EventId> protocolId(new protocol::EventId);
69  // TODO duplicated code with internal sending of events (Notification.cpp)
70  boost::uuids::uuid uuid = eventId->getParticipantId().getId();
71  protocolId->set_sender_id(uuid.data, uuid.size());
72  protocolId->set_sequence_number(eventId->getSequenceNumber());
73 
74  return converter->serialize(
75  make_pair(rsc::runtime::typeName<protocol::EventId>(), protocolId),
76  wire);
77 
78 }
79 
81  const string& wire) {
82 
83  boost::shared_ptr<protocol::EventId> protocolId =
84  boost::static_pointer_cast<protocol::EventId>(
85  converter->deserialize(wireSchema, wire).second);
86 
87  return make_pair(
88  getDataType(),
89  boost::shared_ptr<EventId>(
90  new EventId(
91  rsc::misc::UUID(
92  (boost::uint8_t*) protocolId->sender_id().c_str()),
93  protocolId->sequence_number())));
94 
95 }
96 
97 }
98 }