Jamoma API  0.6.0.a19
MinuitSenderManager.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup modularMinuit
4  *
5  * @brief A OSC send object manager
6  *
7  * @details
8  *
9  * @authors Théo de la Hogue
10  *
11  * @copyright Copyright © 2013, 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 
17 #include "MinuitSenderManager.h"
18 
19 MinuitSenderManager::MinuitSenderManager()
20 {
21  mSenders.setThreadProtection(YES);
22  mSending.setThreadProtection(YES);
23 }
24 
25 MinuitSenderManager::~MinuitSenderManager()
26 {}
27 
28 TTErr MinuitSenderManager::send(TTSymbol applicationName, TTSymbol ip, TTUInt16 port, const TTValue& message)
29 {
30  TTValue last;
31 
32  // if nothing is being sent to an application
33  if (mSending.findEquals(applicationName, last))
34  {
35  // lock application
36  mSending.append(applicationName);
37 
38  TTObject anOscSender;
39 
40  TTErr err = mSenders.lookup(applicationName, last);
41 
42  if (err)
43  {
44  anOscSender = TTObject("osc.send");
45 
46  anOscSender.set("address", ip);
47  anOscSender.set("port", port);
48 
49  TTValue cache(anOscSender, ip, port);
50  mSenders.append(applicationName, cache);
51  }
52  else
53  {
54  anOscSender = last[0];
55  TTSymbol lastIp = last[1];
56  TTUInt16 lastPort = last[2];
57 
58  if (lastIp == ip && lastPort == port)
59  ;
60 
61  else
62  {
63  anOscSender.set("address", ip);
64  anOscSender.set("port", port);
65 
66  TTValue cache(anOscSender, ip, port);
67  mSenders.remove(applicationName);
68  mSenders.append(applicationName, cache);
69  }
70  }
71 
72  err = anOscSender.send("send", message);
73 
74  // unlock application
75  mSending.remove(applicationName);
76 
77  return kTTErrNone;
78  }
79 
80  return kTTErrGeneric;
81 }
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
Create and use Jamoma object instances.
Definition: TTObject.h:29
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
Something went wrong, but what exactly is not known. Typically used for context-specific problems...
Definition: TTBase.h:344
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
A OSC send object manager.
No Error.
Definition: TTBase.h:343
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34