00001 /* 00002 TUIO C++ Library - part of the reacTIVision project 00003 http://reactivision.sourceforge.net/ 00004 00005 Copyright (c) 2005-2009 Martin Kaltenbrunner <mkalten@iua.upf.edu> 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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 namespace TUIO { 00048 00062 class TuioClient : public PacketListener { 00063 00064 public: 00070 TuioClient(int port=3333); 00071 00075 ~TuioClient(); 00076 00083 void connect(bool lock=false); 00084 00088 void disconnect(); 00089 00094 bool isConnected() { return connected; } 00095 00101 void addTuioListener(TuioListener *listener); 00102 00108 void removeTuioListener(TuioListener *listener); 00109 00113 void removeAllTuioListeners() { 00114 listenerList.clear(); 00115 } 00116 00122 std::list<TuioObject*> getTuioObjects(); 00123 00129 std::list<TuioCursor*> getTuioCursors(); 00130 00137 TuioObject* getTuioObject(long s_id); 00138 00145 TuioCursor* getTuioCursor(long s_id); 00146 00150 void lockObjectList(); 00151 00155 void unlockObjectList(); 00156 00160 void lockCursorList(); 00161 00165 void unlockCursorList(); 00166 00167 void ProcessPacket( const char *data, int size, const IpEndpointName &remoteEndpoint ); 00168 UdpListeningReceiveSocket *socket; 00169 00170 protected: 00171 void ProcessBundle( const osc::ReceivedBundle& b, const IpEndpointName& remoteEndpoint); 00172 00180 void ProcessMessage( const osc::ReceivedMessage& message, const IpEndpointName& remoteEndpoint); 00181 00182 void ProcessSMTG(); 00183 00184 private: 00185 std::list<TuioListener*> listenerList; 00186 00187 std::list<TuioObject*> objectList, frameObjects; 00188 std::list<long> aliveObjectList; 00189 std::list<TuioCursor*> cursorList, frameCursors; 00190 std::list<long> aliveCursorList; 00191 00192 osc::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 //pthread_mutexattr_t attr_p; 00203 #else 00204 HANDLE thread; 00205 HANDLE objectMutex; 00206 HANDLE cursorMutex; 00207 #endif 00208 00209 bool locked; 00210 bool connected; 00211 }; 00212 }; 00213 #endif /* INCLUDED_TUIOCLIENT_H */