Jamoma API  0.6.0.a19
TTCallback.h
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup foundationLibrary
4  *
5  * @brief This class is used to create a backward communication channel to notify a client that something changed in the #TTnode.
6  *
7  * @details
8  *
9  * @todo Use the TTObject class functionnality because TTNode is also a TTObject
10  *
11  * @author Théo de la Hogue, Tim Place, Nathan Wolek, Trond Lossius
12  *
13  * @copyright Copyright © 2009, Théo de la Hogue and Timothy Place @n
14  * This code is licensed under the terms of the "New BSD License" @n
15  * http://creativecommons.org/licenses/BSD/
16  */
17 
18 #ifndef __TT_CALLBACK_H__
19 #define __TT_CALLBACK_H__
20 
21 #include "TTFoundationAPI.h"
22 
23 
24 /**
25  This class is used to be sensitive to any TTObject notifications and report them using a function with baton and value
26  We will subclass TTObject in order to gain some functionality -- like observers and notifications.
27  */
28 class TTFOUNDATION_EXPORT TTCallback : public TTObjectBase
29 {
31 
32 protected:
33 
34  TTFunctionWithBatonAndValue mFunction; ///< Function called when the notify message is engaged.
35  TTValue mBaton; ///< User data to be passed back when the callback is triggered.
36  TTSymbol mNotification; ///< the notification the callback is sensitive to
37 
38 private:
39 
40  /** Set baton value
41  @param value any value
42  @return kTTErrNone */
43  TTErr setBaton(const TTValue& value);
44 
45  /** Set to which notification the callback is sensitive to
46  @param value a symbol
47  @return kTTErrNone */
48  TTErr setNotification(const TTValue& value);
49 
50 public:
51 
52  /** Message called because we are registered as an observer to some other object, and then calls our external function.
53  @param anInputValue TODO: Add info
54  @param anUnusedOutputValue TODO: Add info
55  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
56  */
57  TTErr notify(const TTValue& anInputValue, TTValue &anUnusedOutputValue);
58 
59  TTErr deliver(const TTValue anInputValue)
60  {
61  TTValue unused;
62  return notify(anInputValue, unused);
63  }
64 
65 
66  /** Usefull to easily free the baton in case the pointer is a TTValue of something which need to be freed corectly.
67  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
68  */
69  TTPtr getBaton(){return mBaton;};
70 };
71 
72 /** Pointer to a #TTCallback object.
73  @ingroup typedefs
74  */
76 
77 
78 #endif // __TT_CALLBACK_H__
TTSymbol mNotification
the notification the callback is sensitive to
Definition: TTCallback.h:36
This class is used to be sensitive to any TTObject notifications and report them using a function wit...
Definition: TTCallback.h:28
TTValue mBaton
User data to be passed back when the callback is triggered.
Definition: TTCallback.h:35
Base class for all first-class Jamoma objects.
Definition: TTObjectBase.h:109
#define TTCLASS_SETUP(className)
TODO Doxygen: need more comments here.
Definition: TTFoundation.h:54
void * TTPtr
A generic pointer.
Definition: TTBase.h:248
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
TTFunctionWithBatonAndValue mFunction
Function called when the notify message is engaged.
Definition: TTCallback.h:34
TTPtr getBaton()
Usefull to easily free the baton in case the pointer is a TTValue of something which need to be freed...
Definition: TTCallback.h:69
TTCallback * TTCallbackPtr
Pointer to a TTCallback object.
Definition: TTCallback.h:75
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
TTErr(* TTFunctionWithBatonAndValue)(const TTValue &, const TTValue &)
A simple/generic function pointer with a baton as TTValueRef and the value to send back as a TTValueR...
Definition: TTBase.h:361
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34