Fawkes API  Fawkes Development Version
FacialExpressionInterface.cpp
1 
2 /***************************************************************************
3  * FacialExpressionInterface.cpp - Fawkes BlackBoard Interface - FacialExpressionInterface
4  *
5  * Templated created: Thu Oct 12 10:49:19 2006
6  * Copyright 2009 Bahram Maleki-Fard
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <interfaces/FacialExpressionInterface.h>
25 
26 #include <core/exceptions/software.h>
27 
28 #include <cstring>
29 #include <cstdlib>
30 
31 namespace fawkes {
32 
33 /** @class FacialExpressionInterface <interfaces/FacialExpressionInterface.h>
34  * FacialExpressionInterface Fawkes BlackBoard Interface.
35  *
36  Interface to acces facial expressions on display (RCSoft)
37 
38  * @ingroup FawkesInterfaces
39  */
40 
41 
42 
43 /** Constructor */
44 FacialExpressionInterface::FacialExpressionInterface() : Interface()
45 {
46  data_size = sizeof(FacialExpressionInterface_data_t);
47  data_ptr = malloc(data_size);
48  data = (FacialExpressionInterface_data_t *)data_ptr;
49  data_ts = (interface_data_ts_t *)data_ptr;
50  memset(data_ptr, 0, data_size);
51  add_fieldinfo(IFT_ENUM, "brows_action", 1, &data->brows_action, "brows_action");
52  add_fieldinfo(IFT_ENUM, "eyes_action", 1, &data->eyes_action, "eyes_action");
53  add_fieldinfo(IFT_ENUM, "jowl_action", 1, &data->jowl_action, "jowl_action");
54  add_fieldinfo(IFT_ENUM, "mouth_action", 1, &data->mouth_action, "mouth_action");
55  add_messageinfo("MoveBrowsMessage");
56  add_messageinfo("MoveEyesMessage");
57  add_messageinfo("MoveJowlMessage");
58  add_messageinfo("MoveMouthMessage");
59  unsigned char tmp_hash[] = {0x1, 0xbd, 0xc6, 0x65, 0xb3, 0x10, 0xcb, 0x5f, 0xe8, 0x78, 0xdd, 0x6, 0xe, 0x82, 0x7f, 0x80};
60  set_hash(tmp_hash);
61 }
62 
63 /** Destructor */
64 FacialExpressionInterface::~FacialExpressionInterface()
65 {
66  free(data_ptr);
67 }
68 /** Convert brows_t constant to string.
69  * @param value value to convert to string
70  * @return constant value as string.
71  */
72 const char *
74 {
75  switch (value) {
76  case BROWS_DEFAULT: return "BROWS_DEFAULT";
77  case BROWS_FROWN: return "BROWS_FROWN";
78  case BROWS_LIFT: return "BROWS_LIFT";
79  default: return "UNKNOWN";
80  }
81 }
82 /** Convert eyes_t constant to string.
83  * @param value value to convert to string
84  * @return constant value as string.
85  */
86 const char *
88 {
89  switch (value) {
90  case EYES_DEFAULT: return "EYES_DEFAULT";
91  case EYES_UP: return "EYES_UP";
92  case EYES_DOWN: return "EYES_DOWN";
93  case EYES_LEFT: return "EYES_LEFT";
94  case EYES_RIGHT: return "EYES_RIGHT";
95  case EYES_COOL: return "EYES_COOL";
96  case EYES_CROSS: return "EYES_CROSS";
97  case EYES_HEART: return "EYES_HEART";
98  case EYES_DOLLAR: return "EYES_DOLLAR";
99  default: return "UNKNOWN";
100  }
101 }
102 /** Convert jowl_t constant to string.
103  * @param value value to convert to string
104  * @return constant value as string.
105  */
106 const char *
108 {
109  switch (value) {
110  case JOWL_DEFAULT: return "JOWL_DEFAULT";
111  case JOWL_BLUSH: return "JOWL_BLUSH";
112  case JOWL_TEARS: return "JOWL_TEARS";
113  default: return "UNKNOWN";
114  }
115 }
116 /** Convert mouth_t constant to string.
117  * @param value value to convert to string
118  * @return constant value as string.
119  */
120 const char *
122 {
123  switch (value) {
124  case MOUTH_DEFAULT: return "MOUTH_DEFAULT";
125  case MOUTH_OPEN: return "MOUTH_OPEN";
126  case MOUTH_CLOSE: return "MOUTH_CLOSE";
127  case MOUTH_SMILE: return "MOUTH_SMILE";
128  case MOUTH_SCOWL: return "MOUTH_SCOWL";
129  default: return "UNKNOWN";
130  }
131 }
132 /* Methods */
133 /** Get brows_action value.
134  * Type of action of brows
135  * @return brows_action value
136  */
139 {
140  return (FacialExpressionInterface::brows_t)data->brows_action;
141 }
142 
143 /** Get maximum length of brows_action value.
144  * @return length of brows_action value, can be length of the array or number of
145  * maximum number of characters for a string
146  */
147 size_t
149 {
150  return 1;
151 }
152 
153 /** Set brows_action value.
154  * Type of action of brows
155  * @param new_brows_action new brows_action value
156  */
157 void
159 {
160  data->brows_action = new_brows_action;
161  data_changed = true;
162 }
163 
164 /** Get eyes_action value.
165  * Type of action of eyes
166  * @return eyes_action value
167  */
170 {
171  return (FacialExpressionInterface::eyes_t)data->eyes_action;
172 }
173 
174 /** Get maximum length of eyes_action value.
175  * @return length of eyes_action value, can be length of the array or number of
176  * maximum number of characters for a string
177  */
178 size_t
180 {
181  return 1;
182 }
183 
184 /** Set eyes_action value.
185  * Type of action of eyes
186  * @param new_eyes_action new eyes_action value
187  */
188 void
190 {
191  data->eyes_action = new_eyes_action;
192  data_changed = true;
193 }
194 
195 /** Get jowl_action value.
196  * Type of action of jown
197  * @return jowl_action value
198  */
201 {
202  return (FacialExpressionInterface::jowl_t)data->jowl_action;
203 }
204 
205 /** Get maximum length of jowl_action value.
206  * @return length of jowl_action value, can be length of the array or number of
207  * maximum number of characters for a string
208  */
209 size_t
211 {
212  return 1;
213 }
214 
215 /** Set jowl_action value.
216  * Type of action of jown
217  * @param new_jowl_action new jowl_action value
218  */
219 void
221 {
222  data->jowl_action = new_jowl_action;
223  data_changed = true;
224 }
225 
226 /** Get mouth_action value.
227  * Type of action of mouth
228  * @return mouth_action value
229  */
232 {
233  return (FacialExpressionInterface::mouth_t)data->mouth_action;
234 }
235 
236 /** Get maximum length of mouth_action value.
237  * @return length of mouth_action value, can be length of the array or number of
238  * maximum number of characters for a string
239  */
240 size_t
242 {
243  return 1;
244 }
245 
246 /** Set mouth_action value.
247  * Type of action of mouth
248  * @param new_mouth_action new mouth_action value
249  */
250 void
252 {
253  data->mouth_action = new_mouth_action;
254  data_changed = true;
255 }
256 
257 /* =========== message create =========== */
258 Message *
260 {
261  if ( strncmp("MoveBrowsMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
262  return new MoveBrowsMessage();
263  } else if ( strncmp("MoveEyesMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
264  return new MoveEyesMessage();
265  } else if ( strncmp("MoveJowlMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
266  return new MoveJowlMessage();
267  } else if ( strncmp("MoveMouthMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
268  return new MoveMouthMessage();
269  } else {
270  throw UnknownTypeException("The given type '%s' does not match any known "
271  "message type for this interface type.", type);
272  }
273 }
274 
275 
276 /** Copy values from other interface.
277  * @param other other interface to copy values from
278  */
279 void
281 {
282  const FacialExpressionInterface *oi = dynamic_cast<const FacialExpressionInterface *>(other);
283  if (oi == NULL) {
284  throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
285  type(), other->type());
286  }
287  memcpy(data, oi->data, sizeof(FacialExpressionInterface_data_t));
288 }
289 
290 const char *
291 FacialExpressionInterface::enum_tostring(const char *enumtype, int val) const
292 {
293  if (strcmp(enumtype, "brows_t") == 0) {
294  return tostring_brows_t((brows_t)val);
295  }
296  if (strcmp(enumtype, "eyes_t") == 0) {
297  return tostring_eyes_t((eyes_t)val);
298  }
299  if (strcmp(enumtype, "jowl_t") == 0) {
300  return tostring_jowl_t((jowl_t)val);
301  }
302  if (strcmp(enumtype, "mouth_t") == 0) {
303  return tostring_mouth_t((mouth_t)val);
304  }
305  throw UnknownTypeException("Unknown enum type %s", enumtype);
306 }
307 
308 /* =========== messages =========== */
309 /** @class FacialExpressionInterface::MoveBrowsMessage <interfaces/FacialExpressionInterface.h>
310  * MoveBrowsMessage Fawkes BlackBoard Interface Message.
311  *
312 
313  */
314 
315 
316 /** Constructor with initial values.
317  * @param ini_brows_action initial value for brows_action
318  */
320 {
321  data_size = sizeof(MoveBrowsMessage_data_t);
322  data_ptr = malloc(data_size);
323  memset(data_ptr, 0, data_size);
324  data = (MoveBrowsMessage_data_t *)data_ptr;
326  data->brows_action = ini_brows_action;
327  add_fieldinfo(IFT_ENUM, "brows_action", 1, &data->brows_action, "brows_action");
328 }
329 /** Constructor */
331 {
332  data_size = sizeof(MoveBrowsMessage_data_t);
333  data_ptr = malloc(data_size);
334  memset(data_ptr, 0, data_size);
335  data = (MoveBrowsMessage_data_t *)data_ptr;
337  add_fieldinfo(IFT_ENUM, "brows_action", 1, &data->brows_action, "brows_action");
338 }
339 
340 /** Destructor */
342 {
343  free(data_ptr);
344 }
345 
346 /** Copy constructor.
347  * @param m message to copy from
348  */
350 {
351  data_size = m->data_size;
352  data_ptr = malloc(data_size);
353  memcpy(data_ptr, m->data_ptr, data_size);
354  data = (MoveBrowsMessage_data_t *)data_ptr;
356 }
357 
358 /* Methods */
359 /** Get brows_action value.
360  * Type of action of brows
361  * @return brows_action value
362  */
365 {
366  return (FacialExpressionInterface::brows_t)data->brows_action;
367 }
368 
369 /** Get maximum length of brows_action value.
370  * @return length of brows_action value, can be length of the array or number of
371  * maximum number of characters for a string
372  */
373 size_t
375 {
376  return 1;
377 }
378 
379 /** Set brows_action value.
380  * Type of action of brows
381  * @param new_brows_action new brows_action value
382  */
383 void
385 {
386  data->brows_action = new_brows_action;
387 }
388 
389 /** Clone this message.
390  * Produces a message of the same type as this message and copies the
391  * data to the new message.
392  * @return clone of this message
393  */
394 Message *
396 {
398 }
399 /** @class FacialExpressionInterface::MoveEyesMessage <interfaces/FacialExpressionInterface.h>
400  * MoveEyesMessage Fawkes BlackBoard Interface Message.
401  *
402 
403  */
404 
405 
406 /** Constructor with initial values.
407  * @param ini_eyes_action initial value for eyes_action
408  */
410 {
411  data_size = sizeof(MoveEyesMessage_data_t);
412  data_ptr = malloc(data_size);
413  memset(data_ptr, 0, data_size);
414  data = (MoveEyesMessage_data_t *)data_ptr;
416  data->eyes_action = ini_eyes_action;
417  add_fieldinfo(IFT_ENUM, "eyes_action", 1, &data->eyes_action, "eyes_action");
418 }
419 /** Constructor */
421 {
422  data_size = sizeof(MoveEyesMessage_data_t);
423  data_ptr = malloc(data_size);
424  memset(data_ptr, 0, data_size);
425  data = (MoveEyesMessage_data_t *)data_ptr;
427  add_fieldinfo(IFT_ENUM, "eyes_action", 1, &data->eyes_action, "eyes_action");
428 }
429 
430 /** Destructor */
432 {
433  free(data_ptr);
434 }
435 
436 /** Copy constructor.
437  * @param m message to copy from
438  */
440 {
441  data_size = m->data_size;
442  data_ptr = malloc(data_size);
443  memcpy(data_ptr, m->data_ptr, data_size);
444  data = (MoveEyesMessage_data_t *)data_ptr;
446 }
447 
448 /* Methods */
449 /** Get eyes_action value.
450  * Type of action of eyes
451  * @return eyes_action value
452  */
455 {
456  return (FacialExpressionInterface::eyes_t)data->eyes_action;
457 }
458 
459 /** Get maximum length of eyes_action value.
460  * @return length of eyes_action value, can be length of the array or number of
461  * maximum number of characters for a string
462  */
463 size_t
465 {
466  return 1;
467 }
468 
469 /** Set eyes_action value.
470  * Type of action of eyes
471  * @param new_eyes_action new eyes_action value
472  */
473 void
475 {
476  data->eyes_action = new_eyes_action;
477 }
478 
479 /** Clone this message.
480  * Produces a message of the same type as this message and copies the
481  * data to the new message.
482  * @return clone of this message
483  */
484 Message *
486 {
488 }
489 /** @class FacialExpressionInterface::MoveJowlMessage <interfaces/FacialExpressionInterface.h>
490  * MoveJowlMessage Fawkes BlackBoard Interface Message.
491  *
492 
493  */
494 
495 
496 /** Constructor with initial values.
497  * @param ini_jowl_action initial value for jowl_action
498  */
500 {
501  data_size = sizeof(MoveJowlMessage_data_t);
502  data_ptr = malloc(data_size);
503  memset(data_ptr, 0, data_size);
504  data = (MoveJowlMessage_data_t *)data_ptr;
506  data->jowl_action = ini_jowl_action;
507  add_fieldinfo(IFT_ENUM, "jowl_action", 1, &data->jowl_action, "jowl_action");
508 }
509 /** Constructor */
511 {
512  data_size = sizeof(MoveJowlMessage_data_t);
513  data_ptr = malloc(data_size);
514  memset(data_ptr, 0, data_size);
515  data = (MoveJowlMessage_data_t *)data_ptr;
517  add_fieldinfo(IFT_ENUM, "jowl_action", 1, &data->jowl_action, "jowl_action");
518 }
519 
520 /** Destructor */
522 {
523  free(data_ptr);
524 }
525 
526 /** Copy constructor.
527  * @param m message to copy from
528  */
530 {
531  data_size = m->data_size;
532  data_ptr = malloc(data_size);
533  memcpy(data_ptr, m->data_ptr, data_size);
534  data = (MoveJowlMessage_data_t *)data_ptr;
536 }
537 
538 /* Methods */
539 /** Get jowl_action value.
540  * Type of action of jown
541  * @return jowl_action value
542  */
545 {
546  return (FacialExpressionInterface::jowl_t)data->jowl_action;
547 }
548 
549 /** Get maximum length of jowl_action value.
550  * @return length of jowl_action value, can be length of the array or number of
551  * maximum number of characters for a string
552  */
553 size_t
555 {
556  return 1;
557 }
558 
559 /** Set jowl_action value.
560  * Type of action of jown
561  * @param new_jowl_action new jowl_action value
562  */
563 void
565 {
566  data->jowl_action = new_jowl_action;
567 }
568 
569 /** Clone this message.
570  * Produces a message of the same type as this message and copies the
571  * data to the new message.
572  * @return clone of this message
573  */
574 Message *
576 {
578 }
579 /** @class FacialExpressionInterface::MoveMouthMessage <interfaces/FacialExpressionInterface.h>
580  * MoveMouthMessage Fawkes BlackBoard Interface Message.
581  *
582 
583  */
584 
585 
586 /** Constructor with initial values.
587  * @param ini_mouth_action initial value for mouth_action
588  */
590 {
591  data_size = sizeof(MoveMouthMessage_data_t);
592  data_ptr = malloc(data_size);
593  memset(data_ptr, 0, data_size);
594  data = (MoveMouthMessage_data_t *)data_ptr;
596  data->mouth_action = ini_mouth_action;
597  add_fieldinfo(IFT_ENUM, "mouth_action", 1, &data->mouth_action, "mouth_action");
598 }
599 /** Constructor */
601 {
602  data_size = sizeof(MoveMouthMessage_data_t);
603  data_ptr = malloc(data_size);
604  memset(data_ptr, 0, data_size);
605  data = (MoveMouthMessage_data_t *)data_ptr;
607  add_fieldinfo(IFT_ENUM, "mouth_action", 1, &data->mouth_action, "mouth_action");
608 }
609 
610 /** Destructor */
612 {
613  free(data_ptr);
614 }
615 
616 /** Copy constructor.
617  * @param m message to copy from
618  */
620 {
621  data_size = m->data_size;
622  data_ptr = malloc(data_size);
623  memcpy(data_ptr, m->data_ptr, data_size);
624  data = (MoveMouthMessage_data_t *)data_ptr;
626 }
627 
628 /* Methods */
629 /** Get mouth_action value.
630  * Type of action of mouth
631  * @return mouth_action value
632  */
635 {
636  return (FacialExpressionInterface::mouth_t)data->mouth_action;
637 }
638 
639 /** Get maximum length of mouth_action value.
640  * @return length of mouth_action value, can be length of the array or number of
641  * maximum number of characters for a string
642  */
643 size_t
645 {
646  return 1;
647 }
648 
649 /** Set mouth_action value.
650  * Type of action of mouth
651  * @param new_mouth_action new mouth_action value
652  */
653 void
655 {
656  data->mouth_action = new_mouth_action;
657 }
658 
659 /** Clone this message.
660  * Produces a message of the same type as this message and copies the
661  * data to the new message.
662  * @return clone of this message
663  */
664 Message *
666 {
668 }
669 /** Check if message is valid and can be enqueued.
670  * @param message Message to check
671  * @return true if the message is valid, false otherwise.
672  */
673 bool
675 {
676  const MoveBrowsMessage *m0 = dynamic_cast<const MoveBrowsMessage *>(message);
677  if ( m0 != NULL ) {
678  return true;
679  }
680  const MoveEyesMessage *m1 = dynamic_cast<const MoveEyesMessage *>(message);
681  if ( m1 != NULL ) {
682  return true;
683  }
684  const MoveJowlMessage *m2 = dynamic_cast<const MoveJowlMessage *>(message);
685  if ( m2 != NULL ) {
686  return true;
687  }
688  const MoveMouthMessage *m3 = dynamic_cast<const MoveMouthMessage *>(message);
689  if ( m3 != NULL ) {
690  return true;
691  }
692  return false;
693 }
694 
695 /// @cond INTERNALS
696 EXPORT_INTERFACE(FacialExpressionInterface)
697 /// @endcond
698 
699 
700 } // end namespace fawkes
virtual const char * enum_tostring(const char *enumtype, int val) const
Convert arbitrary enum value to string.
void * data_ptr
Pointer to memory that contains local data.
Definition: message.h:114
size_t maxlenof_mouth_action() const
Get maximum length of mouth_action value.
void set_eyes_action(const eyes_t new_eyes_action)
Set eyes_action value.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:43
const char * tostring_jowl_t(jowl_t value) const
Convert jowl_t constant to string.
mouth_t mouth_action() const
Get mouth_action value.
eyes_t
Action types for moving eyes.
size_t maxlenof_jowl_action() const
Get maximum length of jowl_action value.
eyes_t eyes_action() const
Get eyes_action value.
MoveEyesMessage Fawkes BlackBoard Interface Message.
void set_hash(unsigned char *ihash)
Set hash.
Definition: interface.cpp:312
Fawkes library namespace.
Timestamp data, must be present and first entries for each interface data structs! This leans on time...
Definition: message.h:119
brows_t brows_action() const
Get brows_action value.
void set_jowl_action(const jowl_t new_jowl_action)
Set jowl_action value.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
size_t maxlenof_brows_action() const
Get maximum length of brows_action value.
MoveBrowsMessage Fawkes BlackBoard Interface Message.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
jowl_t jowl_action() const
Get jowl_action value.
virtual void copy_values(const Interface *other)
Copy values from other interface.
virtual Message * clone() const
Clone this message.
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:123
unsigned int data_size
Size of memory needed to hold all data.
Definition: message.h:115
void add_messageinfo(const char *name)
Add an entry to the message info list.
Definition: interface.cpp:368
virtual Message * clone() const
Clone this message.
bool data_changed
Indicator if data has changed.
Definition: interface.h:208
MoveJowlMessage Fawkes BlackBoard Interface Message.
void * data_ptr
Pointer to local memory storage.
Definition: interface.h:206
const char * tostring_mouth_t(mouth_t value) const
Convert mouth_t constant to string.
size_t maxlenof_mouth_action() const
Get maximum length of mouth_action value.
void set_jowl_action(const jowl_t new_jowl_action)
Set jowl_action value.
void set_brows_action(const brows_t new_brows_action)
Set brows_action value.
void set_mouth_action(const mouth_t new_mouth_action)
Set mouth_action value.
void set_mouth_action(const mouth_t new_mouth_action)
Set mouth_action value.
FacialExpressionInterface Fawkes BlackBoard Interface.
jowl_t
Action types for moving jowl.
mouth_t
Action types for moving mouth.
size_t maxlenof_eyes_action() const
Get maximum length of eyes_action value.
virtual Message * clone() const
Clone this message.
void set_brows_action(const brows_t new_brows_action)
Set brows_action value.
MoveMouthMessage Fawkes BlackBoard Interface Message.
void add_fieldinfo(interface_fieldtype_t type, const char *name, size_t length, void *value, const char *enumtype=0)
Add an entry to the info list.
Definition: message.cpp:435
const char * tostring_brows_t(brows_t value) const
Convert brows_t constant to string.
void set_eyes_action(const eyes_t new_eyes_action)
Set eyes_action value.
const char * tostring_eyes_t(eyes_t value) const
Convert eyes_t constant to string.
brows_t
Action types for moving brows.
const char * type() const
Get type of interface.
Definition: interface.cpp:635
virtual Message * create_message(const char *type) const
Create message based on type name.
field with interface specific enum type
Definition: types.h:47
size_t maxlenof_eyes_action() const
Get maximum length of eyes_action value.
size_t maxlenof_brows_action() const
Get maximum length of brows_action value.
size_t maxlenof_jowl_action() const
Get maximum length of jowl_action value.
virtual Message * clone() const
Clone this message.