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 #include <cstring>
00036
00037 #include "osc/OscReceivedElements.h"
00038 #include "osc/OscPrintReceivedElements.h"
00039
00040 #include "ip/UdpSocket.h"
00041 #include "ip/PacketListener.h"
00042
00043 #include "TuioListener.h"
00044 #include "TuioObject.h"
00045 #include "TuioCursor.h"
00046
00047 using namespace osc;
00048
00049 namespace TUIO {
00050
00064 class TuioClient : public PacketListener {
00065
00066 public:
00072 TuioClient(int port=3333);
00073
00077 ~TuioClient();
00078
00085 void connect(bool lock=false);
00086
00090 void disconnect();
00091
00096 bool isConnected() { return connected; }
00097
00103 void addTuioListener(TuioListener *listener);
00104
00110 void removeTuioListener(TuioListener *listener);
00111
00115 void removeAllTuioListeners() {
00116 listenerList.clear();
00117 }
00118
00124 std::list<TuioObject*> getTuioObjects();
00125
00131 std::list<TuioCursor*> getTuioCursors();
00132
00139 TuioObject* getTuioObject(long s_id);
00140
00147 TuioCursor* getTuioCursor(long s_id);
00148
00152 void lockObjectList();
00153
00157 void unlockObjectList();
00158
00162 void lockCursorList();
00163
00167 void unlockCursorList();
00168
00169 void ProcessPacket( const char *data, int size, const IpEndpointName& remoteEndpoint );
00170 UdpListeningReceiveSocket *socket;
00171
00172 protected:
00173 void ProcessBundle( const ReceivedBundle& b, const IpEndpointName& remoteEndpoint);
00174
00182 void ProcessMessage( const ReceivedMessage& message, const IpEndpointName& remoteEndpoint);
00183
00184 private:
00185 std::list<TuioListener*> listenerList;
00186
00187 std::list<TuioObject*> objectList, frameObjects;
00188 std::list<long> aliveObjectList, objectBuffer;
00189 std::list<TuioCursor*> cursorList, frameCursors;
00190 std::list<long> aliveCursorList, cursorBuffer;
00191
00192 int32 currentFrame;
00193 TuioTime currentTime;
00194
00195 std::list<TuioCursor*> freeCursorList, freeCursorBuffer;
00196 int maxCursorID;
00197
00198 #ifndef WIN32
00199 pthread_t thread;
00200 pthread_mutex_t objectMutex;
00201 pthread_mutex_t cursorMutex;
00202
00203 #else
00204 HANDLE thread;
00205 HANDLE objectMutex;
00206 HANDLE cursorMutex;
00207 #endif
00208
00209 bool locked;
00210 bool connected;
00211 };
00212 };
00213 #endif