SkillerDebugInterface.cpp

00001
00002 /***************************************************************************
00003  *  SkillerDebugInterface.cpp - Fawkes BlackBoard Interface - SkillerDebugInterface
00004  *
00005  *  Templated created:   Thu Oct 12 10:49:19 2006
00006  *  Copyright  2008  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/SkillerDebugInterface.h>
00025
00026 #include <core/exceptions/software.h>
00027
00028 #include <cstring>
00029 #include <cstdlib>
00030
00031 namespace fawkes {
00032 
00033 /** @class SkillerDebugInterface <interfaces/SkillerDebugInterface.h>
00034  * SkillerDebugInterface Fawkes BlackBoard Interface.
00035  * 
00036       This interface provides internal skiller data that should allow for
00037       easier debugging of skills and the skiller in general. The most notable
00038       feature is a graph representation in the dot language of the available
00039       skills (and highlighting for the currently active skill).
00040     
00041  * @ingroup FawkesInterfaces
00042  */
00043
00044
00045 
00046 /** Constructor */
00047 SkillerDebugInterface::SkillerDebugInterface() : Interface()
00048 {
00049   data_size = sizeof(SkillerDebugInterface_data_t);
00050   data_ptr  = malloc(data_size);
00051   data      = (SkillerDebugInterface_data_t *)data_ptr;
00052   memset(data_ptr, 0, data_size);
00053   add_fieldinfo(IFT_STRING, "graph_fsm", 32, data->graph_fsm);
00054   add_fieldinfo(IFT_STRING, "graph", 8192, data->graph);
00055   add_fieldinfo(IFT_BOOL, "graph_colored", 1, &data->graph_colored);
00056   add_messageinfo("SetGraphMessage");
00057   add_messageinfo("SetGraphDirectionMessage");
00058   add_messageinfo("SetGraphColoredMessage");
00059   unsigned char tmp_hash[] = {0xcf, 0x3d, 0x2f, 0xf8, 0x80, 0x6e, 0x8f, 0xf4, 0x81, 0xa6, 0x7f, 0xd9, 0xb0, 0x29, 0xfc, 0x62};
00060   set_hash(tmp_hash);
00061 }
00062 
00063 /** Destructor */
00064 SkillerDebugInterface::~SkillerDebugInterface()
00065 {
00066   free(data_ptr);
00067 }
00068 /* Methods */
00069 /** Get graph_fsm value.
00070  * 
00071       The finite state machine (FSM) the current graph has been updated for.
00072     
00073  * @return graph_fsm value
00074  */
00075 char *
00076 SkillerDebugInterface::graph_fsm() const
00077 {
00078   return data->graph_fsm;
00079 }
00080 
00081 /** Get maximum length of graph_fsm value.
00082  * @return length of graph_fsm value, can be length of the array or number of 
00083  * maximum number of characters for a string
00084  */
00085 size_t
00086 SkillerDebugInterface::maxlenof_graph_fsm() const
00087 {
00088   return 32;
00089 }
00090 
00091 /** Set graph_fsm value.
00092  * 
00093       The finite state machine (FSM) the current graph has been updated for.
00094     
00095  * @param new_graph_fsm new graph_fsm value
00096  */
00097 void
00098 SkillerDebugInterface::set_graph_fsm(const char * new_graph_fsm)
00099 {
00100   strncpy(data->graph_fsm, new_graph_fsm, sizeof(data->graph_fsm));
00101 }
00102 
00103 /** Get graph value.
00104  * 
00105       The selected graph in a dot string representation.
00106     
00107  * @return graph value
00108  */
00109 char *
00110 SkillerDebugInterface::graph() const
00111 {
00112   return data->graph;
00113 }
00114 
00115 /** Get maximum length of graph value.
00116  * @return length of graph value, can be length of the array or number of 
00117  * maximum number of characters for a string
00118  */
00119 size_t
00120 SkillerDebugInterface::maxlenof_graph() const
00121 {
00122   return 8192;
00123 }
00124 
00125 /** Set graph value.
00126  * 
00127       The selected graph in a dot string representation.
00128     
00129  * @param new_graph new graph value
00130  */
00131 void
00132 SkillerDebugInterface::set_graph(const char * new_graph)
00133 {
00134   strncpy(data->graph, new_graph, sizeof(data->graph));
00135 }
00136 
00137 /** Get graph_dir value.
00138  * 
00139       Primary direction of current graph.
00140     
00141  * @return graph_dir value
00142  */
00143 SkillerDebugInterface::GraphDirectionEnum
00144 SkillerDebugInterface::graph_dir() const
00145 {
00146   return data->graph_dir;
00147 }
00148 
00149 /** Get maximum length of graph_dir value.
00150  * @return length of graph_dir value, can be length of the array or number of 
00151  * maximum number of characters for a string
00152  */
00153 size_t
00154 SkillerDebugInterface::maxlenof_graph_dir() const
00155 {
00156   return 1;
00157 }
00158 
00159 /** Set graph_dir value.
00160  * 
00161       Primary direction of current graph.
00162     
00163  * @param new_graph_dir new graph_dir value
00164  */
00165 void
00166 SkillerDebugInterface::set_graph_dir(const GraphDirectionEnum new_graph_dir)
00167 {
00168   data->graph_dir = new_graph_dir;
00169 }
00170 
00171 /** Get graph_colored value.
00172  * 
00173       True if the graph is colored, false otherwise.
00174     
00175  * @return graph_colored value
00176  */
00177 bool
00178 SkillerDebugInterface::is_graph_colored() const
00179 {
00180   return data->graph_colored;
00181 }
00182 
00183 /** Get maximum length of graph_colored value.
00184  * @return length of graph_colored value, can be length of the array or number of 
00185  * maximum number of characters for a string
00186  */
00187 size_t
00188 SkillerDebugInterface::maxlenof_graph_colored() const
00189 {
00190   return 1;
00191 }
00192 
00193 /** Set graph_colored value.
00194  * 
00195       True if the graph is colored, false otherwise.
00196     
00197  * @param new_graph_colored new graph_colored value
00198  */
00199 void
00200 SkillerDebugInterface::set_graph_colored(const bool new_graph_colored)
00201 {
00202   data->graph_colored = new_graph_colored;
00203 }
00204
00205 /* =========== message create =========== */
00206 Message *
00207 SkillerDebugInterface::create_message(const char *type) const
00208 {
00209   if ( strncmp("SetGraphMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00210     return new SetGraphMessage();
00211   } else if ( strncmp("SetGraphDirectionMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00212     return new SetGraphDirectionMessage();
00213   } else if ( strncmp("SetGraphColoredMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00214     return new SetGraphColoredMessage();
00215   } else {
00216     throw UnknownTypeException("The given type '%s' does not match any known "
00217                                "message type for this interface type.", type);
00218   }
00219 }
00220
00221 
00222 /** Copy values from other interface.
00223  * @param other other interface to copy values from
00224  */
00225 void
00226 SkillerDebugInterface::copy_values(const Interface *other)
00227 {
00228   const SkillerDebugInterface *oi = dynamic_cast<const SkillerDebugInterface *>(other);
00229   if (oi == NULL) {
00230     throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
00231                                 type(), other->type());
00232   }
00233   memcpy(data, oi->data, sizeof(SkillerDebugInterface_data_t));
00234 }
00235
00236 /* =========== messages =========== */
00237 /** @class SkillerDebugInterface::SetGraphMessage <interfaces/SkillerDebugInterface.h>
00238  * SetGraphMessage Fawkes BlackBoard Interface Message.
00239  * 
00240     
00241  */
00242
00243 
00244 /** Constructor with initial values.
00245  * @param ini_graph_fsm initial value for graph_fsm
00246  */
00247 SkillerDebugInterface::SetGraphMessage::SetGraphMessage(const char * ini_graph_fsm) : Message("SetGraphMessage")
00248 {
00249   data_size = sizeof(SetGraphMessage_data_t);
00250   data_ptr  = malloc(data_size);
00251   memset(data_ptr, 0, data_size);
00252   data      = (SetGraphMessage_data_t *)data_ptr;
00253   strncpy(data->graph_fsm, ini_graph_fsm, 32);
00254   add_fieldinfo(IFT_STRING, "graph_fsm", 32, data->graph_fsm);
00255 }
00256 /** Constructor */
00257 SkillerDebugInterface::SetGraphMessage::SetGraphMessage() : Message("SetGraphMessage")
00258 {
00259   data_size = sizeof(SetGraphMessage_data_t);
00260   data_ptr  = malloc(data_size);
00261   memset(data_ptr, 0, data_size);
00262   data      = (SetGraphMessage_data_t *)data_ptr;
00263   add_fieldinfo(IFT_STRING, "graph_fsm", 32, data->graph_fsm);
00264 }
00265 
00266 /** Destructor */
00267 SkillerDebugInterface::SetGraphMessage::~SetGraphMessage()
00268 {
00269   free(data_ptr);
00270 }
00271 
00272 /** Copy constructor.
00273  * @param m message to copy from
00274  */
00275 SkillerDebugInterface::SetGraphMessage::SetGraphMessage(const SetGraphMessage *m) : Message("SetGraphMessage")
00276 {
00277   data_size = m->data_size;
00278   data_ptr  = malloc(data_size);
00279   memcpy(data_ptr, m->data_ptr, data_size);
00280   data      = (SetGraphMessage_data_t *)data_ptr;
00281 }
00282
00283 /* Methods */
00284 /** Get graph_fsm value.
00285  * 
00286       The finite state machine (FSM) the current graph has been updated for.
00287     
00288  * @return graph_fsm value
00289  */
00290 char *
00291 SkillerDebugInterface::SetGraphMessage::graph_fsm() const
00292 {
00293   return data->graph_fsm;
00294 }
00295 
00296 /** Get maximum length of graph_fsm value.
00297  * @return length of graph_fsm value, can be length of the array or number of 
00298  * maximum number of characters for a string
00299  */
00300 size_t
00301 SkillerDebugInterface::SetGraphMessage::maxlenof_graph_fsm() const
00302 {
00303   return 32;
00304 }
00305 
00306 /** Set graph_fsm value.
00307  * 
00308       The finite state machine (FSM) the current graph has been updated for.
00309     
00310  * @param new_graph_fsm new graph_fsm value
00311  */
00312 void
00313 SkillerDebugInterface::SetGraphMessage::set_graph_fsm(const char * new_graph_fsm)
00314 {
00315   strncpy(data->graph_fsm, new_graph_fsm, sizeof(data->graph_fsm));
00316 }
00317 
00318 /** Clone this message.
00319  * Produces a message of the same type as this message and copies the
00320  * data to the new message.
00321  * @return clone of this message
00322  */
00323 Message *
00324 SkillerDebugInterface::SetGraphMessage::clone() const
00325 {
00326   return new SkillerDebugInterface::SetGraphMessage(this);
00327 }
00328 /** @class SkillerDebugInterface::SetGraphDirectionMessage <interfaces/SkillerDebugInterface.h>
00329  * SetGraphDirectionMessage Fawkes BlackBoard Interface Message.
00330  * 
00331     
00332  */
00333
00334 
00335 /** Constructor with initial values.
00336  * @param ini_graph_dir initial value for graph_dir
00337  */
00338 SkillerDebugInterface::SetGraphDirectionMessage::SetGraphDirectionMessage(const GraphDirectionEnum ini_graph_dir) : Message("SetGraphDirectionMessage")
00339 {
00340   data_size = sizeof(SetGraphDirectionMessage_data_t);
00341   data_ptr  = malloc(data_size);
00342   memset(data_ptr, 0, data_size);
00343   data      = (SetGraphDirectionMessage_data_t *)data_ptr;
00344   data->graph_dir = ini_graph_dir;
00345 }
00346 /** Constructor */
00347 SkillerDebugInterface::SetGraphDirectionMessage::SetGraphDirectionMessage() : Message("SetGraphDirectionMessage")
00348 {
00349   data_size = sizeof(SetGraphDirectionMessage_data_t);
00350   data_ptr  = malloc(data_size);
00351   memset(data_ptr, 0, data_size);
00352   data      = (SetGraphDirectionMessage_data_t *)data_ptr;
00353 }
00354 
00355 /** Destructor */
00356 SkillerDebugInterface::SetGraphDirectionMessage::~SetGraphDirectionMessage()
00357 {
00358   free(data_ptr);
00359 }
00360 
00361 /** Copy constructor.
00362  * @param m message to copy from
00363  */
00364 SkillerDebugInterface::SetGraphDirectionMessage::SetGraphDirectionMessage(const SetGraphDirectionMessage *m) : Message("SetGraphDirectionMessage")
00365 {
00366   data_size = m->data_size;
00367   data_ptr  = malloc(data_size);
00368   memcpy(data_ptr, m->data_ptr, data_size);
00369   data      = (SetGraphDirectionMessage_data_t *)data_ptr;
00370 }
00371
00372 /* Methods */
00373 /** Get graph_dir value.
00374  * 
00375       Primary direction of current graph.
00376     
00377  * @return graph_dir value
00378  */
00379 SkillerDebugInterface::GraphDirectionEnum
00380 SkillerDebugInterface::SetGraphDirectionMessage::graph_dir() const
00381 {
00382   return data->graph_dir;
00383 }
00384 
00385 /** Get maximum length of graph_dir value.
00386  * @return length of graph_dir value, can be length of the array or number of 
00387  * maximum number of characters for a string
00388  */
00389 size_t
00390 SkillerDebugInterface::SetGraphDirectionMessage::maxlenof_graph_dir() const
00391 {
00392   return 1;
00393 }
00394 
00395 /** Set graph_dir value.
00396  * 
00397       Primary direction of current graph.
00398     
00399  * @param new_graph_dir new graph_dir value
00400  */
00401 void
00402 SkillerDebugInterface::SetGraphDirectionMessage::set_graph_dir(const GraphDirectionEnum new_graph_dir)
00403 {
00404   data->graph_dir = new_graph_dir;
00405 }
00406 
00407 /** Clone this message.
00408  * Produces a message of the same type as this message and copies the
00409  * data to the new message.
00410  * @return clone of this message
00411  */
00412 Message *
00413 SkillerDebugInterface::SetGraphDirectionMessage::clone() const
00414 {
00415   return new SkillerDebugInterface::SetGraphDirectionMessage(this);
00416 }
00417 /** @class SkillerDebugInterface::SetGraphColoredMessage <interfaces/SkillerDebugInterface.h>
00418  * SetGraphColoredMessage Fawkes BlackBoard Interface Message.
00419  * 
00420     
00421  */
00422
00423 
00424 /** Constructor with initial values.
00425  * @param ini_graph_colored initial value for graph_colored
00426  */
00427 SkillerDebugInterface::SetGraphColoredMessage::SetGraphColoredMessage(const bool ini_graph_colored) : Message("SetGraphColoredMessage")
00428 {
00429   data_size = sizeof(SetGraphColoredMessage_data_t);
00430   data_ptr  = malloc(data_size);
00431   memset(data_ptr, 0, data_size);
00432   data      = (SetGraphColoredMessage_data_t *)data_ptr;
00433   data->graph_colored = ini_graph_colored;
00434   add_fieldinfo(IFT_BOOL, "graph_colored", 1, &data->graph_colored);
00435 }
00436 /** Constructor */
00437 SkillerDebugInterface::SetGraphColoredMessage::SetGraphColoredMessage() : Message("SetGraphColoredMessage")
00438 {
00439   data_size = sizeof(SetGraphColoredMessage_data_t);
00440   data_ptr  = malloc(data_size);
00441   memset(data_ptr, 0, data_size);
00442   data      = (SetGraphColoredMessage_data_t *)data_ptr;
00443   add_fieldinfo(IFT_BOOL, "graph_colored", 1, &data->graph_colored);
00444 }
00445 
00446 /** Destructor */
00447 SkillerDebugInterface::SetGraphColoredMessage::~SetGraphColoredMessage()
00448 {
00449   free(data_ptr);
00450 }
00451 
00452 /** Copy constructor.
00453  * @param m message to copy from
00454  */
00455 SkillerDebugInterface::SetGraphColoredMessage::SetGraphColoredMessage(const SetGraphColoredMessage *m) : Message("SetGraphColoredMessage")
00456 {
00457   data_size = m->data_size;
00458   data_ptr  = malloc(data_size);
00459   memcpy(data_ptr, m->data_ptr, data_size);
00460   data      = (SetGraphColoredMessage_data_t *)data_ptr;
00461 }
00462
00463 /* Methods */
00464 /** Get graph_colored value.
00465  * 
00466       True if the graph is colored, false otherwise.
00467     
00468  * @return graph_colored value
00469  */
00470 bool
00471 SkillerDebugInterface::SetGraphColoredMessage::is_graph_colored() const
00472 {
00473   return data->graph_colored;
00474 }
00475 
00476 /** Get maximum length of graph_colored value.
00477  * @return length of graph_colored value, can be length of the array or number of 
00478  * maximum number of characters for a string
00479  */
00480 size_t
00481 SkillerDebugInterface::SetGraphColoredMessage::maxlenof_graph_colored() const
00482 {
00483   return 1;
00484 }
00485 
00486 /** Set graph_colored value.
00487  * 
00488       True if the graph is colored, false otherwise.
00489     
00490  * @param new_graph_colored new graph_colored value
00491  */
00492 void
00493 SkillerDebugInterface::SetGraphColoredMessage::set_graph_colored(const bool new_graph_colored)
00494 {
00495   data->graph_colored = new_graph_colored;
00496 }
00497 
00498 /** Clone this message.
00499  * Produces a message of the same type as this message and copies the
00500  * data to the new message.
00501  * @return clone of this message
00502  */
00503 Message *
00504 SkillerDebugInterface::SetGraphColoredMessage::clone() const
00505 {
00506   return new SkillerDebugInterface::SetGraphColoredMessage(this);
00507 }
00508 /** Check if message is valid and can be enqueued.
00509  * @param message Message to check
00510  */
00511 bool
00512 SkillerDebugInterface::message_valid(const Message *message) const
00513 {
00514   const SetGraphMessage *m0 = dynamic_cast<const SetGraphMessage *>(message);
00515   if ( m0 != NULL ) {
00516     return true;
00517   }
00518   const SetGraphDirectionMessage *m1 = dynamic_cast<const SetGraphDirectionMessage *>(message);
00519   if ( m1 != NULL ) {
00520     return true;
00521   }
00522   const SetGraphColoredMessage *m2 = dynamic_cast<const SetGraphColoredMessage *>(message);
00523   if ( m2 != NULL ) {
00524     return true;
00525   }
00526   return false;
00527 }
00528 
00529 /// @cond INTERNALS
00530 EXPORT_INTERFACE(SkillerDebugInterface)
00531 /// @endcond
00532 
00533
00534 } // end namespace fawkes