Jamoma API  0.6.0.a19
TTApplicationManager.h
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup modularLibrary
4  *
5  * @brief Handles #TTApplication and #Protocol instances
6  *
7  * @details the #TTApplicationManager class is a kind of tower control between our application (called "local") and all others (called "distant").
8  * This coordination between applications is based on protocol units which one applications have to register. @n
9  * Then, once applications are registered to protocols, any distant applications can : @n
10  * - discover the local application namespace. @n
11  * - get the value an attribute of an object registered into the local application. @n
12  * - set the value an attribute of an object registered into the local application. @n
13  * - listen the value an attribute of an object registered into the local application. @n
14  * First of all, notice those features are not available for all protocols @n
15  * Then, notice the features above can also be done in the opposite way (the local application to the distant applications). @n
16  * The #TTApplicationManager class provides method to instanciate and release #TTApplication and #Protocol instances. @n
17  *
18  * @see TTApplication, TTProtocolLib
19  *
20  * @authors Théo de la Hogue
21  *
22  * @copyright Copyright © 2010-2014, Théo de la Hogue @n
23  * This code is licensed under the terms of the "New BSD License" @n
24  * http://creativecommons.org/licenses/BSD/
25  */
26 
27 #ifndef __TT_APPLICATION_MANAGER_H__
28 #define __TT_APPLICATION_MANAGER_H__
29 
30 #include "TTModularIncludes.h"
31 
32 class TTApplication;
34 
35 class TTProtocol;
36 typedef TTProtocol* TTProtocolPtr;
37 
38 class TTXmlHandler;
40 
41 /** @enum Application notification flags
42  * @brief Defines notification flags to notify observers of #TTApplicationManager
43  */
45  kApplicationReleased = 0, ///< an application have been released by the application manager
46  kApplicationInstantiated= 1, ///< an application have been intantiated by the application manager
47  kApplicationProtocolStarted = 2, ///< application's protocol have been started
48  kApplicationProtocolStopped = 3 ///< application's protocol will be stopped
49 };
50 
51 /** Handles #TTApplication and #Protocol instances
52 
53  the #TTApplicationManager class is a kind of tower control between our application (called "local") and all others (called "distant").
54  This coordination between applications is based on protocol units which one applications have to register. @n
55  Then, once applications are registered to protocols, any distant applications can : @n
56  - discover the local application namespace. @n
57  - get the value an attribute of an object registered into the local application. @n
58  - set the value an attribute of an object registered into the local application. @n
59  - listen the value an attribute of an object registered into the local application. @n
60  First of all, notice those features are not available for all protocols @n
61  Then, notice the features above can also be done in the opposite way (the local application to the distant applications). @n
62  The #TTApplicationManager class provides method to instanciate and release #TTApplication and #Protocol instances. @n
63 
64  @see TTApplication, ProtocolLib
65  */
66 class TTMODULAR_EXPORT TTApplicationManager : public TTObjectBase
67 {
69 
70 private:
71 
72  TTHash mApplications; ///< hash table containing <#TTSymbol applicationName, #TTApplication anApplication>
73  TTHash mProtocols; ///< hash table containing <#TTSymbol protocolName, #Protocol aProtocol>
74 
75  TTObject mApplicationLocal; ///< the local application
76  TTObject mApplicationCurrent; ///< used for ReadFromXml mechanism
77 
78  TTHash mApplicationObservers; ///< a pointer to a hashtab which register all application life cycle observers
79  TTMutexPtr mApplicationObserversMutex; ///< a Mutex to protect the mObservers hash table.
80 
81  TTObject mCurrentProtocol; ///< used for ReadFromXml mechanism
82 
83 #if 0
84 #pragma mark -
85 #pragma mark Application accesors
86 #endif
87 
88  /** Attribute accessor: get application table
89  @return #kTTErrNone */
90  TTErr getApplications(TTValue& value);
91 
92  /** Attribute accessor: get all application names
93  @return #TTErr error code
94  @seealso ApplicationIntantiateLocal, ApplicationIntantiateDistant, ApplicationRelease, ApplicationGet */
95  TTErr getApplicationNames(TTValue& returnedApplicationNames);
96 
97  /** Attribute accessor: get local application name
98  @return #TTErr error code
99  @seealso ApplicationIntantiateLocal */
100  TTErr getApplicationLocalName(TTValue& returnedApplicationLocalName);
101 
102  /** Attribute accessor: get local application
103  @return #TTErr error code
104  @seealso ApplicationIntantiateLocal */
105  TTErr getApplicationLocal(TTValue& returnedApplicationLocal);
106 
107 #if 0
108 #pragma mark -
109 #pragma mark Protocol accesors
110 #endif
111 
112  /** Attribute accessor: get all protocol names
113  @param value
114  @return #TTErr error code
115  @seealso ProtocolInstantiate, ProtocolRelease, ProtocolGet */
116  TTErr getProtocolNames(TTValue& value);
117 
118 #if 0
119 #pragma mark -
120 #pragma mark Application factory
121 #endif
122 
123  /** Instantiate the local application passing a name
124  @param inputValue application name
125  @param outputValue application object
126  @return #TTErr error code */
127  TTErr ApplicationInstantiateLocal(const TTValue& inputValue, TTValue& outputValue);
128 
129  /** Instantiate a distante application passing a name
130  @param inputValue application name
131  @param outputValue application object
132  @return #TTErr error code */
133  TTErr ApplicationInstantiateDistant(const TTValue& inputValue, TTValue& outputValue);
134 
135  /** Release any application passing a name
136  @param inputValue application name
137  @param outputValue nothing
138  @return #TTErr error code */
139  TTErr ApplicationRelease(const TTValue& inputValue, TTValue& outputValue);
140 
141  /** Rename an application passing its old name and a new name
142  @details : this method is hidden because it is only used internally by #TTApplication::setName
143  @param inputValue application old name and a new name
144  @param outputValue nothing
145  @return #TTErr error code */
146  TTErr ApplicationRename(const TTValue& inputValue, TTValue& outputValue);
147 
148  /** Get any application passing a name
149  @param inputValue application name
150  @param outputValue application object
151  @return #TTErr error code */
152  TTErr ApplicationFind(const TTValue& inputValue, TTValue& outputValue);
153 
154  /** Convenient method to notify application observers
155  @param applicationName application name
156  @param anApplication application object
157  @param flag a #TTApplicationNotificationFlag
158  @return #TTErr error code
159  @seealso ApplicationIntantiateLocal, ApplicationIntantiateDistant, ApplicationRelease */
160  TTErr notifyApplicationObservers(TTSymbol applicationName, TTObject anApplication, TTApplicationNotificationFlag flag);
161 
162 #if 0
163 #pragma mark -
164 #pragma mark Protocol factory
165 #endif
166 
167  /** Instantiate a protocol passing a name
168  @param inputValue protocol name
169  @param outputValue protocol object
170  @return #TTErr error code */
171  TTErr ProtocolInstantiate(const TTValue& inputValue, TTValue& outputValue);
172 
173  /** Release a protocol passing a name
174  @param inputValue protocol name
175  @param outputValue nothing
176  @return #TTErr error code */
177  TTErr ProtocolRelease(const TTValue& inputValue, TTValue& outputValue);
178 
179  /** Get any protocol passing a name
180  @param inputValue protocol name
181  @param outputValue protocol object
182  @return #TTErr error code */
183  TTErr ProtocolFind(const TTValue& inputValue, TTValue& outputValue);
184 
185 #if 0
186 #pragma mark -
187 #pragma mark Application features
188 #endif
189 
190  /** Discover the namespace of an application under an address
191  @param inputValue <TTSymbol whereToDiscover>
192  @param outputValue <TTSymbol *returnedType, TTValuePtr returnedChildren, TTValuePtr returnedAttributes>
193  @return #TTErr error code */
194  TTErr ApplicationDiscover(const TTValue& inputValue, TTValue& outputValue);
195 
196  /** Discover all the namespace of an application under an address
197  @param inputValue <TTSymbol whereToDiscover>
198  @param outputValue <TTNodePtr>
199  @return #TTErr error code */
200  TTErr ApplicationDiscoverAll(const TTValue& inputValue, TTValue& outputValue);
201 
202  /** Get a value from an attribute of an object at an address in an application
203  @param inputValue <TTSymbol whereToGet, TTSymbol attributeToGet, TTValuePtr returnedValue>
204  @param outputValue nothing
205  @return #TTErr error code */
206  TTErr ApplicationGet(const TTValue& inputValue, TTValue& outputValue);
207 
208  /** Set a value from an attribute of an object at an address in an application
209  @param inputValue <TTSymbol whereToSet, TTSymbol attributeToSet, TTValuePtr newValue>
210  @param outputValue nothing
211  @return #TTErr error code */
212  TTErr ApplicationSet(const TTValue& inputValue, TTValue& outputValue);
213 
214  /** Listen for value changes from an attribute of an object at an address in an application or for creation/destruction under an address.
215  @param inputValue <TTSymbol protocolName, TTSymbol applicationToNotify, TTSymbol whereToListen, TTBoolean enableListening>
216  @param outputValue nothing
217  @return #TTErr error code */
218  TTErr ApplicationListen(const TTValue& inputValue, TTValue& outputValue);
219 
220  /** Update value changes of an attribute of an object at an address in an application or for creation/destruction under an address.
221  @details this is usually the answer of distant namespace or #TTMirror attribute listening
222  @param inputValue <TTSymbol appAnswering, TTSymbol whereComesFrom, TTValuePtr newValue>
223  @param outputValue nothing
224  @return #TTErr error code */
225  TTErr ApplicationListenAnswer(const TTValue& inputValue, TTValue& outputValue);
226 
227 #if 0
228 #pragma mark -
229 #pragma mark Protocol features
230 #endif
231 
232  /** Scan a protocol network in order to intantiate distant applications automatically
233  @param inputValue <TTSymbol protocolName>
234  @param outputValue nothing
235  @return #TTErr error code */
236  TTErr ProtocolScan(const TTValue& inputValue, TTValue& outputValue);
237 
238  /** Run the reception thread mecanism of a Protocol
239  @param inputValue <TTSymbol protocolName>
240  @param outputValue nothing
241  @return #TTErr error code */
242  TTErr ProtocolRun(const TTValue& inputValue, TTValue& outputValue);
243 
244  /** Stop the reception thread mecanism of a Protocol
245  @param inputValue <TTSymbol protocolName>
246  @param outputValue nothing
247  @return #TTErr error code */
248  TTErr ProtocolStop(const TTValue& inputValue, TTValue& outputValue);
249 
250 #if 0
251 #pragma mark -
252 #pragma mark Backup
253 #endif
254 
255  /** Write all applications and protocols setup
256  @param inputValue <TTXmlHandlerPtr aXmlHandler>
257  @param outputValue nothing
258  @return #TTErr error code */
259  TTErr WriteAsXml(const TTValue& inputValue, TTValue& outputValue);
260 
261  /** Convenient method used to write a protocol setup
262  @param aXmlHandler a xml handler object
263  @param aProtocol a protocol object
264  @return #TTErr error code
265  @seealso WriteAsXml */
266  TTErr writeProtocolAsXml(TTXmlHandlerPtr aXmlHandler, TTObject aProtocol);
267 
268  /** Read an applications and protocols setup
269  @param inputValue <TTXmlHandlerPtr aXmlHandler>
270  @param outputValue nothing
271  @return #TTErr error code */
272  TTErr ReadFromXml(const TTValue& inputValue, TTValue& outputValue);
273 
274 #if 0
275 #pragma mark -
276 #pragma mark Public methods useful to ease access to application and protocol
277 #endif
278 
279 public:
280 
281  /** Get an application relative to a name
282  @param applicationName #TTSymbol
283  @return #TTApplicationPtr or NULL if the application doesn't exist */
284  TTApplicationPtr findApplication(TTSymbol applicationName);
285 
286  /** Get an application directory relative to a name
287  @param applicationName #TTSymbol
288  @return #TTNodeDirectoryPtr or NULL if the application doesn't exist */
289  TTNodeDirectoryPtr findApplicationDirectory(TTSymbol applicationName);
290 
291  /** Get local application
292  @return #TTApplicationPtr or NULL if the application doesn't exist */
293  TTApplicationPtr getApplicationLocal();
294 
295  /** Get an application relative to an address
296  @param anAddress #TTAddress
297  @return #TTApplicationPtr : mApplicationLocal for address without directory part or NULL if the directory part is not an application name */
298  TTApplicationPtr findApplicationFrom(TTAddress anAddress);
299 
300  /** Get an application directory relative to an address
301  @param anAddress #TTAddress
302  @return #TTNodeDirectoryPtr : mApplicationLocal directory for address without directory part or NULL if the directory part is not an application name */
303  TTNodeDirectoryPtr findApplicationDirectoryFrom(TTAddress anAddress);
304 
305  /** Get application protocol names relative to a name
306  @param applicationName #TTSymbol
307  @return a #TTValue containing all protocol names */
308  TTValue getApplicationProtocolNames(TTSymbol applicationName);
309 
310  /** Get a protocol relative to a name
311  @param protocolName #TTSymbol
312  @return #TTProtocolPtr or NULL if the protocol doesn't exist */
313  TTProtocolPtr findProtocol(TTSymbol protocolName);
314 
315 #if 0
316 #pragma mark -
317 #pragma mark Friendship
318 #endif
319 
320  friend TTBoolean TTMODULAR_EXPORT TTApplicationManagerGetLocalApplicationDebug();
321  friend TTApplicationPtr TTMODULAR_EXPORT TTApplicationManagerGetApplicationFrom(TTAddress anAddress);
322 
323  friend TTValue TTMODULAR_EXPORT TTApplicationManagerGetApplicationProtocols(TTSymbol applicationName);
324 
325  friend TTErr TTMODULAR_EXPORT TTApplicationManagerAddApplicationObserver(TTSymbol anApplicationName, const TTObject anObserver);
326  friend TTErr TTMODULAR_EXPORT TTApplicationManagerRemoveApplicationObserver(TTSymbol anApplicationName, const TTObject anObserver);
327 
328  friend TTErr TTMODULAR_EXPORT TTApplicationManagerProtocolActivityInCallback(const TTValue& baton, const TTValue& data);
329  friend TTErr TTMODULAR_EXPORT TTApplicationManagerProtocolActivityOutCallback(const TTValue& baton, const TTValue& data);
330 };
331 
333 
334 #if 0
335 #pragma mark -
336 #pragma mark Some Functions
337 #endif
338 
339 /** Add a TTCallback as observer of application creation/destruction
340  note : it uses the extern TTModularApplications variable
341  @param anApplicationName an application to observe
342  @param observer a TTCallbackPtr to add
343  @return an error code */
344 TTErr TTMODULAR_EXPORT TTApplicationManagerAddApplicationObserver(TTSymbol anApplicationName, const TTObject anObserver);
345 
346 /** Remove a TTCallback as observer of application creation/destruction
347  note : it uses the extern TTModularApplications variable
348  @param anApplicationName an application
349  @param observer a TTCallbackPtr to remove
350  @return a kTTErrGeneric if there isn't observer */
351 TTErr TTMODULAR_EXPORT TTApplicationManagerRemoveApplicationObserver(TTSymbol anApplicationName, const TTObject anObserver);
352 
353 /** To get back raw incoming messages from any protocol
354  @param baton ..
355  @param data ..
356  @return an error code */
357 TTErr TTMODULAR_EXPORT TTApplicationManagerProtocolActivityInCallback(const TTValue& baton, const TTValue& data);
358 
359 /** To get back raw outputing messages from any protocol
360  @param baton ..
361  @param data ..
362  @return an error code */
363 TTErr TTMODULAR_EXPORT TTApplicationManagerProtocolActivityOutCallback(const TTValue& baton, const TTValue& data);
364 
365 #endif // __TT_APPLICATION_MANAGER_H__
an application have been released by the application manager
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
TTModular Library.
TTApplicationNotificationFlag
application's protocol will be stopped
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
Maintain a collection of TTValue objects indexed by TTSymbol pointers.
Definition: TTHash.h:36
TTErr TTMODULAR_EXPORT TTApplicationManagerAddApplicationObserver(TTSymbol anApplicationName, const TTObject anObserver)
Add a TTCallback as observer of application creation/destruction note : it uses the extern TTModularA...
#define TTCLASS_SETUP(className)
TODO Doxygen: need more comments here.
Definition: TTFoundation.h:54
application's protocol have been started
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
TTErr TTMODULAR_EXPORT TTApplicationManagerRemoveApplicationObserver(TTSymbol anApplicationName, const TTObject anObserver)
Remove a TTCallback as observer of application creation/destruction note : it uses the extern TTModul...
an application have been intantiated by the application manager
Handles TTApplication and #Protocol instances.
TTErr TTMODULAR_EXPORT TTApplicationManagerProtocolActivityOutCallback(const TTValue &baton, const TTValue &data)
To get back raw outputing messages from any protocol.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
Write / Read mecanism.
Definition: TTXmlHandler.h:48
TTErr TTMODULAR_EXPORT TTApplicationManagerProtocolActivityInCallback(const TTValue &baton, const TTValue &data)
To get back raw incoming messages from any protocol.
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