00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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 bool periodicMessagesEnabled() {
00270 return periodic_update;
00271 }
00272
00277 int getUpdateInterval() {
00278 return update_interval;
00279 }
00280
00286 std::list<TuioObject*> getUntouchedObjects();
00287
00293 std::list<TuioCursor*> getUntouchedCursors();
00294
00298 void stopUntouchedMovingObjects();
00299
00303 void stopUntouchedMovingCursors();
00304
00308 void removeUntouchedStoppedObjects();
00309
00313 void removeUntouchedStoppedCursors();
00314
00320 std::list<TuioObject*> getTuioObjects();
00321
00322
00328 std::list<TuioCursor*> getTuioCursors();
00329
00336 TuioObject* getTuioObject(long s_id);
00337
00344 TuioCursor* getTuioCursor(long s_id);
00345
00350 bool isConnected() { return connected; }
00351
00356 void setVerbose(bool verbose) { this->verbose=verbose; }
00357
00358 private:
00359 std::list<TuioObject*> objectList;
00360 std::list<TuioCursor*> cursorList;
00361
00362 int maxFingerID;
00363 std::list<TuioCursor*> freeCursorList;
00364 std::list<TuioCursor*> freeCursorBuffer;
00365
00366 UdpTransmitSocket *socket;
00367 osc::OutboundPacketStream *oscPacket;
00368 char *oscBuffer;
00369 osc::OutboundPacketStream *fullPacket;
00370 char *fullBuffer;
00371
00372 void initialize(char *host, int port, int size);
00373
00374 void sendEmptyCursorBundle();
00375 void startCursorBundle();
00376 void addCursorMessage(TuioCursor *tcur);
00377 void sendCursorBundle(long fseq);
00378
00379 void sendEmptyObjectBundle();
00380 void startObjectBundle();
00381 void addObjectMessage(TuioObject *tobj);
00382 void sendObjectBundle(long fseq);
00383
00384 void fullUpdate();
00385 bool periodic_update;
00386 int update_interval;
00387
00388 long currentFrame;
00389 TuioTime currentFrameTime;
00390 bool updateObject, updateCursor;
00391 long lastCursorUpdate, lastObjectUpdate;
00392
00393 long sessionID;
00394 bool verbose;
00395
00396 #ifndef WIN32
00397 pthread_t thread;
00398 #else
00399 HANDLE thread;
00400 #endif
00401 bool connected;
00402 };
00403 };
00404 #endif