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
33
namespace
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 */
46
OpenraveRobotMemoryInterface::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 */
60
OpenraveRobotMemoryInterface::~OpenraveRobotMemoryInterface()
61
{
62
free(
data_ptr
);
63
}
64
/* Methods */
65
/** Get dummy value.
66
*
67
Dummy field
68
69
* @return dummy value
70
*/
71
uint32_t
72
OpenraveRobotMemoryInterface::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
*/
81
size_t
82
OpenraveRobotMemoryInterface::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
*/
93
void
94
OpenraveRobotMemoryInterface::set_dummy
(
const
uint32_t new_dummy)
95
{
96
data->dummy = new_dummy;
97
data_changed
=
true
;
98
}
99
100
/* =========== message create =========== */
101
Message
*
102
OpenraveRobotMemoryInterface::create_message
(
const
char
*
type
)
const
103
{
104
if
( strncmp(
"ConstructSceneMessage"
,
type
, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
105
return
new
ConstructSceneMessage();
106
}
else
{
107
throw
UnknownTypeException
(
"The given type '%s' does not match any known "
108
"message type for this interface type."
,
type
);
109
}
110
}
111
112
113
/** Copy values from other interface.
114
* @param other other interface to copy values from
115
*/
116
void
117
OpenraveRobotMemoryInterface::copy_values
(
const
Interface
*other)
118
{
119
const
OpenraveRobotMemoryInterface *oi = dynamic_cast<const OpenraveRobotMemoryInterface *>(other);
120
if
(oi == NULL) {
121
throw
TypeMismatchException
(
"Can only copy values from interface of same type (%s vs. %s)"
,
122
type
(), other->type());
123
}
124
memcpy(data, oi->data,
sizeof
(OpenraveRobotMemoryInterface_data_t));
125
}
126
127
const
char
*
128
OpenraveRobotMemoryInterface::enum_tostring
(
const
char
*enumtype,
int
val)
const
129
{
130
throw
UnknownTypeException(
"Unknown enum type %s"
, enumtype);
131
}
132
133
/* =========== messages =========== */
134
/** @class OpenraveRobotMemoryInterface::ConstructSceneMessage <interfaces/OpenraveRobotMemoryInterface.h>
135
* ConstructSceneMessage Fawkes BlackBoard Interface Message.
136
*
137
138
*/
139
140
141
/** Constructor */
142
OpenraveRobotMemoryInterface::ConstructSceneMessage::ConstructSceneMessage
() :
Message
(
"ConstructSceneMessage"
)
143
{
144
data_size
=
sizeof
(ConstructSceneMessage_data_t);
145
data_ptr
= malloc(
data_size
);
146
memset(
data_ptr
, 0,
data_size
);
147
data = (ConstructSceneMessage_data_t *)
data_ptr
;
148
data_ts
= (
message_data_ts_t
*)
data_ptr
;
149
}
150
151
/** Destructor */
152
OpenraveRobotMemoryInterface::ConstructSceneMessage::~ConstructSceneMessage
()
153
{
154
free(
data_ptr
);
155
}
156
157
/** Copy constructor.
158
* @param m message to copy from
159
*/
160
OpenraveRobotMemoryInterface::ConstructSceneMessage::ConstructSceneMessage
(
const
ConstructSceneMessage
*m) :
Message
(m)
161
{
162
data_size
= m->
data_size
;
163
data_ptr
= malloc(
data_size
);
164
memcpy(
data_ptr
, m->
data_ptr
,
data_size
);
165
data = (ConstructSceneMessage_data_t *)
data_ptr
;
166
data_ts
= (
message_data_ts_t
*)
data_ptr
;
167
}
168
169
/* Methods */
170
/** Clone this message.
171
* Produces a message of the same type as this message and copies the
172
* data to the new message.
173
* @return clone of this message
174
*/
175
Message
*
176
OpenraveRobotMemoryInterface::ConstructSceneMessage::clone
()
const
177
{
178
return
new
OpenraveRobotMemoryInterface::ConstructSceneMessage
(
this
);
179
}
180
/** Check if message is valid and can be enqueued.
181
* @param message Message to check
182
* @return true if the message is valid, false otherwise.
183
*/
184
bool
185
OpenraveRobotMemoryInterface::message_valid
(
const
Message
*message)
const
186
{
187
const
ConstructSceneMessage
*m0 = dynamic_cast<const ConstructSceneMessage *>(message);
188
if
( m0 != NULL ) {
189
return
true
;
190
}
191
return
false
;
192
}
193
194
/// @cond INTERNALS
195
EXPORT_INTERFACE(OpenraveRobotMemoryInterface)
196
/// @endcond
197
198
199
}
// end namespace fawkes
fawkes::Interface::data_ptr
void * data_ptr
Definition:
interface.h:223
fawkes::OpenraveRobotMemoryInterface::create_message
virtual Message * create_message(const char *type) const
Definition:
OpenraveRobotMemoryInterface.cpp:106
fawkes::Message
Definition:
message.h:40
fawkes::Message::data_ptr
void * data_ptr
Definition:
message.h:124
fawkes::OpenraveRobotMemoryInterface::dummy
uint32_t dummy() const
Get dummy value.
Definition:
OpenraveRobotMemoryInterface.cpp:76
fawkes::Message::data_ts
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition:
message.h:134
fawkes::OpenraveRobotMemoryInterface::ConstructSceneMessage
Definition:
OpenraveRobotMemoryInterface.h:64
fawkes::IFT_UINT32
32 bit unsigned integer field
Definition:
types.h:54
fawkes::Interface::type
const char * type() const
Get type of interface.
Definition:
interface.cpp:643
fawkes::OpenraveRobotMemoryInterface::enum_tostring
virtual const char * enum_tostring(const char *enumtype, int val) const
Definition:
OpenraveRobotMemoryInterface.cpp:132
fawkes::Interface::data_ts
interface_data_ts_t * data_ts
Definition:
interface.h:227
fawkes::Message::message_data_ts_t
Timestamp data, must be present and first entries for each interface data structs!...
Definition:
message.h:129
fawkes::TypeMismatchException
Definition:
software.h:47
fawkes::Interface::data_changed
bool data_changed
Definition:
interface.h:225
fawkes::UnknownTypeException
Definition:
software.h:53
fawkes::Interface::Interface
Interface()
Constructor.
Definition:
interface.cpp:236
fawkes
fawkes::Interface::set_hash
void set_hash(unsigned char *ihash)
Set hash.
Definition:
interface.cpp:319
fawkes::Message::data_size
unsigned int data_size
Definition:
message.h:125
fawkes::OpenraveRobotMemoryInterface::ConstructSceneMessage::ConstructSceneMessage
ConstructSceneMessage()
Constructor.
Definition:
OpenraveRobotMemoryInterface.cpp:146
fawkes::OpenraveRobotMemoryInterface::maxlenof_dummy
size_t maxlenof_dummy() const
Get maximum length of dummy value.
Definition:
OpenraveRobotMemoryInterface.cpp:86
fawkes::OpenraveRobotMemoryInterface::message_valid
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
Definition:
OpenraveRobotMemoryInterface.cpp:189
fawkes::Message::add_fieldinfo
void add_fieldinfo(interface_fieldtype_t type, const char *name, size_t length, void *value, const char *enumtype=0, const interface_enum_map_t *enum_map=0)
Add an entry to the info list.
Definition:
message.cpp:404
fawkes::OpenraveRobotMemoryInterface::ConstructSceneMessage::clone
virtual Message * clone() const
Clone this message.
Definition:
OpenraveRobotMemoryInterface.cpp:180
fawkes::Interface::data_size
unsigned int data_size
Definition:
interface.h:224
fawkes::OpenraveRobotMemoryInterface::copy_values
virtual void copy_values(const Interface *other)
Copy values from other interface.
Definition:
OpenraveRobotMemoryInterface.cpp:121
fawkes::OpenraveRobotMemoryInterface::set_dummy
void set_dummy(const uint32_t new_dummy)
Set dummy value.
Definition:
OpenraveRobotMemoryInterface.cpp:98
fawkes::OpenraveRobotMemoryInterface::ConstructSceneMessage::~ConstructSceneMessage
~ConstructSceneMessage()
Destructor.
Definition:
OpenraveRobotMemoryInterface.cpp:156
fawkes::Interface::add_messageinfo
void add_messageinfo(const char *name)
Add an entry to the message info list.
Definition:
interface.cpp:378
src
libs
interfaces
OpenraveRobotMemoryInterface.cpp
Generated by
1.8.16