Fawkes API  Fawkes Development Version
PclDatabaseMergeInterface.cpp
1 
2 /***************************************************************************
3  * PclDatabaseMergeInterface.cpp - Fawkes BlackBoard Interface - PclDatabaseMergeInterface
4  *
5  * Templated created: Thu Oct 12 10:49:19 2006
6  * Copyright 2012 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/PclDatabaseMergeInterface.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 PclDatabaseMergeInterface <interfaces/PclDatabaseMergeInterface.h>
36  * PclDatabaseMergeInterface Fawkes BlackBoard Interface.
37  *
38  Instruct the pcl-db-merge plugin and receive information.
39 
40  * @ingroup FawkesInterfaces
41  */
42 
43 
44 
45 /** Constructor */
46 PclDatabaseMergeInterface::PclDatabaseMergeInterface() : Interface()
47 {
48  data_size = sizeof(PclDatabaseMergeInterface_data_t);
49  data_ptr = malloc(data_size);
50  data = (PclDatabaseMergeInterface_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("MergeMessage");
57  unsigned char tmp_hash[] = {0x1a, 0xb, 0xb8, 0x5a, 0x7, 0x88, 0x93, 0x55, 0x9e, 0x7e, 0xcb, 0x96, 0x46, 0x8f, 0x97, 0xb1};
58  set_hash(tmp_hash);
59 }
60 
61 /** Destructor */
62 PclDatabaseMergeInterface::~PclDatabaseMergeInterface()
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
75 PclDatabaseMergeInterface::msgid() const
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
85 PclDatabaseMergeInterface::maxlenof_msgid() const
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 PclDatabaseMergeInterface::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
112 PclDatabaseMergeInterface::is_final() const
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
122 PclDatabaseMergeInterface::maxlenof_final() const
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
135 PclDatabaseMergeInterface::set_final(const bool new_final)
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 *
148 PclDatabaseMergeInterface::error() const
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
158 PclDatabaseMergeInterface::maxlenof_error() const
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
170 PclDatabaseMergeInterface::set_error(const char * new_error)
171 {
172  strncpy(data->error, new_error, sizeof(data->error));
173  data_changed = true;
174 }
175 
176 /* =========== message create =========== */
177 Message *
178 PclDatabaseMergeInterface::create_message(const char *type) const
179 {
180  if ( strncmp("MergeMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
181  return new MergeMessage();
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
193 PclDatabaseMergeInterface::copy_values(const Interface *other)
194 {
195  const PclDatabaseMergeInterface *oi = dynamic_cast<const PclDatabaseMergeInterface *>(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(PclDatabaseMergeInterface_data_t));
201 }
202 
203 const char *
204 PclDatabaseMergeInterface::enum_tostring(const char *enumtype, int val) const
205 {
206  throw UnknownTypeException("Unknown enum type %s", enumtype);
207 }
208 
209 /* =========== messages =========== */
210 /** @class PclDatabaseMergeInterface::MergeMessage <interfaces/PclDatabaseMergeInterface.h>
211  * MergeMessage Fawkes BlackBoard Interface Message.
212  *
213 
214  */
215 
216 
217 /** Constructor with initial values.
218  * @param ini_timestamps initial value for timestamps
219  * @param ini_database initial value for database
220  * @param ini_collection initial value for collection
221  */
222 PclDatabaseMergeInterface::MergeMessage::MergeMessage(const int64_t * ini_timestamps, const char * ini_database, const char * ini_collection) : Message("MergeMessage")
223 {
224  data_size = sizeof(MergeMessage_data_t);
225  data_ptr = malloc(data_size);
226  memset(data_ptr, 0, data_size);
227  data = (MergeMessage_data_t *)data_ptr;
229  memcpy(data->timestamps, ini_timestamps, sizeof(int64_t) * 12);
230  strncpy(data->database, ini_database, 64);
231  strncpy(data->collection, ini_collection, 128);
232  add_fieldinfo(IFT_INT64, "timestamps", 12, &data->timestamps);
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(MergeMessage_data_t);
240  data_ptr = malloc(data_size);
241  memset(data_ptr, 0, data_size);
242  data = (MergeMessage_data_t *)data_ptr;
244  add_fieldinfo(IFT_INT64, "timestamps", 12, &data->timestamps);
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 = (MergeMessage_data_t *)data_ptr;
265 }
266 
267 /* Methods */
268 /** Get timestamps value.
269  *
270  Timestamps for which to retrieve the most recent point clouds
271  and merge them.
272 
273  * @return timestamps value
274  */
275 int64_t *
277 {
278  return data->timestamps;
279 }
280 
281 /** Get timestamps value at given index.
282  *
283  Timestamps for which to retrieve the most recent point clouds
284  and merge them.
285 
286  * @param index index of value
287  * @return timestamps value
288  * @exception Exception thrown if index is out of bounds
289  */
290 int64_t
292 {
293  if (index > 12) {
294  throw Exception("Index value %u out of bounds (0..12)", index);
295  }
296  return data->timestamps[index];
297 }
298 
299 /** Get maximum length of timestamps value.
300  * @return length of timestamps value, can be length of the array or number of
301  * maximum number of characters for a string
302  */
303 size_t
305 {
306  return 12;
307 }
308 
309 /** Set timestamps value.
310  *
311  Timestamps for which to retrieve the most recent point clouds
312  and merge them.
313 
314  * @param new_timestamps new timestamps value
315  */
316 void
318 {
319  memcpy(data->timestamps, new_timestamps, sizeof(int64_t) * 12);
320 }
321 
322 /** Set timestamps value at given index.
323  *
324  Timestamps for which to retrieve the most recent point clouds
325  and merge them.
326 
327  * @param new_timestamps new timestamps value
328  * @param index index for of the value
329  */
330 void
331 PclDatabaseMergeInterface::MergeMessage::set_timestamps(unsigned int index, const int64_t new_timestamps)
332 {
333  if (index > 12) {
334  throw Exception("Index value %u out of bounds (0..12)", index);
335  }
336  data->timestamps[index] = new_timestamps;
337 }
338 /** Get database value.
339  *
340  Database name from which to read the point clouds. If empty will
341  use plugin-configured default.
342 
343  * @return database value
344  */
345 char *
347 {
348  return data->database;
349 }
350 
351 /** Get maximum length of database value.
352  * @return length of database 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 64;
359 }
360 
361 /** Set database value.
362  *
363  Database name from which to read the point clouds. If empty will
364  use plugin-configured default.
365 
366  * @param new_database new database value
367  */
368 void
370 {
371  strncpy(data->database, new_database, sizeof(data->database));
372 }
373 
374 /** Get collection value.
375  *
376  Collection name from which to read the point clouds. May NOT
377  include the database name.
378 
379  * @return collection value
380  */
381 char *
383 {
384  return data->collection;
385 }
386 
387 /** Get maximum length of collection value.
388  * @return length of collection value, can be length of the array or number of
389  * maximum number of characters for a string
390  */
391 size_t
393 {
394  return 128;
395 }
396 
397 /** Set collection value.
398  *
399  Collection name from which to read the point clouds. May NOT
400  include the database name.
401 
402  * @param new_collection new collection value
403  */
404 void
406 {
407  strncpy(data->collection, new_collection, sizeof(data->collection));
408 }
409 
410 /** Clone this message.
411  * Produces a message of the same type as this message and copies the
412  * data to the new message.
413  * @return clone of this message
414  */
415 Message *
417 {
419 }
420 /** Check if message is valid and can be enqueued.
421  * @param message Message to check
422  * @return true if the message is valid, false otherwise.
423  */
424 bool
426 {
427  const MergeMessage *m0 = dynamic_cast<const MergeMessage *>(message);
428  if ( m0 != NULL ) {
429  return true;
430  }
431  return false;
432 }
433 
434 /// @cond INTERNALS
435 EXPORT_INTERFACE(PclDatabaseMergeInterface)
436 /// @endcond
437 
438 
439 } // end namespace fawkes
64 bit integer field
Definition: types.h:43
PclDatabaseMergeInterface Fawkes BlackBoard Interface.
void * data_ptr
Pointer to memory that contains local data.
Definition: message.h:124
size_t maxlenof_collection() const
Get maximum length of collection value.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
Fawkes library namespace.
Timestamp data, must be present and first entries for each interface data structs! This leans on time...
Definition: message.h:129
string field
Definition: types.h:47
void set_collection(const char *new_collection)
Set collection value.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
size_t maxlenof_database() const
Get maximum length of database value.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
int64_t * timestamps() const
Get timestamps value.
void set_database(const char *new_database)
Set database value.
MergeMessage Fawkes BlackBoard Interface Message.
size_t maxlenof_timestamps() const
Get maximum length of timestamps value.
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:133
unsigned int data_size
Size of memory needed to hold all data.
Definition: message.h:125
const char * type() const
Get type of interface.
Definition: interface.cpp:651
Base class for exceptions in Fawkes.
Definition: exception.h:36
void set_timestamps(unsigned int index, const int64_t new_timestamps)
Set timestamps value at given index.
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
virtual Message * clone() const
Clone this message.