Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TestInterface.cpp
1 
2 /***************************************************************************
3  * TestInterface.cpp - Fawkes BlackBoard Interface - TestInterface
4  *
5  * Templated created: Thu Oct 12 10:49:19 2006
6  * Copyright 2006-2007 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/TestInterface.h>
25 
26 #include <core/exceptions/software.h>
27 
28 #include <cstring>
29 #include <cstdlib>
30 
31 namespace fawkes {
32 
33 /** @class TestInterface <interfaces/TestInterface.h>
34  * TestInterface Fawkes BlackBoard Interface.
35  * Test interface. Use this to play around. Do NOT remove any fields, as this
36  interface is used by BlackBoard QA.
37  * @ingroup FawkesInterfaces
38  */
39 
40 
41 /** TEST_CONSTANT constant */
42 const int32_t TestInterface::TEST_CONSTANT = 5;
43 /** TEST_FLOAT_CONSTANT constant */
44 const float TestInterface::TEST_FLOAT_CONSTANT = 1.2;
45 
46 /** Constructor */
47 TestInterface::TestInterface() : Interface()
48 {
49  data_size = sizeof(TestInterface_data_t);
50  data_ptr = malloc(data_size);
51  data = (TestInterface_data_t *)data_ptr;
52  data_ts = (interface_data_ts_t *)data_ptr;
53  memset(data_ptr, 0, data_size);
54  add_fieldinfo(IFT_BOOL, "test_bool", 1, &data->test_bool);
55  add_fieldinfo(IFT_INT32, "test_int", 1, &data->test_int);
56  add_fieldinfo(IFT_BYTE, "flags", 1, &data->flags);
57  add_fieldinfo(IFT_STRING, "test_string", 30, data->test_string);
58  add_fieldinfo(IFT_INT32, "result", 1, &data->result);
59  add_fieldinfo(IFT_UINT32, "test_uint", 1, &data->test_uint);
60  add_messageinfo("SetTestIntMessage");
61  add_messageinfo("SetTestStringMessage");
62  add_messageinfo("CalculateMessage");
63  unsigned char tmp_hash[] = {0xe4, 0xe2, 0x1, 0xa9, 0xc8, 0x87, 0x8d, 0x3d, 0xa3, 0xab, 0xc9, 0xcd, 0xf3, 0xf, 0x5a, 0x33};
64  set_hash(tmp_hash);
65 }
66 
67 /** Destructor */
68 TestInterface::~TestInterface()
69 {
70  free(data_ptr);
71 }
72 /** Convert TestEnum constant to string.
73  * @param value value to convert to string
74  * @return constant value as string.
75  */
76 const char *
78 {
79  switch (value) {
80  case TEST_ENUM_1: return "TEST_ENUM_1";
81  case TEST_ENUM_2: return "TEST_ENUM_2";
82  default: return "UNKNOWN";
83  }
84 }
85 /* Methods */
86 /** Get test_bool value.
87  * Test Bool
88  * @return test_bool value
89  */
90 bool
92 {
93  return data->test_bool;
94 }
95 
96 /** Get maximum length of test_bool value.
97  * @return length of test_bool value, can be length of the array or number of
98  * maximum number of characters for a string
99  */
100 size_t
102 {
103  return 1;
104 }
105 
106 /** Set test_bool value.
107  * Test Bool
108  * @param new_test_bool new test_bool value
109  */
110 void
111 TestInterface::set_test_bool(const bool new_test_bool)
112 {
113  data->test_bool = new_test_bool;
114  data_changed = true;
115 }
116 
117 /** Get test_int value.
118  * Test integer
119  * @return test_int value
120  */
121 int32_t
123 {
124  return data->test_int;
125 }
126 
127 /** Get maximum length of test_int value.
128  * @return length of test_int value, can be length of the array or number of
129  * maximum number of characters for a string
130  */
131 size_t
133 {
134  return 1;
135 }
136 
137 /** Set test_int value.
138  * Test integer
139  * @param new_test_int new test_int value
140  */
141 void
142 TestInterface::set_test_int(const int32_t new_test_int)
143 {
144  data->test_int = new_test_int;
145  data_changed = true;
146 }
147 
148 /** Get flags value.
149  * Flags spit down by the writer
150  * @return flags value
151  */
152 uint8_t
154 {
155  return data->flags;
156 }
157 
158 /** Get maximum length of flags value.
159  * @return length of flags value, can be length of the array or number of
160  * maximum number of characters for a string
161  */
162 size_t
164 {
165  return 1;
166 }
167 
168 /** Set flags value.
169  * Flags spit down by the writer
170  * @param new_flags new flags value
171  */
172 void
173 TestInterface::set_flags(const uint8_t new_flags)
174 {
175  data->flags = new_flags;
176  data_changed = true;
177 }
178 
179 /** Get test_string value.
180  * A test sring
181  * @return test_string value
182  */
183 char *
185 {
186  return data->test_string;
187 }
188 
189 /** Get maximum length of test_string value.
190  * @return length of test_string value, can be length of the array or number of
191  * maximum number of characters for a string
192  */
193 size_t
195 {
196  return 30;
197 }
198 
199 /** Set test_string value.
200  * A test sring
201  * @param new_test_string new test_string value
202  */
203 void
204 TestInterface::set_test_string(const char * new_test_string)
205 {
206  strncpy(data->test_string, new_test_string, sizeof(data->test_string));
207  data_changed = true;
208 }
209 
210 /** Get result value.
211  * Result of operation add operation from Calculate message.
212  * @return result value
213  */
214 int32_t
216 {
217  return data->result;
218 }
219 
220 /** Get maximum length of result value.
221  * @return length of result value, can be length of the array or number of
222  * maximum number of characters for a string
223  */
224 size_t
226 {
227  return 1;
228 }
229 
230 /** Set result value.
231  * Result of operation add operation from Calculate message.
232  * @param new_result new result value
233  */
234 void
235 TestInterface::set_result(const int32_t new_result)
236 {
237  data->result = new_result;
238  data_changed = true;
239 }
240 
241 /** Get test_uint value.
242  * Test uint32
243  * @return test_uint value
244  */
245 uint32_t
247 {
248  return data->test_uint;
249 }
250 
251 /** Get maximum length of test_uint value.
252  * @return length of test_uint value, can be length of the array or number of
253  * maximum number of characters for a string
254  */
255 size_t
257 {
258  return 1;
259 }
260 
261 /** Set test_uint value.
262  * Test uint32
263  * @param new_test_uint new test_uint value
264  */
265 void
266 TestInterface::set_test_uint(const uint32_t new_test_uint)
267 {
268  data->test_uint = new_test_uint;
269  data_changed = true;
270 }
271 
272 /* =========== message create =========== */
273 Message *
275 {
276  if ( strncmp("SetTestIntMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
277  return new SetTestIntMessage();
278  } else if ( strncmp("SetTestStringMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
279  return new SetTestStringMessage();
280  } else if ( strncmp("CalculateMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
281  return new CalculateMessage();
282  } else {
283  throw UnknownTypeException("The given type '%s' does not match any known "
284  "message type for this interface type.", type);
285  }
286 }
287 
288 
289 /** Copy values from other interface.
290  * @param other other interface to copy values from
291  */
292 void
294 {
295  const TestInterface *oi = dynamic_cast<const TestInterface *>(other);
296  if (oi == NULL) {
297  throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
298  type(), other->type());
299  }
300  memcpy(data, oi->data, sizeof(TestInterface_data_t));
301 }
302 
303 const char *
304 TestInterface::enum_tostring(const char *enumtype, int val) const
305 {
306  if (strcmp(enumtype, "TestEnum") == 0) {
307  return tostring_TestEnum((TestEnum)val);
308  }
309  throw UnknownTypeException("Unknown enum type %s", enumtype);
310 }
311 
312 /* =========== messages =========== */
313 /** @class TestInterface::SetTestIntMessage <interfaces/TestInterface.h>
314  * SetTestIntMessage Fawkes BlackBoard Interface Message.
315  *
316 
317  */
318 
319 
320 /** Constructor with initial values.
321  * @param ini_test_int initial value for test_int
322  */
323 TestInterface::SetTestIntMessage::SetTestIntMessage(const int32_t ini_test_int) : Message("SetTestIntMessage")
324 {
325  data_size = sizeof(SetTestIntMessage_data_t);
326  data_ptr = malloc(data_size);
327  memset(data_ptr, 0, data_size);
328  data = (SetTestIntMessage_data_t *)data_ptr;
330  data->test_int = ini_test_int;
331  add_fieldinfo(IFT_INT32, "test_int", 1, &data->test_int);
332 }
333 /** Constructor */
335 {
336  data_size = sizeof(SetTestIntMessage_data_t);
337  data_ptr = malloc(data_size);
338  memset(data_ptr, 0, data_size);
339  data = (SetTestIntMessage_data_t *)data_ptr;
341  add_fieldinfo(IFT_INT32, "test_int", 1, &data->test_int);
342 }
343 
344 /** Destructor */
346 {
347  free(data_ptr);
348 }
349 
350 /** Copy constructor.
351  * @param m message to copy from
352  */
354 {
355  data_size = m->data_size;
356  data_ptr = malloc(data_size);
357  memcpy(data_ptr, m->data_ptr, data_size);
358  data = (SetTestIntMessage_data_t *)data_ptr;
360 }
361 
362 /* Methods */
363 /** Get test_int value.
364  * Test integer
365  * @return test_int value
366  */
367 int32_t
369 {
370  return data->test_int;
371 }
372 
373 /** Get maximum length of test_int value.
374  * @return length of test_int value, can be length of the array or number of
375  * maximum number of characters for a string
376  */
377 size_t
379 {
380  return 1;
381 }
382 
383 /** Set test_int value.
384  * Test integer
385  * @param new_test_int new test_int value
386  */
387 void
389 {
390  data->test_int = new_test_int;
391 }
392 
393 /** Clone this message.
394  * Produces a message of the same type as this message and copies the
395  * data to the new message.
396  * @return clone of this message
397  */
398 Message *
400 {
401  return new TestInterface::SetTestIntMessage(this);
402 }
403 /** @class TestInterface::SetTestStringMessage <interfaces/TestInterface.h>
404  * SetTestStringMessage Fawkes BlackBoard Interface Message.
405  *
406 
407  */
408 
409 
410 /** Constructor with initial values.
411  * @param ini_test_string initial value for test_string
412  */
413 TestInterface::SetTestStringMessage::SetTestStringMessage(const char * ini_test_string) : Message("SetTestStringMessage")
414 {
415  data_size = sizeof(SetTestStringMessage_data_t);
416  data_ptr = malloc(data_size);
417  memset(data_ptr, 0, data_size);
418  data = (SetTestStringMessage_data_t *)data_ptr;
420  strncpy(data->test_string, ini_test_string, 30);
421  add_fieldinfo(IFT_STRING, "test_string", 30, data->test_string);
422 }
423 /** Constructor */
425 {
426  data_size = sizeof(SetTestStringMessage_data_t);
427  data_ptr = malloc(data_size);
428  memset(data_ptr, 0, data_size);
429  data = (SetTestStringMessage_data_t *)data_ptr;
431  add_fieldinfo(IFT_STRING, "test_string", 30, data->test_string);
432 }
433 
434 /** Destructor */
436 {
437  free(data_ptr);
438 }
439 
440 /** Copy constructor.
441  * @param m message to copy from
442  */
444 {
445  data_size = m->data_size;
446  data_ptr = malloc(data_size);
447  memcpy(data_ptr, m->data_ptr, data_size);
448  data = (SetTestStringMessage_data_t *)data_ptr;
450 }
451 
452 /* Methods */
453 /** Get test_string value.
454  * A test sring
455  * @return test_string value
456  */
457 char *
459 {
460  return data->test_string;
461 }
462 
463 /** Get maximum length of test_string value.
464  * @return length of test_string value, can be length of the array or number of
465  * maximum number of characters for a string
466  */
467 size_t
469 {
470  return 30;
471 }
472 
473 /** Set test_string value.
474  * A test sring
475  * @param new_test_string new test_string value
476  */
477 void
479 {
480  strncpy(data->test_string, new_test_string, sizeof(data->test_string));
481 }
482 
483 /** Clone this message.
484  * Produces a message of the same type as this message and copies the
485  * data to the new message.
486  * @return clone of this message
487  */
488 Message *
490 {
491  return new TestInterface::SetTestStringMessage(this);
492 }
493 /** @class TestInterface::CalculateMessage <interfaces/TestInterface.h>
494  * CalculateMessage Fawkes BlackBoard Interface Message.
495  *
496 
497  */
498 
499 
500 /** Constructor with initial values.
501  * @param ini_summand initial value for summand
502  * @param ini_addend initial value for addend
503  */
504 TestInterface::CalculateMessage::CalculateMessage(const int32_t ini_summand, const int32_t ini_addend) : Message("CalculateMessage")
505 {
506  data_size = sizeof(CalculateMessage_data_t);
507  data_ptr = malloc(data_size);
508  memset(data_ptr, 0, data_size);
509  data = (CalculateMessage_data_t *)data_ptr;
511  data->summand = ini_summand;
512  data->addend = ini_addend;
513  add_fieldinfo(IFT_INT32, "summand", 1, &data->summand);
514  add_fieldinfo(IFT_INT32, "addend", 1, &data->addend);
515 }
516 /** Constructor */
518 {
519  data_size = sizeof(CalculateMessage_data_t);
520  data_ptr = malloc(data_size);
521  memset(data_ptr, 0, data_size);
522  data = (CalculateMessage_data_t *)data_ptr;
524  add_fieldinfo(IFT_INT32, "summand", 1, &data->summand);
525  add_fieldinfo(IFT_INT32, "addend", 1, &data->addend);
526 }
527 
528 /** Destructor */
530 {
531  free(data_ptr);
532 }
533 
534 /** Copy constructor.
535  * @param m message to copy from
536  */
538 {
539  data_size = m->data_size;
540  data_ptr = malloc(data_size);
541  memcpy(data_ptr, m->data_ptr, data_size);
542  data = (CalculateMessage_data_t *)data_ptr;
544 }
545 
546 /* Methods */
547 /** Get summand value.
548  * Summand
549  * @return summand value
550  */
551 int32_t
553 {
554  return data->summand;
555 }
556 
557 /** Get maximum length of summand value.
558  * @return length of summand value, can be length of the array or number of
559  * maximum number of characters for a string
560  */
561 size_t
563 {
564  return 1;
565 }
566 
567 /** Set summand value.
568  * Summand
569  * @param new_summand new summand value
570  */
571 void
573 {
574  data->summand = new_summand;
575 }
576 
577 /** Get addend value.
578  * Addend
579  * @return addend value
580  */
581 int32_t
583 {
584  return data->addend;
585 }
586 
587 /** Get maximum length of addend value.
588  * @return length of addend value, can be length of the array or number of
589  * maximum number of characters for a string
590  */
591 size_t
593 {
594  return 1;
595 }
596 
597 /** Set addend value.
598  * Addend
599  * @param new_addend new addend value
600  */
601 void
603 {
604  data->addend = new_addend;
605 }
606 
607 /** Clone this message.
608  * Produces a message of the same type as this message and copies the
609  * data to the new message.
610  * @return clone of this message
611  */
612 Message *
614 {
615  return new TestInterface::CalculateMessage(this);
616 }
617 /** Check if message is valid and can be enqueued.
618  * @param message Message to check
619  * @return true if the message is valid, false otherwise.
620  */
621 bool
623 {
624  const SetTestIntMessage *m0 = dynamic_cast<const SetTestIntMessage *>(message);
625  if ( m0 != NULL ) {
626  return true;
627  }
628  const SetTestStringMessage *m1 = dynamic_cast<const SetTestStringMessage *>(message);
629  if ( m1 != NULL ) {
630  return true;
631  }
632  const CalculateMessage *m2 = dynamic_cast<const CalculateMessage *>(message);
633  if ( m2 != NULL ) {
634  return true;
635  }
636  return false;
637 }
638 
639 /// @cond INTERNALS
640 EXPORT_INTERFACE(TestInterface)
641 /// @endcond
642 
643 
644 } // end namespace fawkes
size_t maxlenof_result() const
Get maximum length of result value.
void set_test_string(const char *new_test_string)
Set test_string value.
void * data_ptr
Pointer to memory that contains local data.
Definition: message.h:114
const char * tostring_TestEnum(TestEnum value) const
Convert TestEnum constant to string.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:43
size_t maxlenof_test_int() const
Get maximum length of test_int value.
TestEnum
Demonstrating enums.
Definition: TestInterface.h:44
void set_hash(unsigned char *ihash)
Set hash.
Definition: interface.cpp:312
float value() const
Get value value.
Timestamp data, must be present and first entries for each interface data structs! This leans on time...
Definition: message.h:119
size_t maxlenof_test_string() const
Get maximum length of test_string value.
uint32_t test_uint() const
Get test_uint value.
char * test_string() const
Get test_string value.
virtual void copy_values(const Interface *other)
Copy values from other interface.
string field
Definition: types.h:45
byte field, alias for uint8
Definition: types.h:46
virtual Message * create_message(const char *type) const
Create message based on type name.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
size_t maxlenof_addend() const
Get maximum length of addend value.
virtual Message * clone() const
Clone this message.
size_t maxlenof_summand() const
Get maximum length of summand value.
void set_summand(const int32_t new_summand)
Set summand value.
virtual const char * enum_tostring(const char *enumtype, int val) const
Convert arbitrary enum value to string.
char * test_string() const
Get test_string value.
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:123
unsigned int data_size
Size of memory needed to hold all data.
Definition: message.h:115
int32_t test_int() const
Get test_int value.
void set_test_int(const int32_t new_test_int)
Set test_int value.
void add_messageinfo(const char *name)
Add an entry to the message info list.
Definition: interface.cpp:368
bool data_changed
Indicator if data has changed.
Definition: interface.h:208
static const int32_t TEST_CONSTANT
TEST_CONSTANT constant.
Definition: TestInterface.h:40
void * data_ptr
Pointer to local memory storage.
Definition: interface.h:206
size_t maxlenof_flags() const
Get maximum length of flags value.
int32_t test_int() const
Get test_int value.
bool is_test_bool() const
Get test_bool value.
int32_t result() const
Get result value.
void set_addend(const int32_t new_addend)
Set addend value.
void set_test_bool(const bool new_test_bool)
Set test_bool value.
virtual Message * clone() const
Clone this message.
CalculateMessage Fawkes BlackBoard Interface Message.
void set_flags(const uint8_t new_flags)
Set flags value.
SetTestIntMessage Fawkes BlackBoard Interface Message.
Definition: TestInterface.h:69
void set_test_uint(const uint32_t new_test_uint)
Set test_uint value.
void set_test_string(const char *new_test_string)
Set test_string value.
32 bit integer field
Definition: types.h:39
virtual Message * clone() const
Clone this message.
uint8_t flags() const
Get flags value.
size_t maxlenof_test_int() const
Get maximum length of test_int value.
size_t maxlenof_test_uint() const
Get maximum length of test_uint value.
size_t maxlenof_test_bool() const
Get maximum length of test_bool value.
void add_fieldinfo(interface_fieldtype_t type, const char *name, size_t length, void *value, const char *enumtype=0)
Add an entry to the info list.
Definition: message.cpp:435
int32_t addend() const
Get addend value.
static const float TEST_FLOAT_CONSTANT
TEST_FLOAT_CONSTANT constant.
Definition: TestInterface.h:41
int32_t summand() const
Get summand value.
boolean field
Definition: types.h:34
SetTestStringMessage Fawkes BlackBoard Interface Message.
Definition: TestInterface.h:96
void set_result(const int32_t new_result)
Set result value.
void set_test_int(const int32_t new_test_int)
Set test_int value.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
const char * type() const
Get type of interface.
Definition: interface.cpp:635
size_t maxlenof_test_string() const
Get maximum length of test_string value.
32 bit unsigned integer field
Definition: types.h:40
TestInterface Fawkes BlackBoard Interface.
Definition: TestInterface.h:33