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