FacialExpressionInterface.cpp

00001
00002 /***************************************************************************
00003  *  FacialExpressionInterface.cpp - Fawkes BlackBoard Interface - FacialExpressionInterface
00004  *
00005  *  Templated created:   Thu Oct 12 10:49:19 2006
00006  *  Copyright  2009  Bahram Maleki-Fard
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/FacialExpressionInterface.h>
00025
00026 #include <core/exceptions/software.h>
00027
00028 #include <cstring>
00029 #include <cstdlib>
00030
00031 namespace fawkes {
00032 
00033 /** @class FacialExpressionInterface <interfaces/FacialExpressionInterface.h>
00034  * FacialExpressionInterface Fawkes BlackBoard Interface.
00035  * 
00036       Interface to acces facial expressions on display (RCSoft)
00037     
00038  * @ingroup FawkesInterfaces
00039  */
00040
00041
00042 
00043 /** Constructor */
00044 FacialExpressionInterface::FacialExpressionInterface() : Interface()
00045 {
00046   data_size = sizeof(FacialExpressionInterface_data_t);
00047   data_ptr  = malloc(data_size);
00048   data      = (FacialExpressionInterface_data_t *)data_ptr;
00049   memset(data_ptr, 0, data_size);
00050   add_messageinfo("MoveBrowsMessage");
00051   add_messageinfo("MoveEyesMessage");
00052   add_messageinfo("MoveJowlMessage");
00053   add_messageinfo("MoveMouthMessage");
00054   unsigned char tmp_hash[] = {0x1, 0xbd, 0xc6, 0x65, 0xb3, 0x10, 0xcb, 0x5f, 0xe8, 0x78, 0xdd, 0x6, 0xe, 0x82, 0x7f, 0x80};
00055   set_hash(tmp_hash);
00056 }
00057 
00058 /** Destructor */
00059 FacialExpressionInterface::~FacialExpressionInterface()
00060 {
00061   free(data_ptr);
00062 }
00063 /* Methods */
00064 /** Get brows_action value.
00065  * Type of action of brows
00066  * @return brows_action value
00067  */
00068 FacialExpressionInterface::brows_t
00069 FacialExpressionInterface::brows_action() const
00070 {
00071   return data->brows_action;
00072 }
00073 
00074 /** Get maximum length of brows_action value.
00075  * @return length of brows_action value, can be length of the array or number of 
00076  * maximum number of characters for a string
00077  */
00078 size_t
00079 FacialExpressionInterface::maxlenof_brows_action() const
00080 {
00081   return 1;
00082 }
00083 
00084 /** Set brows_action value.
00085  * Type of action of brows
00086  * @param new_brows_action new brows_action value
00087  */
00088 void
00089 FacialExpressionInterface::set_brows_action(const brows_t new_brows_action)
00090 {
00091   data->brows_action = new_brows_action;
00092 }
00093 
00094 /** Get eyes_action value.
00095  * Type of action of eyes
00096  * @return eyes_action value
00097  */
00098 FacialExpressionInterface::eyes_t
00099 FacialExpressionInterface::eyes_action() const
00100 {
00101   return data->eyes_action;
00102 }
00103 
00104 /** Get maximum length of eyes_action value.
00105  * @return length of eyes_action value, can be length of the array or number of 
00106  * maximum number of characters for a string
00107  */
00108 size_t
00109 FacialExpressionInterface::maxlenof_eyes_action() const
00110 {
00111   return 1;
00112 }
00113 
00114 /** Set eyes_action value.
00115  * Type of action of eyes
00116  * @param new_eyes_action new eyes_action value
00117  */
00118 void
00119 FacialExpressionInterface::set_eyes_action(const eyes_t new_eyes_action)
00120 {
00121   data->eyes_action = new_eyes_action;
00122 }
00123 
00124 /** Get jowl_action value.
00125  * Type of action of jown
00126  * @return jowl_action value
00127  */
00128 FacialExpressionInterface::jowl_t
00129 FacialExpressionInterface::jowl_action() const
00130 {
00131   return data->jowl_action;
00132 }
00133 
00134 /** Get maximum length of jowl_action value.
00135  * @return length of jowl_action value, can be length of the array or number of 
00136  * maximum number of characters for a string
00137  */
00138 size_t
00139 FacialExpressionInterface::maxlenof_jowl_action() const
00140 {
00141   return 1;
00142 }
00143 
00144 /** Set jowl_action value.
00145  * Type of action of jown
00146  * @param new_jowl_action new jowl_action value
00147  */
00148 void
00149 FacialExpressionInterface::set_jowl_action(const jowl_t new_jowl_action)
00150 {
00151   data->jowl_action = new_jowl_action;
00152 }
00153 
00154 /** Get mouth_action value.
00155  * Type of action of mouth
00156  * @return mouth_action value
00157  */
00158 FacialExpressionInterface::mouth_t
00159 FacialExpressionInterface::mouth_action() const
00160 {
00161   return data->mouth_action;
00162 }
00163 
00164 /** Get maximum length of mouth_action value.
00165  * @return length of mouth_action value, can be length of the array or number of 
00166  * maximum number of characters for a string
00167  */
00168 size_t
00169 FacialExpressionInterface::maxlenof_mouth_action() const
00170 {
00171   return 1;
00172 }
00173 
00174 /** Set mouth_action value.
00175  * Type of action of mouth
00176  * @param new_mouth_action new mouth_action value
00177  */
00178 void
00179 FacialExpressionInterface::set_mouth_action(const mouth_t new_mouth_action)
00180 {
00181   data->mouth_action = new_mouth_action;
00182 }
00183
00184 /* =========== message create =========== */
00185 Message *
00186 FacialExpressionInterface::create_message(const char *type) const
00187 {
00188   if ( strncmp("MoveBrowsMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00189     return new MoveBrowsMessage();
00190   } else if ( strncmp("MoveEyesMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00191     return new MoveEyesMessage();
00192   } else if ( strncmp("MoveJowlMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00193     return new MoveJowlMessage();
00194   } else if ( strncmp("MoveMouthMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00195     return new MoveMouthMessage();
00196   } else {
00197     throw UnknownTypeException("The given type '%s' does not match any known "
00198                                "message type for this interface type.", type);
00199   }
00200 }
00201
00202 
00203 /** Copy values from other interface.
00204  * @param other other interface to copy values from
00205  */
00206 void
00207 FacialExpressionInterface::copy_values(const Interface *other)
00208 {
00209   const FacialExpressionInterface *oi = dynamic_cast<const FacialExpressionInterface *>(other);
00210   if (oi == NULL) {
00211     throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
00212                                 type(), other->type());
00213   }
00214   memcpy(data, oi->data, sizeof(FacialExpressionInterface_data_t));
00215 }
00216
00217 /* =========== messages =========== */
00218 /** @class FacialExpressionInterface::MoveBrowsMessage <interfaces/FacialExpressionInterface.h>
00219  * MoveBrowsMessage Fawkes BlackBoard Interface Message.
00220  * 
00221     
00222  */
00223
00224 
00225 /** Constructor with initial values.
00226  * @param ini_brows_action initial value for brows_action
00227  */
00228 FacialExpressionInterface::MoveBrowsMessage::MoveBrowsMessage(const brows_t ini_brows_action) : Message("MoveBrowsMessage")
00229 {
00230   data_size = sizeof(MoveBrowsMessage_data_t);
00231   data_ptr  = malloc(data_size);
00232   memset(data_ptr, 0, data_size);
00233   data      = (MoveBrowsMessage_data_t *)data_ptr;
00234   data->brows_action = ini_brows_action;
00235 }
00236 /** Constructor */
00237 FacialExpressionInterface::MoveBrowsMessage::MoveBrowsMessage() : Message("MoveBrowsMessage")
00238 {
00239   data_size = sizeof(MoveBrowsMessage_data_t);
00240   data_ptr  = malloc(data_size);
00241   memset(data_ptr, 0, data_size);
00242   data      = (MoveBrowsMessage_data_t *)data_ptr;
00243 }
00244 
00245 /** Destructor */
00246 FacialExpressionInterface::MoveBrowsMessage::~MoveBrowsMessage()
00247 {
00248   free(data_ptr);
00249 }
00250 
00251 /** Copy constructor.
00252  * @param m message to copy from
00253  */
00254 FacialExpressionInterface::MoveBrowsMessage::MoveBrowsMessage(const MoveBrowsMessage *m) : Message("MoveBrowsMessage")
00255 {
00256   data_size = m->data_size;
00257   data_ptr  = malloc(data_size);
00258   memcpy(data_ptr, m->data_ptr, data_size);
00259   data      = (MoveBrowsMessage_data_t *)data_ptr;
00260 }
00261
00262 /* Methods */
00263 /** Get brows_action value.
00264  * Type of action of brows
00265  * @return brows_action value
00266  */
00267 FacialExpressionInterface::brows_t
00268 FacialExpressionInterface::MoveBrowsMessage::brows_action() const
00269 {
00270   return data->brows_action;
00271 }
00272 
00273 /** Get maximum length of brows_action value.
00274  * @return length of brows_action value, can be length of the array or number of 
00275  * maximum number of characters for a string
00276  */
00277 size_t
00278 FacialExpressionInterface::MoveBrowsMessage::maxlenof_brows_action() const
00279 {
00280   return 1;
00281 }
00282 
00283 /** Set brows_action value.
00284  * Type of action of brows
00285  * @param new_brows_action new brows_action value
00286  */
00287 void
00288 FacialExpressionInterface::MoveBrowsMessage::set_brows_action(const brows_t new_brows_action)
00289 {
00290   data->brows_action = new_brows_action;
00291 }
00292 
00293 /** Clone this message.
00294  * Produces a message of the same type as this message and copies the
00295  * data to the new message.
00296  * @return clone of this message
00297  */
00298 Message *
00299 FacialExpressionInterface::MoveBrowsMessage::clone() const
00300 {
00301   return new FacialExpressionInterface::MoveBrowsMessage(this);
00302 }
00303 /** @class FacialExpressionInterface::MoveEyesMessage <interfaces/FacialExpressionInterface.h>
00304  * MoveEyesMessage Fawkes BlackBoard Interface Message.
00305  * 
00306     
00307  */
00308
00309 
00310 /** Constructor with initial values.
00311  * @param ini_eyes_action initial value for eyes_action
00312  */
00313 FacialExpressionInterface::MoveEyesMessage::MoveEyesMessage(const eyes_t ini_eyes_action) : Message("MoveEyesMessage")
00314 {
00315   data_size = sizeof(MoveEyesMessage_data_t);
00316   data_ptr  = malloc(data_size);
00317   memset(data_ptr, 0, data_size);
00318   data      = (MoveEyesMessage_data_t *)data_ptr;
00319   data->eyes_action = ini_eyes_action;
00320 }
00321 /** Constructor */
00322 FacialExpressionInterface::MoveEyesMessage::MoveEyesMessage() : Message("MoveEyesMessage")
00323 {
00324   data_size = sizeof(MoveEyesMessage_data_t);
00325   data_ptr  = malloc(data_size);
00326   memset(data_ptr, 0, data_size);
00327   data      = (MoveEyesMessage_data_t *)data_ptr;
00328 }
00329 
00330 /** Destructor */
00331 FacialExpressionInterface::MoveEyesMessage::~MoveEyesMessage()
00332 {
00333   free(data_ptr);
00334 }
00335 
00336 /** Copy constructor.
00337  * @param m message to copy from
00338  */
00339 FacialExpressionInterface::MoveEyesMessage::MoveEyesMessage(const MoveEyesMessage *m) : Message("MoveEyesMessage")
00340 {
00341   data_size = m->data_size;
00342   data_ptr  = malloc(data_size);
00343   memcpy(data_ptr, m->data_ptr, data_size);
00344   data      = (MoveEyesMessage_data_t *)data_ptr;
00345 }
00346
00347 /* Methods */
00348 /** Get eyes_action value.
00349  * Type of action of eyes
00350  * @return eyes_action value
00351  */
00352 FacialExpressionInterface::eyes_t
00353 FacialExpressionInterface::MoveEyesMessage::eyes_action() const
00354 {
00355   return data->eyes_action;
00356 }
00357 
00358 /** Get maximum length of eyes_action value.
00359  * @return length of eyes_action value, can be length of the array or number of 
00360  * maximum number of characters for a string
00361  */
00362 size_t
00363 FacialExpressionInterface::MoveEyesMessage::maxlenof_eyes_action() const
00364 {
00365   return 1;
00366 }
00367 
00368 /** Set eyes_action value.
00369  * Type of action of eyes
00370  * @param new_eyes_action new eyes_action value
00371  */
00372 void
00373 FacialExpressionInterface::MoveEyesMessage::set_eyes_action(const eyes_t new_eyes_action)
00374 {
00375   data->eyes_action = new_eyes_action;
00376 }
00377 
00378 /** Clone this message.
00379  * Produces a message of the same type as this message and copies the
00380  * data to the new message.
00381  * @return clone of this message
00382  */
00383 Message *
00384 FacialExpressionInterface::MoveEyesMessage::clone() const
00385 {
00386   return new FacialExpressionInterface::MoveEyesMessage(this);
00387 }
00388 /** @class FacialExpressionInterface::MoveJowlMessage <interfaces/FacialExpressionInterface.h>
00389  * MoveJowlMessage Fawkes BlackBoard Interface Message.
00390  * 
00391     
00392  */
00393
00394 
00395 /** Constructor with initial values.
00396  * @param ini_jowl_action initial value for jowl_action
00397  */
00398 FacialExpressionInterface::MoveJowlMessage::MoveJowlMessage(const jowl_t ini_jowl_action) : Message("MoveJowlMessage")
00399 {
00400   data_size = sizeof(MoveJowlMessage_data_t);
00401   data_ptr  = malloc(data_size);
00402   memset(data_ptr, 0, data_size);
00403   data      = (MoveJowlMessage_data_t *)data_ptr;
00404   data->jowl_action = ini_jowl_action;
00405 }
00406 /** Constructor */
00407 FacialExpressionInterface::MoveJowlMessage::MoveJowlMessage() : Message("MoveJowlMessage")
00408 {
00409   data_size = sizeof(MoveJowlMessage_data_t);
00410   data_ptr  = malloc(data_size);
00411   memset(data_ptr, 0, data_size);
00412   data      = (MoveJowlMessage_data_t *)data_ptr;
00413 }
00414 
00415 /** Destructor */
00416 FacialExpressionInterface::MoveJowlMessage::~MoveJowlMessage()
00417 {
00418   free(data_ptr);
00419 }
00420 
00421 /** Copy constructor.
00422  * @param m message to copy from
00423  */
00424 FacialExpressionInterface::MoveJowlMessage::MoveJowlMessage(const MoveJowlMessage *m) : Message("MoveJowlMessage")
00425 {
00426   data_size = m->data_size;
00427   data_ptr  = malloc(data_size);
00428   memcpy(data_ptr, m->data_ptr, data_size);
00429   data      = (MoveJowlMessage_data_t *)data_ptr;
00430 }
00431
00432 /* Methods */
00433 /** Get jowl_action value.
00434  * Type of action of jown
00435  * @return jowl_action value
00436  */
00437 FacialExpressionInterface::jowl_t
00438 FacialExpressionInterface::MoveJowlMessage::jowl_action() const
00439 {
00440   return data->jowl_action;
00441 }
00442 
00443 /** Get maximum length of jowl_action value.
00444  * @return length of jowl_action value, can be length of the array or number of 
00445  * maximum number of characters for a string
00446  */
00447 size_t
00448 FacialExpressionInterface::MoveJowlMessage::maxlenof_jowl_action() const
00449 {
00450   return 1;
00451 }
00452 
00453 /** Set jowl_action value.
00454  * Type of action of jown
00455  * @param new_jowl_action new jowl_action value
00456  */
00457 void
00458 FacialExpressionInterface::MoveJowlMessage::set_jowl_action(const jowl_t new_jowl_action)
00459 {
00460   data->jowl_action = new_jowl_action;
00461 }
00462 
00463 /** Clone this message.
00464  * Produces a message of the same type as this message and copies the
00465  * data to the new message.
00466  * @return clone of this message
00467  */
00468 Message *
00469 FacialExpressionInterface::MoveJowlMessage::clone() const
00470 {
00471   return new FacialExpressionInterface::MoveJowlMessage(this);
00472 }
00473 /** @class FacialExpressionInterface::MoveMouthMessage <interfaces/FacialExpressionInterface.h>
00474  * MoveMouthMessage Fawkes BlackBoard Interface Message.
00475  * 
00476     
00477  */
00478
00479 
00480 /** Constructor with initial values.
00481  * @param ini_mouth_action initial value for mouth_action
00482  */
00483 FacialExpressionInterface::MoveMouthMessage::MoveMouthMessage(const mouth_t ini_mouth_action) : Message("MoveMouthMessage")
00484 {
00485   data_size = sizeof(MoveMouthMessage_data_t);
00486   data_ptr  = malloc(data_size);
00487   memset(data_ptr, 0, data_size);
00488   data      = (MoveMouthMessage_data_t *)data_ptr;
00489   data->mouth_action = ini_mouth_action;
00490 }
00491 /** Constructor */
00492 FacialExpressionInterface::MoveMouthMessage::MoveMouthMessage() : Message("MoveMouthMessage")
00493 {
00494   data_size = sizeof(MoveMouthMessage_data_t);
00495   data_ptr  = malloc(data_size);
00496   memset(data_ptr, 0, data_size);
00497   data      = (MoveMouthMessage_data_t *)data_ptr;
00498 }
00499 
00500 /** Destructor */
00501 FacialExpressionInterface::MoveMouthMessage::~MoveMouthMessage()
00502 {
00503   free(data_ptr);
00504 }
00505 
00506 /** Copy constructor.
00507  * @param m message to copy from
00508  */
00509 FacialExpressionInterface::MoveMouthMessage::MoveMouthMessage(const MoveMouthMessage *m) : Message("MoveMouthMessage")
00510 {
00511   data_size = m->data_size;
00512   data_ptr  = malloc(data_size);
00513   memcpy(data_ptr, m->data_ptr, data_size);
00514   data      = (MoveMouthMessage_data_t *)data_ptr;
00515 }
00516
00517 /* Methods */
00518 /** Get mouth_action value.
00519  * Type of action of mouth
00520  * @return mouth_action value
00521  */
00522 FacialExpressionInterface::mouth_t
00523 FacialExpressionInterface::MoveMouthMessage::mouth_action() const
00524 {
00525   return data->mouth_action;
00526 }
00527 
00528 /** Get maximum length of mouth_action value.
00529  * @return length of mouth_action value, can be length of the array or number of 
00530  * maximum number of characters for a string
00531  */
00532 size_t
00533 FacialExpressionInterface::MoveMouthMessage::maxlenof_mouth_action() const
00534 {
00535   return 1;
00536 }
00537 
00538 /** Set mouth_action value.
00539  * Type of action of mouth
00540  * @param new_mouth_action new mouth_action value
00541  */
00542 void
00543 FacialExpressionInterface::MoveMouthMessage::set_mouth_action(const mouth_t new_mouth_action)
00544 {
00545   data->mouth_action = new_mouth_action;
00546 }
00547 
00548 /** Clone this message.
00549  * Produces a message of the same type as this message and copies the
00550  * data to the new message.
00551  * @return clone of this message
00552  */
00553 Message *
00554 FacialExpressionInterface::MoveMouthMessage::clone() const
00555 {
00556   return new FacialExpressionInterface::MoveMouthMessage(this);
00557 }
00558 /** Check if message is valid and can be enqueued.
00559  * @param message Message to check
00560  */
00561 bool
00562 FacialExpressionInterface::message_valid(const Message *message) const
00563 {
00564   const MoveBrowsMessage *m0 = dynamic_cast<const MoveBrowsMessage *>(message);
00565   if ( m0 != NULL ) {
00566     return true;
00567   }
00568   const MoveEyesMessage *m1 = dynamic_cast<const MoveEyesMessage *>(message);
00569   if ( m1 != NULL ) {
00570     return true;
00571   }
00572   const MoveJowlMessage *m2 = dynamic_cast<const MoveJowlMessage *>(message);
00573   if ( m2 != NULL ) {
00574     return true;
00575   }
00576   const MoveMouthMessage *m3 = dynamic_cast<const MoveMouthMessage *>(message);
00577   if ( m3 != NULL ) {
00578     return true;
00579   }
00580   return false;
00581 }
00582 
00583 /// @cond INTERNALS
00584 EXPORT_INTERFACE(FacialExpressionInterface)
00585 /// @endcond
00586 
00587
00588 } // end namespace fawkes