Fawkes API  Fawkes Development Version
SkillerDebugInterface.cpp
1 
2 /***************************************************************************
3  * SkillerDebugInterface.cpp - Fawkes BlackBoard Interface - SkillerDebugInterface
4  *
5  * Templated created: Thu Oct 12 10:49:19 2006
6  * Copyright 2008 Tim Niemueller
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/SkillerDebugInterface.h>
25 
26 #include <core/exceptions/software.h>
27 
28 #include <map>
29 #include <string>
30 #include <cstring>
31 #include <cstdlib>
32 
33 namespace fawkes {
34 
35 /** @class SkillerDebugInterface <interfaces/SkillerDebugInterface.h>
36  * SkillerDebugInterface Fawkes BlackBoard Interface.
37  *
38  This interface provides internal skiller data that should allow for
39  easier debugging of skills and the skiller in general. The most notable
40  feature is a graph representation in the dot language of the available
41  skills (and highlighting for the currently active skill).
42 
43  * @ingroup FawkesInterfaces
44  */
45 
46 
47 
48 /** Constructor */
49 SkillerDebugInterface::SkillerDebugInterface() : Interface()
50 {
51  data_size = sizeof(SkillerDebugInterface_data_t);
52  data_ptr = malloc(data_size);
53  data = (SkillerDebugInterface_data_t *)data_ptr;
54  data_ts = (interface_data_ts_t *)data_ptr;
55  memset(data_ptr, 0, data_size);
56  enum_map_GraphDirectionEnum[(int)GD_TOP_BOTTOM] = "GD_TOP_BOTTOM";
57  enum_map_GraphDirectionEnum[(int)GD_BOTTOM_TOP] = "GD_BOTTOM_TOP";
58  enum_map_GraphDirectionEnum[(int)GD_LEFT_RIGHT] = "GD_LEFT_RIGHT";
59  enum_map_GraphDirectionEnum[(int)GD_RIGHT_LEFT] = "GD_RIGHT_LEFT";
60  add_fieldinfo(IFT_STRING, "graph_fsm", 32, data->graph_fsm);
61  add_fieldinfo(IFT_STRING, "graph", 8192, data->graph);
62  add_fieldinfo(IFT_ENUM, "graph_dir", 1, &data->graph_dir, "GraphDirectionEnum", &enum_map_GraphDirectionEnum);
63  add_fieldinfo(IFT_BOOL, "graph_colored", 1, &data->graph_colored);
64  add_messageinfo("SetGraphMessage");
65  add_messageinfo("SetGraphDirectionMessage");
66  add_messageinfo("SetGraphColoredMessage");
67  unsigned char tmp_hash[] = {0xcf, 0x3d, 0x2f, 0xf8, 0x80, 0x6e, 0x8f, 0xf4, 0x81, 0xa6, 0x7f, 0xd9, 0xb0, 0x29, 0xfc, 0x62};
68  set_hash(tmp_hash);
69 }
70 
71 /** Destructor */
72 SkillerDebugInterface::~SkillerDebugInterface()
73 {
74  free(data_ptr);
75 }
76 /** Convert GraphDirectionEnum constant to string.
77  * @param value value to convert to string
78  * @return constant value as string.
79  */
80 const char *
81 SkillerDebugInterface::tostring_GraphDirectionEnum(GraphDirectionEnum value) const
82 {
83  switch (value) {
84  case GD_TOP_BOTTOM: return "GD_TOP_BOTTOM";
85  case GD_BOTTOM_TOP: return "GD_BOTTOM_TOP";
86  case GD_LEFT_RIGHT: return "GD_LEFT_RIGHT";
87  case GD_RIGHT_LEFT: return "GD_RIGHT_LEFT";
88  default: return "UNKNOWN";
89  }
90 }
91 /* Methods */
92 /** Get graph_fsm value.
93  *
94  The finite state machine (FSM) the current graph has been updated for.
95 
96  * @return graph_fsm value
97  */
98 char *
99 SkillerDebugInterface::graph_fsm() const
100 {
101  return data->graph_fsm;
102 }
103 
104 /** Get maximum length of graph_fsm value.
105  * @return length of graph_fsm value, can be length of the array or number of
106  * maximum number of characters for a string
107  */
108 size_t
109 SkillerDebugInterface::maxlenof_graph_fsm() const
110 {
111  return 32;
112 }
113 
114 /** Set graph_fsm value.
115  *
116  The finite state machine (FSM) the current graph has been updated for.
117 
118  * @param new_graph_fsm new graph_fsm value
119  */
120 void
121 SkillerDebugInterface::set_graph_fsm(const char * new_graph_fsm)
122 {
123  strncpy(data->graph_fsm, new_graph_fsm, sizeof(data->graph_fsm));
124  data_changed = true;
125 }
126 
127 /** Get graph value.
128  *
129  The selected graph in a dot string representation.
130 
131  * @return graph value
132  */
133 char *
134 SkillerDebugInterface::graph() const
135 {
136  return data->graph;
137 }
138 
139 /** Get maximum length of graph value.
140  * @return length of graph value, can be length of the array or number of
141  * maximum number of characters for a string
142  */
143 size_t
144 SkillerDebugInterface::maxlenof_graph() const
145 {
146  return 8192;
147 }
148 
149 /** Set graph value.
150  *
151  The selected graph in a dot string representation.
152 
153  * @param new_graph new graph value
154  */
155 void
156 SkillerDebugInterface::set_graph(const char * new_graph)
157 {
158  strncpy(data->graph, new_graph, sizeof(data->graph));
159  data_changed = true;
160 }
161 
162 /** Get graph_dir value.
163  *
164  Primary direction of current graph.
165 
166  * @return graph_dir value
167  */
169 SkillerDebugInterface::graph_dir() const
170 {
171  return (SkillerDebugInterface::GraphDirectionEnum)data->graph_dir;
172 }
173 
174 /** Get maximum length of graph_dir value.
175  * @return length of graph_dir value, can be length of the array or number of
176  * maximum number of characters for a string
177  */
178 size_t
179 SkillerDebugInterface::maxlenof_graph_dir() const
180 {
181  return 1;
182 }
183 
184 /** Set graph_dir value.
185  *
186  Primary direction of current graph.
187 
188  * @param new_graph_dir new graph_dir value
189  */
190 void
191 SkillerDebugInterface::set_graph_dir(const GraphDirectionEnum new_graph_dir)
192 {
193  data->graph_dir = new_graph_dir;
194  data_changed = true;
195 }
196 
197 /** Get graph_colored value.
198  *
199  True if the graph is colored, false otherwise.
200 
201  * @return graph_colored value
202  */
203 bool
204 SkillerDebugInterface::is_graph_colored() const
205 {
206  return data->graph_colored;
207 }
208 
209 /** Get maximum length of graph_colored value.
210  * @return length of graph_colored value, can be length of the array or number of
211  * maximum number of characters for a string
212  */
213 size_t
214 SkillerDebugInterface::maxlenof_graph_colored() const
215 {
216  return 1;
217 }
218 
219 /** Set graph_colored value.
220  *
221  True if the graph is colored, false otherwise.
222 
223  * @param new_graph_colored new graph_colored value
224  */
225 void
226 SkillerDebugInterface::set_graph_colored(const bool new_graph_colored)
227 {
228  data->graph_colored = new_graph_colored;
229  data_changed = true;
230 }
231 
232 /* =========== message create =========== */
233 Message *
234 SkillerDebugInterface::create_message(const char *type) const
235 {
236  if ( strncmp("SetGraphMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
237  return new SetGraphMessage();
238  } else if ( strncmp("SetGraphDirectionMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
239  return new SetGraphDirectionMessage();
240  } else if ( strncmp("SetGraphColoredMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
241  return new SetGraphColoredMessage();
242  } else {
243  throw UnknownTypeException("The given type '%s' does not match any known "
244  "message type for this interface type.", type);
245  }
246 }
247 
248 
249 /** Copy values from other interface.
250  * @param other other interface to copy values from
251  */
252 void
253 SkillerDebugInterface::copy_values(const Interface *other)
254 {
255  const SkillerDebugInterface *oi = dynamic_cast<const SkillerDebugInterface *>(other);
256  if (oi == NULL) {
257  throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
258  type(), other->type());
259  }
260  memcpy(data, oi->data, sizeof(SkillerDebugInterface_data_t));
261 }
262 
263 const char *
264 SkillerDebugInterface::enum_tostring(const char *enumtype, int val) const
265 {
266  if (strcmp(enumtype, "GraphDirectionEnum") == 0) {
267  return tostring_GraphDirectionEnum((GraphDirectionEnum)val);
268  }
269  throw UnknownTypeException("Unknown enum type %s", enumtype);
270 }
271 
272 /* =========== messages =========== */
273 /** @class SkillerDebugInterface::SetGraphMessage <interfaces/SkillerDebugInterface.h>
274  * SetGraphMessage Fawkes BlackBoard Interface Message.
275  *
276 
277  */
278 
279 
280 /** Constructor with initial values.
281  * @param ini_graph_fsm initial value for graph_fsm
282  */
283 SkillerDebugInterface::SetGraphMessage::SetGraphMessage(const char * ini_graph_fsm) : Message("SetGraphMessage")
284 {
285  data_size = sizeof(SetGraphMessage_data_t);
286  data_ptr = malloc(data_size);
287  memset(data_ptr, 0, data_size);
288  data = (SetGraphMessage_data_t *)data_ptr;
290  strncpy(data->graph_fsm, ini_graph_fsm, 32);
291  enum_map_GraphDirectionEnum[(int)GD_TOP_BOTTOM] = "GD_TOP_BOTTOM";
292  enum_map_GraphDirectionEnum[(int)GD_BOTTOM_TOP] = "GD_BOTTOM_TOP";
293  enum_map_GraphDirectionEnum[(int)GD_LEFT_RIGHT] = "GD_LEFT_RIGHT";
294  enum_map_GraphDirectionEnum[(int)GD_RIGHT_LEFT] = "GD_RIGHT_LEFT";
295  add_fieldinfo(IFT_STRING, "graph_fsm", 32, data->graph_fsm);
296 }
297 /** Constructor */
299 {
300  data_size = sizeof(SetGraphMessage_data_t);
301  data_ptr = malloc(data_size);
302  memset(data_ptr, 0, data_size);
303  data = (SetGraphMessage_data_t *)data_ptr;
305  enum_map_GraphDirectionEnum[(int)GD_TOP_BOTTOM] = "GD_TOP_BOTTOM";
306  enum_map_GraphDirectionEnum[(int)GD_BOTTOM_TOP] = "GD_BOTTOM_TOP";
307  enum_map_GraphDirectionEnum[(int)GD_LEFT_RIGHT] = "GD_LEFT_RIGHT";
308  enum_map_GraphDirectionEnum[(int)GD_RIGHT_LEFT] = "GD_RIGHT_LEFT";
309  add_fieldinfo(IFT_STRING, "graph_fsm", 32, data->graph_fsm);
310 }
311 
312 /** Destructor */
314 {
315  free(data_ptr);
316 }
317 
318 /** Copy constructor.
319  * @param m message to copy from
320  */
322 {
323  data_size = m->data_size;
324  data_ptr = malloc(data_size);
325  memcpy(data_ptr, m->data_ptr, data_size);
326  data = (SetGraphMessage_data_t *)data_ptr;
328 }
329 
330 /* Methods */
331 /** Get graph_fsm value.
332  *
333  The finite state machine (FSM) the current graph has been updated for.
334 
335  * @return graph_fsm value
336  */
337 char *
339 {
340  return data->graph_fsm;
341 }
342 
343 /** Get maximum length of graph_fsm value.
344  * @return length of graph_fsm value, can be length of the array or number of
345  * maximum number of characters for a string
346  */
347 size_t
349 {
350  return 32;
351 }
352 
353 /** Set graph_fsm value.
354  *
355  The finite state machine (FSM) the current graph has been updated for.
356 
357  * @param new_graph_fsm new graph_fsm value
358  */
359 void
361 {
362  strncpy(data->graph_fsm, new_graph_fsm, sizeof(data->graph_fsm));
363 }
364 
365 /** Clone this message.
366  * Produces a message of the same type as this message and copies the
367  * data to the new message.
368  * @return clone of this message
369  */
370 Message *
372 {
374 }
375 /** @class SkillerDebugInterface::SetGraphDirectionMessage <interfaces/SkillerDebugInterface.h>
376  * SetGraphDirectionMessage Fawkes BlackBoard Interface Message.
377  *
378 
379  */
380 
381 
382 /** Constructor with initial values.
383  * @param ini_graph_dir initial value for graph_dir
384  */
386 {
387  data_size = sizeof(SetGraphDirectionMessage_data_t);
388  data_ptr = malloc(data_size);
389  memset(data_ptr, 0, data_size);
390  data = (SetGraphDirectionMessage_data_t *)data_ptr;
392  data->graph_dir = ini_graph_dir;
393  enum_map_GraphDirectionEnum[(int)GD_TOP_BOTTOM] = "GD_TOP_BOTTOM";
394  enum_map_GraphDirectionEnum[(int)GD_BOTTOM_TOP] = "GD_BOTTOM_TOP";
395  enum_map_GraphDirectionEnum[(int)GD_LEFT_RIGHT] = "GD_LEFT_RIGHT";
396  enum_map_GraphDirectionEnum[(int)GD_RIGHT_LEFT] = "GD_RIGHT_LEFT";
397  add_fieldinfo(IFT_ENUM, "graph_dir", 1, &data->graph_dir, "GraphDirectionEnum", &enum_map_GraphDirectionEnum);
398 }
399 /** Constructor */
401 {
402  data_size = sizeof(SetGraphDirectionMessage_data_t);
403  data_ptr = malloc(data_size);
404  memset(data_ptr, 0, data_size);
405  data = (SetGraphDirectionMessage_data_t *)data_ptr;
407  enum_map_GraphDirectionEnum[(int)GD_TOP_BOTTOM] = "GD_TOP_BOTTOM";
408  enum_map_GraphDirectionEnum[(int)GD_BOTTOM_TOP] = "GD_BOTTOM_TOP";
409  enum_map_GraphDirectionEnum[(int)GD_LEFT_RIGHT] = "GD_LEFT_RIGHT";
410  enum_map_GraphDirectionEnum[(int)GD_RIGHT_LEFT] = "GD_RIGHT_LEFT";
411  add_fieldinfo(IFT_ENUM, "graph_dir", 1, &data->graph_dir, "GraphDirectionEnum", &enum_map_GraphDirectionEnum);
412 }
413 
414 /** Destructor */
416 {
417  free(data_ptr);
418 }
419 
420 /** Copy constructor.
421  * @param m message to copy from
422  */
424 {
425  data_size = m->data_size;
426  data_ptr = malloc(data_size);
427  memcpy(data_ptr, m->data_ptr, data_size);
428  data = (SetGraphDirectionMessage_data_t *)data_ptr;
430 }
431 
432 /* Methods */
433 /** Get graph_dir value.
434  *
435  Primary direction of current graph.
436 
437  * @return graph_dir value
438  */
441 {
442  return (SkillerDebugInterface::GraphDirectionEnum)data->graph_dir;
443 }
444 
445 /** Get maximum length of graph_dir value.
446  * @return length of graph_dir value, can be length of the array or number of
447  * maximum number of characters for a string
448  */
449 size_t
451 {
452  return 1;
453 }
454 
455 /** Set graph_dir value.
456  *
457  Primary direction of current graph.
458 
459  * @param new_graph_dir new graph_dir value
460  */
461 void
463 {
464  data->graph_dir = new_graph_dir;
465 }
466 
467 /** Clone this message.
468  * Produces a message of the same type as this message and copies the
469  * data to the new message.
470  * @return clone of this message
471  */
472 Message *
474 {
476 }
477 /** @class SkillerDebugInterface::SetGraphColoredMessage <interfaces/SkillerDebugInterface.h>
478  * SetGraphColoredMessage Fawkes BlackBoard Interface Message.
479  *
480 
481  */
482 
483 
484 /** Constructor with initial values.
485  * @param ini_graph_colored initial value for graph_colored
486  */
487 SkillerDebugInterface::SetGraphColoredMessage::SetGraphColoredMessage(const bool ini_graph_colored) : Message("SetGraphColoredMessage")
488 {
489  data_size = sizeof(SetGraphColoredMessage_data_t);
490  data_ptr = malloc(data_size);
491  memset(data_ptr, 0, data_size);
492  data = (SetGraphColoredMessage_data_t *)data_ptr;
494  data->graph_colored = ini_graph_colored;
495  enum_map_GraphDirectionEnum[(int)GD_TOP_BOTTOM] = "GD_TOP_BOTTOM";
496  enum_map_GraphDirectionEnum[(int)GD_BOTTOM_TOP] = "GD_BOTTOM_TOP";
497  enum_map_GraphDirectionEnum[(int)GD_LEFT_RIGHT] = "GD_LEFT_RIGHT";
498  enum_map_GraphDirectionEnum[(int)GD_RIGHT_LEFT] = "GD_RIGHT_LEFT";
499  add_fieldinfo(IFT_BOOL, "graph_colored", 1, &data->graph_colored);
500 }
501 /** Constructor */
503 {
504  data_size = sizeof(SetGraphColoredMessage_data_t);
505  data_ptr = malloc(data_size);
506  memset(data_ptr, 0, data_size);
507  data = (SetGraphColoredMessage_data_t *)data_ptr;
509  enum_map_GraphDirectionEnum[(int)GD_TOP_BOTTOM] = "GD_TOP_BOTTOM";
510  enum_map_GraphDirectionEnum[(int)GD_BOTTOM_TOP] = "GD_BOTTOM_TOP";
511  enum_map_GraphDirectionEnum[(int)GD_LEFT_RIGHT] = "GD_LEFT_RIGHT";
512  enum_map_GraphDirectionEnum[(int)GD_RIGHT_LEFT] = "GD_RIGHT_LEFT";
513  add_fieldinfo(IFT_BOOL, "graph_colored", 1, &data->graph_colored);
514 }
515 
516 /** Destructor */
518 {
519  free(data_ptr);
520 }
521 
522 /** Copy constructor.
523  * @param m message to copy from
524  */
526 {
527  data_size = m->data_size;
528  data_ptr = malloc(data_size);
529  memcpy(data_ptr, m->data_ptr, data_size);
530  data = (SetGraphColoredMessage_data_t *)data_ptr;
532 }
533 
534 /* Methods */
535 /** Get graph_colored value.
536  *
537  True if the graph is colored, false otherwise.
538 
539  * @return graph_colored value
540  */
541 bool
543 {
544  return data->graph_colored;
545 }
546 
547 /** Get maximum length of graph_colored value.
548  * @return length of graph_colored value, can be length of the array or number of
549  * maximum number of characters for a string
550  */
551 size_t
553 {
554  return 1;
555 }
556 
557 /** Set graph_colored value.
558  *
559  True if the graph is colored, false otherwise.
560 
561  * @param new_graph_colored new graph_colored value
562  */
563 void
565 {
566  data->graph_colored = new_graph_colored;
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 /** Check if message is valid and can be enqueued.
580  * @param message Message to check
581  * @return true if the message is valid, false otherwise.
582  */
583 bool
585 {
586  const SetGraphMessage *m0 = dynamic_cast<const SetGraphMessage *>(message);
587  if ( m0 != NULL ) {
588  return true;
589  }
590  const SetGraphDirectionMessage *m1 = dynamic_cast<const SetGraphDirectionMessage *>(message);
591  if ( m1 != NULL ) {
592  return true;
593  }
594  const SetGraphColoredMessage *m2 = dynamic_cast<const SetGraphColoredMessage *>(message);
595  if ( m2 != NULL ) {
596  return true;
597  }
598  return false;
599 }
600 
601 /// @cond INTERNALS
602 EXPORT_INTERFACE(SkillerDebugInterface)
603 /// @endcond
604 
605 
606 } // end namespace fawkes
SkillerDebugInterface Fawkes BlackBoard Interface.
size_t maxlenof_graph_fsm() const
Get maximum length of graph_fsm value.
void * data_ptr
Pointer to memory that contains local data.
Definition: message.h:124
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
size_t maxlenof_graph_dir() const
Get maximum length of graph_dir value.
Fawkes library namespace.
virtual Message * clone() const
Clone this message.
Timestamp data, must be present and first entries for each interface data structs! This leans on time...
Definition: message.h:129
GraphDirectionEnum graph_dir() const
Get graph_dir value.
void set_graph_colored(const bool new_graph_colored)
Set graph_colored value.
string field
Definition: types.h:47
SetGraphMessage Fawkes BlackBoard Interface Message.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
void set_graph_fsm(const char *new_graph_fsm)
Set graph_fsm value.
size_t maxlenof_graph_colored() const
Get maximum length of graph_colored value.
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:133
unsigned int data_size
Size of memory needed to hold all data.
Definition: message.h:125
const char * type() const
Get type of interface.
Definition: interface.cpp:651
virtual Message * clone() const
Clone this message.
GraphDirectionEnum
Primary direction of the graph.
SetGraphColoredMessage Fawkes BlackBoard Interface Message.
virtual Message * clone() const
Clone this message.
void set_graph_dir(const GraphDirectionEnum new_graph_dir)
Set graph_dir value.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
void add_fieldinfo(interface_fieldtype_t type, const char *name, size_t length, void *value, const char *enumtype=0, const interface_enum_map_t *enum_map=0)
Add an entry to the info list.
Definition: message.cpp:436
boolean field
Definition: types.h:36
SetGraphDirectionMessage Fawkes BlackBoard Interface Message.
field with interface specific enum type
Definition: types.h:49