- Main Page
- Classes
- Files

# TuioClient.h

    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 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                 //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 */