C++ SDK Reference  12.5
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
diguySignal.h
Go to the documentation of this file.
1 
2 /*
3  * Copyright (C) 1992-2013 Boston Dynamics
4  * ALL RIGHTS RESERVED.
5  *
6  * These coded instructions, statements, and computer programs
7  * contain unpublished proprietary information of Boston Dynamics
8  * and are protected by Copyright Laws of the United States.
9  * They may not be used, duplicated, or disclosed in any form, in
10  * whole or in part, without the prior written consent from Boston
11  * Dynamics.
12  *
13  * RESTRICTED RIGHTS LEGEND
14  * Use, duplication, or disclosure by the government is subject
15  * to restrictions as set forth in FAR 52.227.19(c)(2) or
16  * subparagraph (c)(1)(ii) of the Rights in Technical Data and
17  * Computer Software clause at DFARS 252.227-7013 and/or in
18  * similar or successor clauses in the FAR, or the DOD or NASA
19  * FAR Supplement, or to subparagraphs (c)(1) and (c)(2) of the
20  * Commercial Computer Software--Restricted Rights at 48 CFR
21  * 52.227-19, as applicable. Unpublished-rights reserved under
22  * the Copyright Laws of the United States.
23  * Contractor/Manufacturer is:
24  * Boston Dynamics/78 Fourth Avenue/Waltham MA 02451.
25  */
26 
27 /*********************************************************************
28  **
29  *t diguySignal
30  **
31  *b Link against: libdiguy
32  */
33 
34 #ifndef __diguySignal_H
35 #define __diguySignal_H
36 
37 #ifdef SWIG
38 %module diguySignal
39 #else
40 #define CPLUSPLUS_ONLY
41 #endif
42 
43 #ifdef CPLUSPLUS_ONLY
44 
45 class bdiScenarioSignal;
46 class diguySignal;
47 
48 #include <stdio.h> // for NULL
49 #include <diguy_constants.h>
50 #include <diguy_typedefs.h>
51 
52 #endif /* CPLUSPLUS_ONLY */
53 
54 
55 #include <declspec_diguy.h>
56 
57 /****************************************************************************/
58 class BDI_DECLSPEC_diguy diguySignal
59 {
60 
61 public:
62 
63  /*l
64  *b Description:
65  **
66  ** Returns the name of the object. This pointer will
67  ** never be NULL.
68  **
69  *b Returns:
70  **
71  ** name of the signal
72  **
73  *b Callable From:
74  **
75  *- - C++
76  *- - Script
77  */
78  const char* get_name();
79 
80  /*l
81  *b Description:
82  **
83  ** This function sets the name of this object.
84  **
85  *b Returns:
86  **
87  ** 0 on success, -1 on failure
88  **
89  *b Callable From:
90  **
91  *- - C++
92  *- - Script
93  */
94  int set_name(const char* name);
95 
96  /*l
97  *b Description:
98  **
99  ** Returns the type name of the object. This pointer will
100  ** never be NULL.
101  **
102  *b Returns:
103  **
104  ** type name of the object
105  **
106  *b Callable From:
107  **
108  *- - C++
109  *- - Script
110  */
111  const char* get_type_name();
112 
113  /*l
114  *b Description:
115  **
116  ** This function resets the signal. The number of times the signal
117  ** has been triggered will be set to 0.
118  **
119  *b Returns:
120  **
121  ** 0 on success, -1 on failure
122  **
123  *b Callable From:
124  **
125  *- - C++
126  *- - Script
127  *- - Decision Bead
128  */
129  int reset();
130 
131  /*l
132  *b Description:
133  **
134  ** This function triggers the signal. If a sound is associated with
135  ** the signal, it will be played. The number of times the signal
136  ** has been triggered will be incremented by one.
137  **
138  *b Returns:
139  **
140  ** 0 on success, -1 on failure
141  **
142  *b Callable From:
143  **
144  *- - C++
145  *- - Script
146  *- - Decision Bead
147  */
148  int trigger();
149 
150  /*l
151  *b Returns:
152  **
153  ** Returns the number of times this signal has been triggered since
154  ** the scenario started or since the last call to reset().
155  **
156  *b Callable From:
157  **
158  *- - C++
159  *- - Script
160  *- - Decision Bead
161  */
162  int triggered();
163 
164  /*l
165  *b Returns:
166  **
167  ** Returns 1 if the signal has been triggered at least n
168  ** times, else returns 0.
169  **
170  *b Callable From:
171  **
172  *- - C++
173  *- - Script
174  *- - Decision Bead
175  */
176  int triggered_at_least_n_times(int n);
177 
178  /*l
179  *b Description:
180  **
181  ** This function causes the button for this signal to become visible
182  ** in the DI-Guy Scenario Signal Palette.
183  **
184  ** This function is for DI-Guy Scenario only.
185  **
186  *b Returns:
187  **
188  ** 0 on success, -1 on failure
189  **
190  *b Callable From:
191  **
192  *- - C++
193  *- - Script
194  */
195  int signal_palette_show();
196 
197  /*l
198  *b Description:
199  **
200  ** This function causes the button for this signal to become hidden
201  ** in the DI-Guy Scenario Signal Palette.
202  **
203  ** This function is for DI-Guy Scenario only.
204  **
205  *b Returns:
206  **
207  ** 0 on success, -1 on failure
208  **
209  *b Callable From:
210  **
211  *- - C++
212  *- - Script
213  */
214  int signal_palette_hide();
215 
216  /*l
217  *b Description:
218  **
219  ** This function returns a flag specifying whether the signal's
220  ** button is visible in the DI-Guy Scenario Signal Palette.
221  **
222  ** This function is for DI-Guy Scenario only.
223  **
224  *b Returns:
225  **
226  ** 1 if the signal's button is visible, 0 if not
227  **
228  *b Callable From:
229  **
230  *- - C++
231  *- - Script
232  */
233  int get_is_visible_in_signal_palette();
234 
235  /*l
236  *b Description:
237  **
238  ** This function returns an optional signal description buffer.
239  **
240  *b Returns:
241  **
242  ** pointer to info text
243  **
244  *b Callable From:
245  **
246  *- - C++
247  *- - Script
248  */
249  const char* get_info_text();
250 
251  /*l
252  *b Description:
253  **
254  ** This function sets an optional signal description buffer.
255  **
256  *b Arguments:
257  **
258  *a info_text - text of info
259  **
260  *b Callable From:
261  **
262  *- - C++
263  *- - Script
264  */
265  void set_info_text(const char* info_text);
266 
267 
268 /*****************************************************************************/
273  /*l
274  *b Description:
275  **
276  ** This is an enumeration of the different callbacks
277  ** that can be registered with add_callback() and
278  ** add_callback_script().
279  **
280  *b Usable From:
281  **
282  *- - C++
283  *- - Script
284  */
285  enum {
286  CALLBACK_ID_PRE_TRIGGER = 1,
287  CALLBACK_ID_POST_TRIGGER
288  };
289 
290 #ifdef CPLUSPLUS_ONLY
291 
292  /*l
293  *b Description:
294  **
295  ** This function adds a user callback.
296  **
297  *b Arguments:
298  **
299  *a callback - pointer to function with prototype
300  *a diguySignalCallback (typedefed above)
301  *a callback_id - integer id of when this callback is to be called
302  *a callback_params - not currently used; pass NULL
303  *a callback_user_data - pointer for user's own use; DI-Guy will
304  *a do nothing to the contents of this pointer
305  *a beyond passing it back when the callback is
306  *a invoked
307  **
308  ** callback_id should be one of the following values:
309  **
310  *i CALLBACK_ID_PRE_TRIGGER
311  **
312  ** This callback will be called whenever the trigger() function
313  ** is called, whether internally by DI-Guy of explicitly by
314  ** the user in C++ or in a script. It will be called before
315  ** the default handler of the function.
316  **
317  ** There are no parameters for this callback.
318  **
319  *i CALLBACK_ID_POST_TRIGGER
320  **
321  ** This callback will be called whenever the trigger() function
322  ** is called, whether internally by DI-Guy of explicitly by
323  ** the user in C++ or in a script. It will be called after
324  ** the default handler of the function.
325  **
326  ** There are no parameters for this callback.
327  **
328  *i Callback Return Values:
329  **
330  ** Callbacks return a value of type diguyCallbackReturn,
331  ** which will be DIGUY_CALLBACK_STOP or DIGUY_CALLBACK_CONTINUE.
332  ** If the callback returns DIGUY_CALLBACK_STOP, the default handler
333  ** of the function will not be called; the callback is asserting
334  ** that it has done everything necessary for the function call.
335  ** If the callback returns DIGUY_CALLBACK_CONTINUE, the default
336  ** handler for the function will be called after the callback.
337  **
338  *b Returns:
339  **
340  ** 0 on success, -1 on failure
341  **
342  *b Callable From:
343  **
344  *- - C++
345  */
346  int add_callback(int callback_id,
347  diguySignalCallback* callback,
348  void* callback_params = 0,
349  void* callback_user_data = 0);
350 
351  /*l
352  *b Description:
353  **
354  ** This function removes a user callback. All callbacks matching
355  ** the specified callback_id and callback function will be removed.
356  **
357  *b Arguments:
358  **
359  *a callback_id - integer id of when this callback is to be called
360  *a callback - pointer to function with prototype
361  *a diguySignalCallback (typedefed above)
362  **
363  *b Returns:
364  **
365  ** 0 on success, -1 on failure
366  **
367  *b Callable From:
368  **
369  *- - C++
370  */
371  int remove_callback(int callback_id,
372  diguySignalCallback* callback);
373 
374  /*l
375  *b Description:
376  **
377  ** This function removes a user callback. All callbacks matching
378  ** the specified callback_id and callback_user_data pointer will
379  ** be removed.
380  **
381  *b Arguments:
382  **
383  *a callback_id - integer id of when this callback is to be called
384  *a callback_user_data - pointer for user's own use
385  **
386  *b Returns:
387  **
388  ** 0 on success, -1 on failure
389  **
390  *b Callable From:
391  **
392  *- - C++
393  */
394  int remove_callback_with_user_data(int callback_id,
395  void* callback_user_data);
396 
397 #endif /* CPLUSPLUS_ONLY */
398 
399  /*l
400  *b Description:
401  **
402  ** This function adds a user callback script. Callback scripts can
403  ** be removed with remove_callback_script().
404  **
405  ** See diguyCharacter::add_callback_script() for an example
406  ** of use.
407  **
408  *b Arguments:
409  **
410  *a callback_id - integer id of the callback
411  *a callback_script - script text of callback to be added
412  *a callback_script_type - the type of script contained in
413  *a callback_script
414  **
415  ** If NULL is passed for callback_script_type, a default script type
416  ** will be derived based on the default script interpreter of the
417  ** scenario.
418  **
419  *i Lua specific:
420  **
421  ** When the script is called, the object for which it is being called
422  ** will be in the callback_object global.
423  **
424  ** To pass NULL when calling from a lua script, use nil.
425  **
426  *b Returns:
427  **
428  ** 0 on success, -1 on failure
429  **
430  *b Callable From:
431  **
432  *- - C++
433  *- - Script
434  */
435  int add_callback_script(int callback_id,
436  const char* callback_script,
437  const char* callback_script_type = NULL);
438 
439  /*l
440  *b Description:
441  **
442  ** This function removes a user callback script previously added with
443  ** add_callback_script().
444  **
445  ** See diguyCharacter::remove_callback_script() for an example
446  ** of use.
447  **
448  *b Arguments:
449  **
450  *a callback_id - integer id of the callback
451  *a callback_script - script text of callback previously added
452  *a callback_script_type - the type of script contained in
453  *a callback_script
454  **
455  ** If NULL is passed for callback_script, all callback
456  ** scripts whose ids match callback_id and whose types match
457  ** callback_script_type will be removed.
458  **
459  ** If NULL is passed for callback_script_type, a default script type
460  ** will be derived based on the default script interpreter of the
461  ** scenario.
462  **
463  *i Lua specific:
464  **
465  ** To pass NULL when calling from a lua script, use nil.
466  **
467  *b Returns:
468  **
469  ** 0 on success, -1 on failure
470  **
471  *b Callable From:
472  **
473  *- - C++
474  *- - Script
475  */
476  int remove_callback_script(int callback_id,
477  const char* callback_script,
478  const char* callback_script_type = NULL);
479 
480 
481 /*****************************************************************************/
487  /*l
488  *b Description:
489  **
490  ** This function maps the event handler with the given name
491  ** to a callback id. This mapping will be saved in the .dss
492  ** file and restored when the .dss file is loaded.
493  **
494  ** Mappings can also be made via the DI-Guy Scenario UI.
495  **
496  ** The event handler is one of the following:
497  **
498  *- - a signal callback function registered by
499  *- diguyScenario::register_signal_event_handler() or
500  *- diguyScenario::register_signal_event_handler_from_library()
501  *- - a script registered by
502  *- diguyScenario::register_signal_event_handler_script()
503  *- - a Script, Decision, or Library Function in the scenario
504  *- whose "Event Type" is "Signal"
505  **
506  *b Arguments:
507  **
508  *a callback_id - integer id of callback
509  *a handler_name - name of the event handler to map
510  **
511  *b Returns:
512  **
513  ** 0 on success, -1 on failure
514  **
515  *b Callable From:
516  **
517  *- - C++
518  *- - Script
519  */
520  int map_event_handler_to_callback_id(int callback_id,
521  const char* handler_name);
522 
523  /*l
524  *b Description:
525  **
526  ** This function unmaps the event handler with the given name
527  ** from a callback id.
528  **
529  *b Arguments:
530  **
531  *a callback_id - integer id of callback
532  *a handler_name - name of the event handler to map
533  *a unmap_all_matches - pass 0 to unmap only the first match,
534  *a pass 1 to unmap all matches
535  **
536  *b Returns:
537  **
538  ** 0 on success, -1 on failure
539  **
540  *b Callable From:
541  **
542  *- - C++
543  *- - Script
544  */
545  int unmap_event_handler_from_callback_id(int callback_id,
546  const char* handler_name,
547  int unmap_all_matches = 0);
548 
549 
554 #ifdef CPLUSPLUS_ONLY
555 
556  bdiScenarioSignal* get_scripted_object() {return m_signal;}
557 
558 private:
559 
560  /*l
561  ** A private constructor.
562  */
563  diguySignal(bdiScenarioSignal* signal);
564 
565  /*l
566  ** A pointer to internal data.
567  */
568  bdiScenarioSignal* m_signal;
569 
570  friend class bdiScenarioSignal;
571 
572 #endif /* CPLUSPLUS_ONLY */
573 
574 };
575 
576 #endif /* __diguySignal_H */