TestInterface.cpp

00001 
00002 /***************************************************************************
00003  *  TestInterface.cpp - Fawkes BlackBoard Interface - TestInterface
00004  *
00005  *  Templated created:   Thu Oct 12 10:49:19 2006
00006  *  Copyright  2006-2007  Tim Niemueller
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #include <interfaces/TestInterface.h>
00025 
00026 #include <core/exceptions/software.h>
00027 
00028 #include <cstring>
00029 #include <cstdlib>
00030 
00031 namespace fawkes {
00032 
00033 /** @class TestInterface <interfaces/TestInterface.h>
00034  * TestInterface Fawkes BlackBoard Interface.
00035  * Test interface. Use this to play around. Do NOT remove any fields, as this
00036       interface is used by BlackBoard QA.
00037  * @ingroup FawkesInterfaces
00038  */
00039 
00040 
00041 /** TEST_CONSTANT constant */
00042 const int32_t TestInterface::TEST_CONSTANT = 5;
00043 /** TEST_FLOAT_CONSTANT constant */
00044 const float TestInterface::TEST_FLOAT_CONSTANT = 1.2;
00045 
00046 /** Constructor */
00047 TestInterface::TestInterface() : Interface()
00048 {
00049   data_size = sizeof(TestInterface_data_t);
00050   data_ptr  = malloc(data_size);
00051   data      = (TestInterface_data_t *)data_ptr;
00052   data_ts   = (interface_data_ts_t *)data_ptr;
00053   memset(data_ptr, 0, data_size);
00054   add_fieldinfo(IFT_BOOL, "test_bool", 1, &data->test_bool);
00055   add_fieldinfo(IFT_INT32, "test_int", 1, &data->test_int);
00056   add_fieldinfo(IFT_BYTE, "flags", 1, &data->flags);
00057   add_fieldinfo(IFT_STRING, "test_string", 30, data->test_string);
00058   add_fieldinfo(IFT_INT32, "result", 1, &data->result);
00059   add_fieldinfo(IFT_UINT32, "test_uint", 1, &data->test_uint);
00060   add_fieldinfo(IFT_UINT64, "test_ulint", 1, &data->test_ulint);
00061   add_fieldinfo(IFT_INT64, "test_lint", 1, &data->test_lint);
00062   add_messageinfo("SetTestIntMessage");
00063   add_messageinfo("SetTestStringMessage");
00064   add_messageinfo("CalculateMessage");
00065   unsigned char tmp_hash[] = {0x76, 0x67, 0x99, 0x23, 0x8, 0xa7, 0xba, 0xe0, 0x34, 0x70, 0x34, 0xf8, 0xe6, 0x99, 0x7d, 0x99};
00066   set_hash(tmp_hash);
00067 }
00068 
00069 /** Destructor */
00070 TestInterface::~TestInterface()
00071 {
00072   free(data_ptr);
00073 }
00074 /** Convert TestEnum constant to string.
00075  * @param value value to convert to string
00076  * @return constant value as string.
00077  */
00078 const char *
00079 TestInterface::tostring_TestEnum(TestEnum value) const
00080 {
00081   switch (value) {
00082   case TEST_ENUM_1: return "TEST_ENUM_1";
00083   case TEST_ENUM_2: return "TEST_ENUM_2";
00084   default: return "UNKNOWN";
00085   }
00086 }
00087 /* Methods */
00088 /** Get test_bool value.
00089  * Test Bool
00090  * @return test_bool value
00091  */
00092 bool
00093 TestInterface::is_test_bool() const
00094 {
00095   return data->test_bool;
00096 }
00097 
00098 /** Get maximum length of test_bool value.
00099  * @return length of test_bool value, can be length of the array or number of 
00100  * maximum number of characters for a string
00101  */
00102 size_t
00103 TestInterface::maxlenof_test_bool() const
00104 {
00105   return 1;
00106 }
00107 
00108 /** Set test_bool value.
00109  * Test Bool
00110  * @param new_test_bool new test_bool value
00111  */
00112 void
00113 TestInterface::set_test_bool(const bool new_test_bool)
00114 {
00115   data->test_bool = new_test_bool;
00116   data_changed = true;
00117 }
00118 
00119 /** Get test_int value.
00120  * Test integer
00121  * @return test_int value
00122  */
00123 int32_t
00124 TestInterface::test_int() const
00125 {
00126   return data->test_int;
00127 }
00128 
00129 /** Get maximum length of test_int value.
00130  * @return length of test_int value, can be length of the array or number of 
00131  * maximum number of characters for a string
00132  */
00133 size_t
00134 TestInterface::maxlenof_test_int() const
00135 {
00136   return 1;
00137 }
00138 
00139 /** Set test_int value.
00140  * Test integer
00141  * @param new_test_int new test_int value
00142  */
00143 void
00144 TestInterface::set_test_int(const int32_t new_test_int)
00145 {
00146   data->test_int = new_test_int;
00147   data_changed = true;
00148 }
00149 
00150 /** Get flags value.
00151  * Flags spit down by the writer
00152  * @return flags value
00153  */
00154 uint8_t
00155 TestInterface::flags() const
00156 {
00157   return data->flags;
00158 }
00159 
00160 /** Get maximum length of flags value.
00161  * @return length of flags value, can be length of the array or number of 
00162  * maximum number of characters for a string
00163  */
00164 size_t
00165 TestInterface::maxlenof_flags() const
00166 {
00167   return 1;
00168 }
00169 
00170 /** Set flags value.
00171  * Flags spit down by the writer
00172  * @param new_flags new flags value
00173  */
00174 void
00175 TestInterface::set_flags(const uint8_t new_flags)
00176 {
00177   data->flags = new_flags;
00178   data_changed = true;
00179 }
00180 
00181 /** Get test_string value.
00182  * A test sring
00183  * @return test_string value
00184  */
00185 char *
00186 TestInterface::test_string() const
00187 {
00188   return data->test_string;
00189 }
00190 
00191 /** Get maximum length of test_string value.
00192  * @return length of test_string value, can be length of the array or number of 
00193  * maximum number of characters for a string
00194  */
00195 size_t
00196 TestInterface::maxlenof_test_string() const
00197 {
00198   return 30;
00199 }
00200 
00201 /** Set test_string value.
00202  * A test sring
00203  * @param new_test_string new test_string value
00204  */
00205 void
00206 TestInterface::set_test_string(const char * new_test_string)
00207 {
00208   strncpy(data->test_string, new_test_string, sizeof(data->test_string));
00209   data_changed = true;
00210 }
00211 
00212 /** Get result value.
00213  * Result of operation add operation from Calculate message.
00214  * @return result value
00215  */
00216 int32_t
00217 TestInterface::result() const
00218 {
00219   return data->result;
00220 }
00221 
00222 /** Get maximum length of result value.
00223  * @return length of result value, can be length of the array or number of 
00224  * maximum number of characters for a string
00225  */
00226 size_t
00227 TestInterface::maxlenof_result() const
00228 {
00229   return 1;
00230 }
00231 
00232 /** Set result value.
00233  * Result of operation add operation from Calculate message.
00234  * @param new_result new result value
00235  */
00236 void
00237 TestInterface::set_result(const int32_t new_result)
00238 {
00239   data->result = new_result;
00240   data_changed = true;
00241 }
00242 
00243 /** Get test_uint value.
00244  * Test uint32
00245  * @return test_uint value
00246  */
00247 uint32_t
00248 TestInterface::test_uint() const
00249 {
00250   return data->test_uint;
00251 }
00252 
00253 /** Get maximum length of test_uint value.
00254  * @return length of test_uint value, can be length of the array or number of 
00255  * maximum number of characters for a string
00256  */
00257 size_t
00258 TestInterface::maxlenof_test_uint() const
00259 {
00260   return 1;
00261 }
00262 
00263 /** Set test_uint value.
00264  * Test uint32
00265  * @param new_test_uint new test_uint value
00266  */
00267 void
00268 TestInterface::set_test_uint(const uint32_t new_test_uint)
00269 {
00270   data->test_uint = new_test_uint;
00271   data_changed = true;
00272 }
00273 
00274 /** Get test_ulint value.
00275  * Test unsigned long int
00276  * @return test_ulint value
00277  */
00278 uint64_t
00279 TestInterface::test_ulint() const
00280 {
00281   return data->test_ulint;
00282 }
00283 
00284 /** Get maximum length of test_ulint value.
00285  * @return length of test_ulint value, can be length of the array or number of 
00286  * maximum number of characters for a string
00287  */
00288 size_t
00289 TestInterface::maxlenof_test_ulint() const
00290 {
00291   return 1;
00292 }
00293 
00294 /** Set test_ulint value.
00295  * Test unsigned long int
00296  * @param new_test_ulint new test_ulint value
00297  */
00298 void
00299 TestInterface::set_test_ulint(const uint64_t new_test_ulint)
00300 {
00301   data->test_ulint = new_test_ulint;
00302   data_changed = true;
00303 }
00304 
00305 /** Get test_lint value.
00306  * Test long int
00307  * @return test_lint value
00308  */
00309 int64_t
00310 TestInterface::test_lint() const
00311 {
00312   return data->test_lint;
00313 }
00314 
00315 /** Get maximum length of test_lint value.
00316  * @return length of test_lint value, can be length of the array or number of 
00317  * maximum number of characters for a string
00318  */
00319 size_t
00320 TestInterface::maxlenof_test_lint() const
00321 {
00322   return 1;
00323 }
00324 
00325 /** Set test_lint value.
00326  * Test long int
00327  * @param new_test_lint new test_lint value
00328  */
00329 void
00330 TestInterface::set_test_lint(const int64_t new_test_lint)
00331 {
00332   data->test_lint = new_test_lint;
00333   data_changed = true;
00334 }
00335 
00336 /* =========== message create =========== */
00337 Message *
00338 TestInterface::create_message(const char *type) const
00339 {
00340   if ( strncmp("SetTestIntMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00341     return new SetTestIntMessage();
00342   } else if ( strncmp("SetTestStringMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00343     return new SetTestStringMessage();
00344   } else if ( strncmp("CalculateMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00345     return new CalculateMessage();
00346   } else {
00347     throw UnknownTypeException("The given type '%s' does not match any known "
00348                                "message type for this interface type.", type);
00349   }
00350 }
00351 
00352 
00353 /** Copy values from other interface.
00354  * @param other other interface to copy values from
00355  */
00356 void
00357 TestInterface::copy_values(const Interface *other)
00358 {
00359   const TestInterface *oi = dynamic_cast<const TestInterface *>(other);
00360   if (oi == NULL) {
00361     throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
00362                                 type(), other->type());
00363   }
00364   memcpy(data, oi->data, sizeof(TestInterface_data_t));
00365 }
00366 
00367 const char *
00368 TestInterface::enum_tostring(const char *enumtype, int val) const
00369 {
00370   if (strcmp(enumtype, "TestEnum") == 0) {
00371     return tostring_TestEnum((TestEnum)val);
00372   }
00373   throw UnknownTypeException("Unknown enum type %s", enumtype);
00374 }
00375 
00376 /* =========== messages =========== */
00377 /** @class TestInterface::SetTestIntMessage <interfaces/TestInterface.h>
00378  * SetTestIntMessage Fawkes BlackBoard Interface Message.
00379  * 
00380     
00381  */
00382 
00383 
00384 /** Constructor with initial values.
00385  * @param ini_test_int initial value for test_int
00386  */
00387 TestInterface::SetTestIntMessage::SetTestIntMessage(const int32_t ini_test_int) : Message("SetTestIntMessage")
00388 {
00389   data_size = sizeof(SetTestIntMessage_data_t);
00390   data_ptr  = malloc(data_size);
00391   memset(data_ptr, 0, data_size);
00392   data      = (SetTestIntMessage_data_t *)data_ptr;
00393   data_ts   = (message_data_ts_t *)data_ptr;
00394   data->test_int = ini_test_int;
00395   add_fieldinfo(IFT_INT32, "test_int", 1, &data->test_int);
00396 }
00397 /** Constructor */
00398 TestInterface::SetTestIntMessage::SetTestIntMessage() : Message("SetTestIntMessage")
00399 {
00400   data_size = sizeof(SetTestIntMessage_data_t);
00401   data_ptr  = malloc(data_size);
00402   memset(data_ptr, 0, data_size);
00403   data      = (SetTestIntMessage_data_t *)data_ptr;
00404   data_ts   = (message_data_ts_t *)data_ptr;
00405   add_fieldinfo(IFT_INT32, "test_int", 1, &data->test_int);
00406 }
00407 
00408 /** Destructor */
00409 TestInterface::SetTestIntMessage::~SetTestIntMessage()
00410 {
00411   free(data_ptr);
00412 }
00413 
00414 /** Copy constructor.
00415  * @param m message to copy from
00416  */
00417 TestInterface::SetTestIntMessage::SetTestIntMessage(const SetTestIntMessage *m) : Message("SetTestIntMessage")
00418 {
00419   data_size = m->data_size;
00420   data_ptr  = malloc(data_size);
00421   memcpy(data_ptr, m->data_ptr, data_size);
00422   data      = (SetTestIntMessage_data_t *)data_ptr;
00423   data_ts   = (message_data_ts_t *)data_ptr;
00424 }
00425 
00426 /* Methods */
00427 /** Get test_int value.
00428  * Test integer
00429  * @return test_int value
00430  */
00431 int32_t
00432 TestInterface::SetTestIntMessage::test_int() const
00433 {
00434   return data->test_int;
00435 }
00436 
00437 /** Get maximum length of test_int value.
00438  * @return length of test_int value, can be length of the array or number of 
00439  * maximum number of characters for a string
00440  */
00441 size_t
00442 TestInterface::SetTestIntMessage::maxlenof_test_int() const
00443 {
00444   return 1;
00445 }
00446 
00447 /** Set test_int value.
00448  * Test integer
00449  * @param new_test_int new test_int value
00450  */
00451 void
00452 TestInterface::SetTestIntMessage::set_test_int(const int32_t new_test_int)
00453 {
00454   data->test_int = new_test_int;
00455 }
00456 
00457 /** Clone this message.
00458  * Produces a message of the same type as this message and copies the
00459  * data to the new message.
00460  * @return clone of this message
00461  */
00462 Message *
00463 TestInterface::SetTestIntMessage::clone() const
00464 {
00465   return new TestInterface::SetTestIntMessage(this);
00466 }
00467 /** @class TestInterface::SetTestStringMessage <interfaces/TestInterface.h>
00468  * SetTestStringMessage Fawkes BlackBoard Interface Message.
00469  * 
00470     
00471  */
00472 
00473 
00474 /** Constructor with initial values.
00475  * @param ini_test_string initial value for test_string
00476  */
00477 TestInterface::SetTestStringMessage::SetTestStringMessage(const char * ini_test_string) : Message("SetTestStringMessage")
00478 {
00479   data_size = sizeof(SetTestStringMessage_data_t);
00480   data_ptr  = malloc(data_size);
00481   memset(data_ptr, 0, data_size);
00482   data      = (SetTestStringMessage_data_t *)data_ptr;
00483   data_ts   = (message_data_ts_t *)data_ptr;
00484   strncpy(data->test_string, ini_test_string, 30);
00485   add_fieldinfo(IFT_STRING, "test_string", 30, data->test_string);
00486 }
00487 /** Constructor */
00488 TestInterface::SetTestStringMessage::SetTestStringMessage() : Message("SetTestStringMessage")
00489 {
00490   data_size = sizeof(SetTestStringMessage_data_t);
00491   data_ptr  = malloc(data_size);
00492   memset(data_ptr, 0, data_size);
00493   data      = (SetTestStringMessage_data_t *)data_ptr;
00494   data_ts   = (message_data_ts_t *)data_ptr;
00495   add_fieldinfo(IFT_STRING, "test_string", 30, data->test_string);
00496 }
00497 
00498 /** Destructor */
00499 TestInterface::SetTestStringMessage::~SetTestStringMessage()
00500 {
00501   free(data_ptr);
00502 }
00503 
00504 /** Copy constructor.
00505  * @param m message to copy from
00506  */
00507 TestInterface::SetTestStringMessage::SetTestStringMessage(const SetTestStringMessage *m) : Message("SetTestStringMessage")
00508 {
00509   data_size = m->data_size;
00510   data_ptr  = malloc(data_size);
00511   memcpy(data_ptr, m->data_ptr, data_size);
00512   data      = (SetTestStringMessage_data_t *)data_ptr;
00513   data_ts   = (message_data_ts_t *)data_ptr;
00514 }
00515 
00516 /* Methods */
00517 /** Get test_string value.
00518  * A test sring
00519  * @return test_string value
00520  */
00521 char *
00522 TestInterface::SetTestStringMessage::test_string() const
00523 {
00524   return data->test_string;
00525 }
00526 
00527 /** Get maximum length of test_string value.
00528  * @return length of test_string value, can be length of the array or number of 
00529  * maximum number of characters for a string
00530  */
00531 size_t
00532 TestInterface::SetTestStringMessage::maxlenof_test_string() const
00533 {
00534   return 30;
00535 }
00536 
00537 /** Set test_string value.
00538  * A test sring
00539  * @param new_test_string new test_string value
00540  */
00541 void
00542 TestInterface::SetTestStringMessage::set_test_string(const char * new_test_string)
00543 {
00544   strncpy(data->test_string, new_test_string, sizeof(data->test_string));
00545 }
00546 
00547 /** Clone this message.
00548  * Produces a message of the same type as this message and copies the
00549  * data to the new message.
00550  * @return clone of this message
00551  */
00552 Message *
00553 TestInterface::SetTestStringMessage::clone() const
00554 {
00555   return new TestInterface::SetTestStringMessage(this);
00556 }
00557 /** @class TestInterface::CalculateMessage <interfaces/TestInterface.h>
00558  * CalculateMessage Fawkes BlackBoard Interface Message.
00559  * 
00560     
00561  */
00562 
00563 
00564 /** Constructor with initial values.
00565  * @param ini_summand initial value for summand
00566  * @param ini_addend initial value for addend
00567  */
00568 TestInterface::CalculateMessage::CalculateMessage(const int32_t ini_summand, const int32_t ini_addend) : Message("CalculateMessage")
00569 {
00570   data_size = sizeof(CalculateMessage_data_t);
00571   data_ptr  = malloc(data_size);
00572   memset(data_ptr, 0, data_size);
00573   data      = (CalculateMessage_data_t *)data_ptr;
00574   data_ts   = (message_data_ts_t *)data_ptr;
00575   data->summand = ini_summand;
00576   data->addend = ini_addend;
00577   add_fieldinfo(IFT_INT32, "summand", 1, &data->summand);
00578   add_fieldinfo(IFT_INT32, "addend", 1, &data->addend);
00579 }
00580 /** Constructor */
00581 TestInterface::CalculateMessage::CalculateMessage() : Message("CalculateMessage")
00582 {
00583   data_size = sizeof(CalculateMessage_data_t);
00584   data_ptr  = malloc(data_size);
00585   memset(data_ptr, 0, data_size);
00586   data      = (CalculateMessage_data_t *)data_ptr;
00587   data_ts   = (message_data_ts_t *)data_ptr;
00588   add_fieldinfo(IFT_INT32, "summand", 1, &data->summand);
00589   add_fieldinfo(IFT_INT32, "addend", 1, &data->addend);
00590 }
00591 
00592 /** Destructor */
00593 TestInterface::CalculateMessage::~CalculateMessage()
00594 {
00595   free(data_ptr);
00596 }
00597 
00598 /** Copy constructor.
00599  * @param m message to copy from
00600  */
00601 TestInterface::CalculateMessage::CalculateMessage(const CalculateMessage *m) : Message("CalculateMessage")
00602 {
00603   data_size = m->data_size;
00604   data_ptr  = malloc(data_size);
00605   memcpy(data_ptr, m->data_ptr, data_size);
00606   data      = (CalculateMessage_data_t *)data_ptr;
00607   data_ts   = (message_data_ts_t *)data_ptr;
00608 }
00609 
00610 /* Methods */
00611 /** Get summand value.
00612  * Summand
00613  * @return summand value
00614  */
00615 int32_t
00616 TestInterface::CalculateMessage::summand() const
00617 {
00618   return data->summand;
00619 }
00620 
00621 /** Get maximum length of summand value.
00622  * @return length of summand value, can be length of the array or number of 
00623  * maximum number of characters for a string
00624  */
00625 size_t
00626 TestInterface::CalculateMessage::maxlenof_summand() const
00627 {
00628   return 1;
00629 }
00630 
00631 /** Set summand value.
00632  * Summand
00633  * @param new_summand new summand value
00634  */
00635 void
00636 TestInterface::CalculateMessage::set_summand(const int32_t new_summand)
00637 {
00638   data->summand = new_summand;
00639 }
00640 
00641 /** Get addend value.
00642  * Addend
00643  * @return addend value
00644  */
00645 int32_t
00646 TestInterface::CalculateMessage::addend() const
00647 {
00648   return data->addend;
00649 }
00650 
00651 /** Get maximum length of addend value.
00652  * @return length of addend value, can be length of the array or number of 
00653  * maximum number of characters for a string
00654  */
00655 size_t
00656 TestInterface::CalculateMessage::maxlenof_addend() const
00657 {
00658   return 1;
00659 }
00660 
00661 /** Set addend value.
00662  * Addend
00663  * @param new_addend new addend value
00664  */
00665 void
00666 TestInterface::CalculateMessage::set_addend(const int32_t new_addend)
00667 {
00668   data->addend = new_addend;
00669 }
00670 
00671 /** Clone this message.
00672  * Produces a message of the same type as this message and copies the
00673  * data to the new message.
00674  * @return clone of this message
00675  */
00676 Message *
00677 TestInterface::CalculateMessage::clone() const
00678 {
00679   return new TestInterface::CalculateMessage(this);
00680 }
00681 /** Check if message is valid and can be enqueued.
00682  * @param message Message to check
00683  * @return true if the message is valid, false otherwise.
00684  */
00685 bool
00686 TestInterface::message_valid(const Message *message) const
00687 {
00688   const SetTestIntMessage *m0 = dynamic_cast<const SetTestIntMessage *>(message);
00689   if ( m0 != NULL ) {
00690     return true;
00691   }
00692   const SetTestStringMessage *m1 = dynamic_cast<const SetTestStringMessage *>(message);
00693   if ( m1 != NULL ) {
00694     return true;
00695   }
00696   const CalculateMessage *m2 = dynamic_cast<const CalculateMessage *>(message);
00697   if ( m2 != NULL ) {
00698     return true;
00699   }
00700   return false;
00701 }
00702 
00703 /// @cond INTERNALS
00704 EXPORT_INTERFACE(TestInterface)
00705 /// @endcond
00706 
00707 
00708 } // end namespace fawkes

Generated on Tue Feb 22 13:31:24 2011 for Fawkes API by  doxygen 1.4.7