Jamoma API  0.6.0.a19
WebSocket.h
Go to the documentation of this file.
1 /**
2  * @file WebSocket.h
3  * @ingroup modularWebSocket
4  * @brief It's the WebSocket protocol
5  * @authors Laurent Garnier
6  *
7  * @copyright © 2013, Laurent Garnier @n
8  * This code is licensed under the terms of the "New BSD License" @n
9  * http://creativecommons.org/licenses/BSD/
10  *
11  * @details Use cross platform libjson library from http://libjson.sourceforge.net/
12  */
13 
14 
15 #ifndef __WEBSOCKET_H__
16 #define __WEBSOCKET_H__
17 
18 #include "TTProtocol.h"
19 #include "WebSocketInclude.h"
20 #include "WebSocketAnswerManager.h"
21 #include "WebSocketSenderManager.h"
22 
23 class WebSocketAnswerManager;
24 typedef WebSocketAnswerManager* WebSocketAnswerManagerPtr;
25 
26 class WebSocketSenderManager;
27 typedef WebSocketSenderManager* WebSocketSenderManagerPtr;
28 
29 /**
30  * Create a web socket plugin.
31  */
32 
33 class WebSocket : public TTProtocol {
34 
36 
37 private:
38 
39  TT_PROTOCOL_PARAMETER(Port); ///< PROTOCOL PARAMETER : each registered application have to setup its port
40  TT_PROTOCOL_PARAMETER(HtmlPath); ///< PROTOCOL PARAMETER : each registered application have to setup its html path
41 
42  TTObject mWebSocketReceive;
43  TTThreadPtr mWaitThread; ///< a thread used to wait in some case
44 
45  WebSocketAnswerManagerPtr mAnswerManager;
46  WebSocketSenderManagerPtr mSenderManager;
47 
48  TTErr sendMessage(TTSymbol distantApplicationName, TTSymbol localApplicationName, TTSymbol operation, JSONNode* jsonNode);
49  TTErr receivedMessage(const TTValue& message, TTValue& outputValue);
50 
51  /** Get osc address string from a json string */
52  TTErr parseJSON(const JSONNode &n, TTString address, TTValue& value);
53 
54  /** Scan to find remote applications and add them to the application manager
55  * \param inputValue : anything needed for scanning
56  * \param outputValue : all remote application name
57  * \return errorcode : return a kTTErrGeneric if the protocol fails to start or if it was running already
58  */
59  TTErr Scan(const TTValue& inputValue, TTValue& outputValue);
60 
61  /*!
62  * Run reception thread mechanism for the local application only
63  * \param inputValue : kTTValNONE
64  * \param outputValue : kTTValNONE
65  * \return errorcode : return a kTTErrGeneric if the protocol fails to start or if it was running already
66  */
67  TTErr Run(const TTValue& inputValue, TTValue& outputValue);
68 
69  /*!
70  * Stop the reception thread mechanism for the local application only
71  * \param inputValue : kTTValNONE
72  * \param outputValue : kTTValNONE
73  * \return errorcode : return a kTTErrGeneric if the protocol fails to stop or if it was already stopped
74  */
75  TTErr Stop(const TTValue& inputValue, TTValue& outputValue);
76 
77  /**************************************************************************************************************************
78  *
79  * SEND REQUEST METHODS
80  *
81  **************************************************************************************************************************/
82 
83  /*!
84  * Send a discover request to an application to get a part of the namespace at the given address
85  *
86  * \param to : the application where to discover
87  * \param address : the address to discover
88  * \param returnedType : the type of the node at the address (default is none which means no type)
89  * \param returnedChildren : all names of nodes below the address
90  * \param returnedAttributes : all attributes the node at the address
91  * \param tryCount : number of try for this request
92  * \return errorcode : kTTErrNone means the answer has been received, kTTErrValueNotFound means something is bad in the request
93  else it returns kTTErrGeneric if no answer or timeout
94  */
95  TTErr SendDiscoverRequest(TTSymbol to, TTAddress address,
96  TTSymbol& returnedType,
97  TTValue& returnedChildren,
98  TTValue& returnedAttributes,
99  TTUInt8 tryCount=0);
100 
101  /*!
102  * Send a discover all request to an application to fill all the directory under this address
103  *
104  * \param to : the application where to discover
105  * \param address : the address to discover
106  * \param node : the node for this address
107  * \param tryCount : number of try for this request
108  * \return errorcode : kTTErrNone means the answer has been received, kTTErrValueNotFound means something is bad in the request
109  else it returns kTTErrGeneric if no answer or timeout
110  */
111  TTErr SendDiscoverAllRequest(TTSymbol to, TTAddress address,
112  TTNodePtr node,
113  TTUInt8 tryCount=0);
114 
115  /*!
116  * Send a get request to an application to get a value at the given address
117  *
118  * \param to : the application where to get
119  * \param address : the address to get
120  * \param returnedValue : the value which is going to be filled
121  * \param tryCount : number of try for this request
122  * \return errorcode : kTTErrNone means the answer has been received, kTTErrValueNotFound means something is bad in the request
123  else it returns kTTErrGeneric if no answer or timeout
124  */
125  TTErr SendGetRequest(TTSymbol to, TTAddress address,
126  TTValue& returnedValue,
127  TTUInt8 tryCount=0);
128 
129  /*!
130  * Send a set request to set a value of a specific application
131  *
132  * \param to : the application where to set
133  * \param address : the address to set
134  * \param value : anything to send
135  * \param tryCount : number of try for this request
136  * \return errorcode : kTTErrNone means the answer has been received, kTTErrValueNotFound means something is bad in the request
137  */
138  TTErr SendSetRequest(TTSymbol to, TTAddress address,
139  TTValue& value,
140  TTUInt8 tryCount=0);
141 
142  /*!
143  * Send a listen request to a specific application
144  *
145  * \param to : the application where to listen
146  * \param address : the address to listen
147  * \param attribute : the attribute to listen
148  * \param enable : enable/disable the listening
149  * \param tryCount : number of try for this request
150  * \return errorcode : kTTErrNone means the answer has been received, kTTErrValueNotFound means something is bad in the request
151  */
152  TTErr SendListenRequest(TTSymbol to, TTAddress address,
153  TTBoolean enable,
154  TTUInt8 tryCount=0);
155 
156 
157  /**************************************************************************************************************************
158  *
159  * SEND ANSWER METHODS
160  *
161  **************************************************************************************************************************/
162 
163  /*!
164  * Send a disover answer to a application which ask for.
165  *
166  * \param to : the application where to send answer
167  * \param address : the address where comes from the description
168  * \param returnedType : the type of the node at the address (default is none which means no type)
169  * \param returnedChildren : all names of nodes below the address
170  * \param returnedAttributes : all attributes the node at the address
171  */
172  TTErr SendDiscoverAnswer(TTSymbol to, TTAddress address,
173  TTSymbol& returnedType,
174  TTValue& returnedChildren,
175  TTValue& returnedAttributes,
176  TTErr err=kTTErrNone);
177 
178  /*!
179  * Send a discover all answer to a application which ask for.
180  *
181  * \param to : the application where to send answer
182  * \param address : the address where comes from the description
183  * \param node : the node for this address
184  */
185  TTErr SendDiscoverAllAnswer(TTSymbol to, TTAddress address,
186  TTNodePtr node,
187  TTErr err=kTTErrNone);
188 
189  /*!
190  * Send a get answer to a application which ask for.
191  *
192  * \param to : the application where to send answer
193  * \param address : the address where comes from the value
194  * \param returnedValue : the value of the attribute at the address
195  */
196  TTErr SendGetAnswer(TTSymbol to, TTAddress address,
197  const TTValue& returnedValue,
198  TTErr err=kTTErrNone);
199 
200  /*!
201  * Send a listen answer to a application which ask for.
202  *
203  * \param to : the application where to send answer
204  * \param address : the address where comes from the value
205  * \param returnedValue : the value of the attribute at the address
206  */
207  TTErr SendListenAnswer(TTSymbol to, TTAddress address,
208  const TTValue& returnedValue,
209  TTErr err=kTTErrNone);
210 
211 };
212 typedef WebSocket* WebSocketPtr;
213 
214 #endif // __WEBSOCKET_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
#define TTCLASS_SETUP(className)
TODO Doxygen: need more comments here.
Definition: TTFoundation.h:54
Create a web socket plugin.
Definition: WebSocket.h:33
A Protocol interface.
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
It's the WebSocket protocol.
A WebSocket 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
The TTString class is used to represent a string.
Definition: TTString.h:34
A Protocol interface.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
unsigned char TTUInt8
8 bit unsigned integer (char)
Definition: TTBase.h:174