00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef INCLUDED_TUIOCLIENT_H
00023 #define INCLUDED_TUIOCLIENT_H
00024
00025 #ifndef WIN32
00026 #include <pthread.h>
00027 #include <sys/time.h>
00028 #else
00029 #include <windows.h>
00030 #endif
00031
00032 #include <iostream>
00033 #include <list>
00034 #include <algorithm>
00035
00036 #include "osc/OscReceivedElements.h"
00037 #include "osc/OscPrintReceivedElements.h"
00038
00039 #include "ip/UdpSocket.h"
00040 #include "ip/PacketListener.h"
00041
00042 #include "TuioListener.h"
00043 #include "TuioObject.h"
00044 #include "TuioCursor.h"
00045
00046 using namespace osc;
00047
00048 namespace TUIO {
00049
00063 class TuioClient : public PacketListener {
00064
00065 public:
00071 TuioClient(int port=3333);
00072
00076 ~TuioClient();
00077
00084 void connect(bool lock=false);
00085
00089 void disconnect();
00090
00095 bool isConnected() { return connected; }
00096
00102 void addTuioListener(TuioListener *listener);
00103
00109 void removeTuioListener(TuioListener *listener);
00110
00114 void removeAllTuioListeners() {
00115 listenerList.clear();
00116 }
00117
00123 std::list<TuioObject*> getTuioObjects();
00124
00130 std::list<TuioCursor*> getTuioCursors();
00131
00138 TuioObject* getTuioObject(long s_id);
00139
00146 TuioCursor* getTuioCursor(long s_id);
00147
00151 void lockObjectList();
00152
00156 void unlockObjectList();
00157
00161 void lockCursorList();
00162
00166 void unlockCursorList();
00167
00168 void ProcessPacket( const char *data, int size, const IpEndpointName& remoteEndpoint );
00169 UdpListeningReceiveSocket *socket;
00170
00171 protected:
00172 void ProcessBundle( const ReceivedBundle& b, const IpEndpointName& remoteEndpoint);
00173
00181 void ProcessMessage( const ReceivedMessage& message, const IpEndpointName& remoteEndpoint);
00182
00183 private:
00184 std::list<TuioListener*> listenerList;
00185
00186 std::list<TuioObject*> objectList;
00187 std::list<long> aliveObjectList, objectBuffer;
00188 std::list<TuioCursor*> cursorList;
00189 std::list<long> aliveCursorList, cursorBuffer;
00190
00191 int32 currentFrame;
00192 TuioTime currentTime;
00193
00194 std::list<TuioCursor*> freeCursorList, freeCursorBuffer;
00195 int maxCursorID;
00196
00197 #ifndef WIN32
00198 pthread_t thread;
00199 pthread_mutex_t objectMutex;
00200 pthread_mutex_t cursorMutex;
00201 #else
00202 HANDLE thread;
00203 HANDLE objectMutex;
00204 HANDLE cursorMutex;
00205 #endif
00206
00207 bool locked;
00208 bool connected;
00209 };
00210 };
00211 #endif