61 #define thisTTClass Minuit
62 #define thisTTClassName "Minuit"
63 #define thisTTClassTags "network, protocol, minuit"
65 #define thisProtocolVersion "0.3"
66 #define thisProtocolAuthor "Raphael Marczak/Laurent Garnier/Theo de la Hogue"
67 #define thisProtocolGet YES
68 #define thisProtocolSet YES
69 #define thisProtocolListen YES
70 #define thisProtocolDiscover YES
71 #define thisProtocolDiscoverAll NO
73 extern "C" TT_EXTENSION_EXPORT
TTErr TTLoadJamomaExtension_Minuit(
void)
76 Minuit::registerClass();
96 delete mAnswerManager;
99 delete mSenderManager;
119 if (inputValue.
size())
124 mAnswerManager =
new MinuitAnswerManager((MinuitPtr)
this);
125 mSenderManager =
new MinuitSenderManager();
127 mOscReceive =
TTObject(
"osc.receive");
129 if (mOscReceive.valid()) {
134 ApplicationSelectLocal();
135 minuitProtocol.get(
"port", v);
141 err = mOscReceive.
set(
"port", v);
145 mOscReceive.registerObserverForNotifications(minuitProtocol);
149 TTLogMessage(
"Minuit::Run : connected to port %ld\n", port);
158 TTLogError(
"Minuit::Run : unable to connect to port %ld\n", port);
174 if (inputValue.
size())
179 delete mAnswerManager;
180 mAnswerManager = NULL;
182 delete mSenderManager;
183 mSenderManager = NULL;
187 mOscReceive.unregisterObserverForNotifications(minuitProtocol);
226 header = mLocalApplicationName.
c_str();
227 header += MINUIT_REQUEST_DISCOVER;
232 if (!sendMessage(to,
TTSymbol(header), arguments)) {
234 #ifdef TT_PROTOCOL_DEBUG
235 std::cout <<
"Minuit : applicationSendDiscoverRequest " << std::endl;
239 mAnswerManager->AddDiscoverAnswer(to, address);
244 state = mAnswerManager->CheckDiscoverAnswer(to, address, answer);
246 while (state == NO_ANSWER);
248 if (state == ANSWER_RECEIVED)
249 return mAnswerManager->ParseDiscoverAnswer(answer, returnedType, returnedChildren, returnedAttributes);
251 else if (state == TIMEOUT_EXCEEDED && tryCount < MAX_TRY)
252 return SendDiscoverRequest(to, address, returnedType, returnedChildren, returnedAttributes, tryCount+1);
291 header = mLocalApplicationName.
c_str();
292 header += MINUIT_REQUEST_GET;
297 if (!sendMessage(to,
TTSymbol(header), arguments)) {
299 #ifdef TT_PROTOCOL_DEBUG
300 std::cout <<
"Minuit : applicationSendGetRequest " << std::endl;
304 mAnswerManager->AddGetAnswer(to, address);
306 state = ANSWER_RECEIVED;
309 state = mAnswerManager->CheckGetAnswer(to, address, returnedValue);
311 while(state == NO_ANSWER);
313 if (state == ANSWER_RECEIVED)
316 else if (state == TIMEOUT_EXCEEDED && tryCount < MAX_TRY)
317 return SendGetRequest(to, address, returnedValue, tryCount+1);
337 #ifdef TT_PROTOCOL_DEBUG
338 std::cout <<
"Minuit : applicationSendSetRequest " << std::endl;
344 return sendMessage(to, address, value);
363 header = mLocalApplicationName.
c_str();
364 header += MINUIT_REQUEST_LISTEN;
374 #ifdef TT_PROTOCOL_DEBUG
375 std::cout <<
"Minuit : applicationSendListenRequest " << std::endl;
378 return sendMessage(to,
TTSymbol(header), arguments);
408 header = mLocalApplicationName.
c_str();
409 header += MINUIT_ANSWER_DISCOVER;
412 header = mLocalApplicationName.
c_str();
413 header += MINUIT_ERROR_DISCOVER;
419 if (returnedAttributes.
size()) {
420 arguments = returnedAttributes;
425 if (returnedChildren.
size()) {
427 if (arguments.
size()) {
429 arguments.
prepend(returnedChildren);
433 arguments = returnedChildren;
439 if (arguments.
size()) {
440 arguments.
prepend(returnedType);
445 arguments.
append(returnedType);
448 #ifdef TT_PROTOCOL_DEBUG
449 std::cout <<
"Minuit : applicationSendDiscoverAnswer " << std::endl;
452 return sendMessage(to,
TTSymbol(header), arguments);
483 header = mLocalApplicationName.
c_str();
484 header += MINUIT_ANSWER_GET;
487 header = mLocalApplicationName.
c_str();
488 header += MINUIT_ERROR_GET;
493 arguments = returnedValue;
496 #ifdef TT_PROTOCOL_DEBUG
497 std::cout <<
"Minuit : applicationSendGetAnswer" << std::endl;
500 return sendMessage(to,
TTSymbol(header), arguments);
519 header = mLocalApplicationName.
c_str();
520 header += MINUIT_ANSWER_LISTEN;
523 header = mLocalApplicationName.
c_str();
524 header += MINUIT_ERROR_LISTEN;
529 arguments = returnedValue;
532 #ifdef TT_PROTOCOL_DEBUG
533 std::cout <<
"Minuit : applicationSendListenAnswer " << std::endl;
536 return sendMessage(to,
TTSymbol(header), arguments);
546 TTErr err = mApplicationParameters.lookup(applicationName, v);
555 if (errIp || errPort)
559 message.append((
TTPtr)&arguments);
561 err = mSenderManager->send(applicationName, vIp, vPort, message);
573 ActivityOutMessage(v);
582 TTSymbol aSymbol, sender, operation;
614 if (mActivity) ActivityInMessage(message);
616 aSymbol = message[0];
617 headerString = aSymbol.string();
619 #ifdef TT_PROTOCOL_DEBUG
620 cout <<
"Message header is " << aSymbol.
c_str() << endl;
624 if (headerString[0] ==
'/')
626 aSymbol = message[0];
631 #ifdef TT_PROTOCOL_DEBUG
632 cout <<
"Receive set request at " << whereTo.
c_str() << endl;
635 return ReceiveSetRequest(kTTSymEmpty, whereTo, arguments);
641 if (operationStart >= 0)
647 err = mApplicationParameters.lookup(sender, v);
651 operation =
TTSymbol(headerString.
substr(operationStart, headerString.
size() - operationStart));
655 aSymbol = message[1];
659 #ifdef TT_PROTOCOL_DEBUG
660 cout <<
"Receive " << operation.
c_str() <<
" request from "<< sender.
c_str() <<
" at " << whereTo.
c_str() << endl;
664 if (operation ==
TTSymbol(MINUIT_REQUEST_DISCOVER))
665 return ReceiveDiscoverRequest(sender, whereTo);
667 else if (operation ==
TTSymbol(MINUIT_REQUEST_GET))
668 return ReceiveGetRequest(sender, whereTo);
670 else if (operation ==
TTSymbol(MINUIT_REQUEST_LISTEN)) {
674 message.
get(2, aSymbol);
676 if (aSymbol ==
TTSymbol(MINUIT_REQUEST_LISTEN_ENABLE))
677 return ReceiveListenRequest(sender, whereTo,
true);
679 else if (aSymbol ==
TTSymbol(MINUIT_REQUEST_LISTEN_DISABLE))
680 return ReceiveListenRequest(sender, whereTo,
false);
692 if (operationStart >= 0)
698 err = mApplicationParameters.lookup(sender, v);
702 operation =
TTSymbol(headerString.
substr(operationStart, headerString.
size() - operationStart));
706 aSymbol = message[1];
710 #ifdef TT_PROTOCOL_DEBUG
711 cout <<
"Receive " << operation.
c_str() <<
" answer from "<< sender.
c_str() <<
" at " << whereTo.
c_str() << endl;
717 if (operation ==
TTSymbol(MINUIT_ANSWER_DISCOVER))
718 return mAnswerManager->ReceiveDiscoverAnswer(sender, whereTo, arguments);
720 else if (operation ==
TTSymbol(MINUIT_ANSWER_GET))
721 return mAnswerManager->ReceiveGetAnswer(sender, whereTo, arguments);
723 else if (operation ==
TTSymbol(MINUIT_ANSWER_LISTEN))
724 return ReceiveListenAnswer(sender, whereTo, arguments);
731 if (operationStart >= 0)
737 err = mApplicationParameters.lookup(sender, v);
741 operation =
TTSymbol(headerString.
substr(operationStart, headerString.
size() - operationStart));
745 aSymbol = message[1];
749 #ifdef TT_PROTOCOL_DEBUG
750 cout <<
"Receive " << operation.
c_str() <<
" error from "<< sender.
c_str() <<
" at " << whereTo.
c_str() << endl;
752 if (message.
size() > 2)
756 if (operation ==
TTSymbol(MINUIT_ERROR_DISCOVER))
757 return mAnswerManager->ReceiveDiscoverAnswer(sender, whereTo, arguments,
kTTErrGeneric);
759 else if (operation ==
TTSymbol(MINUIT_ERROR_GET))
760 return mAnswerManager->ReceiveGetAnswer(sender, whereTo, arguments,
kTTErrGeneric);
TTErr sendMessage(const TTSymbol name)
TODO: Document this function.
It's the Minuit protocol which use the Open Sound Control protocol.
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
std::uint16_t TTUInt16
16 bit unsigned integer
#define TT_PROTOCOL_INITIALIZE
Declares all members needed by any protocol class.
TTErr lookup(const TTSymbol key, TTValue &value)
Find the value for the given key.
We build a directory of TTNodes, and you can request a pointer for any TTNode, or add an observer to ...
void copyFrom(const TTValue &obj, TTUInt16 index)
Copy a value starting from an index until the last element.
const char * c_str() const
Return a pointer to the internal C-string.
The TTAddress class is used to represent a string and efficiently pass and compare that string...
Create and use Jamoma object instances.
size_type size() const noexcept
Return the number of elements.
Maintain a collection of TTValue objects indexed by TTSymbol pointers.
16-bit unsigned integer, range is 0 through 65,535.
void prepend(const TTValue &aValueToPrepend)
Insert another TTValue before the first element.
void append(const T &anElementValueToAppend)
Insert a single TTElement at the end.
void * TTPtr
A generic pointer.
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
void TTFOUNDATION_EXPORT TTLogError(TTImmutableCString message,...)
Platform and host independent method for posting errors.
void get(const TTUInt16 index, T &returnedElementValue) const
DEPRECATED.
TTSymbol & getAttribute()
Get the attribute part.
#define addMessageWithArguments(name)
A convenience macro to be used by subclasses for registering messages.
TTString substr(size_t pos=0, size_t n=1) const
Returns a string object with its contents initialized to a substring of the current object...
const char * c_str() const
Return a pointer to the internal string as a C-string.
std::int32_t TTInt32
32 bit signed integer
void set(const TTUInt16 index, const T &anElementValue)
DEPRECATED.
void TTFOUNDATION_EXPORT TTLogMessage(TTImmutableCString message,...)
Platform and host independent method for posting log messages.
Something went wrong, but what exactly is not known. Typically used for context-specific problems...
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
size_t size() const
Find out the length of a string.
size_t find_first_of(const char aChar, size_t from=0)
Return the index of the first instance of a specified char in the string.
#define TT_PROTOCOL_CONSTRUCTOR
Declares instantiation and registration methods to add the protocol class as any TTObject class...
#define addAttributeAsProtocolParameter(name, type)
Add a protocol parameter as an attribute of the class.
TTAddress removeAttribute()
Return a new TTAddress without attribute part.
The TTString class is used to represent a string.
[doxygenAppendixC_copyExample]
unsigned char TTUInt8
8 bit unsigned integer (char)
#define addMessageProperty(messageName, propertyName, initialValue)
A convenience macro to be used for registering properties of messages.