Jamoma API  0.6.0.a19
OSC.h
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup modularOSC
4  *
5  * @brief The OSC Protocol
6  *
7  * @details
8  *
9  * @authors Théo de la Hogue
10  *
11  * @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 #ifndef __OSC_H__
18 #define __OSC_H__
19 
20 #include "TTProtocol.h"
21 #include "OSCInclude.h"
22 #include "OSCSenderManager.h"
23 
24 class OSCSenderManager;
25 typedef OSCSenderManager* OSCSenderManagerPtr;
26 
27 class OSC : public TTProtocol {
28 
29  TTCLASS_SETUP(OSC)
30 
31 private:
32 
33  TT_PROTOCOL_PARAMETER(Ip); ///< PROTOCOL PARAMETER : each registered application have to setup its ip
34  TT_PROTOCOL_PARAMETER(Port); ///< PROTOCOL PARAMETER : each registered application have to setup its port
35 
36  TTObject mLocalApplicationOscReceiver;
37 
38  TTHash mDistantApplicationOscReceivers;
39 
40  OSCSenderManagerPtr mSenderManager;
41 
42  TTThreadPtr mWaitThread; // a thread used to wait after critical part
43 
44  TTSymbol mReceivedFrom; // memorize who sent a message to us to avoid loop when receiving an address and resending the same
45  TTAddress mReceivedAddress; // memorize received address to avoid loop when receiving an address and resending the same
46 
47  TTErr sendMessage(TTSymbol applicationName, TTSymbol header, TTValue& message);
48  TTErr receivedMessage(const TTValue& message, TTValue& outputValue);
49 
50  /** Get parameters names needed by this protocol */
51  TTErr getParameterNames(TTValue& value);
52 
53  /** Scan to find remote applications and add them to the application manager
54  * \param inputValue : anything needed for scanning
55  * \param outputValue : all remote application ip and port
56  * \return errorcode : return a kTTErrGeneric if the protocol fails to start or if it was running already
57  */
58  TTErr Scan(const TTValue& inputValue, TTValue& outputValue);
59 
60  /*!
61  * Run reception thread mechanism for the local application only
62  * \param inputValue : nothing to run all registered applications or a #TTSymbol application name
63  * \param outputValue : when the running failed because of a port connection failure : the port number
64  * \return errorcode : return a kTTErrGeneric if the protocol fails to start or if it was running already
65  */
66  TTErr Run(const TTValue& inputValue, TTValue& outputValue);
67 
68  /*!
69  * Stop the reception thread mechanism for the local application only
70  * \param inputValue : nothing to stop all registered applications or a #TTSymbol application name
71  * \param outputValue : any informations relative to a failure when stopping the protocol
72  * \return errorcode : return a kTTErrGeneric if the protocol fails to stop or if it was already stopped
73  */
74  TTErr Stop(const TTValue& inputValue, TTValue& outputValue);
75 
76  /**************************************************************************************************************************
77  *
78  * SEND REQUEST METHODS
79  *
80  **************************************************************************************************************************/
81 
82  /*!
83  * Send a discover request to an application to get a part of the namespace at the given address
84  *
85  * \param to : the application where to discover
86  * \param address : the address to discover
87  * \param returnedType : the type of the node at the address (default is none which means no type)
88  * \param returnedChildren : all names of nodes below the address
89  * \param returnedAttributes : all attributes the node at the address
90  * \param tryCount : number of try for this request
91  * \return errorcode : kTTErrNone means the answer has been received, kTTErrValueNotFound means something is bad in the request
92  else it returns kTTErrGeneric if no answer or timeout
93  */
94  TTErr SendDiscoverRequest(TTSymbol to, TTAddress address,
95  TTSymbol& returnedType,
96  TTValue& returnedChildren,
97  TTValue& returnedAttributes,
98  TTUInt8 tryCount=0);
99 
100  /*!
101  * Send a discover all request to an application to fill all the directory under this address
102  *
103  * \param to : the application where to discover
104  * \param address : the address to discover
105  * \param node : the node for this address
106  * \param tryCount : number of try for this request
107  * \return errorcode : kTTErrNone means the answer has been received, kTTErrValueNotFound means something is bad in the request
108  else it returns kTTErrGeneric if no answer or timeout
109  */
110  TTErr SendDiscoverAllRequest(TTSymbol to, TTAddress address,
111  TTNodePtr node,
112  TTUInt8 tryCount=0);
113 
114  /*!
115  * Send a get request to an application to get a value at the given address
116  *
117  * \param to : the application where to get
118  * \param address : the address to get
119  * \param returnedValue : the value which is going to be filled
120  * \param tryCount : number of try for this request
121  * \return errorcode : kTTErrNone means the answer has been received, kTTErrValueNotFound means something is bad in the request
122  else it returns kTTErrGeneric if no answer or timeout
123  */
124  TTErr SendGetRequest(TTSymbol to, TTAddress address,
125  TTValue& returnedValue,
126  TTUInt8 tryCount=0);
127 
128  /*!
129  * Send a set request to set a value of a specific application
130  *
131  * \param to : the application where to set
132  * \param address : the address to set
133  * \param value : anything to send
134  * \param tryCount : number of try for this request
135  * \return errorcode : kTTErrNone means the answer has been received, kTTErrValueNotFound means something is bad in the request
136  */
137  TTErr SendSetRequest(TTSymbol to, TTAddress address,
138  TTValue& value,
139  TTUInt8 tryCount=0);
140 
141  /*!
142  * Send a listen request to a specific application
143  *
144  * \param to : the application where to listen
145  * \param address : the address to listen
146  * \param attribute : the attribute to listen
147  * \param enable : enable/disable the listening
148  * \param tryCount : number of try for this request
149  * \return errorcode : kTTErrNone means the answer has been received, kTTErrValueNotFound means something is bad in the request
150  */
151  TTErr SendListenRequest(TTSymbol to, TTAddress address,
152  TTBoolean enable,
153  TTUInt8 tryCount=0);
154 
155 
156  /**************************************************************************************************************************
157  *
158  * SEND ANSWER METHODS
159  *
160  **************************************************************************************************************************/
161 
162  /*!
163  * Send a disover answer to a application which ask for.
164  *
165  * \param to : the application where to send answer
166  * \param address : the address where comes from the description
167  * \param returnedType : the type of the node at the address (default is none which means no type)
168  * \param returnedChildren : all names of nodes below the address
169  * \param returnedAttributes : all attributes the node at the address
170  */
171  TTErr SendDiscoverAnswer(TTSymbol to, TTAddress address,
172  TTSymbol& returnedType,
173  TTValue& returnedChildren,
174  TTValue& returnedAttributes,
175  TTErr err=kTTErrNone);
176 
177  /*!
178  * Send a discover answer to a application which ask for.
179  *
180  * \param to : the application where to send answer
181  * \param address : the address where comes from the description
182  * \param node : the node for this address
183  */
184  TTErr SendDiscoverAllAnswer(TTSymbol to, TTAddress address,
185  TTNodePtr node,
186  TTErr err=kTTErrNone);
187 
188  /*!
189  * Send a get answer to a application which ask for.
190  *
191  * \param to : the application where to send answer
192  * \param address : the address where comes from the value
193  * \param returnedValue : the value of the attribute at the address
194  */
195  TTErr SendGetAnswer(TTSymbol to, TTAddress address,
196  const TTValue& returnedValue,
197  TTErr err=kTTErrNone);
198 
199  /*!
200  * Send a listen answer to a application which ask for.
201  *
202  * \param to : the application where to send answer
203  * \param address : the address where comes from the value
204  * \param returnedValue : the value of the attribute at the address
205  */
206  TTErr SendListenAnswer(TTSymbol to, TTAddress address,
207  const TTValue& returnedValue,
208  TTErr err=kTTErrNone);
209 
210 
211 
212  friend TTErr TT_EXTENSION_EXPORT OSCReceiveMessageCallback(const TTValue& baton, const TTValue& data);
213 
214 };
215 typedef OSC* OSCPtr;
216 
217 /**
218  @param baton ..
219  @param data ..
220  @return an error code */
221 TTErr TT_EXTENSION_EXPORT OSCReceiveMessageCallback(const TTValue& baton, const TTValue& data);
222 
223 #endif // __OSC_H__
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
We build a directory of TTNodes, and you can request a pointer for any TTNode, or add an observer to ...
Definition: TTNode.h:59
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
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
#define TT_PROTOCOL_PARAMETER(name)
Declares specific accessors methods to manage the parameter value in order to have one value per regi...
Definition: TTProtocol.h:43
A Protocol interface.
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
A OSC send object manager.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
No Error.
Definition: TTBase.h:343
TTErr TT_EXTENSION_EXPORT OSCReceiveMessageCallback(const TTValue &baton, const TTValue &data)
Definition: OSC.cpp:568
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
unsigned char TTUInt8
8 bit unsigned integer (char)
Definition: TTBase.h:174