Fawkes API Fawkes Development Version
OpenraveRobotMemoryInterface.cpp
1
2/***************************************************************************
3 * OpenraveRobotMemoryInterface.cpp - Fawkes BlackBoard Interface - OpenraveRobotMemoryInterface
4 *
5 * Templated created: Thu Oct 12 10:49:19 2006
6 * Copyright 2016 Frederik Zwilling
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. A runtime exception applies to
14 * this software (see LICENSE.GPL_WRE file mentioned below for details).
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
20 *
21 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22 */
23
24#include <interfaces/OpenraveRobotMemoryInterface.h>
25
26#include <core/exceptions/software.h>
27
28#include <map>
29#include <string>
30#include <cstring>
31#include <cstdlib>
32
33namespace fawkes {
34
35/** @class OpenraveRobotMemoryInterface <interfaces/OpenraveRobotMemoryInterface.h>
36 * OpenraveRobotMemoryInterface Fawkes BlackBoard Interface.
37 *
38 Interface to instruct the OpenraveRobotMemory Plugin
39
40 * @ingroup FawkesInterfaces
41 */
42
43
44
45/** Constructor */
46OpenraveRobotMemoryInterface::OpenraveRobotMemoryInterface() : Interface()
47{
48 data_size = sizeof(OpenraveRobotMemoryInterface_data_t);
49 data_ptr = malloc(data_size);
50 data = (OpenraveRobotMemoryInterface_data_t *)data_ptr;
51 data_ts = (interface_data_ts_t *)data_ptr;
52 memset(data_ptr, 0, data_size);
53 add_fieldinfo(IFT_UINT32, "dummy", 1, &data->dummy);
54 add_messageinfo("ConstructSceneMessage");
55 unsigned char tmp_hash[] = {0x49, 0x41, 0x1e, 0x3, 0xf2, 0xeb, 0x23, 0xb8, 0x2a, 0x6e, 0x90, 0xc2, 0x3e, 0xe9, 0xa4, 0x24};
56 set_hash(tmp_hash);
57}
58
59/** Destructor */
60OpenraveRobotMemoryInterface::~OpenraveRobotMemoryInterface()
61{
62 free(data_ptr);
63}
64/* Methods */
65/** Get dummy value.
66 *
67 Dummy field
68
69 * @return dummy value
70 */
71uint32_t
72OpenraveRobotMemoryInterface::dummy() const
73{
74 return data->dummy;
75}
76
77/** Get maximum length of dummy value.
78 * @return length of dummy value, can be length of the array or number of
79 * maximum number of characters for a string
80 */
81size_t
82OpenraveRobotMemoryInterface::maxlenof_dummy() const
83{
84 return 1;
85}
86
87/** Set dummy value.
88 *
89 Dummy field
90
91 * @param new_dummy new dummy value
92 */
93void
94OpenraveRobotMemoryInterface::set_dummy(const uint32_t new_dummy)
95{
96 set_field(data->dummy, new_dummy);
97}
98
99/* =========== message create =========== */
100Message *
101OpenraveRobotMemoryInterface::create_message(const char *type) const
102{
103 if ( strncmp("ConstructSceneMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
104 return new ConstructSceneMessage();
105 } else {
106 throw UnknownTypeException("The given type '%s' does not match any known "
107 "message type for this interface type.", type);
108 }
109}
110
111
112/** Copy values from other interface.
113 * @param other other interface to copy values from
114 */
115void
116OpenraveRobotMemoryInterface::copy_values(const Interface *other)
117{
118 const OpenraveRobotMemoryInterface *oi = dynamic_cast<const OpenraveRobotMemoryInterface *>(other);
119 if (oi == NULL) {
120 throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
121 type(), other->type());
122 }
123 memcpy(data, oi->data, sizeof(OpenraveRobotMemoryInterface_data_t));
124}
125
126const char *
127OpenraveRobotMemoryInterface::enum_tostring(const char *enumtype, int val) const
128{
129 throw UnknownTypeException("Unknown enum type %s", enumtype);
130}
131
132/* =========== messages =========== */
133/** @class OpenraveRobotMemoryInterface::ConstructSceneMessage <interfaces/OpenraveRobotMemoryInterface.h>
134 * ConstructSceneMessage Fawkes BlackBoard Interface Message.
135 *
136
137 */
138
139
140/** Constructor */
141OpenraveRobotMemoryInterface::ConstructSceneMessage::ConstructSceneMessage() : Message("ConstructSceneMessage")
142{
143 data_size = sizeof(ConstructSceneMessage_data_t);
144 data_ptr = malloc(data_size);
145 memset(data_ptr, 0, data_size);
146 data = (ConstructSceneMessage_data_t *)data_ptr;
148}
149
150/** Destructor */
152{
153 free(data_ptr);
154}
155
156/** Copy constructor.
157 * @param m message to copy from
158 */
160{
161 data_size = m->data_size;
162 data_ptr = malloc(data_size);
163 memcpy(data_ptr, m->data_ptr, data_size);
164 data = (ConstructSceneMessage_data_t *)data_ptr;
166}
167
168/* Methods */
169/** Clone this message.
170 * Produces a message of the same type as this message and copies the
171 * data to the new message.
172 * @return clone of this message
173 */
174Message *
176{
178}
179/** Check if message is valid and can be enqueued.
180 * @param message Message to check
181 * @return true if the message is valid, false otherwise.
182 */
183bool
185{
186 const ConstructSceneMessage *m0 = dynamic_cast<const ConstructSceneMessage *>(message);
187 if ( m0 != NULL ) {
188 return true;
189 }
190 return false;
191}
192
193/// @cond INTERNALS
194EXPORT_INTERFACE(OpenraveRobotMemoryInterface)
195/// @endcond
196
197
198} // end namespace fawkes
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
const char * type() const
Get type of interface.
Definition: interface.cpp:652
void * data_ptr
Pointer to local memory storage.
Definition: interface.h:244
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
void * data_ptr
Pointer to memory that contains local data.
Definition: message.h:146
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:156
unsigned int data_size
Size of memory needed to hold all data.
Definition: message.h:147
ConstructSceneMessage Fawkes BlackBoard Interface Message.
OpenraveRobotMemoryInterface Fawkes BlackBoard Interface.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
Fawkes library namespace.
Timestamp data, must be present and first entries for each interface data structs!...
Definition: message.h:152