- Main Page
- Classes
- Files

# TuioServer.h

    00001 /*
    00002  TUIO Server Component - 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_TuioServer_H
    00023 #define INCLUDED_TuioServer_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/OscOutboundPacketStream.h"
    00037 #include "ip/NetworkingUtils.h"
    00038 #include "ip/UdpSocket.h"
    00039
    00040 #include "TuioObject.h"
    00041 #include "TuioCursor.h"
    00042
    00043 #define IP_MTU_SIZE 1500
    00044 #define MAX_UDP_SIZE 65536
    00045 #define MIN_UDP_SIZE 576
    00046 #define OBJ_MESSAGE_SIZE 108    // setMessage + seqMessage size
    00047 #define CUR_MESSAGE_SIZE 88
    00048
    00049 using namespace osc;
    00050
    00051 namespace TUIO {
    00080         class TuioServer {
    00081
    00082         public:
    00083
    00088                 TuioServer();
    00089
    00097                 TuioServer(char *host, int port);
    00098
    00107                 TuioServer(char *host, int port, int size);
    00108
    00112                 ~TuioServer();
    00113
    00125                 TuioObject* addTuioObject(int sym, float xp, float yp, float a);
    00126
    00135                 void updateTuioObject(TuioObject *tobj, float xp, float yp, float a);
    00136
    00143                 void removeTuioObject(TuioObject *tobj);
    00144
    00150                 void addExternalTuioObject(TuioObject *tobj);
    00151
    00157                 void updateExternalTuioObject(TuioObject *tobj);
    00158
    00165                 void removeExternalTuioObject(TuioObject *tobj);
    00166
    00176                 TuioCursor* addTuioCursor(float xp, float yp);
    00177
    00185                 void updateTuioCursor(TuioCursor *tcur, float xp, float yp);
    00186
    00193                 void removeTuioCursor(TuioCursor *tcur);
    00194
    00200                 void addExternalTuioCursor(TuioCursor *tcur);
    00201
    00207                 void updateExternalTuioCursor(TuioCursor *tcur);
    00208
    00215                 void removeExternalTuioCursor(TuioCursor *tcur);
    00216
    00222                 void initFrame(TuioTime ttime);
    00223
    00228                 void commitFrame();
    00229
    00234                 long getSessionID();
    00235
    00240                 long getFrameID();
    00241
    00246                 TuioTime getFrameTime();
    00247
    00251                 void sendFullMessages();
    00252
    00258                 void enablePeriodicMessages(int interval=1);
    00259
    00263                 void disablePeriodicMessages();
    00264
    00269                 void enableFullUpdate()  {
    00270                         full_update = true;
    00271                 }
    00272
    00276                 void disableFullUpdate() {
    00277                         full_update = false;
    00278                 }
    00279
    00284                 bool periodicMessagesEnabled() {
    00285                         return periodic_update;
    00286                 }
    00287
    00292                 int getUpdateInterval() {
    00293                         return update_interval;
    00294                 }
    00295
    00301                 std::list<TuioObject*> getUntouchedObjects();
    00302
    00308                 std::list<TuioCursor*> getUntouchedCursors();
    00309
    00313                 void stopUntouchedMovingObjects();
    00314
    00318                 void stopUntouchedMovingCursors();
    00319
    00323                 void removeUntouchedStoppedObjects();
    00324
    00328                 void removeUntouchedStoppedCursors();
    00329
    00335                 std::list<TuioObject*> getTuioObjects();
    00336
    00337
    00343                 std::list<TuioCursor*> getTuioCursors();
    00344
    00351                 TuioObject* getTuioObject(long s_id);
    00352
    00359                 TuioCursor* getTuioCursor(long s_id);
    00360
    00367                 TuioObject* getClosestTuioObject(float xp, float yp);
    00368
    00375                 TuioCursor* getClosestTuioCursor(float xp, float yp);
    00376
    00381                 bool isConnected() { return connected; }
    00382
    00387                 void setVerbose(bool verbose) { this->verbose=verbose; }
    00388
    00389         private:
    00390                 std::list<TuioObject*> objectList;
    00391                 std::list<TuioCursor*> cursorList;
    00392
    00393                 int maxCursorID;
    00394                 std::list<TuioCursor*> freeCursorList;
    00395                 std::list<TuioCursor*> freeCursorBuffer;
    00396
    00397                 UdpTransmitSocket *socket;
    00398                 osc::OutboundPacketStream  *oscPacket;
    00399                 char *oscBuffer;
    00400                 osc::OutboundPacketStream  *fullPacket;
    00401                 char *fullBuffer;
    00402
    00403                 void initialize(char *host, int port, int size);
    00404
    00405                 void sendEmptyCursorBundle();
    00406                 void startCursorBundle();
    00407                 void addCursorMessage(TuioCursor *tcur);
    00408                 void sendCursorBundle(long fseq);
    00409
    00410                 void sendEmptyObjectBundle();
    00411                 void startObjectBundle();
    00412                 void addObjectMessage(TuioObject *tobj);
    00413                 void sendObjectBundle(long fseq);
    00414
    00415                 bool full_update;
    00416                 int update_interval;
    00417                 bool periodic_update;
    00418
    00419                 long currentFrame;
    00420                 TuioTime currentFrameTime;
    00421                 bool updateObject, updateCursor;
    00422                 long lastCursorUpdate, lastObjectUpdate;
    00423
    00424                 long sessionID;
    00425                 bool verbose;
    00426
    00427 #ifndef WIN32
    00428                 pthread_t thread;
    00429 #else
    00430                 HANDLE thread;
    00431 #endif
    00432                 bool connected;
    00433         };
    00434 };
    00435 #endif /* INCLUDED_TuioServer_H */