Jamoma API  0.6.0.a19
TTCallback.cpp
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 to notify a client that something changed in the #TTnode
6  *
7  * @details
8  *
9  * @todo Use the TTObjectBase class fonctionnality besause TTNode is also a TTObjectBase
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 #include "TTCallback.h"
19 
20 #define thisTTClass TTCallback
21 #define thisTTClassName "callback"
22 #define thisTTClassTags "system"
23 
25 mFunction(NULL),
26 mNotification(kTTSym_notify)
27 {
28  addAttribute(Function, kTypePointer);
29  addAttributeProperty(Function, hidden, YES);
30 
32  addAttributeProperty(Baton, hidden, YES);
33 
34  addAttributeWithSetter(Notification, kTypeSymbol);
35  addAttributeProperty(Notification, hidden, YES);
36 
37  // by default the callback is sensitive to the kTTSym_notify notification sent from a TTObject
38  registerMessage(mNotification, (TTMethod)& TTCallback::notify);
39 }
40 
41 TTCallback::~TTCallback()
42 {
43  mFunction = NULL;
44 }
45 
46 TTErr TTCallback::setBaton(const TTValue& value)
47 {
48  mBaton = value;
49  return kTTErrNone;
50 }
51 
52 TTErr TTCallback::setNotification(const TTValue& value)
53 {
54  if (value.size() == 1) {
55 
56  if (value[0].type() == kTypeSymbol) {
57 
59 
60  mNotification = value[0];
61 
63  }
64  }
65 
66  return kTTErrGeneric;
67 }
68 
69 TTErr TTCallback::notify(const TTValue& anInputValue, TTValue &anUnusedOutputValue)
70 {
71  if (mFunction)
72  return mFunction(mBaton, anInputValue);
73 
74  return kTTErrGeneric;
75 }
TTSymbol mNotification
the notification the callback is sensitive to
Definition: TTCallback.h:36
TTValue mBaton
User data to be passed back when the callback is triggered.
Definition: TTCallback.h:35
#define addAttribute(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom getter...
Definition: TTAttribute.h:29
size_type size() const noexcept
Return the number of elements.
TTErr(TTObjectBase::* TTMethod)(const TTSymbol methodName, const TTValue &anInputValue, TTValue &anOutputValue)
A type that can be used to store a pointer to a message for an object.
Definition: TTObjectBase.h:46
TTErr removeMessage(const TTSymbol name)
Remove a message.
Symbol type.
Definition: TTBase.h:282
This is a special type used by TTAttribute to indicate that a value is a TTValue and is locally maint...
Definition: TTBase.h:286
TTErr registerMessage(const TTSymbol name, TTMethod method)
Register a message with this object.
This class is used to create a backward communication channel to notify a client that something chang...
#define addAttributeProperty(attributeName, propertyName, initialValue)
A convenience macro to be used for registering properties of attributes.
Definition: TTAttribute.h:68
TTFunctionWithBatonAndValue mFunction
Function called when the notify message is engaged.
Definition: TTCallback.h:34
#define TT_BASE_OBJECT_CONSTRUCTOR
TODO Doxygen: need more comments here.
Definition: TTFoundation.h:44
Something went wrong, but what exactly is not known. Typically used for context-specific problems...
Definition: TTBase.h:344
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
Pointer type.
Definition: TTBase.h:284
#define addAttributeWithSetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom setter...
Definition: TTAttribute.h:47
No Error.
Definition: TTBase.h:343
TTErr notify(const TTValue &anInputValue, TTValue &anUnusedOutputValue)
Message called because we are registered as an observer to some other object, and then calls our exte...
Definition: TTCallback.cpp:69
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34