Jamoma API  0.6.0.a19
TTApplication.h
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup modularLibrary
4  *
5  * @brief Handles application namespace using a #TTNodeDirectory and two tables to convert any TTName into a specific application name (AppName)
6  *
7  * @details some details about the class.
8 
9  * other details. @n@n
10 
11  * another details. @n@n
12 
13  *
14  * @see TTApplicationManager, Protocol, TTMirror
15  *
16  * @copyright Copyright © 2010, Théo de la Hogue @n
17  * This code is licensed under the terms of the "New BSD License" @n
18  * http://creativecommons.org/licenses/BSD/
19  */
20 
21 #ifndef __TT_APPLICATION_H__
22 #define __TT_APPLICATION_H__
23 
24 #include "TTModularIncludes.h"
25 #include "TTProtocol.h"
26 #include "TTMirror.h"
27 
28 class TTApplication;
30 
33 
34 class TTProtocol;
35 typedef TTProtocol* TTProtocolPtr;
36 
37 class TTMirror;
38 typedef TTMirror* TTMirrorPtr;
39 
40 class TTXmlHandler;
42 
43 
44 /** Handles application data structure like a #TTNodeDirectory and a hash tables of names
45  *
46  * some details about the class.
47  * other details.
48  * another details.
49  *
50  * @see TTApplicationManager, Protocol
51  */
52 class TTMODULAR_EXPORT TTApplication : public TTObjectBase
53 {
55 
56 private:
57  TTNodeDirectoryPtr mDirectory; ///< ATTRIBUTE : the namespace directory of the application
58 
59  TTSymbol mName; ///< ATTRIBUTE : the name of the application
60  TTSymbol mType; ///< ATTRIBUTE : the type of the application : local (default), mirror or proxy
61  TTSymbol mVersion; ///< ATTRIBUTE : the version of the application
62  TTSymbol mAuthor; ///< ATTRIBUTE : the author of the application
63 
64  TTBoolean mActivity; ///< ATTRIBUTE : enable the activity mechanism
65  TTBoolean mDebug; ///< ATTRIBUTE : to enable the debug mode for the application (default : NO)
66  TTBoolean mLearn; ///< ATTRIBUTE : enable the learning mechanism (see in UpdateAttribute)
67 
68  TTHash mCachedAttributes; ///< ATTRIBUTE : all attribute names which need to be cached by a mirror application to reduce the number of network requests
69 
70  TTHash mDirectoryListenersCache; ///< hash table containing all <address, Listener> for quick access
71  TTHash mAttributeListenersCache; ///< hash table containing all <address:attribute, Listener> for quick access
72 
73  TTHash mAppToTT; ///< hash table to convert Application names into TT names
74  TTValue mAllAppNames; ///< all Application names
75  TTHash mTTToApp; ///< hash table to convert TT names into Application names
76  TTValue mAllTTNames; ///< all TT names
77 
78  TTAddress mTempAddress; ///< a temporary address to parse xml file
79  TTAddress mFoldAddress; ///< a temporary address to duplicate address content
80  TTUInt32 mFolderSize; ///< how many times the fold address have to be duplicated
81 
82 #if 0
83 #pragma mark -
84 #pragma mark Attribute accesors
85 #endif
86 
87  /** Attribute accesor: set the name of the application
88  @details set also the name of his #TTNodeDirectory
89  @param value the new name
90  @return #TTErr always returns #kTTErrNone */
91  TTErr setName(const TTValue& value);
92 
93  /** Attribute accesor: enable activity
94  @param value
95  @return #TTErr always returns #kTTErrNone */
96  TTErr setActivity(const TTValue& value);
97 
98  /** Attribute accesor: get activity in
99  @param value
100  @return #TTErr always returns #kTTErrNone */
101  TTErr getActivityIn(TTValue& value);
102 
103  /** Attribute accesor: set activity in
104  @param value
105  @return #TTErr always returns #kTTErrNone */
106  TTErr setActivityIn(const TTValue& value);
107 
108  /** Attribute accesor: get activity out
109  @param value
110  @return #TTErr always returns #kTTErrNone */
111  TTErr getActivityOut(TTValue& value);
112 
113  /** Attribute accesor: set activity out
114  @param value
115  @return #TTErr always returns #kTTErrNone */
116  TTErr setActivityOut(const TTValue& value);
117 
118  /** Attribute accesor: get the cached attributes (for mirror application only)
119  @param value all cached attribute names
120  @return #TTErr error code */
121  TTErr getCachedAttributes(TTValue& value);
122 
123  /** Attribute accesor: set the attributes to cache (for mirror application only)
124  @param value all attribute names to cache
125  @return #TTErr error code */
126  TTErr setCachedAttributes(const TTValue& value);
127 
128  /** Convenient recursive method to cache or uncache an attribute of an object of a node and do the same under all its children
129  @param aNode a node to process
130  @param attributeName the name of the attribute
131  @param cacheOrUncache a boolean to cache (YES) or uncache (NO) the attribute
132  @return #TTErr error code */
133  TTErr cacheAttributeNode(TTNodePtr aNode, TTSymbol attributeName, TTBoolean cacheOrUncache);
134 
135 #if 0
136 #pragma mark -
137 #pragma mark Directory management
138 #endif
139 
140  /** Init the application
141  @return #TTErr always returns #kTTErrNone */
142  TTErr Init();
143  TTErr initNode(TTNodePtr aNode);
144 
145  /** Clear the directory of an application (for distant application only)
146  @return #TTErr always returns #kTTErrNone */
147  TTErr DirectoryClear();
148 
149  /** Build the directory of an application (for distant application only)
150  @return #TTErr always returns #kTTErrNone */
151  TTErr DirectoryBuild();
152 
153  /** Convenient method to build the directory under an address using a protocol
154  @return #TTErr error code
155  @seealso DirectoryBuild */
156  TTErr buildNode(TTProtocolPtr aProtocol, TTAddress anAddress);
157 
158  /** Observe the directory of an application (for distant application only)
159  @param inputValue #TTBoolean to enable or disable directory observation
160  @param outputValue nothing
161  @return #TTErr error code */
162  TTErr DirectoryObserve(const TTValue& inputValue, TTValue& outputValue);
163 
164  /** Add Directory observer
165  @param inputValue
166  @param outputValue
167  @return #TTErr error code */
168  TTErr AddDirectoryListener(const TTValue& inputValue, TTValue& outputValue);
169 
170  /** Add Attribute observer
171  @param inputValue
172  @param outputValue
173  @return #TTErr error code */
174  TTErr AddAttributeListener(const TTValue& inputValue, TTValue& outputValue);
175 
176  /** Remove Directory observer
177  @param inputValue
178  @param outputValue
179  @return #TTErr error code */
180  TTErr RemoveDirectoryListener(const TTValue& inputValue, TTValue& outputValue);
181 
182  /** Remove Attribute observer
183  @param inputValue
184  @param outputValue
185  @return #TTErr error code */
186  TTErr RemoveAttributeListener(const TTValue& inputValue, TTValue& outputValue);
187 
188  /** Update Directory (usually for distant application)
189  @param inputValue
190  @param outputValue
191  @return #TTErr error code */
192  TTErr UpdateDirectory(const TTValue& inputValue, TTValue& outputValue);
193 
194  /** Update Attribute value (usually for Mirror objects)
195  @param inputValue
196  @param outputValue
197  @return #TTErr error code */
198  TTErr UpdateAttribute(const TTValue& inputValue, TTValue& outputValue);
199 
200  /** Register an object into the application directory at an address
201  @param inputValue an address, an object and an optional context pointer
202  @param outputValue the effective registration address
203  @return #TTErr error code */
204  TTErr ObjectRegister(const TTValue& inputValue, TTValue& outputValue);
205 
206  /** Unregister an object registered into the application directory at an address
207  @param inputValue the address
208  @param outputValue the registered object
209  @return #TTErr error code */
210  TTErr ObjectUnregister(const TTValue& inputValue, TTValue& outputValue);
211 
212  /** Change the name.instance part of the address of a registered object
213  @param inputValue a registered object, the new name.instance
214  @param outputValue the effective name.instance
215  @return #TTErr error code */
216  TTErr ObjectRename(const TTValue& inputValue, TTValue& outputValue);
217 
218  /** Retreive a registered object into the application directory at an address
219  @param inputValue an address
220  @param outputValue the registered object
221  @return #TTErr error code */
222  TTErr ObjectRetreive(const TTValue& inputValue, TTValue& outputValue);
223 
224  /** Send any value to a registered object into the application directory at an address
225  @param inputValue an address:attribute followed by any value
226  @param outputValue nothing
227  @return #TTErr error code */
228  TTErr ObjectSend(const TTValue& inputValue, TTValue& outputValue);
229 
230 #if 0
231 #pragma mark -
232 #pragma mark TTName / AppName conversion
233 #endif
234 
235  /** Attribute accesor: Get all AppNames
236  @return #TTErr error code */
237  TTErr getAllAppNames(TTValue& value);
238 
239  /** Get all AppNames
240  @return #TTErr error code */
241  TTErr getAllTTNames(TTValue& value);
242 
243  /** Convert TTName into AppName
244  @param inputValue <TTSymbol toConvert>
245  @param outputValue <TTSymbol converted>
246  @return #TTErr error code */
247  TTErr ConvertToAppName(const TTValue& inputValue, TTValue& outputValue);
248 
249  /** Convert AppName into TTName
250  @param inputValue <TTSymbol toConvert>
251  @param outputValue <TTSymbol converted>
252  @return #TTErr error code */
253  TTErr ConvertToTTName(const TTValue& inputValue, TTValue& outputValue);
254 
255 #if 0
256 #pragma mark -
257 #pragma mark Backup
258 #endif
259 
260  /** Write application namespace
261  @param inputValue <TTXmlHandlerPtr aXmlHandler>
262  @param outputValue nothing
263  @return #TTErr error code */
264  TTErr WriteAsXml(const TTValue& inputValue, TTValue& outputValue);
265 
266  /** Convenient method used to write a node
267  @param aXmlHandler a xml handler object
268  @param aNode a node object
269  @return #TTErr error code
270  @seealso WriteAsXml */
271  void writeNodeAsXml(TTXmlHandlerPtr aXmlHandler, TTNodePtr aNode);
272 
273  /** Read application namespace
274  @param inputValue <TTXmlHandlerPtr aXmlHandler>
275  @param outputValue nothing
276  @return #TTErr error code */
277  TTErr ReadFromXml(const TTValue& inputValue, TTValue& outputValue);
278 
279  /** Convenient method used to read a node
280  @param aXmlHandler a xml handler object
281  @seealso ReadFromXml */
282  void readNodeFromXml(TTXmlHandlerPtr aXmlHandler);
283 
284  /* Instantiate and register a #TTData object
285  note : this a temporary message to allow proxy data creation
286  @param inputValue an address, service of the data
287  @param outputValue the new object
288  @return #TTErr error code */
289  TTErr ProxyDataInstantiate(const TTValue& inputValue, TTValue& outputValue);
290 
291  /** Convenient method used to create a mirror object
292  @param aProtocol a protocol object
293  @param anAddress where to register the mirror object
294  @param objectName object type to mirror
295  @param attributesName attributes of the object to mirror
296  @return #TTObject
297  @seealso readNodeFromXml */
298  TTObject appendMirrorObject(TTProtocolPtr aProtocol, TTAddress anAddress, TTSymbol objectName, TTValue& attributesName);
299 
300  /** Convenient method used to create a data object
301  @param aProtocol a protocol object
302  @param anAddress where to register the data object
303  @param service data service
304  @return #TTObject
305  @seealso readNodeFromXml */
306  TTObject appendProxyData(TTProtocolPtr aProtocol, TTAddress anAddress, TTSymbol service);
307 
308  /** Convenient method used to create a container object
309  @param aProtocol a protocol object
310  @param anAddress where to register the container object
311  @return #TTObject
312  @seealso readNodeFromXml */
313  TTObject appendProxyContainer(TTProtocolPtr aProtocol, TTAddress anAddress);
314 
315 #if 0
316 #pragma mark -
317 #pragma mark Inline public methods useful to ease access to directory
318 #endif
319 
320 public:
321 
322  /** Get directory object
323  @return a #TTNodeDirectoryPtr */
324  inline TTNodeDirectoryPtr getDirectory() { return mDirectory; };
325 
326  /** Get debug status
327  @return a #TTBoolean */
328  inline TTBoolean getDebug() { return mDebug; };
329 
330  /** To convert an application name into standard TT name
331  @param anAppName #TTSymbol
332  @return #TTSymbol */
334  {
335  TTValue c;
336  TTSymbol converted = anAppName;
337 
338  if (!mAppToTT.lookup(anAppName, c))
339  converted = c[0];
340 
341  return converted;
342  }
343 
344  /** To convert standard TT name into an application name
345  @param aTTName #TTSymbol
346  @return #TTSymbol */
348  {
349  TTValue c;
350  TTSymbol converted = aTTName;
351 
352  if (!mTTToApp.lookup(aTTName, c))
353  converted = c[0];
354 
355  return converted;
356  }
357 
358 #if 0
359 #pragma mark -
360 #pragma mark Test
361 #endif
362 
363  /** Default (empty) template for unit tests.
364  @param returnedTestInfo Returned information on the outcome of the unit test(s)
365  @return #kTTErrNone if tests exists and they all pass, else #TTErr error codes depending on the outcome of the test.
366  */
367  virtual TTErr test(TTValue& returnedTestInfo);
368 
369 #if 0
370 #pragma mark -
371 #pragma mark Friendship
372 #endif
373 
374  friend TTErr TTMODULAR_EXPORT TTApplicationProxyDataValueCallback(const TTValue& baton, const TTValue& data);
375 };
376 
377 #if 0
378 #pragma mark -
379 #pragma mark Some Functions
380 #endif
381 
382 /** A callback used by proxy data (see in appendData method)
383  @param baton ..
384  @param data ..
385  @return an error code */
386 TTErr TTMODULAR_EXPORT TTApplicationProxyDataValueCallback(const TTValue& baton, const TTValue& data);
387 
388 #endif // __TT_APPLICATION_H__
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
TTModular Library.
TTSymbol convertTTNameToAppName(TTSymbol aTTName)
To convert standard TT name into an application name.
TTErr lookup(const TTSymbol key, TTValue &value)
Find the value for the given key.
Definition: TTHash.cpp:76
We build a directory of TTNodes, and you can request a pointer for any TTNode, or add an observer to ...
Definition: TTNode.h:59
TTNodeDirectoryPtr getDirectory()
Get directory object.
The TTAddress class is used to represent a string and efficiently pass and compare that string...
Definition: TTAddress.h:29
Create and use Jamoma object instances.
Definition: TTObject.h:29
TTProtocol is the base class for all protocol protocol.
Definition: TTProtocol.h:60
Base class for all first-class Jamoma objects.
Definition: TTObjectBase.h:109
TTBoolean getDebug()
Get debug status.
Maintain a collection of TTValue objects indexed by TTSymbol pointers.
Definition: TTHash.h:36
#define TTCLASS_SETUP(className)
TODO Doxygen: need more comments here.
Definition: TTFoundation.h:54
A Protocol interface.
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
Handles application data structure like a TTNodeDirectory and a hash tables of names.
Definition: TTApplication.h:52
Handles TTApplication and #Protocol instances.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
std::uint32_t TTUInt32
32 bit unsigned integer
Definition: TTBase.h:178
A Mirror Object.
Write / Read mecanism.
Definition: TTXmlHandler.h:48
TODO : how to have TTGetterMethod and TTSetterMethod for Mirror message Property ?
Definition: TTMirror.h:70
TTSymbol convertAppNameToTTName(TTSymbol anAppName)
To convert an application name into standard TT name.
We build a tree of TTNodes, and you can request a pointer for any TTNode, or add an observer to any T...
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
TTErr TTMODULAR_EXPORT TTApplicationProxyDataValueCallback(const TTValue &baton, const TTValue &data)
A callback used by proxy data (see in appendData method)