FacerInterface.cpp

00001
00002 /***************************************************************************
00003  *  FacerInterface.cpp - Fawkes BlackBoard Interface - FacerInterface
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/FacerInterface.h>
00025
00026 #include <core/exceptions/software.h>
00027
00028 #include <cstring>
00029 #include <cstdlib>
00030
00031 namespace fawkes {
00032 
00033 /** @class FacerInterface <interfaces/FacerInterface.h>
00034  * FacerInterface Fawkes BlackBoard Interface.
00035  * 
00036       The interface provides access to the face recognition plugin
00037       (facer). It provides basic status information about facer and
00038       allows for setting a specific mode and access the resolut.
00039       calling skills via messages. It can also be used to manually
00040       restart the Lua interpreter if something is wedged.
00041     
00042  * @ingroup FawkesInterfaces
00043  */
00044
00045
00046 
00047 /** Constructor */
00048 FacerInterface::FacerInterface() : Interface()
00049 {
00050   data_size = sizeof(FacerInterface_data_t);
00051   data_ptr  = malloc(data_size);
00052   data      = (FacerInterface_data_t *)data_ptr;
00053   memset(data_ptr, 0, data_size);
00054   add_fieldinfo(IFT_UINT, "num_identities", 1, &data->num_identities);
00055   add_fieldinfo(IFT_UINT, "recognized_identity", 1, &data->recognized_identity);
00056   add_fieldinfo(IFT_STRING, "recognized_name", 64, data->recognized_name);
00057   add_fieldinfo(IFT_UINT, "num_detections", 1, &data->num_detections);
00058   add_fieldinfo(IFT_UINT, "num_recognitions", 1, &data->num_recognitions);
00059   add_fieldinfo(IFT_UINT, "most_likely_identity", 1, &data->most_likely_identity);
00060   add_fieldinfo(IFT_FLOAT, "history_ratio", 1, &data->history_ratio);
00061   add_fieldinfo(IFT_FLOAT, "sec_since_detection", 1, &data->sec_since_detection);
00062   add_fieldinfo(IFT_INT, "visibility_history", 1, &data->visibility_history);
00063   add_fieldinfo(IFT_BOOL, "learning_in_progress", 1, &data->learning_in_progress);
00064   add_fieldinfo(IFT_FLOAT, "recording_progress", 1, &data->recording_progress);
00065   add_fieldinfo(IFT_FLOAT, "bearing", 1, &data->bearing);
00066   add_fieldinfo(IFT_FLOAT, "slope", 1, &data->slope);
00067   add_fieldinfo(IFT_UINT, "requested_index", 1, &data->requested_index);
00068   add_fieldinfo(IFT_STRING, "requested_name", 64, data->requested_name);
00069   add_messageinfo("LearnFaceMessage");
00070   add_messageinfo("SetOpmodeMessage");
00071   add_messageinfo("EnableIdentityMessage");
00072   add_messageinfo("SetNameMessage");
00073   add_messageinfo("GetNameMessage");
00074   unsigned char tmp_hash[] = {0x2b, 0x6e, 0x8c, 0x6f, 0x9d, 0x2a, 0x9a, 0x3a, 0xe, 0x4, 0x58, 0x50, 0xa4, 0x60, 0x79, 0xa6};
00075   set_hash(tmp_hash);
00076 }
00077 
00078 /** Destructor */
00079 FacerInterface::~FacerInterface()
00080 {
00081   free(data_ptr);
00082 }
00083 /* Methods */
00084 /** Get opmode value.
00085  * 
00086       Current opmode.
00087     
00088  * @return opmode value
00089  */
00090 FacerInterface::if_facer_opmode_t
00091 FacerInterface::opmode() const
00092 {
00093   return data->opmode;
00094 }
00095 
00096 /** Get maximum length of opmode value.
00097  * @return length of opmode value, can be length of the array or number of 
00098  * maximum number of characters for a string
00099  */
00100 size_t
00101 FacerInterface::maxlenof_opmode() const
00102 {
00103   return 1;
00104 }
00105 
00106 /** Set opmode value.
00107  * 
00108       Current opmode.
00109     
00110  * @param new_opmode new opmode value
00111  */
00112 void
00113 FacerInterface::set_opmode(const if_facer_opmode_t new_opmode)
00114 {
00115   data->opmode = new_opmode;
00116 }
00117 
00118 /** Get num_identities value.
00119  * 
00120       The number of identities in the database.
00121     
00122  * @return num_identities value
00123  */
00124 unsigned int
00125 FacerInterface::num_identities() const
00126 {
00127   return data->num_identities;
00128 }
00129 
00130 /** Get maximum length of num_identities value.
00131  * @return length of num_identities value, can be length of the array or number of 
00132  * maximum number of characters for a string
00133  */
00134 size_t
00135 FacerInterface::maxlenof_num_identities() const
00136 {
00137   return 1;
00138 }
00139 
00140 /** Set num_identities value.
00141  * 
00142       The number of identities in the database.
00143     
00144  * @param new_num_identities new num_identities value
00145  */
00146 void
00147 FacerInterface::set_num_identities(const unsigned int new_num_identities)
00148 {
00149   data->num_identities = new_num_identities;
00150 }
00151 
00152 /** Get recognized_identity value.
00153  * 
00154       The index of the recognized identity.
00155     
00156  * @return recognized_identity value
00157  */
00158 unsigned int
00159 FacerInterface::recognized_identity() const
00160 {
00161   return data->recognized_identity;
00162 }
00163 
00164 /** Get maximum length of recognized_identity value.
00165  * @return length of recognized_identity value, can be length of the array or number of 
00166  * maximum number of characters for a string
00167  */
00168 size_t
00169 FacerInterface::maxlenof_recognized_identity() const
00170 {
00171   return 1;
00172 }
00173 
00174 /** Set recognized_identity value.
00175  * 
00176       The index of the recognized identity.
00177     
00178  * @param new_recognized_identity new recognized_identity value
00179  */
00180 void
00181 FacerInterface::set_recognized_identity(const unsigned int new_recognized_identity)
00182 {
00183   data->recognized_identity = new_recognized_identity;
00184 }
00185 
00186 /** Get recognized_name value.
00187  * 
00188       The name of the recognized identity.
00189     
00190  * @return recognized_name value
00191  */
00192 char *
00193 FacerInterface::recognized_name() const
00194 {
00195   return data->recognized_name;
00196 }
00197 
00198 /** Get maximum length of recognized_name value.
00199  * @return length of recognized_name value, can be length of the array or number of 
00200  * maximum number of characters for a string
00201  */
00202 size_t
00203 FacerInterface::maxlenof_recognized_name() const
00204 {
00205   return 64;
00206 }
00207 
00208 /** Set recognized_name value.
00209  * 
00210       The name of the recognized identity.
00211     
00212  * @param new_recognized_name new recognized_name value
00213  */
00214 void
00215 FacerInterface::set_recognized_name(const char * new_recognized_name)
00216 {
00217   strncpy(data->recognized_name, new_recognized_name, sizeof(data->recognized_name));
00218 }
00219 
00220 /** Get num_detections value.
00221  * 
00222       Number of currently detected faces.
00223     
00224  * @return num_detections value
00225  */
00226 unsigned int
00227 FacerInterface::num_detections() const
00228 {
00229   return data->num_detections;
00230 }
00231 
00232 /** Get maximum length of num_detections value.
00233  * @return length of num_detections value, can be length of the array or number of 
00234  * maximum number of characters for a string
00235  */
00236 size_t
00237 FacerInterface::maxlenof_num_detections() const
00238 {
00239   return 1;
00240 }
00241 
00242 /** Set num_detections value.
00243  * 
00244       Number of currently detected faces.
00245     
00246  * @param new_num_detections new num_detections value
00247  */
00248 void
00249 FacerInterface::set_num_detections(const unsigned int new_num_detections)
00250 {
00251   data->num_detections = new_num_detections;
00252 }
00253 
00254 /** Get num_recognitions value.
00255  * 
00256       Number of recognized faces.
00257     
00258  * @return num_recognitions value
00259  */
00260 unsigned int
00261 FacerInterface::num_recognitions() const
00262 {
00263   return data->num_recognitions;
00264 }
00265 
00266 /** Get maximum length of num_recognitions value.
00267  * @return length of num_recognitions value, can be length of the array or number of 
00268  * maximum number of characters for a string
00269  */
00270 size_t
00271 FacerInterface::maxlenof_num_recognitions() const
00272 {
00273   return 1;
00274 }
00275 
00276 /** Set num_recognitions value.
00277  * 
00278       Number of recognized faces.
00279     
00280  * @param new_num_recognitions new num_recognitions value
00281  */
00282 void
00283 FacerInterface::set_num_recognitions(const unsigned int new_num_recognitions)
00284 {
00285   data->num_recognitions = new_num_recognitions;
00286 }
00287 
00288 /** Get most_likely_identity value.
00289  * 
00290       The identity that was recognized most prevalently.
00291     
00292  * @return most_likely_identity value
00293  */
00294 unsigned int
00295 FacerInterface::most_likely_identity() const
00296 {
00297   return data->most_likely_identity;
00298 }
00299 
00300 /** Get maximum length of most_likely_identity value.
00301  * @return length of most_likely_identity value, can be length of the array or number of 
00302  * maximum number of characters for a string
00303  */
00304 size_t
00305 FacerInterface::maxlenof_most_likely_identity() const
00306 {
00307   return 1;
00308 }
00309 
00310 /** Set most_likely_identity value.
00311  * 
00312       The identity that was recognized most prevalently.
00313     
00314  * @param new_most_likely_identity new most_likely_identity value
00315  */
00316 void
00317 FacerInterface::set_most_likely_identity(const unsigned int new_most_likely_identity)
00318 {
00319   data->most_likely_identity = new_most_likely_identity;
00320 }
00321 
00322 /** Get history_ratio value.
00323  * 
00324       The ratio of the most likely identity showing up in the history
00325       and the length of the history.
00326     
00327  * @return history_ratio value
00328  */
00329 float
00330 FacerInterface::history_ratio() const
00331 {
00332   return data->history_ratio;
00333 }
00334 
00335 /** Get maximum length of history_ratio value.
00336  * @return length of history_ratio value, can be length of the array or number of 
00337  * maximum number of characters for a string
00338  */
00339 size_t
00340 FacerInterface::maxlenof_history_ratio() const
00341 {
00342   return 1;
00343 }
00344 
00345 /** Set history_ratio value.
00346  * 
00347       The ratio of the most likely identity showing up in the history
00348       and the length of the history.
00349     
00350  * @param new_history_ratio new history_ratio value
00351  */
00352 void
00353 FacerInterface::set_history_ratio(const float new_history_ratio)
00354 {
00355   data->history_ratio = new_history_ratio;
00356 }
00357 
00358 /** Get sec_since_detection value.
00359  * 
00360       Time in seconds since the last successful detection.
00361     
00362  * @return sec_since_detection value
00363  */
00364 float
00365 FacerInterface::sec_since_detection() const
00366 {
00367   return data->sec_since_detection;
00368 }
00369 
00370 /** Get maximum length of sec_since_detection value.
00371  * @return length of sec_since_detection value, can be length of the array or number of 
00372  * maximum number of characters for a string
00373  */
00374 size_t
00375 FacerInterface::maxlenof_sec_since_detection() const
00376 {
00377   return 1;
00378 }
00379 
00380 /** Set sec_since_detection value.
00381  * 
00382       Time in seconds since the last successful detection.
00383     
00384  * @param new_sec_since_detection new sec_since_detection value
00385  */
00386 void
00387 FacerInterface::set_sec_since_detection(const float new_sec_since_detection)
00388 {
00389   data->sec_since_detection = new_sec_since_detection;
00390 }
00391 
00392 /** Get visibility_history value.
00393  * 
00394       The number of consecutive sighting ( <= 1 ) and non-sightings
00395       ( >= -1 ), respectively.
00396     
00397  * @return visibility_history value
00398  */
00399 int
00400 FacerInterface::visibility_history() const
00401 {
00402   return data->visibility_history;
00403 }
00404 
00405 /** Get maximum length of visibility_history value.
00406  * @return length of visibility_history value, can be length of the array or number of 
00407  * maximum number of characters for a string
00408  */
00409 size_t
00410 FacerInterface::maxlenof_visibility_history() const
00411 {
00412   return 1;
00413 }
00414 
00415 /** Set visibility_history value.
00416  * 
00417       The number of consecutive sighting ( <= 1 ) and non-sightings
00418       ( >= -1 ), respectively.
00419     
00420  * @param new_visibility_history new visibility_history value
00421  */
00422 void
00423 FacerInterface::set_visibility_history(const int new_visibility_history)
00424 {
00425   data->visibility_history = new_visibility_history;
00426 }
00427 
00428 /** Get learning_in_progress value.
00429  * 
00430       Indicates whether a new identity is currently learnt. If
00431       learning is in progress only "old" faces can be recognized.
00432     
00433  * @return learning_in_progress value
00434  */
00435 bool
00436 FacerInterface::is_learning_in_progress() const
00437 {
00438   return data->learning_in_progress;
00439 }
00440 
00441 /** Get maximum length of learning_in_progress value.
00442  * @return length of learning_in_progress value, can be length of the array or number of 
00443  * maximum number of characters for a string
00444  */
00445 size_t
00446 FacerInterface::maxlenof_learning_in_progress() const
00447 {
00448   return 1;
00449 }
00450 
00451 /** Set learning_in_progress value.
00452  * 
00453       Indicates whether a new identity is currently learnt. If
00454       learning is in progress only "old" faces can be recognized.
00455     
00456  * @param new_learning_in_progress new learning_in_progress value
00457  */
00458 void
00459 FacerInterface::set_learning_in_progress(const bool new_learning_in_progress)
00460 {
00461   data->learning_in_progress = new_learning_in_progress;
00462 }
00463 
00464 /** Get recording_progress value.
00465  * 
00466       Indicates the progress of recording images of a new face.
00467     
00468  * @return recording_progress value
00469  */
00470 float
00471 FacerInterface::recording_progress() const
00472 {
00473   return data->recording_progress;
00474 }
00475 
00476 /** Get maximum length of recording_progress value.
00477  * @return length of recording_progress value, can be length of the array or number of 
00478  * maximum number of characters for a string
00479  */
00480 size_t
00481 FacerInterface::maxlenof_recording_progress() const
00482 {
00483   return 1;
00484 }
00485 
00486 /** Set recording_progress value.
00487  * 
00488       Indicates the progress of recording images of a new face.
00489     
00490  * @param new_recording_progress new recording_progress value
00491  */
00492 void
00493 FacerInterface::set_recording_progress(const float new_recording_progress)
00494 {
00495   data->recording_progress = new_recording_progress;
00496 }
00497 
00498 /** Get bearing value.
00499  * 
00500       The relative bearing to the recognized face in radians.
00501     
00502  * @return bearing value
00503  */
00504 float
00505 FacerInterface::bearing() const
00506 {
00507   return data->bearing;
00508 }
00509 
00510 /** Get maximum length of bearing value.
00511  * @return length of bearing value, can be length of the array or number of 
00512  * maximum number of characters for a string
00513  */
00514 size_t
00515 FacerInterface::maxlenof_bearing() const
00516 {
00517   return 1;
00518 }
00519 
00520 /** Set bearing value.
00521  * 
00522       The relative bearing to the recognized face in radians.
00523     
00524  * @param new_bearing new bearing value
00525  */
00526 void
00527 FacerInterface::set_bearing(const float new_bearing)
00528 {
00529   data->bearing = new_bearing;
00530 }
00531 
00532 /** Get slope value.
00533  * 
00534       The relative slope to the recognized face in radians.
00535     
00536  * @return slope value
00537  */
00538 float
00539 FacerInterface::slope() const
00540 {
00541   return data->slope;
00542 }
00543 
00544 /** Get maximum length of slope value.
00545  * @return length of slope value, can be length of the array or number of 
00546  * maximum number of characters for a string
00547  */
00548 size_t
00549 FacerInterface::maxlenof_slope() const
00550 {
00551   return 1;
00552 }
00553 
00554 /** Set slope value.
00555  * 
00556       The relative slope to the recognized face in radians.
00557     
00558  * @param new_slope new slope value
00559  */
00560 void
00561 FacerInterface::set_slope(const float new_slope)
00562 {
00563   data->slope = new_slope;
00564 }
00565 
00566 /** Get requested_index value.
00567  * 
00568       Index of the identity for which the name was requested.
00569     
00570  * @return requested_index value
00571  */
00572 unsigned int
00573 FacerInterface::requested_index() const
00574 {
00575   return data->requested_index;
00576 }
00577 
00578 /** Get maximum length of requested_index value.
00579  * @return length of requested_index value, can be length of the array or number of 
00580  * maximum number of characters for a string
00581  */
00582 size_t
00583 FacerInterface::maxlenof_requested_index() const
00584 {
00585   return 1;
00586 }
00587 
00588 /** Set requested_index value.
00589  * 
00590       Index of the identity for which the name was requested.
00591     
00592  * @param new_requested_index new requested_index value
00593  */
00594 void
00595 FacerInterface::set_requested_index(const unsigned int new_requested_index)
00596 {
00597   data->requested_index = new_requested_index;
00598 }
00599 
00600 /** Get requested_name value.
00601  * 
00602       Requested name.
00603     
00604  * @return requested_name value
00605  */
00606 char *
00607 FacerInterface::requested_name() const
00608 {
00609   return data->requested_name;
00610 }
00611 
00612 /** Get maximum length of requested_name value.
00613  * @return length of requested_name value, can be length of the array or number of 
00614  * maximum number of characters for a string
00615  */
00616 size_t
00617 FacerInterface::maxlenof_requested_name() const
00618 {
00619   return 64;
00620 }
00621 
00622 /** Set requested_name value.
00623  * 
00624       Requested name.
00625     
00626  * @param new_requested_name new requested_name value
00627  */
00628 void
00629 FacerInterface::set_requested_name(const char * new_requested_name)
00630 {
00631   strncpy(data->requested_name, new_requested_name, sizeof(data->requested_name));
00632 }
00633
00634 /* =========== message create =========== */
00635 Message *
00636 FacerInterface::create_message(const char *type) const
00637 {
00638   if ( strncmp("LearnFaceMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00639     return new LearnFaceMessage();
00640   } else if ( strncmp("SetOpmodeMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00641     return new SetOpmodeMessage();
00642   } else if ( strncmp("EnableIdentityMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00643     return new EnableIdentityMessage();
00644   } else if ( strncmp("SetNameMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00645     return new SetNameMessage();
00646   } else if ( strncmp("GetNameMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00647     return new GetNameMessage();
00648   } else {
00649     throw UnknownTypeException("The given type '%s' does not match any known "
00650                                "message type for this interface type.", type);
00651   }
00652 }
00653
00654 
00655 /** Copy values from other interface.
00656  * @param other other interface to copy values from
00657  */
00658 void
00659 FacerInterface::copy_values(const Interface *other)
00660 {
00661   const FacerInterface *oi = dynamic_cast<const FacerInterface *>(other);
00662   if (oi == NULL) {
00663     throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
00664                                 type(), other->type());
00665   }
00666   memcpy(data, oi->data, sizeof(FacerInterface_data_t));
00667 }
00668
00669 /* =========== messages =========== */
00670 /** @class FacerInterface::LearnFaceMessage <interfaces/FacerInterface.h>
00671  * LearnFaceMessage Fawkes BlackBoard Interface Message.
00672  * 
00673     
00674  */
00675
00676 
00677 /** Constructor with initial values.
00678  * @param ini_name initial value for name
00679  */
00680 FacerInterface::LearnFaceMessage::LearnFaceMessage(const char * ini_name) : Message("LearnFaceMessage")
00681 {
00682   data_size = sizeof(LearnFaceMessage_data_t);
00683   data_ptr  = malloc(data_size);
00684   memset(data_ptr, 0, data_size);
00685   data      = (LearnFaceMessage_data_t *)data_ptr;
00686   strncpy(data->name, ini_name, 64);
00687   add_fieldinfo(IFT_STRING, "name", 64, data->name);
00688 }
00689 /** Constructor */
00690 FacerInterface::LearnFaceMessage::LearnFaceMessage() : Message("LearnFaceMessage")
00691 {
00692   data_size = sizeof(LearnFaceMessage_data_t);
00693   data_ptr  = malloc(data_size);
00694   memset(data_ptr, 0, data_size);
00695   data      = (LearnFaceMessage_data_t *)data_ptr;
00696   add_fieldinfo(IFT_STRING, "name", 64, data->name);
00697 }
00698 
00699 /** Destructor */
00700 FacerInterface::LearnFaceMessage::~LearnFaceMessage()
00701 {
00702   free(data_ptr);
00703 }
00704 
00705 /** Copy constructor.
00706  * @param m message to copy from
00707  */
00708 FacerInterface::LearnFaceMessage::LearnFaceMessage(const LearnFaceMessage *m) : Message("LearnFaceMessage")
00709 {
00710   data_size = m->data_size;
00711   data_ptr  = malloc(data_size);
00712   memcpy(data_ptr, m->data_ptr, data_size);
00713   data      = (LearnFaceMessage_data_t *)data_ptr;
00714 }
00715
00716 /* Methods */
00717 /** Get name value.
00718  * The name assigned to the new identity.
00719  * @return name value
00720  */
00721 char *
00722 FacerInterface::LearnFaceMessage::name() const
00723 {
00724   return data->name;
00725 }
00726 
00727 /** Get maximum length of name value.
00728  * @return length of name value, can be length of the array or number of 
00729  * maximum number of characters for a string
00730  */
00731 size_t
00732 FacerInterface::LearnFaceMessage::maxlenof_name() const
00733 {
00734   return 64;
00735 }
00736 
00737 /** Set name value.
00738  * The name assigned to the new identity.
00739  * @param new_name new name value
00740  */
00741 void
00742 FacerInterface::LearnFaceMessage::set_name(const char * new_name)
00743 {
00744   strncpy(data->name, new_name, sizeof(data->name));
00745 }
00746 
00747 /** Clone this message.
00748  * Produces a message of the same type as this message and copies the
00749  * data to the new message.
00750  * @return clone of this message
00751  */
00752 Message *
00753 FacerInterface::LearnFaceMessage::clone() const
00754 {
00755   return new FacerInterface::LearnFaceMessage(this);
00756 }
00757 /** @class FacerInterface::SetOpmodeMessage <interfaces/FacerInterface.h>
00758  * SetOpmodeMessage Fawkes BlackBoard Interface Message.
00759  * 
00760     
00761  */
00762
00763 
00764 /** Constructor with initial values.
00765  * @param ini_opmode initial value for opmode
00766  */
00767 FacerInterface::SetOpmodeMessage::SetOpmodeMessage(const if_facer_opmode_t ini_opmode) : Message("SetOpmodeMessage")
00768 {
00769   data_size = sizeof(SetOpmodeMessage_data_t);
00770   data_ptr  = malloc(data_size);
00771   memset(data_ptr, 0, data_size);
00772   data      = (SetOpmodeMessage_data_t *)data_ptr;
00773   data->opmode = ini_opmode;
00774 }
00775 /** Constructor */
00776 FacerInterface::SetOpmodeMessage::SetOpmodeMessage() : Message("SetOpmodeMessage")
00777 {
00778   data_size = sizeof(SetOpmodeMessage_data_t);
00779   data_ptr  = malloc(data_size);
00780   memset(data_ptr, 0, data_size);
00781   data      = (SetOpmodeMessage_data_t *)data_ptr;
00782 }
00783 
00784 /** Destructor */
00785 FacerInterface::SetOpmodeMessage::~SetOpmodeMessage()
00786 {
00787   free(data_ptr);
00788 }
00789 
00790 /** Copy constructor.
00791  * @param m message to copy from
00792  */
00793 FacerInterface::SetOpmodeMessage::SetOpmodeMessage(const SetOpmodeMessage *m) : Message("SetOpmodeMessage")
00794 {
00795   data_size = m->data_size;
00796   data_ptr  = malloc(data_size);
00797   memcpy(data_ptr, m->data_ptr, data_size);
00798   data      = (SetOpmodeMessage_data_t *)data_ptr;
00799 }
00800
00801 /* Methods */
00802 /** Get opmode value.
00803  * 
00804       Current opmode.
00805     
00806  * @return opmode value
00807  */
00808 FacerInterface::if_facer_opmode_t
00809 FacerInterface::SetOpmodeMessage::opmode() const
00810 {
00811   return data->opmode;
00812 }
00813 
00814 /** Get maximum length of opmode value.
00815  * @return length of opmode value, can be length of the array or number of 
00816  * maximum number of characters for a string
00817  */
00818 size_t
00819 FacerInterface::SetOpmodeMessage::maxlenof_opmode() const
00820 {
00821   return 1;
00822 }
00823 
00824 /** Set opmode value.
00825  * 
00826       Current opmode.
00827     
00828  * @param new_opmode new opmode value
00829  */
00830 void
00831 FacerInterface::SetOpmodeMessage::set_opmode(const if_facer_opmode_t new_opmode)
00832 {
00833   data->opmode = new_opmode;
00834 }
00835 
00836 /** Clone this message.
00837  * Produces a message of the same type as this message and copies the
00838  * data to the new message.
00839  * @return clone of this message
00840  */
00841 Message *
00842 FacerInterface::SetOpmodeMessage::clone() const
00843 {
00844   return new FacerInterface::SetOpmodeMessage(this);
00845 }
00846 /** @class FacerInterface::EnableIdentityMessage <interfaces/FacerInterface.h>
00847  * EnableIdentityMessage Fawkes BlackBoard Interface Message.
00848  * 
00849     
00850  */
00851
00852 
00853 /** Constructor with initial values.
00854  * @param ini_index initial value for index
00855  * @param ini_enable initial value for enable
00856  */
00857 FacerInterface::EnableIdentityMessage::EnableIdentityMessage(const unsigned int ini_index, const bool ini_enable) : Message("EnableIdentityMessage")
00858 {
00859   data_size = sizeof(EnableIdentityMessage_data_t);
00860   data_ptr  = malloc(data_size);
00861   memset(data_ptr, 0, data_size);
00862   data      = (EnableIdentityMessage_data_t *)data_ptr;
00863   data->index = ini_index;
00864   data->enable = ini_enable;
00865   add_fieldinfo(IFT_UINT, "index", 1, &data->index);
00866   add_fieldinfo(IFT_BOOL, "enable", 1, &data->enable);
00867 }
00868 /** Constructor */
00869 FacerInterface::EnableIdentityMessage::EnableIdentityMessage() : Message("EnableIdentityMessage")
00870 {
00871   data_size = sizeof(EnableIdentityMessage_data_t);
00872   data_ptr  = malloc(data_size);
00873   memset(data_ptr, 0, data_size);
00874   data      = (EnableIdentityMessage_data_t *)data_ptr;
00875   add_fieldinfo(IFT_UINT, "index", 1, &data->index);
00876   add_fieldinfo(IFT_BOOL, "enable", 1, &data->enable);
00877 }
00878 
00879 /** Destructor */
00880 FacerInterface::EnableIdentityMessage::~EnableIdentityMessage()
00881 {
00882   free(data_ptr);
00883 }
00884 
00885 /** Copy constructor.
00886  * @param m message to copy from
00887  */
00888 FacerInterface::EnableIdentityMessage::EnableIdentityMessage(const EnableIdentityMessage *m) : Message("EnableIdentityMessage")
00889 {
00890   data_size = m->data_size;
00891   data_ptr  = malloc(data_size);
00892   memcpy(data_ptr, m->data_ptr, data_size);
00893   data      = (EnableIdentityMessage_data_t *)data_ptr;
00894 }
00895
00896 /* Methods */
00897 /** Get index value.
00898  * Index of the identity.
00899  * @return index value
00900  */
00901 unsigned int
00902 FacerInterface::EnableIdentityMessage::index() const
00903 {
00904   return data->index;
00905 }
00906 
00907 /** Get maximum length of index value.
00908  * @return length of index value, can be length of the array or number of 
00909  * maximum number of characters for a string
00910  */
00911 size_t
00912 FacerInterface::EnableIdentityMessage::maxlenof_index() const
00913 {
00914   return 1;
00915 }
00916 
00917 /** Set index value.
00918  * Index of the identity.
00919  * @param new_index new index value
00920  */
00921 void
00922 FacerInterface::EnableIdentityMessage::set_index(const unsigned int new_index)
00923 {
00924   data->index = new_index;
00925 }
00926 
00927 /** Get enable value.
00928  * En-/disable flag.
00929  * @return enable value
00930  */
00931 bool
00932 FacerInterface::EnableIdentityMessage::is_enable() const
00933 {
00934   return data->enable;
00935 }
00936 
00937 /** Get maximum length of enable value.
00938  * @return length of enable value, can be length of the array or number of 
00939  * maximum number of characters for a string
00940  */
00941 size_t
00942 FacerInterface::EnableIdentityMessage::maxlenof_enable() const
00943 {
00944   return 1;
00945 }
00946 
00947 /** Set enable value.
00948  * En-/disable flag.
00949  * @param new_enable new enable value
00950  */
00951 void
00952 FacerInterface::EnableIdentityMessage::set_enable(const bool new_enable)
00953 {
00954   data->enable = new_enable;
00955 }
00956 
00957 /** Clone this message.
00958  * Produces a message of the same type as this message and copies the
00959  * data to the new message.
00960  * @return clone of this message
00961  */
00962 Message *
00963 FacerInterface::EnableIdentityMessage::clone() const
00964 {
00965   return new FacerInterface::EnableIdentityMessage(this);
00966 }
00967 /** @class FacerInterface::SetNameMessage <interfaces/FacerInterface.h>
00968  * SetNameMessage Fawkes BlackBoard Interface Message.
00969  * 
00970     
00971  */
00972
00973 
00974 /** Constructor with initial values.
00975  * @param ini_index initial value for index
00976  * @param ini_name initial value for name
00977  */
00978 FacerInterface::SetNameMessage::SetNameMessage(const unsigned int ini_index, const char * ini_name) : Message("SetNameMessage")
00979 {
00980   data_size = sizeof(SetNameMessage_data_t);
00981   data_ptr  = malloc(data_size);
00982   memset(data_ptr, 0, data_size);
00983   data      = (SetNameMessage_data_t *)data_ptr;
00984   data->index = ini_index;
00985   strncpy(data->name, ini_name, 64);
00986   add_fieldinfo(IFT_UINT, "index", 1, &data->index);
00987   add_fieldinfo(IFT_STRING, "name", 64, data->name);
00988 }
00989 /** Constructor */
00990 FacerInterface::SetNameMessage::SetNameMessage() : Message("SetNameMessage")
00991 {
00992   data_size = sizeof(SetNameMessage_data_t);
00993   data_ptr  = malloc(data_size);
00994   memset(data_ptr, 0, data_size);
00995   data      = (SetNameMessage_data_t *)data_ptr;
00996   add_fieldinfo(IFT_UINT, "index", 1, &data->index);
00997   add_fieldinfo(IFT_STRING, "name", 64, data->name);
00998 }
00999 
01000 /** Destructor */
01001 FacerInterface::SetNameMessage::~SetNameMessage()
01002 {
01003   free(data_ptr);
01004 }
01005 
01006 /** Copy constructor.
01007  * @param m message to copy from
01008  */
01009 FacerInterface::SetNameMessage::SetNameMessage(const SetNameMessage *m) : Message("SetNameMessage")
01010 {
01011   data_size = m->data_size;
01012   data_ptr  = malloc(data_size);
01013   memcpy(data_ptr, m->data_ptr, data_size);
01014   data      = (SetNameMessage_data_t *)data_ptr;
01015 }
01016
01017 /* Methods */
01018 /** Get index value.
01019  * Index of the identity.
01020  * @return index value
01021  */
01022 unsigned int
01023 FacerInterface::SetNameMessage::index() const
01024 {
01025   return data->index;
01026 }
01027 
01028 /** Get maximum length of index value.
01029  * @return length of index value, can be length of the array or number of 
01030  * maximum number of characters for a string
01031  */
01032 size_t
01033 FacerInterface::SetNameMessage::maxlenof_index() const
01034 {
01035   return 1;
01036 }
01037 
01038 /** Set index value.
01039  * Index of the identity.
01040  * @param new_index new index value
01041  */
01042 void
01043 FacerInterface::SetNameMessage::set_index(const unsigned int new_index)
01044 {
01045   data->index = new_index;
01046 }
01047 
01048 /** Get name value.
01049  * Name of the identity.
01050  * @return name value
01051  */
01052 char *
01053 FacerInterface::SetNameMessage::name() const
01054 {
01055   return data->name;
01056 }
01057 
01058 /** Get maximum length of name value.
01059  * @return length of name value, can be length of the array or number of 
01060  * maximum number of characters for a string
01061  */
01062 size_t
01063 FacerInterface::SetNameMessage::maxlenof_name() const
01064 {
01065   return 64;
01066 }
01067 
01068 /** Set name value.
01069  * Name of the identity.
01070  * @param new_name new name value
01071  */
01072 void
01073 FacerInterface::SetNameMessage::set_name(const char * new_name)
01074 {
01075   strncpy(data->name, new_name, sizeof(data->name));
01076 }
01077 
01078 /** Clone this message.
01079  * Produces a message of the same type as this message and copies the
01080  * data to the new message.
01081  * @return clone of this message
01082  */
01083 Message *
01084 FacerInterface::SetNameMessage::clone() const
01085 {
01086   return new FacerInterface::SetNameMessage(this);
01087 }
01088 /** @class FacerInterface::GetNameMessage <interfaces/FacerInterface.h>
01089  * GetNameMessage Fawkes BlackBoard Interface Message.
01090  * 
01091     
01092  */
01093
01094 
01095 /** Constructor with initial values.
01096  * @param ini_index initial value for index
01097  */
01098 FacerInterface::GetNameMessage::GetNameMessage(const unsigned int ini_index) : Message("GetNameMessage")
01099 {
01100   data_size = sizeof(GetNameMessage_data_t);
01101   data_ptr  = malloc(data_size);
01102   memset(data_ptr, 0, data_size);
01103   data      = (GetNameMessage_data_t *)data_ptr;
01104   data->index = ini_index;
01105   add_fieldinfo(IFT_UINT, "index", 1, &data->index);
01106 }
01107 /** Constructor */
01108 FacerInterface::GetNameMessage::GetNameMessage() : Message("GetNameMessage")
01109 {
01110   data_size = sizeof(GetNameMessage_data_t);
01111   data_ptr  = malloc(data_size);
01112   memset(data_ptr, 0, data_size);
01113   data      = (GetNameMessage_data_t *)data_ptr;
01114   add_fieldinfo(IFT_UINT, "index", 1, &data->index);
01115 }
01116 
01117 /** Destructor */
01118 FacerInterface::GetNameMessage::~GetNameMessage()
01119 {
01120   free(data_ptr);
01121 }
01122 
01123 /** Copy constructor.
01124  * @param m message to copy from
01125  */
01126 FacerInterface::GetNameMessage::GetNameMessage(const GetNameMessage *m) : Message("GetNameMessage")
01127 {
01128   data_size = m->data_size;
01129   data_ptr  = malloc(data_size);
01130   memcpy(data_ptr, m->data_ptr, data_size);
01131   data      = (GetNameMessage_data_t *)data_ptr;
01132 }
01133
01134 /* Methods */
01135 /** Get index value.
01136  * Index of the identity.
01137  * @return index value
01138  */
01139 unsigned int
01140 FacerInterface::GetNameMessage::index() const
01141 {
01142   return data->index;
01143 }
01144 
01145 /** Get maximum length of index value.
01146  * @return length of index value, can be length of the array or number of 
01147  * maximum number of characters for a string
01148  */
01149 size_t
01150 FacerInterface::GetNameMessage::maxlenof_index() const
01151 {
01152   return 1;
01153 }
01154 
01155 /** Set index value.
01156  * Index of the identity.
01157  * @param new_index new index value
01158  */
01159 void
01160 FacerInterface::GetNameMessage::set_index(const unsigned int new_index)
01161 {
01162   data->index = new_index;
01163 }
01164 
01165 /** Clone this message.
01166  * Produces a message of the same type as this message and copies the
01167  * data to the new message.
01168  * @return clone of this message
01169  */
01170 Message *
01171 FacerInterface::GetNameMessage::clone() const
01172 {
01173   return new FacerInterface::GetNameMessage(this);
01174 }
01175 /** Check if message is valid and can be enqueued.
01176  * @param message Message to check
01177  */
01178 bool
01179 FacerInterface::message_valid(const Message *message) const
01180 {
01181   const LearnFaceMessage *m0 = dynamic_cast<const LearnFaceMessage *>(message);
01182   if ( m0 != NULL ) {
01183     return true;
01184   }
01185   const SetOpmodeMessage *m1 = dynamic_cast<const SetOpmodeMessage *>(message);
01186   if ( m1 != NULL ) {
01187     return true;
01188   }
01189   const EnableIdentityMessage *m2 = dynamic_cast<const EnableIdentityMessage *>(message);
01190   if ( m2 != NULL ) {
01191     return true;
01192   }
01193   const SetNameMessage *m3 = dynamic_cast<const SetNameMessage *>(message);
01194   if ( m3 != NULL ) {
01195     return true;
01196   }
01197   const GetNameMessage *m4 = dynamic_cast<const GetNameMessage *>(message);
01198   if ( m4 != NULL ) {
01199     return true;
01200   }
01201   return false;
01202 }
01203 
01204 /// @cond INTERNALS
01205 EXPORT_INTERFACE(FacerInterface)
01206 /// @endcond
01207 
01208
01209 } // end namespace fawkes