Fawkes API  Fawkes Development Version
PclDatabaseRetrieveInterface.cpp
1 
2 /***************************************************************************
3  * PclDatabaseRetrieveInterface.cpp - Fawkes BlackBoard Interface - PclDatabaseRetrieveInterface
4  *
5  * Templated created: Thu Oct 12 10:49:19 2006
6  * Copyright 2012-2013 Tim Niemueller
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/PclDatabaseRetrieveInterface.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 PclDatabaseRetrieveInterface <interfaces/PclDatabaseRetrieveInterface.h>
36  * PclDatabaseRetrieveInterface Fawkes BlackBoard Interface.
37  *
38  Instruct the pcl-db-retrieve plugin and receive information.
39 
40  * @ingroup FawkesInterfaces
41  */
42 
43 
44 
45 /** Constructor */
46 PclDatabaseRetrieveInterface::PclDatabaseRetrieveInterface() : Interface()
47 {
48  data_size = sizeof(PclDatabaseRetrieveInterface_data_t);
49  data_ptr = malloc(data_size);
50  data = (PclDatabaseRetrieveInterface_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, "msgid", 1, &data->msgid);
54  add_fieldinfo(IFT_BOOL, "final", 1, &data->final);
55  add_fieldinfo(IFT_STRING, "error", 256, data->error);
56  add_messageinfo("RetrieveMessage");
57  unsigned char tmp_hash[] = {0x9d, 0xf8, 0x9d, 0x53, 0xd7, 0x74, 0xc1, 0x96, 0x38, 0x39, 0xd3, 0xee, 0x76, 0x54, 0x88, 0x75};
58  set_hash(tmp_hash);
59 }
60 
61 /** Destructor */
62 PclDatabaseRetrieveInterface::~PclDatabaseRetrieveInterface()
63 {
64  free(data_ptr);
65 }
66 /* Methods */
67 /** Get msgid value.
68  *
69  The ID of the message that is currently being processed, or 0 if
70  no message is being processed.
71 
72  * @return msgid value
73  */
74 uint32_t
76 {
77  return data->msgid;
78 }
79 
80 /** Get maximum length of msgid value.
81  * @return length of msgid value, can be length of the array or number of
82  * maximum number of characters for a string
83  */
84 size_t
86 {
87  return 1;
88 }
89 
90 /** Set msgid value.
91  *
92  The ID of the message that is currently being processed, or 0 if
93  no message is being processed.
94 
95  * @param new_msgid new msgid value
96  */
97 void
98 PclDatabaseRetrieveInterface::set_msgid(const uint32_t new_msgid)
99 {
100  data->msgid = new_msgid;
101  data_changed = true;
102 }
103 
104 /** Get final value.
105  *
106  True, if the last goto command has been finished, false if it is
107  still running.
108 
109  * @return final value
110  */
111 bool
113 {
114  return data->final;
115 }
116 
117 /** Get maximum length of final value.
118  * @return length of final value, can be length of the array or number of
119  * maximum number of characters for a string
120  */
121 size_t
123 {
124  return 1;
125 }
126 
127 /** Set final value.
128  *
129  True, if the last goto command has been finished, false if it is
130  still running.
131 
132  * @param new_final new final value
133  */
134 void
136 {
137  data->final = new_final;
138  data_changed = true;
139 }
140 
141 /** Get error value.
142  *
143  Error description if reconstruction fails.
144 
145  * @return error value
146  */
147 char *
149 {
150  return data->error;
151 }
152 
153 /** Get maximum length of error value.
154  * @return length of error value, can be length of the array or number of
155  * maximum number of characters for a string
156  */
157 size_t
159 {
160  return 256;
161 }
162 
163 /** Set error value.
164  *
165  Error description if reconstruction fails.
166 
167  * @param new_error new error value
168  */
169 void
171 {
172  strncpy(data->error, new_error, sizeof(data->error));
173  data_changed = true;
174 }
175 
176 /* =========== message create =========== */
177 Message *
179 {
180  if ( strncmp("RetrieveMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
181  return new RetrieveMessage();
182  } else {
183  throw UnknownTypeException("The given type '%s' does not match any known "
184  "message type for this interface type.", type);
185  }
186 }
187 
188 
189 /** Copy values from other interface.
190  * @param other other interface to copy values from
191  */
192 void
194 {
195  const PclDatabaseRetrieveInterface *oi = dynamic_cast<const PclDatabaseRetrieveInterface *>(other);
196  if (oi == NULL) {
197  throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
198  type(), other->type());
199  }
200  memcpy(data, oi->data, sizeof(PclDatabaseRetrieveInterface_data_t));
201 }
202 
203 const char *
204 PclDatabaseRetrieveInterface::enum_tostring(const char *enumtype, int val) const
205 {
206  throw UnknownTypeException("Unknown enum type %s", enumtype);
207 }
208 
209 /* =========== messages =========== */
210 /** @class PclDatabaseRetrieveInterface::RetrieveMessage <interfaces/PclDatabaseRetrieveInterface.h>
211  * RetrieveMessage Fawkes BlackBoard Interface Message.
212  *
213 
214  */
215 
216 
217 /** Constructor with initial values.
218  * @param ini_timestamp initial value for timestamp
219  * @param ini_database initial value for database
220  * @param ini_collection initial value for collection
221  * @param ini_target_frame initial value for target_frame
222  * @param ini_original_timestamp initial value for original_timestamp
223  */
224 PclDatabaseRetrieveInterface::RetrieveMessage::RetrieveMessage(const int64_t ini_timestamp, const char * ini_database, const char * ini_collection, const char * ini_target_frame, const bool ini_original_timestamp) : Message("RetrieveMessage")
225 {
226  data_size = sizeof(RetrieveMessage_data_t);
227  data_ptr = malloc(data_size);
228  memset(data_ptr, 0, data_size);
229  data = (RetrieveMessage_data_t *)data_ptr;
231  data->timestamp = ini_timestamp;
232  strncpy(data->database, ini_database, 64);
233  strncpy(data->collection, ini_collection, 128);
234  strncpy(data->target_frame, ini_target_frame, 64);
235  data->original_timestamp = ini_original_timestamp;
236  add_fieldinfo(IFT_INT64, "timestamp", 1, &data->timestamp);
237  add_fieldinfo(IFT_STRING, "database", 64, data->database);
238  add_fieldinfo(IFT_STRING, "collection", 128, data->collection);
239  add_fieldinfo(IFT_STRING, "target_frame", 64, data->target_frame);
240  add_fieldinfo(IFT_BOOL, "original_timestamp", 1, &data->original_timestamp);
241 }
242 /** Constructor */
244 {
245  data_size = sizeof(RetrieveMessage_data_t);
246  data_ptr = malloc(data_size);
247  memset(data_ptr, 0, data_size);
248  data = (RetrieveMessage_data_t *)data_ptr;
250  add_fieldinfo(IFT_INT64, "timestamp", 1, &data->timestamp);
251  add_fieldinfo(IFT_STRING, "database", 64, data->database);
252  add_fieldinfo(IFT_STRING, "collection", 128, data->collection);
253  add_fieldinfo(IFT_STRING, "target_frame", 64, data->target_frame);
254  add_fieldinfo(IFT_BOOL, "original_timestamp", 1, &data->original_timestamp);
255 }
256 
257 /** Destructor */
259 {
260  free(data_ptr);
261 }
262 
263 /** Copy constructor.
264  * @param m message to copy from
265  */
267 {
268  data_size = m->data_size;
269  data_ptr = malloc(data_size);
270  memcpy(data_ptr, m->data_ptr, data_size);
271  data = (RetrieveMessage_data_t *)data_ptr;
273 }
274 
275 /* Methods */
276 /** Get timestamp value.
277  *
278  Timestamp for which to retrieve the most recent point clouds.
279 
280  * @return timestamp value
281  */
282 int64_t
284 {
285  return data->timestamp;
286 }
287 
288 /** Get maximum length of timestamp value.
289  * @return length of timestamp value, can be length of the array or number of
290  * maximum number of characters for a string
291  */
292 size_t
294 {
295  return 1;
296 }
297 
298 /** Set timestamp value.
299  *
300  Timestamp for which to retrieve the most recent point clouds.
301 
302  * @param new_timestamp new timestamp value
303  */
304 void
306 {
307  data->timestamp = new_timestamp;
308 }
309 
310 /** Get database value.
311  *
312  Database name from which to read the point clouds. If empty will
313  use plugin-configured default.
314 
315  * @return database value
316  */
317 char *
319 {
320  return data->database;
321 }
322 
323 /** Get maximum length of database value.
324  * @return length of database value, can be length of the array or number of
325  * maximum number of characters for a string
326  */
327 size_t
329 {
330  return 64;
331 }
332 
333 /** Set database value.
334  *
335  Database name from which to read the point clouds. If empty will
336  use plugin-configured default.
337 
338  * @param new_database new database value
339  */
340 void
342 {
343  strncpy(data->database, new_database, sizeof(data->database));
344 }
345 
346 /** Get collection value.
347  *
348  Collection name from which to read the point clouds. May NOT
349  include the database name.
350 
351  * @return collection value
352  */
353 char *
355 {
356  return data->collection;
357 }
358 
359 /** Get maximum length of collection value.
360  * @return length of collection value, can be length of the array or number of
361  * maximum number of characters for a string
362  */
363 size_t
365 {
366  return 128;
367 }
368 
369 /** Set collection value.
370  *
371  Collection name from which to read the point clouds. May NOT
372  include the database name.
373 
374  * @param new_collection new collection value
375  */
376 void
378 {
379  strncpy(data->collection, new_collection, sizeof(data->collection));
380 }
381 
382 /** Get target_frame value.
383  *
384  Coordinate frame to which to transform the output point cloud.
385  The transformation will be done through a fixed frame specified
386  in the plugin config. If empty, no transformation is
387  performed. If set to "SENSOR" will convert to the sensor frame
388  specified in the plugin config.
389 
390  * @return target_frame value
391  */
392 char *
394 {
395  return data->target_frame;
396 }
397 
398 /** Get maximum length of target_frame value.
399  * @return length of target_frame value, can be length of the array or number of
400  * maximum number of characters for a string
401  */
402 size_t
404 {
405  return 64;
406 }
407 
408 /** Set target_frame value.
409  *
410  Coordinate frame to which to transform the output point cloud.
411  The transformation will be done through a fixed frame specified
412  in the plugin config. If empty, no transformation is
413  performed. If set to "SENSOR" will convert to the sensor frame
414  specified in the plugin config.
415 
416  * @param new_target_frame new target_frame value
417  */
418 void
420 {
421  strncpy(data->target_frame, new_target_frame, sizeof(data->target_frame));
422 }
423 
424 /** Get original_timestamp value.
425  *
426  Set to true to set the original timestamp on the point cloud,
427  false (default) to publish with current time.
428 
429  * @return original_timestamp value
430  */
431 bool
433 {
434  return data->original_timestamp;
435 }
436 
437 /** Get maximum length of original_timestamp value.
438  * @return length of original_timestamp value, can be length of the array or number of
439  * maximum number of characters for a string
440  */
441 size_t
443 {
444  return 1;
445 }
446 
447 /** Set original_timestamp value.
448  *
449  Set to true to set the original timestamp on the point cloud,
450  false (default) to publish with current time.
451 
452  * @param new_original_timestamp new original_timestamp value
453  */
454 void
456 {
457  data->original_timestamp = new_original_timestamp;
458 }
459 
460 /** Clone this message.
461  * Produces a message of the same type as this message and copies the
462  * data to the new message.
463  * @return clone of this message
464  */
465 Message *
467 {
469 }
470 /** Check if message is valid and can be enqueued.
471  * @param message Message to check
472  * @return true if the message is valid, false otherwise.
473  */
474 bool
476 {
477  const RetrieveMessage *m0 = dynamic_cast<const RetrieveMessage *>(message);
478  if ( m0 != NULL ) {
479  return true;
480  }
481  return false;
482 }
483 
484 /// @cond INTERNALS
485 EXPORT_INTERFACE(PclDatabaseRetrieveInterface)
486 /// @endcond
487 
488 
489 } // end namespace fawkes
64 bit integer field
Definition: types.h:43
void * data_ptr
Pointer to memory that contains local data.
Definition: message.h:124
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
RetrieveMessage Fawkes BlackBoard Interface Message.
void set_final(const bool new_final)
Set final value.
void set_error(const char *new_error)
Set error value.
void set_target_frame(const char *new_target_frame)
Set target_frame value.
void set_hash(unsigned char *ihash)
Set hash.
Definition: interface.cpp:314
PclDatabaseRetrieveInterface Fawkes BlackBoard Interface.
Fawkes library namespace.
Timestamp data, must be present and first entries for each interface data structs! This leans on time...
Definition: message.h:129
unsigned int data_size
Minimal data size to hold data storage.
Definition: interface.h:221
string field
Definition: types.h:47
void set_timestamp(const int64_t new_timestamp)
Set timestamp value.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
size_t maxlenof_original_timestamp() const
Get maximum length of original_timestamp value.
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:133
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 field info list.
Definition: interface.cpp:335
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
bool is_original_timestamp() const
Get original_timestamp value.
size_t maxlenof_final() const
Get maximum length of final value.
unsigned int data_size
Size of memory needed to hold all data.
Definition: message.h:125
void add_messageinfo(const char *name)
Add an entry to the message info list.
Definition: interface.cpp:373
virtual Message * create_message(const char *type) const
Create message based on type name.
bool data_changed
Indicator if data has changed.
Definition: interface.h:222
void set_msgid(const uint32_t new_msgid)
Set msgid value.
const char * type() const
Get type of interface.
Definition: interface.cpp:651
void * data_ptr
Pointer to local memory storage.
Definition: interface.h:220
virtual void copy_values(const Interface *other)
Copy values from other interface.
void set_collection(const char *new_collection)
Set collection value.
virtual const char * enum_tostring(const char *enumtype, int val) const
Convert arbitrary enum value to string.
size_t maxlenof_target_frame() const
Get maximum length of target_frame value.
size_t maxlenof_msgid() const
Get maximum length of msgid value.
size_t maxlenof_error() const
Get maximum length of error value.
void set_database(const char *new_database)
Set database value.
size_t maxlenof_database() const
Get maximum length of database value.
interface_data_ts_t * data_ts
Pointer to data casted to timestamp struct.
Definition: interface.h:224
void set_original_timestamp(const bool new_original_timestamp)
Set original_timestamp value.
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:436
boolean field
Definition: types.h:36
size_t maxlenof_timestamp() const
Get maximum length of timestamp value.
32 bit unsigned integer field
Definition: types.h:42
size_t maxlenof_collection() const
Get maximum length of collection value.