Jamoma API  0.6.0.a19
TTOscSocket.h
1 /*
2  * Jamoma OSC Receiver
3  * Copyright © 2011, Théo de la Hogue
4  *
5  * License: This code is licensed under the terms of the "New BSD License"
6  * http://creativecommons.org/licenses/BSD/
7  */
8 
9 #ifndef __TT_OSC_SOCKET_H__
10 #define __TT_OSC_SOCKET_H__
11 
12 #include "TTFoundationAPI.h"
13 
14 #include "OscPacketListener.h"
15 #include "UdpSocket.h"
16 #include "OscOutboundPacketStream.h"
17 
18 /** ...
19  @param anArgument a TTOscSocket pointer
20  @return NULL */
21 TTPtr TTOscSocketListenerCreate(TTPtr anArgument);
22 
23 /** ...
24  @param anArgument a TTOscSocket pointer
25  @return NO if the Osc listener should abort or YES if it should continue */
26 TTBoolean TTOscSocketListenerRun(TTPtr anArgument);
27 
28 /** \ingroup enums
29  Connection flag used to know if the OSC socket manage to connect to a port
30  */
32  kOscSocketConnectionTrying = 0, ///< this flag means the OSC socket is trying to connect
33  kOscSocketConnectionSucceeded = 1, ///< this flag means the OSC socket connection succeeded
34  kOscSocketConnectionFailed = 2, ///< this flag means the OSC socket failed to connect
35 };
36 
37 /** TTOscSocket is ...
38  */
39 class TTOscSocket : public osc::OscPacketListener
40 {
41 
42 private:
43 
44  TTObjectBasePtr mOwner; ///< The object that instantiated this socket and will receive notifications.
45 
46  TTString mAddress;
47  TTUInt16 mPort;
48 
49  UdpListeningReceiveSocket* mSocketListener;
50  UdpTransmitSocket* mSocketTransmitter;
51 
52  TTThreadPtr mSocketListenerThread; /// for receiving data
53 
54  TTOscSocketConnectionFlag mSocketListenerStatus;
55 
56 public:
57 
58  /** Create a socket to receive osc messages.
59  @param owner the TTObjectBase to notify
60  @param port the port number
61  */
62  TTOscSocket(const TTObjectBasePtr owner, const TTUInt16 port);
63 
64  /** Create a socket to send osc messages.
65  @param address the ip address
66  @param port the port number
67  */
68  TTOscSocket(const TTString& address, const TTUInt16 port);
69 
70  virtual ~TTOscSocket();
71 
72  TTErr SendMessage(TTSymbol& message, const TTValue& arguments);
73 
74  TTOscSocketConnectionFlag getSocketListenerStatus();
75 
76 private:
77  // internal helper method
78  TTUInt32 computeMessageSize(TTSymbol& message, const TTValue& arguments);
79 
80 protected:
81 
82  virtual void ProcessMessage(const osc::ReceivedMessage&m, const IpEndpointName& remoteEndPoint);
83 
84 
85  friend TTPtr TTOscSocketListenerCreate(TTPtr anArgument);
86  friend TTBoolean TTOscSocketListenerRun(TTPtr anArgument);
87 };
89 
90 #endif // __TT_OSC_SOCKET_H__
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
friend TTBoolean TTOscSocketListenerRun(TTPtr anArgument)
...
Definition: TTOscSocket.cpp:32
Base class for all first-class Jamoma objects.
Definition: TTObjectBase.h:109
this flag means the OSC socket failed to connect
Definition: TTOscSocket.h:34
TTOscSocketConnectionFlag
Connection flag used to know if the OSC socket manage to connect to a port.
Definition: TTOscSocket.h:31
void * TTPtr
A generic pointer.
Definition: TTBase.h:248
TTOscSocket is ...
Definition: TTOscSocket.h:39
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
this flag means the OSC socket is trying to connect
Definition: TTOscSocket.h:32
this flag means the OSC socket connection succeeded
Definition: TTOscSocket.h:33
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
std::uint32_t TTUInt32
32 bit unsigned integer
Definition: TTBase.h:178
TTOscSocket(const TTObjectBasePtr owner, const TTUInt16 port)
Create a socket to receive osc messages.
Definition: TTOscSocket.cpp:58
friend TTPtr TTOscSocketListenerCreate(TTPtr anArgument)
...
Definition: TTOscSocket.cpp:12
The TTString class is used to represent a string.
Definition: TTString.h:34
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34