Fawkes API  Fawkes Development Version
PclDatabaseStoreInterface.cpp
1 
2 /***************************************************************************
3  * PclDatabaseStoreInterface.cpp - Fawkes BlackBoard Interface - PclDatabaseStoreInterface
4  *
5  * Templated created: Thu Oct 12 10:49:19 2006
6  * Copyright 2012-2014 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/PclDatabaseStoreInterface.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 PclDatabaseStoreInterface <interfaces/PclDatabaseStoreInterface.h>
36  * PclDatabaseStoreInterface Fawkes BlackBoard Interface.
37  *
38  Instruct the pcl-db-store plugin.
39 
40  * @ingroup FawkesInterfaces
41  */
42 
43 
44 
45 /** Constructor */
46 PclDatabaseStoreInterface::PclDatabaseStoreInterface() : Interface()
47 {
48  data_size = sizeof(PclDatabaseStoreInterface_data_t);
49  data_ptr = malloc(data_size);
50  data = (PclDatabaseStoreInterface_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("StoreMessage");
57  unsigned char tmp_hash[] = {0x80, 0xe0, 0x2f, 0x81, 0x4a, 0x5, 0x5c, 0xec, 0xd8, 0x64, 0xed, 0x5c, 0xee, 0x17, 0x19, 0xa6};
58  set_hash(tmp_hash);
59 }
60 
61 /** Destructor */
62 PclDatabaseStoreInterface::~PclDatabaseStoreInterface()
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 PclDatabaseStoreInterface::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("StoreMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
181  return new StoreMessage();
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 PclDatabaseStoreInterface *oi = dynamic_cast<const PclDatabaseStoreInterface *>(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(PclDatabaseStoreInterface_data_t));
201 }
202 
203 const char *
204 PclDatabaseStoreInterface::enum_tostring(const char *enumtype, int val) const
205 {
206  throw UnknownTypeException("Unknown enum type %s", enumtype);
207 }
208 
209 /* =========== messages =========== */
210 /** @class PclDatabaseStoreInterface::StoreMessage <interfaces/PclDatabaseStoreInterface.h>
211  * StoreMessage Fawkes BlackBoard Interface Message.
212  *
213 
214  */
215 
216 
217 /** Constructor with initial values.
218  * @param ini_pcl_id initial value for pcl_id
219  * @param ini_database initial value for database
220  * @param ini_collection initial value for collection
221  */
222 PclDatabaseStoreInterface::StoreMessage::StoreMessage(const char * ini_pcl_id, const char * ini_database, const char * ini_collection) : Message("StoreMessage")
223 {
224  data_size = sizeof(StoreMessage_data_t);
225  data_ptr = malloc(data_size);
226  memset(data_ptr, 0, data_size);
227  data = (StoreMessage_data_t *)data_ptr;
229  strncpy(data->pcl_id, ini_pcl_id, 64);
230  strncpy(data->database, ini_database, 64);
231  strncpy(data->collection, ini_collection, 128);
232  add_fieldinfo(IFT_STRING, "pcl_id", 64, data->pcl_id);
233  add_fieldinfo(IFT_STRING, "database", 64, data->database);
234  add_fieldinfo(IFT_STRING, "collection", 128, data->collection);
235 }
236 /** Constructor */
238 {
239  data_size = sizeof(StoreMessage_data_t);
240  data_ptr = malloc(data_size);
241  memset(data_ptr, 0, data_size);
242  data = (StoreMessage_data_t *)data_ptr;
244  add_fieldinfo(IFT_STRING, "pcl_id", 64, data->pcl_id);
245  add_fieldinfo(IFT_STRING, "database", 64, data->database);
246  add_fieldinfo(IFT_STRING, "collection", 128, data->collection);
247 }
248 
249 /** Destructor */
251 {
252  free(data_ptr);
253 }
254 
255 /** Copy constructor.
256  * @param m message to copy from
257  */
259 {
260  data_size = m->data_size;
261  data_ptr = malloc(data_size);
262  memcpy(data_ptr, m->data_ptr, data_size);
263  data = (StoreMessage_data_t *)data_ptr;
265 }
266 
267 /* Methods */
268 /** Get pcl_id value.
269  *
270  ID of the point cloud to store.
271 
272  * @return pcl_id value
273  */
274 char *
276 {
277  return data->pcl_id;
278 }
279 
280 /** Get maximum length of pcl_id value.
281  * @return length of pcl_id value, can be length of the array or number of
282  * maximum number of characters for a string
283  */
284 size_t
286 {
287  return 64;
288 }
289 
290 /** Set pcl_id value.
291  *
292  ID of the point cloud to store.
293 
294  * @param new_pcl_id new pcl_id value
295  */
296 void
298 {
299  strncpy(data->pcl_id, new_pcl_id, sizeof(data->pcl_id));
300 }
301 
302 /** Get database value.
303  *
304  Database name from which to read the point clouds. If empty will
305  use plugin-configured default.
306 
307  * @return database value
308  */
309 char *
311 {
312  return data->database;
313 }
314 
315 /** Get maximum length of database value.
316  * @return length of database value, can be length of the array or number of
317  * maximum number of characters for a string
318  */
319 size_t
321 {
322  return 64;
323 }
324 
325 /** Set database value.
326  *
327  Database name from which to read the point clouds. If empty will
328  use plugin-configured default.
329 
330  * @param new_database new database value
331  */
332 void
334 {
335  strncpy(data->database, new_database, sizeof(data->database));
336 }
337 
338 /** Get collection value.
339  *
340  Collection name from which to read the point clouds. May NOT
341  include the database name.
342 
343  * @return collection value
344  */
345 char *
347 {
348  return data->collection;
349 }
350 
351 /** Get maximum length of collection value.
352  * @return length of collection value, can be length of the array or number of
353  * maximum number of characters for a string
354  */
355 size_t
357 {
358  return 128;
359 }
360 
361 /** Set collection value.
362  *
363  Collection name from which to read the point clouds. May NOT
364  include the database name.
365 
366  * @param new_collection new collection value
367  */
368 void
370 {
371  strncpy(data->collection, new_collection, sizeof(data->collection));
372 }
373 
374 /** Clone this message.
375  * Produces a message of the same type as this message and copies the
376  * data to the new message.
377  * @return clone of this message
378  */
379 Message *
381 {
383 }
384 /** Check if message is valid and can be enqueued.
385  * @param message Message to check
386  * @return true if the message is valid, false otherwise.
387  */
388 bool
390 {
391  const StoreMessage *m0 = dynamic_cast<const StoreMessage *>(message);
392  if ( m0 != NULL ) {
393  return true;
394  }
395  return false;
396 }
397 
398 /// @cond INTERNALS
399 EXPORT_INTERFACE(PclDatabaseStoreInterface)
400 /// @endcond
401 
402 
403 } // end namespace fawkes
void set_msgid(const uint32_t new_msgid)
Set msgid value.
virtual Message * create_message(const char *type) const
Create message based on type name.
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
void set_final(const bool new_final)
Set final value.
virtual const char * enum_tostring(const char *enumtype, int val) const
Convert arbitrary enum value to string.
void set_hash(unsigned char *ihash)
Set hash.
Definition: interface.cpp:314
void set_error(const char *new_error)
Set error value.
void set_database(const char *new_database)
Set database value.
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
void set_pcl_id(const char *new_pcl_id)
Set pcl_id value.
size_t maxlenof_msgid() const
Get maximum length of msgid value.
string field
Definition: types.h:47
char * error() const
Get error value.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
size_t maxlenof_database() const
Get maximum length of database 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
size_t maxlenof_collection() const
Get maximum length of collection 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
bool data_changed
Indicator if data has changed.
Definition: interface.h:222
void set_collection(const char *new_collection)
Set collection 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
size_t maxlenof_final() const
Get maximum length of final value.
virtual void copy_values(const Interface *other)
Copy values from other interface.
virtual Message * clone() const
Clone this message.
uint32_t msgid() const
Get msgid value.
size_t maxlenof_pcl_id() const
Get maximum length of pcl_id value.
StoreMessage Fawkes BlackBoard Interface Message.
size_t maxlenof_error() const
Get maximum length of error value.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
interface_data_ts_t * data_ts
Pointer to data casted to timestamp struct.
Definition: interface.h:224
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
PclDatabaseStoreInterface Fawkes BlackBoard Interface.
32 bit unsigned integer field
Definition: types.h:42