Jamoma API  0.6.0.a19
TTApplicationManager.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup modularLibrary
4  *
5  * @brief Handles #TTApplication and #Protocol instances
6  *
7  * @see TTApplication, ProtocolLib
8  *
9  * @authors Théo de la Hogue
10  *
11  * @copyright Copyright © 2010-2014, Théo de la Hogue @n
12  * This code is licensed under the terms of the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 #include "TTApplicationManager.h"
17 #include "TTProtocol.h"
18 #include <libxml/encoding.h>
19 #include <libxml/xmlwriter.h>
20 #include <libxml/xmlreader.h>
21 
22 #define thisTTClass TTApplicationManager
23 #define thisTTClassName "ApplicationManager"
24 #define thisTTClassTags "application, manager"
25 
26 TT_MODULAR_CONSTRUCTOR,
27 mApplicationObserversMutex(NULL)
28 {
29  TT_ASSERT("TTModularApplicationManager is NULL", (TTModularApplicationManager == NULL));
30 
31  // application attributes
32  addAttributeWithGetter(Applications, kTypePointer);
33  addAttributeProperty(Applications, readOnly, YES);
34  addAttributeProperty(Applications, hidden, YES);
35 
36  addAttribute(ApplicationLocal, kTypeObject);
37 
38  registerAttribute(TTSymbol("applicationNames"), kTypeLocalValue, NULL, (TTGetterMethod)& TTApplicationManager::getApplicationNames);
39  registerAttribute(TTSymbol("applicationLocalName"), kTypeLocalValue, NULL, (TTGetterMethod)& TTApplicationManager::getApplicationLocalName);
40 
41  // protocol attributes
42  registerAttribute(TTSymbol("protocolNames"), kTypeLocalValue, NULL, (TTGetterMethod)& TTApplicationManager::getProtocolNames);
43 
44  // application messages
45  addMessageWithArguments(ApplicationInstantiateLocal);
46  addMessageWithArguments(ApplicationInstantiateDistant);
47 
48  addMessageWithArguments(ApplicationRename);
49  addMessageProperty(ApplicationRename, hidden, YES);
50 
51  addMessageWithArguments(ApplicationRelease);
52  addMessageWithArguments(ApplicationFind);
53 
54  addMessageWithArguments(ApplicationDiscover);
55  addMessageProperty(ApplicationDiscover, hidden, YES);
56 
57  addMessageWithArguments(ApplicationDiscoverAll);
58  addMessageProperty(ApplicationDiscoverAll, hidden, YES);
59 
60  addMessageWithArguments(ApplicationGet);
61  addMessageProperty(ApplicationGet, hidden, YES);
62 
63  addMessageWithArguments(ApplicationSet);
64  addMessageProperty(ApplicationSet, hidden, YES);
65 
66  addMessageWithArguments(ApplicationListen);
67  addMessageProperty(ApplicationListen, hidden, YES);
68 
69  addMessageWithArguments(ApplicationListenAnswer);
70  addMessageProperty(ApplicationListenAnswer, hidden, YES);
71 
72  // protocol messages
73  addMessageWithArguments(ProtocolInstantiate);
74  addMessageWithArguments(ProtocolRelease);
75  addMessageWithArguments(ProtocolFind);
76 
77  addMessageWithArguments(ProtocolScan);
78  addMessageWithArguments(ProtocolRun);
79  addMessageWithArguments(ProtocolStop);
80 
81  // needed to be handled by a TTXmlHandler
82  addMessageWithArguments(WriteAsXml);
83  addMessageProperty(WriteAsXml, hidden, YES);
84 
85  addMessageWithArguments(ReadFromXml);
86  addMessageProperty(ReadFromXml, hidden, YES);
87 
88  // create a ApplicationObservers table and protect it from multithreading access
89  // why ? because observers could disappear when they know an application is destroyed
90  mApplicationObservers.setThreadProtection(true);
91  mApplicationObserversMutex = new TTMutex(true);
92 
93  // filled the TTModularApplicationManager pointer
95 
96  // protect applications and protocol from multithreading access
97  mApplications.setThreadProtection(YES);
98  mProtocols.setThreadProtection(YES);
99 }
100 
101 #if 0
102 #pragma mark -
103 #pragma mark Destructor
104 #endif
105 
106 TTApplicationManager::~TTApplicationManager()
107 {
108  delete mApplicationObserversMutex;
109 
110  // reset the TTModularApplicationManager pointer
112 }
113 
114 #if 0
115 #pragma mark -
116 #pragma mark Application accesors
117 #endif
118 
119 TTErr TTApplicationManager::getApplications(TTValue& value)
120 {
121  value = TTPtr(&mApplications);
122  return kTTErrNone;
123 }
124 
125 TTErr TTApplicationManager::getApplicationNames(TTValue& returnedApplicationNames)
126 {
127  return mApplications.getKeys(returnedApplicationNames);
128 }
129 
130 TTErr TTApplicationManager::getApplicationLocalName(TTValue& returnedApplicationLocalName)
131 {
132 
133  return mApplicationLocal.get(kTTSym_name, returnedApplicationLocalName);
134 }
135 
137 {
138  if (mApplicationLocal.valid()) {
139 
140  returnedApplicationLocal = mApplicationLocal;
141  return kTTErrNone;
142  }
143  else
144  return kTTErrGeneric;
145 }
146 
147 #if 0
148 #pragma mark -
149 #pragma mark Protocol accesors
150 #endif
151 
152 TTErr TTApplicationManager::getProtocolNames(TTValue& value)
153 {
154  return mProtocols.getKeys(value);
155 }
156 
157 #if 0
158 #pragma mark -
159 #pragma mark Application factory
160 #endif
161 
162 TTErr TTApplicationManager::ApplicationInstantiateLocal(const TTValue& inputValue, TTValue& outputValue)
163 {
164  TTValue v, none;
165  TTSymbol applicationName;
166  TTObject anApplication;
167 
168  // can't register two local applications
169  if (mApplicationLocal.valid())
170  return kTTErrGeneric;
171 
172  if (inputValue.size() == 1) {
173 
174  if (inputValue[0].type() == kTypeSymbol) {
175 
176  applicationName = inputValue[0];
177 
178  // check if the new application name doesn't exist
179  if (!mApplications.lookup(applicationName, v)) {
180 
181  TTLogError("%s application already exists\n", applicationName.c_str());
182  return kTTErrGeneric;
183  }
184 
185  // create an application
186  anApplication = TTObject(kTTSym_Application);
187  anApplication.set(kTTSym_name, applicationName);
188 
189  // register the application under its own root
190  v = TTValue(kTTAdrsRoot, anApplication);
191  anApplication.send("ObjectRegister", v);
192 
193  // register the application as any application
194  mApplications.append(applicationName, anApplication);
195 
196  // register it as the local application
197  mApplicationLocal = anApplication;
198 
199  // return the application back
200  outputValue = anApplication;
201 
202  // notify applications observer that an application has been instantiated
203  notifyApplicationObservers(applicationName, anApplication, kApplicationInstantiated);
204 
205  TTLogMessage("%s application instantiated\n", applicationName.c_str());
206 
207  return kTTErrNone;
208  }
209  }
210 
211  return kTTErrGeneric;
212 }
213 
214 TTErr TTApplicationManager::ApplicationInstantiateDistant(const TTValue& inputValue, TTValue& outputValue)
215 {
216  TTValue v, none;
217  TTSymbol applicationName;
218  TTObject anApplication;
219 
220  if (inputValue.size() == 1) {
221 
222  if (inputValue[0].type() == kTypeSymbol) {
223 
224  applicationName = inputValue[0];
225 
226  // check if the new application name doesn't exist
227  if (!mApplications.lookup(applicationName, v)) {
228 
229  TTLogError("%s application already exists\n", applicationName.c_str());
230  return kTTErrGeneric;
231  }
232 
233  // create an application
234  anApplication = TTObject(kTTSym_Application);
235  anApplication.set(kTTSym_name, applicationName);
236  anApplication.set(kTTSym_type, kTTSym_mirror);
237 
238  // register the application under its own root
239  v = TTValue(kTTAdrsRoot, anApplication);
240  anApplication.send("ObjectRegister", v);
241 
242  // register the application as any application
243  mApplications.append(applicationName, anApplication);
244 
245  // return the application back
246  outputValue = anApplication;
247 
248  // notify applications observer that an application has been instantiated
249  notifyApplicationObservers(applicationName, anApplication, kApplicationInstantiated);
250 
251  TTLogMessage("%s application instantiated\n", applicationName.c_str());
252  return kTTErrNone;
253  }
254  }
255 
256  return kTTErrGeneric;
257 }
258 
259 TTErr TTApplicationManager::ApplicationRelease(const TTValue& inputValue, TTValue& outputValue)
260 {
261  TTValue v, protocols, none;
262  TTSymbol applicationName, protocolName;
263  TTObject anApplication, aProtocol;
264  TTErr err;
265 
266  if (inputValue.size() == 1) {
267 
268  if (inputValue[0].type() == kTypeSymbol) {
269 
270  applicationName = inputValue[0];
271 
272  err = mApplications.lookup(applicationName, v);
273 
274  if (!err) {
275 
276  anApplication = v[0];
277 
278  // notify applications observer that an application will be removed
279  notifyApplicationObservers(applicationName, anApplication, kApplicationReleased);
280 
281  // unregister the application to each protocol
282  protocols = getApplicationProtocolNames(applicationName);
283  for (TTUInt8 i = 0; i < protocols.size(); i++) {
284 
285  protocolName = protocols[i];
286  mProtocols.lookup(protocolName, v);
287 
288  aProtocol = v[0];
289  aProtocol.send("ApplicationUnregister", applicationName);
290  }
291 
292  // unregister the application from its own root
293  anApplication.send("ObjectUnregister", kTTAdrsRoot);
294 
295  // if the application is the local one : forget it
296  if (anApplication.instance() == mApplicationLocal.instance())
297  mApplicationLocal = TTObject();
298 
299  // unregister the application and release it
300  mApplications.remove(applicationName);
301 
302  TTLogMessage("%s application released\n", applicationName.c_str());
303  return kTTErrNone;
304  }
305 
306  TTLogError("%s application doesn't exist\n", applicationName.c_str());
307  return err;
308  }
309  }
310 
311  return kTTErrGeneric;
312 }
313 
314 TTErr TTApplicationManager::ApplicationRename(const TTValue& inputValue, TTValue& outputValue)
315 {
316  if (inputValue.size() == 2) {
317 
318  if (inputValue[0].type() == kTypeSymbol && inputValue[1].type() == kTypeSymbol) {
319 
320  TTValue v;
321  TTSymbol oldApplicationName = inputValue[0];
322  TTSymbol newApplicationName = inputValue[1];
323 
324  // check if the new application name doesn't exist
325  if (!mApplications.lookup(newApplicationName, v)) {
326 
327  TTLogError("%s application already exists\n", newApplicationName.c_str());
328  return kTTErrGeneric;
329  }
330 
331  if (!mApplications.lookup(oldApplicationName, v)) {
332 
333  TTObject anApplication = v[0];
334 
335  // notify applications observer that an application will be removed
336  notifyApplicationObservers(oldApplicationName, anApplication, kApplicationReleased);
337 
338  mApplications.remove(oldApplicationName);
339  mApplications.append(newApplicationName, anApplication);
340 
341  // Rename the application into each protocol
342  TTValue protocolNames;
343  mProtocols.getKeys(protocolNames);
344  for (TTUInt16 i = 0; i < protocolNames.size(); i++) {
345 
346  TTSymbol protocolName = protocolNames[i];
347 
348  if (!mProtocols.lookup(protocolName, v)) {
349  TTObject aProtocol = v[0];
350  aProtocol.send("ApplicationRename", inputValue, outputValue);
351  }
352  }
353 
354  // notify applications observer that an application has been instantiated
355  notifyApplicationObservers(newApplicationName, anApplication, kApplicationInstantiated);
356 
357  return kTTErrNone;
358  }
359  }
360  }
361 
362  return kTTErrGeneric;
363 }
364 
365 TTErr TTApplicationManager::ApplicationFind(const TTValue& inputValue, TTValue& outputValue)
366 {
367  if (inputValue.size()) {
368 
369  if (inputValue[0].type() == kTypeSymbol) {
370 
371  TTSymbol applicationName = inputValue[0];
372 
373  return mApplications.lookup(applicationName, outputValue);
374  }
375  }
376 
377  return kTTErrGeneric;
378 }
379 
380 TTErr TTApplicationManager::notifyApplicationObservers(TTSymbol anApplicationName, TTObject anApplication, TTApplicationNotificationFlag flag)
381 {
382  unsigned int i;
383  TTValue hk, lk, o, f, data;
384  TTSymbol key;
385  TTListPtr lk_o;
386  TTObject anObserver;
387  bool foundObsv = false;
388 
389  // if there are observers
390  if (!mApplicationObservers.isEmpty()) {
391 
392  // enable observers protection
393  mApplicationObserversMutex->lock();
394 
395  this->mApplicationObservers.getKeys(hk);
396 
397  // for each key of mObserver tab
398  for (i = 0; i < hk.size(); i++) {
399 
400  key = hk[i];
401 
402  // compare the key with the applicationName
403  if (key == anApplicationName){
404 
405  // get the Observers list
406  mApplicationObservers.lookup(key, lk);
407  lk_o = TTListPtr((TTPtr)lk[0]);
408 
409  if (!lk_o->isEmpty()) {
410  for (lk_o->begin(); lk_o->end(); lk_o->next())
411  {
412  TTValue dummy;
413 
414  anObserver = lk_o->current()[0];
415 
416  data.append(anApplicationName);
417  data.append(anApplication);
418  data.append((TTInt8)flag);
419  data.append(anObserver);
420 
421  anObserver.send("notify", data, dummy);
422  }
423 
424  foundObsv = true;
425  }
426  }
427  }
428 
429  // disable observers protection
430  mApplicationObserversMutex->unlock();
431 
432  if (foundObsv)
433  return kTTErrNone;
434  else
435  return kTTErrGeneric;
436  }
437  else
438  return kTTErrGeneric;
439 }
440 
441 #if 0
442 #pragma mark -
443 #pragma mark Protocol factory
444 #endif
445 
446 TTErr TTApplicationManager::ProtocolInstantiate(const TTValue& inputValue, TTValue& outputValue)
447 {
448  TTSymbol protocolName;
449  TTObject aProtocol, activityInCallback, activityOutCallback;
450  TTValue args, v;
451 
452  if (inputValue.size() == 1) {
453 
454  if (inputValue[0].type() == kTypeSymbol) {
455 
456  protocolName = inputValue[0];
457 
458  // check if the new protocol name doesn't exist
459  if (!mProtocols.lookup(protocolName, v)) {
460 
461  TTLogError("%s protocol already exists\n", protocolName.c_str());
462  return kTTErrGeneric;
463  }
464 
465  // prepare arguments
466  args = TTObject(this);
467 
468  // create 2 callbacks to get raw protocol messages back
469  activityInCallback = TTObject("callback");
470  activityInCallback.set(kTTSym_baton, protocolName);
471  activityInCallback.set(kTTSym_function, TTPtr(&TTApplicationManagerProtocolActivityInCallback));
472  args.append(activityInCallback);
473 
474  activityOutCallback = TTObject("callback");
475  activityOutCallback.set(kTTSym_baton, protocolName);
476  activityOutCallback.set(kTTSym_function, TTPtr(&TTApplicationManagerProtocolActivityOutCallback));
477  args.append(activityOutCallback);
478 
479  // create an instance of a Protocol object
480  aProtocol = TTObject(protocolName, args);
481 
482  if (aProtocol.valid()) {
483 
484  // register the protocol into the application manager
485  args = aProtocol;
486  mProtocols.append(protocolName, args);
487 
488  // return the protocol back
489  outputValue = aProtocol;
490 
491  TTLogMessage("%s protocol instantiated\n", protocolName.c_str());
492  return kTTErrNone;
493  }
494 
495  TTLogMessage("%s protocol cannot be instantiated\n", protocolName.c_str());
496  return kTTErrGeneric;
497  }
498  }
499 
500  return kTTErrGeneric;
501 }
502 
503 TTErr TTApplicationManager::ProtocolRelease(const TTValue& inputValue, TTValue& outputValue)
504 {
505  TTValue v;
506  TTSymbol protocolName;
507 
508  if (inputValue.size()) {
509 
510  if (inputValue[0].type() == kTypeSymbol) {
511 
512  protocolName = inputValue[0];
513 
514  if (!mProtocols.lookup(protocolName, v)) {
515 
516  TTObject aProtocol = v[0];
517  aProtocol.send("Stop");
518 
519  mProtocols.remove(protocolName);
520 
521  TTLogMessage("%s protocol released\n", protocolName.c_str());
522  return kTTErrNone;
523  }
524 
525  TTLogError("%s protocol doesn't exist\n", protocolName.c_str());
526  return kTTErrValueNotFound;
527  }
528  }
529 
530  return kTTErrGeneric;
531 }
532 
533 TTErr TTApplicationManager::ProtocolFind(const TTValue& inputValue, TTValue& outputValue)
534 {
535  if (inputValue.size()) {
536 
537  if (inputValue[0].type() == kTypeSymbol) {
538 
539  TTSymbol protocolName = inputValue[0];
540 
541  return mProtocols.lookup(protocolName, outputValue);
542  }
543  }
544 
545  return kTTErrGeneric;
546 }
547 
548 #if 0
549 #pragma mark -
550 #pragma mark Application features
551 #endif
552 
553 TTErr TTApplicationManager::ApplicationDiscover(const TTValue& inputValue, TTValue& outputValue)
554 {
555  TTNodeDirectoryPtr directory;
556  TTAddress whereToDiscover;
557  TTSymbol *returnedType = NULL;
558  TTValuePtr returnedChildren;
559  TTValuePtr returnedAttributes;
560 
561  whereToDiscover = inputValue[0];
562 
563  returnedType = (TTSymbol*)((TTPtr)outputValue[0]);
564  returnedChildren = TTValuePtr((TTPtr)outputValue[1]);
565  returnedAttributes = TTValuePtr((TTPtr)outputValue[2]);
566 
567  TTList nodeList, childList;
568  TTNodePtr firstNode, aNode;
569  TTAddress nodeAddress;
570  TTSymbol objectType;
571  TTObject anObject;
572  TTErr err;
573 
574  directory = accessApplicationDirectoryFrom(whereToDiscover);
575  if (!directory)
576  return kTTErrGeneric;
577 
578  err = directory->Lookup(whereToDiscover, nodeList, &firstNode);
579 
580  // if the address to discover exist : fill the answer
581  if (!err) {
582 
583  firstNode->getChildren(S_WILDCARD, S_WILDCARD, childList);
584 
585  *returnedType = kTTSym_none;
586 
587  // check if there is an object
588  anObject = firstNode->getObject();
589  if (anObject.valid()) {
590 
591  // fill returned type
592  objectType = anObject.name();
593 
594  if (objectType != kTTSymEmpty)
595  *returnedType = objectType;
596 
597  // fill returned attributes
598  anObject.attributes(*returnedAttributes);
599  }
600 
601  // sort children by priority
602  childList.sort(&compareNodePriorityThenNameThenInstance);
603 
604  // fill returned children names
605  for (childList.begin(); childList.end(); childList.next()) {
606 
607  // get the returned node
608  aNode = TTNodePtr((TTPtr)childList.current()[0]);
609 
610  // get the relative address
611  aNode->getAddress(nodeAddress, whereToDiscover);
612  returnedChildren->append(nodeAddress);
613  }
614 
615  return kTTErrNone;
616  }
617 
618  return kTTErrGeneric;
619 }
620 
621 TTErr TTApplicationManager::ApplicationDiscoverAll(const TTValue& inputValue, TTValue& outputValue)
622 {
623  TTNodeDirectoryPtr directory;
624  TTAddress whereToDiscover;
625 
626  whereToDiscover = inputValue[0];
627 
628  TTNodePtr aNode;
629  TTErr err;
630 
631  directory = accessApplicationDirectoryFrom(whereToDiscover);
632  if (!directory)
633  return kTTErrGeneric;
634 
635  err = directory->getTTNode(whereToDiscover, &aNode);
636 
637  // if the address to discover exist : fill the answer
638  if (!err)
639  outputValue = TTPtr(aNode);
640 
641  return err;
642 }
643 
644 TTErr TTApplicationManager::ApplicationGet(const TTValue& inputValue, TTValue& outputValue)
645 {
646  TTNodeDirectoryPtr directory;
647  TTAddress whereToGet;
648 
649  whereToGet = inputValue[0];
650 
651  TTNodePtr nodeToGet;
652  TTObject anObject;
653  TTErr err;
654 
655  directory = accessApplicationDirectoryFrom(whereToGet);
656  if (!directory)
657  return kTTErrGeneric;
658 
659  // can't allow to use wilcards here because one value is returned
660  err = directory->getTTNode(whereToGet, &nodeToGet);
661 
662  if (!err) {
663 
664  anObject = nodeToGet->getObject();
665  if (anObject.valid())
666  return anObject.get(whereToGet.getAttribute(), outputValue);
667  }
668 
669  return kTTErrGeneric;
670 }
671 
672 TTErr TTApplicationManager::ApplicationSet(const TTValue& inputValue, TTValue& outputValue)
673 {
674  TTNodeDirectoryPtr directory;
675  TTAddress whereToSet;
676  TTValuePtr newValue;
677 
678  whereToSet = inputValue[0];
679  newValue = TTValuePtr((TTPtr)inputValue[1]);
680 
681  TTList aNodeList;
682  TTNodePtr nodeToSet;
683  TTSymbol objectType;
684  TTObject anObject;
685  TTValue none;
686  TTErr err;
687 
688  directory = accessApplicationDirectoryFrom(whereToSet);
689  if (!directory)
690  return kTTErrGeneric;
691 
692  // allow to use wilcards
693  err = directory->Lookup(whereToSet, aNodeList, &nodeToSet);
694 
695  if (!err) {
696 
697  err = kTTErrNone;
698  for (aNodeList.begin(); aNodeList.end(); aNodeList.next())
699  {
700  // get a node from the selection
701  nodeToSet = TTNodePtr((TTPtr)aNodeList.current()[0]);
702 
703  anObject = nodeToSet->getObject();
704 
705  if (anObject.valid()) {
706 
707  objectType = anObject.name();
708 
709  // TTData case : for value attribute use Command message
710  if (objectType == kTTSym_Data) {
711 
712  if (whereToSet.getAttribute() == kTTSym_value)
713  err = anObject.send(kTTSym_Command, *newValue);
714  else
715  err = anObject.set(whereToSet.getAttribute(), *newValue);
716  }
717  else {
718  // try to set an attribute
719  err = anObject.set(whereToSet.getAttribute(), *newValue);
720 
721  // try to use a message
722  if (err == kTTErrInvalidAttribute)
723  err = anObject.send(whereToSet.getAttribute(), *newValue);
724  }
725  }
726 
727  if (err)
728  break;
729  }
730 
731  return err;
732  }
733 
734  return kTTErrGeneric; // TODO : return an error notification
735 }
736 
737 TTErr TTApplicationManager::ApplicationListen(const TTValue& inputValue, TTValue& outputValue)
738 {
739  TTAddress whereToListen;
740  TTSymbol appToNotify, protocolName;
741  TTBoolean enableListening;
742  TTObject applicationToListen;
743  TTObject aProtocol;
744  TTValue v, args, none;
745 
746  protocolName = inputValue[0];
747  appToNotify = inputValue[1];
748  whereToListen = inputValue[2];
749  enableListening = inputValue[3];
750 
751  applicationToListen = findApplicationFrom(whereToListen);
752 
753  if (applicationToListen.valid()) {
754 
755  if (!mProtocols.lookup(protocolName, v)) {
756 
757  aProtocol = v[0];
758 
759  TTLogDebug("TTApplicationManager::Listen");
760 
761  // add observer
762  if (enableListening) {
763 
764  args.append(aProtocol);
765  args.append(appToNotify);
766  args.append(whereToListen);
767 
768  // start local directory listening
769  if (whereToListen.getAttribute() == TTSymbol("life")) // TODO : find a better name
770  return applicationToListen.send("AddDirectoryListener", args);
771 
772  // start local attribute listening
773  else
774  return applicationToListen.send("AddAttributeListener", args);
775  }
776  // remove listener
777  else {
778 
779  args.append(appToNotify);
780  args.append(whereToListen);
781 
782  // stop local directory listening
783  if (whereToListen.getAttribute() == TTSymbol("life")) // TODO : find a better name
784  return applicationToListen.send("RemoveDirectoryListener", args);
785 
786  // stop local attribute listening
787  else
788  return applicationToListen.send("RemoveAttributeListener", args);
789  }
790  }
791  }
792 
793  return kTTErrGeneric;
794 }
795 
796 TTErr TTApplicationManager::ApplicationListenAnswer(const TTValue& inputValue, TTValue& outputValue)
797 {
798  TTObject anApplication;
799  TTSymbol appAnswering;
800  TTAddress whereComesFrom;
801  TTValuePtr newValue;
802  TTValue v, args, none;
803 
804  appAnswering = inputValue[0];
805  whereComesFrom = inputValue[1];
806  newValue = TTValuePtr((TTPtr)inputValue[2]);
807 
808  if (!mApplications.lookup(appAnswering, v)) {
809 
810  TTLogDebug("TTApplicationManager::ListenAnswer");
811 
812  anApplication = v[0];
813 
814  args.append(whereComesFrom);
815  args.append((TTPtr)newValue);
816 
817  // notify directory updates
818  if (whereComesFrom.getAttribute() == TTSymbol("life")) // TODO : find a better name
819  return anApplication.send("UpdateDirectory", args);
820 
821  // notify attribute updates
822  else
823  return anApplication.send("UpdateAttribute", args);
824  }
825 
826  return kTTErrGeneric;
827 }
828 
829 #if 0
830 #pragma mark -
831 #pragma mark Protocol features
832 #endif
833 
834 TTErr TTApplicationManager::ProtocolScan(const TTValue& inputValue, TTValue& outputValue)
835 {
836  TTValue v, allProtocolNames;
837  TTSymbol protocolName;
838  TTObject aProtocol;
839  TTErr err;
840 
841  // if no name do it for all protocol
842  if (inputValue.size()) {
843 
844  protocolName = inputValue[0];
845 
846  if (!mProtocols.lookup(protocolName, v)) {
847  aProtocol = v[0];
848  aProtocol.send("Scan");
849  }
850  }
851  else {
852  // Scan each protocol
853  mProtocols.getKeys(allProtocolNames);
854  for (TTUInt16 i = 0; i < allProtocolNames.size(); i++) {
855 
856  protocolName = allProtocolNames[i];
857  err = mProtocols.lookup(protocolName, v);
858 
859  if (!err) {
860  aProtocol = v[0];
861  aProtocol.send("Scan");
862  }
863  }
864  }
865 
866  return kTTErrNone;
867 }
868 
869 TTErr TTApplicationManager::ProtocolRun(const TTValue& inputValue, TTValue& outputValue)
870 {
871  TTValue v, protocolNames, applicationNames;
872  TTSymbol protocolName, applicationName;
873  TTObject aProtocol;
874  TTObject anApplication;
875  TTBoolean isRegistered;
876  TTErr start = kTTErrGeneric;
877 
878  // if no name do it for all protocol
879  if (inputValue.size()) {
880 
881  protocolName = inputValue[0];
882 
883  if (!mProtocols.lookup(protocolName, v)) {
884  aProtocol = v[0];
885  start = aProtocol.send(kTTSym_Run);
886  }
887  }
888  else {
889 
890  // Run each protocol
891  mProtocols.getKeys(protocolNames);
892  for (TTUInt16 i = 0; i < protocolNames.size(); i++) {
893  TTValue dummy;
894  protocolName = protocolNames[i];
895  this->ProtocolRun(protocolName, dummy);
896  }
897 
898  return kTTErrNone;
899  }
900 
901  // if the protocol starts
902  if (start == kTTErrNone) {
903 
904  // notify application obervers for application that use this protocol
905  mApplications.getKeys(applicationNames);
906  for (TTUInt16 j = 0; j < applicationNames.size(); j++) {
907 
908  // get application
909  applicationName = applicationNames[j];
910  mApplications.lookup(applicationName, v);
911  anApplication = v[0];
912 
913  // don't notify local application observers
914  if (anApplication.instance() != mApplicationLocal.instance()) {
915 
916  aProtocol.send("isRegistered", applicationName, v);
917  isRegistered = v[0];
918 
919  if (isRegistered)
920  notifyApplicationObservers(applicationName, anApplication, kApplicationProtocolStarted);
921 
922  }
923  }
924  }
925 
926  return kTTErrNone;
927 }
928 
929 TTErr TTApplicationManager::ProtocolStop(const TTValue& inputValue, TTValue& outputValue)
930 {
931  TTValue v, protocolNames, applicationNames;
932  TTSymbol protocolName, applicationName;
933  TTObject aProtocol;
934  TTObject anApplication;
935  TTBoolean isRegistered;
936  TTErr stop = kTTErrGeneric;
937 
938  // if no name do it for all protocol
939  if (inputValue.size()) {
940 
941  protocolName = inputValue[0];
942 
943  if (!mProtocols.lookup(protocolName, v)) {
944  aProtocol = v[0];
945  stop = aProtocol.send(kTTSym_Stop);
946  }
947  }
948  else {
949 
950  // Stop each protocol
951  mProtocols.getKeys(protocolNames);
952  for (TTUInt16 i = 0; i < protocolNames.size(); i++) {
953  TTValue dummy;
954 
955  protocolName = protocolNames[i];
956  this->ProtocolStop(protocolName, dummy);
957  }
958 
959  return kTTErrNone;
960  }
961 
962  // if the protocol stops
963  if (stop == kTTErrNone) {
964 
965  // notify application obervers for application that use this protocol
966  mApplications.getKeys(applicationNames);
967  for (TTUInt16 j = 0; j < applicationNames.size(); j++) {
968 
969  // get application
970  applicationName = applicationNames[j];
971  mApplications.lookup(applicationName, v);
972  anApplication = v[0];
973 
974  // don't notify local application observers
975  if (anApplication.instance() != mApplicationLocal.instance()) {
976 
977  aProtocol.send("isRegistered", applicationName, v);
978  isRegistered = v[0];
979 
980  if (isRegistered)
981  notifyApplicationObservers(applicationName, anApplication, kApplicationProtocolStopped);
982 
983  }
984  }
985  }
986 
987  return kTTErrNone;
988 }
989 
990 #if 0
991 #pragma mark -
992 #pragma mark Backup
993 #endif
994 
995 TTErr TTApplicationManager::WriteAsXml(const TTValue& inputValue, TTValue& outputValue)
996 {
997  TTObject o = inputValue[0];
998  TTXmlHandlerPtr aXmlHandler = (TTXmlHandlerPtr)o.instance();
999  if (!aXmlHandler)
1000  return kTTErrGeneric;
1001 
1002  TTSymbol name;
1003  TTObject anApplication;
1004  TTObject aProtocol;
1005  TTValue keys, v;
1006  TTUInt16 i;
1007 
1008  // Write each protocol
1009  xmlTextWriterWriteComment((xmlTextWriterPtr)aXmlHandler->mWriter, BAD_CAST "protocols setup");
1010 
1011  mProtocols.getKeys(keys);
1012  for (i = 0; i < keys.size(); i++) {
1013 
1014  name = keys[i];
1015  mProtocols.lookup(name, v);
1016  aProtocol = v[0];
1017 
1018  writeProtocolAsXml(aXmlHandler, aProtocol);
1019  }
1020 
1021  // Write each application
1022  xmlTextWriterWriteComment((xmlTextWriterPtr)aXmlHandler->mWriter, BAD_CAST "applications namespace");
1023 
1024  mApplications.getKeys(keys);
1025  for (i = 0; i < keys.size(); i++) {
1026 
1027  name = keys[i];
1028  mApplications.lookup(name, v);
1029  anApplication = v[0];
1030 
1031  v = TTValue(anApplication);
1032  aXmlHandler->setAttributeValue(kTTSym_object, v);
1033  aXmlHandler->sendMessage(TTSymbol("Write"));
1034  }
1035 
1036  return kTTErrNone;
1037 }
1038 
1039 TTErr TTApplicationManager::writeProtocolAsXml(TTXmlHandlerPtr aXmlHandler, TTObject aProtocol)
1040 {
1041  TTSymbol name, type;
1042  TTBoolean registered;
1043  TTValue v, none, applicationNames, parametersNames;
1044  TTString s;
1045  TTErr err;
1046 
1047  // Start "protocol" xml node
1048  xmlTextWriterStartElement((xmlTextWriterPtr)aXmlHandler->mWriter, BAD_CAST "protocol");
1049 
1050  // Write protocol name
1051  xmlTextWriterWriteAttribute((xmlTextWriterPtr)aXmlHandler->mWriter, BAD_CAST "name", BAD_CAST aProtocol.name().c_str());
1052 
1053  // Start an xml node for each application registered to this protocol
1054  mApplications.getKeys(applicationNames);
1055 
1056  for (TTElementIter it1 = applicationNames.begin() ; it1 != applicationNames.end() ; it1++)
1057  {
1058  name = TTElement(*it1);
1059 
1060  aProtocol.send("isRegistered", name, v);
1061 
1062  registered = v[0];
1063 
1064  // if the application is registered to this protocol
1065  if (registered)
1066  {
1067  // select an application to get its parameters
1068  err = aProtocol.send("ApplicationSelect", name);
1069 
1070  // Start an xml node for distant application parameters
1071  xmlTextWriterStartElement((xmlTextWriterPtr)aXmlHandler->mWriter, BAD_CAST name.c_str());
1072 
1073  // write each parameter value
1074  aProtocol.get("parameterNames", parametersNames);
1075  for (TTElementIter it2 = parametersNames.begin() ; it2 != parametersNames.end() ; it2++)
1076  {
1077  name = TTElement(*it2);
1078  type = aProtocol.attributeType(name);
1079 
1080  aProtocol.get(name, v);
1081  v.toString(type != kTTSym_symbol);
1082  s = TTString(v[0]);
1083 
1084  xmlTextWriterWriteAttribute((xmlTextWriterPtr)aXmlHandler->mWriter, BAD_CAST name.c_str(), BAD_CAST s.data());
1085  }
1086 
1087  // End application parameters xml node
1088  xmlTextWriterEndElement((xmlTextWriterPtr)aXmlHandler->mWriter);
1089  }
1090  }
1091 
1092  // End "protocol" xml node
1093  xmlTextWriterEndElement((xmlTextWriterPtr)aXmlHandler->mWriter);
1094 
1095  return kTTErrNone;
1096 }
1097 
1098 TTErr TTApplicationManager::ReadFromXml(const TTValue& inputValue, TTValue& outputValue)
1099 {
1100  TTObject o = inputValue[0];
1101  TTXmlHandlerPtr aXmlHandler = (TTXmlHandlerPtr)o.instance();
1102  if (!aXmlHandler)
1103  return kTTErrGeneric;
1104 
1105  TTSymbol applicationName, applicationType, currentApplicationName;
1106  TTSymbol protocolName, currentProtocolName, parameterName, parameterType;
1107  TTValue v, args, applicationNames, protocolNames, parameterValue, out, none;
1108  TTUInt16 i, j;
1109  TTErr err;
1110 
1111  // switch on the name of the XML node
1112 
1113  // starts reading
1114  if (aXmlHandler->mXmlNodeName == kTTSym_xmlHandlerReadingStarts) {
1115 
1116  // stop protocol reception threads
1117  ProtocolStop(v, out);
1118 
1119  // unregister all applications from all protocols
1120  mProtocols.getKeys(protocolNames);
1121  for (i = 0; i < protocolNames.size(); i++) {
1122 
1123  protocolName = protocolNames[i];
1124  mProtocols.lookup(protocolName, v);
1125  mCurrentProtocol = v[0];
1126 
1127  mApplications.getKeys(applicationNames);
1128  for (j = 0; j < applicationNames.size(); j++)
1129  mCurrentProtocol.send("ApplicationUnregister", applicationNames[j]);
1130 
1131  }
1132 
1133  // remove all applications except the local one
1134  mApplications.getKeys(applicationNames);
1135  for (i = 0; i < applicationNames.size(); i++) {
1136 
1137  applicationName = applicationNames[i];
1138  mApplications.lookup(applicationName, v);
1139  mApplicationCurrent = v[0];
1140 
1141  if (mApplicationCurrent.instance() != mApplicationLocal.instance())
1142  mApplications.remove(applicationName);
1143  }
1144 
1145  mApplicationCurrent = TTObject();
1146  mCurrentProtocol = TTObject();
1147 
1148  return kTTErrNone;
1149  }
1150 
1151  // ends reading
1152  if (aXmlHandler->mXmlNodeName == kTTSym_xmlHandlerReadingEnds) {
1153 
1154  // start protocol reception threads
1155  ProtocolRun(v, out);
1156 
1157  return kTTErrNone;
1158  }
1159 
1160  // comment node
1161  if (aXmlHandler->mXmlNodeName == TTSymbol("comment"))
1162  return kTTErrNone;
1163 
1164  // protocol node
1165  if (aXmlHandler->mXmlNodeName == TTSymbol("protocol")) {
1166 
1167  // get the protocol name
1168  xmlTextReaderMoveToAttribute((xmlTextReaderPtr)aXmlHandler->mReader, (const xmlChar*)("name"));
1169  aXmlHandler->fromXmlChar(xmlTextReaderValue((xmlTextReaderPtr)aXmlHandler->mReader), v);
1170 
1171  if (v.size() == 1)
1172  if (v[0].type() == kTypeSymbol)
1173  protocolName = v[0];
1174 
1175  // if it is the end of a "protocol" xml node
1176  if (!aXmlHandler->mXmlNodeStart && mCurrentProtocol.valid()) {
1177 
1178  mCurrentProtocol.get(kTTSym_name, v);
1179  currentProtocolName = v[0];
1180 
1181  if (protocolName == currentProtocolName) {
1182  mCurrentProtocol = TTObject();
1183  return kTTErrNone;
1184  }
1185  }
1186 
1187  // if the protocol exists and if the node is not empty : get it and use it
1188  if (!mProtocols.lookup(protocolName, v) && !aXmlHandler->mXmlNodeIsEmpty)
1189  mCurrentProtocol = v[0];
1190 
1191  return kTTErrNone;
1192  }
1193 
1194  if (mCurrentProtocol.valid()) {
1195 
1196  // the node name is the name of an application
1197 
1198  // register the application to the current protocol
1199  err = mCurrentProtocol.send("ApplicationRegister", aXmlHandler->mXmlNodeName);
1200 
1201  if (!err) {
1202 
1203  // select the application to set its parameters
1204  mCurrentProtocol.send("ApplicationSelect", aXmlHandler->mXmlNodeName);
1205 
1206  // get all protocol attributes and their value for this application
1207  while (xmlTextReaderMoveToNextAttribute((xmlTextReaderPtr)aXmlHandler->mReader) == 1) {
1208 
1209  // get parameter's name
1210  aXmlHandler->fromXmlChar(xmlTextReaderName((xmlTextReaderPtr)aXmlHandler->mReader), v);
1211 
1212  if (v.size() == 1) {
1213 
1214  if (v[0].type() == kTypeSymbol) {
1215 
1216  parameterName = v[0];
1217 
1218  parameterType = mCurrentProtocol.attributeType(parameterName);
1219 
1220  // get parameter's value
1221  aXmlHandler->fromXmlChar(xmlTextReaderValue((xmlTextReaderPtr)aXmlHandler->mReader), parameterValue, parameterType == kTTSym_symbol);
1222 
1223  // set parameter
1224  mCurrentProtocol.set(parameterName, parameterValue);
1225  }
1226  }
1227  }
1228  }
1229 
1230  return err;
1231  }
1232 
1233  // application node
1234  if (aXmlHandler->mXmlNodeName == TTSymbol("application")) {
1235 
1236  // get the application name
1237  xmlTextReaderMoveToAttribute((xmlTextReaderPtr)aXmlHandler->mReader, (const xmlChar*)("name"));
1238  aXmlHandler->fromXmlChar(xmlTextReaderValue((xmlTextReaderPtr)aXmlHandler->mReader), v);
1239 
1240  if (v.size() == 1)
1241  if (v[0].type() == kTypeSymbol)
1242  applicationName = v[0];
1243 
1244  // if it is the end of a "application" xml node
1245  if (!aXmlHandler->mXmlNodeStart && mApplicationCurrent.valid()) {
1246  mApplicationCurrent.get(kTTSym_name, v);
1247  currentApplicationName = v[0];
1248 
1249  if (applicationName == currentApplicationName) {
1250  mApplicationCurrent = NULL;
1251  return kTTErrNone;
1252  }
1253  }
1254 
1255  // if the application exists : get it
1256  if (!mApplications.lookup(applicationName, v))
1257  mApplicationCurrent = v[0];
1258 
1259  // else create one local or distant depending of the type
1260  else {
1261 
1262  // get the application type
1263  xmlTextReaderMoveToAttribute((xmlTextReaderPtr)aXmlHandler->mReader, (const xmlChar*)("type"));
1264  aXmlHandler->fromXmlChar(xmlTextReaderValue((xmlTextReaderPtr)aXmlHandler->mReader), v);
1265 
1266  if (v.size() == 1)
1267  if (v[0].type() == kTypeSymbol)
1268  applicationType = v[0];
1269 
1270  if (applicationType == kTTSym_local)
1271  ApplicationInstantiateLocal(applicationName, v);
1272  else
1273  ApplicationInstantiateDistant(applicationName, v);
1274 
1275  mApplicationCurrent = v[0];
1276  }
1277 
1278  // if the node is empty : don't use it
1279  if (aXmlHandler->mXmlNodeIsEmpty)
1280  mApplicationCurrent = TTObject();
1281  }
1282 
1283  if (mApplicationCurrent.valid()) {
1284 
1285  // pass the current application to the XmlHandler to build its directory
1286  v = TTValue(mApplicationCurrent);
1287  aXmlHandler->setAttributeValue(kTTSym_object, v);
1288  return aXmlHandler->sendMessage(TTSymbol("Read"));
1289  }
1290 
1291  return kTTErrNone;
1292 }
1293 
1294 #if 0
1295 #pragma mark -
1296 #pragma mark Public methods useful to ease access for other Modular classes
1297 #endif
1298 
1300 {
1301  TTValue v;
1302 
1303  if (!mApplications.lookup(applicationName, v)) {
1304 
1305  // TODO: How to use TTObject instead of TTObjectBasePtr here ?
1306  TTObject anApplication = v[0];
1307  return TTApplicationPtr(anApplication.instance());
1308  }
1309  else
1310  return NULL;
1311 }
1312 
1314 {
1315  TTApplicationPtr anApplication = findApplication(applicationName);
1316 
1317  if (anApplication)
1318  return anApplication->getDirectory();
1319 
1320  return NULL;
1321 }
1322 
1324 {
1325  // TODO: How to use TTObject instead of TTObjectBasePtr here ?
1326  return TTApplicationPtr(mApplicationLocal.instance());
1327 }
1328 
1330 {
1331  TTSymbol applicationName = anAddress.getDirectory();
1332 
1333  if (applicationName == NO_DIRECTORY)
1334 
1335  // TODO: How to use TTObject instead of TTObjectBasePtr here ?
1336  return TTApplicationPtr(mApplicationLocal.instance());
1337 
1338  else
1339 
1340  return findApplication(applicationName);
1341 }
1342 
1344 {
1345  TTApplicationPtr anApplication = findApplicationFrom(anAddress);
1346 
1347  if (anApplication)
1348  return anApplication->getDirectory();
1349 
1350  return NULL;
1351 }
1352 
1354 {
1355  TTValue v, keys, result;
1356  TTSymbol name;
1357  TTObject anObject;
1358  TTBoolean registered;
1359  TTErr err;
1360 
1361  // release each protocol
1362  mProtocols.getKeys(keys);
1363  for (TTUInt16 i = 0; i < keys.size(); i++) {
1364 
1365  name = keys[i];
1366  err = mProtocols.lookup(name, v);
1367 
1368  if (!err) {
1369 
1370  anObject = v[0];
1371  anObject.send("isRegistered", applicationName, v);
1372 
1373  registered = v[0];
1374  if (registered)
1375  result.append(name);
1376  }
1377  }
1378 
1379  return result;
1380 }
1381 
1383 {
1384  TTValue v;
1385 
1386  if (!mProtocols.lookup(protocolName, v)) {
1387  // TODO: How to use TTObject instead of TTObjectBasePtr here ?
1388  TTObject aProtocol = v[0];
1389  return TTProtocolPtr(aProtocol.instance());
1390  }
1391  else {
1392 
1393  TTLogError("TTApplicationManager::findProtocol : wrong protocol name\n");
1394  return NULL;
1395  }
1396 }
1397 
1398 #if 0
1399 #pragma mark -
1400 #pragma mark Some Functions
1401 #endif
1402 
1404 {
1405  TTErr err;
1406  TTValue lk;
1407  TTValue o = anObserver;
1408  TTListPtr lk_o;
1409 
1410  // enable observers protection
1411  TTModularApplicationManager->mApplicationObserversMutex->lock();
1412 
1413  // is the key already exists ?
1414  err = TTModularApplicationManager->mApplicationObservers.lookup(anApplicationName, lk);
1415 
1416  // create a new observers list for this address
1417  if(err == kTTErrValueNotFound){
1418  lk_o = new TTList();
1419  lk_o->appendUnique(o);
1420 
1421  TTModularApplicationManager->mApplicationObservers.append(anApplicationName, TTValue(lk_o));
1422  }
1423  // add it to the existing list
1424  else{
1425  lk_o = TTListPtr((TTPtr)lk[0]);
1426  lk_o->appendUnique(o);
1427  }
1428 
1429  // disable observers protection
1430  TTModularApplicationManager->mApplicationObserversMutex->unlock();
1431 
1432  return kTTErrNone;
1433 }
1434 
1436 {
1437  TTErr err;
1438  TTValue lk, o, v;
1439  TTListPtr lk_o;
1440 
1441  // enable observers protection
1442  TTModularApplicationManager->mApplicationObserversMutex->lock();
1443 
1444  // is the key exists ?
1445  err = TTModularApplicationManager->mApplicationObservers.lookup(anApplicationName, lk);
1446 
1447  if(err != kTTErrValueNotFound){
1448  // get the observers list
1449  lk_o = TTListPtr((TTPtr)lk[0]);
1450 
1451  // is observer exists ?
1452  o = TTValue(anObserver);
1453  err = lk_o->findEquals(o, v);
1454  if(!err)
1455  lk_o->remove(v);
1456 
1457  // was it the last observer ?
1458  if(lk_o->getSize() == 0) {
1459  // remove the key
1460  TTModularApplicationManager->mApplicationObservers.remove(anApplicationName);
1461  }
1462  }
1463 
1464  // disable observers protection
1465  TTModularApplicationManager->mApplicationObserversMutex->unlock();
1466 
1467  return err;
1468 }
1469 
1471 {
1472  TTSymbol aProtocolName;
1473  TTValue v;
1474 
1475  // unpack baton
1476  aProtocolName = baton[0];
1477 
1478  // set the activityIn attribute of the local application
1479  v = data;
1480  v.prepend(aProtocolName);
1481  TTModularApplicationManager->mApplicationLocal.set(kTTSym_activityIn, v);
1482 
1483  return kTTErrNone;
1484 }
1485 
1487 {
1488  TTSymbol aProtocolName;
1489  TTValue v;
1490 
1491  // unpack baton
1492  aProtocolName = baton[0];
1493 
1494  // set the activityOut attribute of the local application
1495  v = data;
1496  v.prepend(aProtocolName);
1497  TTModularApplicationManager->mApplicationLocal.set(kTTSym_activityOut, v);
1498 
1499  return kTTErrNone;
1500 }
TTErr sendMessage(const TTSymbol name)
TODO: Document this function.
TTApplicationPtr findApplicationFrom(TTAddress anAddress)
Get an application relative to an address.
an application have been released by the application manager
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
#define accessApplicationDirectoryFrom(anAddress)
Access to an application directory using an address.
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
TTErr send(const TTSymbol aName)
Send a message to this object with no arguments.
Definition: TTObject.cpp:135
TTApplicationNotificationFlag
TTString toString(TTBoolean quotes=YES) const
Return the content as a single string with spaces between elements.
Definition: TTValue.h:351
TTErr lookup(const TTSymbol key, TTValue &value)
Find the value for the given key.
Definition: TTHash.cpp:76
TTErr fromXmlChar(const void *xCh, TTValue &v, TTBoolean addQuote=NO, TTBoolean numberAsSymbol=NO)
TTXmlReader make a TTValue from an xmlChar* using the fromString method (see in TTValue.h)
TTSymbol & getDirectory()
Get the directory part.
Definition: TTAddress.h:106
#define addAttribute(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom getter...
Definition: TTAttribute.h:29
We build a directory of TTNodes, and you can request a pointer for any TTNode, or add an observer to ...
Definition: TTNode.h:59
application's protocol will be stopped
TTNodeDirectoryPtr getDirectory()
Get directory object.
Object type.
Definition: TTBase.h:283
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
TTObject & getObject()
Get the object binded by this node.
Definition: TTNode.cpp:468
size_type size() const noexcept
Return the number of elements.
TTErr getKeys(TTValue &hashKeys)
Get an array of all of the keys for the hash table.
Definition: TTHash.cpp:126
TTBoolean mXmlNodeIsEmpty
true if the Node is empty
Definition: TTXmlHandler.h:66
TTErr setAttributeValue(const TTSymbol name, TTValue &value)
Set an attribute value for an object.
Symbol type.
Definition: TTBase.h:282
TTErr Lookup(TTAddress anAddress, TTList &returnedTTNodes, TTNodePtr *firstReturnedTTNode)
Find TTNodes by address.
This is a special type used by TTAttribute to indicate that a value is a TTValue and is locally maint...
Definition: TTBase.h:286
void prepend(const TTValue &aValueToPrepend)
Insert another TTValue before the first element.
Definition: TTValue.h:162
void append(const T &anElementValueToAppend)
Insert a single TTElement at the end.
Definition: TTValue.h:243
#define addAttributeWithGetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom getter...
Definition: TTAttribute.h:38
void * TTPtr
A generic pointer.
Definition: TTBase.h:248
TTErr TTApplicationManagerAddApplicationObserver(TTSymbol anApplicationName, const TTObject anObserver)
Add a TTCallback as observer of application creation/destruction note : it uses the extern TTModularA...
TTErr get(const TTSymbol aName, T &aReturnedValue) const
Get an attribute value for an object.
TTMODULAR_EXPORT TTApplicationManagerPtr TTModularApplicationManager
Export a pointer to a TTApplicationManager instance.
Definition: TTModular.cpp:34
friend TTErr TTMODULAR_EXPORT TTApplicationManagerProtocolActivityInCallback(const TTValue &baton, const TTValue &data)
To get back raw incoming messages from any protocol.
application's protocol have been started
A Protocol interface.
TTValue getApplicationProtocolNames(TTSymbol applicationName)
Get application protocol names relative to a name.
TTSymbol name() const
Return the name of this class.
Definition: TTObject.cpp:129
#define addAttributeProperty(attributeName, propertyName, initialValue)
A convenience macro to be used for registering properties of attributes.
Definition: TTAttribute.h:68
TTErr set(const TTSymbol aName, T aValue)
Set an attribute value for an object.
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
TTErr append(const TTSymbol key, const TTValue &value)
Insert an item into the hash table.
Definition: TTHash.cpp:70
TTBoolean mXmlNodeStart
true if the Reader starts to read a Node
Definition: TTXmlHandler.h:65
void TTFOUNDATION_EXPORT TTLogError(TTImmutableCString message,...)
Platform and host independent method for posting errors.
Definition: TTBase.cpp:572
TTApplicationPtr findApplication(TTSymbol applicationName)
Get an application relative to a name.
TTSymbol attributeType(const TTSymbol aName)
Return the type of an attribute as a symbol.
Definition: TTObject.cpp:117
TTBoolean isEmpty()
Return true if the hash has nothing stored in it.
Definition: TTHash.cpp:205
Handles application data structure like a TTNodeDirectory and a hash tables of names.
Definition: TTApplication.h:52
TTSymbol & getAttribute()
Get the attribute part.
Definition: TTAddress.h:130
A value was not found when doing a look up for it (in a TTHash, TTList, or other class).
Definition: TTBase.h:352
#define addMessageWithArguments(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:27
Individual items found in a TTValue.
Definition: TTElement.h:89
const char * c_str() const
Return a pointer to the internal string as a C-string.
Definition: TTSymbol.h:77
an application have been intantiated by the application manager
TTErr getAddress(TTAddress &returnedAddress, TTAddress from=kTTAdrsEmpty)
Get the address of the node.
Definition: TTNode.cpp:478
void TTFOUNDATION_EXPORT TTLogMessage(TTImmutableCString message,...)
Platform and host independent method for posting log messages.
Definition: TTBase.cpp:534
Something went wrong, but what exactly is not known. Typically used for context-specific problems...
Definition: TTBase.h:344
TTApplicationPtr getApplicationLocal()
Get local application.
TTErr remove(const TTSymbol key)
Remove an item from the hash table.
Definition: TTHash.cpp:108
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
signed char TTInt8
8 bit signed integer (char)
Definition: TTBase.h:173
void attributes(TTValue &returnedAttributeNames) const
Return a list of names of the available attributes.
Definition: TTObject.cpp:111
TTSymbol mXmlNodeName
the Node name being read by the Reader
Definition: TTXmlHandler.h:67
Pointer type.
Definition: TTBase.h:284
void TTFOUNDATION_EXPORT TTLogDebug(TTImmutableCString message,...)
Platform and host independent method for posting messages only when debugging is enabled in the envir...
Definition: TTBase.cpp:591
Handles TTApplication and #Protocol instances.
Write / Read mecanism.
Definition: TTXmlHandler.h:48
TTErr getChildren(TTSymbol &name, TTSymbol &instance, TTList &returnedChildren)
Get a linklist of children of the node : select them by name and instance (use wilcards to select the...
Definition: TTNode.cpp:301
TTObjectBase * instance() const
Return a direct pointer to the internal instance.
Definition: TTObject.cpp:105
No Error.
Definition: TTBase.h:343
The TTString class is used to represent a string.
Definition: TTString.h:34
TTNodeDirectoryPtr findApplicationDirectory(TTSymbol applicationName)
Get an application directory relative to a name.
TTNodeDirectoryPtr findApplicationDirectoryFrom(TTAddress anAddress)
Get an application directory relative to an address.
TTErr TTApplicationManagerProtocolActivityOutCallback(const TTValue &baton, const TTValue &data)
To get back raw outputing messages from any protocol.
TTBoolean valid() const
Determine if the object contained by this TTObject is truly ready for use.
Definition: TTObject.cpp:179
friend TTErr TTMODULAR_EXPORT TTApplicationManagerProtocolActivityOutCallback(const TTValue &baton, const TTValue &data)
To get back raw outputing messages from any protocol.
TTErr(TTObjectBase::* TTGetterMethod)(const TTAttribute &attribute, TTValue &value)
A type that can be used to store a pointer to a message for an object.
Definition: TTObjectBase.h:73
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 TTApplicationManagerRemoveApplicationObserver(TTSymbol anApplicationName, const TTObject anObserver)
Remove a TTCallback as observer of application creation/destruction note : it uses the extern TTModul...
TTErr TTApplicationManagerProtocolActivityInCallback(const TTValue &baton, const TTValue &data)
To get back raw incoming messages from any protocol.
Bad Attribute specified.
Definition: TTBase.h:348
TTErr getTTNode(const char *anAddress, TTNodePtr *returnedTTNode)
Given an address, return a pointer to a TTNode.
TTProtocolPtr findProtocol(TTSymbol protocolName)
Get a protocol relative to a name.
unsigned char TTUInt8
8 bit unsigned integer (char)
Definition: TTBase.h:174
#define addMessageProperty(messageName, propertyName, initialValue)
A convenience macro to be used for registering properties of messages.
Definition: TTMessage.h:37