Go to the documentation of this file.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 namespace TUIO {
00078 class TuioServer {
00079
00080 public:
00081
00086 TuioServer();
00087
00095 TuioServer(const char *host, int port);
00096
00105 TuioServer(const char *host, int port, int size);
00106
00110 ~TuioServer();
00111
00123 TuioObject* addTuioObject(int sym, float xp, float yp, float a);
00124
00133 void updateTuioObject(TuioObject *tobj, float xp, float yp, float a);
00134
00141 void removeTuioObject(TuioObject *tobj);
00142
00148 void addExternalTuioObject(TuioObject *tobj);
00149
00155 void updateExternalTuioObject(TuioObject *tobj);
00156
00163 void removeExternalTuioObject(TuioObject *tobj);
00164
00174 TuioCursor* addTuioCursor(float xp, float yp);
00175
00183 void updateTuioCursor(TuioCursor *tcur, float xp, float yp);
00184
00191 void removeTuioCursor(TuioCursor *tcur);
00192
00198 void addExternalTuioCursor(TuioCursor *tcur);
00199
00205 void updateExternalTuioCursor(TuioCursor *tcur);
00206
00213 void removeExternalTuioCursor(TuioCursor *tcur);
00214
00220 void initFrame(TuioTime ttime);
00221
00226 void commitFrame();
00227
00232 long getSessionID();
00233
00238 long getFrameID();
00239
00244 TuioTime getFrameTime();
00245
00249 void sendFullMessages();
00250
00256 void enablePeriodicMessages(int interval=1);
00257
00261 void disablePeriodicMessages();
00262
00267 void enableFullUpdate() {
00268 full_update = true;
00269 }
00270
00274 void disableFullUpdate() {
00275 full_update = false;
00276 }
00277
00282 bool periodicMessagesEnabled() {
00283 return periodic_update;
00284 }
00285
00290 int getUpdateInterval() {
00291 return update_interval;
00292 }
00293
00299 std::list<TuioObject*> getUntouchedObjects();
00300
00306 std::list<TuioCursor*> getUntouchedCursors();
00307
00311 void stopUntouchedMovingObjects();
00312
00316 void stopUntouchedMovingCursors();
00317
00321 void removeUntouchedStoppedObjects();
00322
00326 void removeUntouchedStoppedCursors();
00327
00333 std::list<TuioObject*> getTuioObjects();
00334
00335
00341 std::list<TuioCursor*> getTuioCursors();
00342
00349 TuioObject* getTuioObject(long s_id);
00350
00357 TuioCursor* getTuioCursor(long s_id);
00358
00365 TuioObject* getClosestTuioObject(float xp, float yp);
00366
00373 TuioCursor* getClosestTuioCursor(float xp, float yp);
00374
00379 bool isConnected() { return connected; }
00380
00385 void setVerbose(bool verbose) { this->verbose=verbose; }
00386
00387 private:
00388 std::list<TuioObject*> objectList;
00389 std::list<TuioCursor*> cursorList;
00390
00391 int maxCursorID;
00392 std::list<TuioCursor*> freeCursorList;
00393 std::list<TuioCursor*> freeCursorBuffer;
00394
00395 UdpTransmitSocket *socket;
00396 osc::OutboundPacketStream *oscPacket;
00397 char *oscBuffer;
00398 osc::OutboundPacketStream *fullPacket;
00399 char *fullBuffer;
00400
00401 void initialize(const char *host, int port, int size);
00402
00403 void sendEmptyCursorBundle();
00404 void startCursorBundle();
00405 void addCursorMessage(TuioCursor *tcur);
00406 void sendCursorBundle(long fseq);
00407
00408 void sendEmptyObjectBundle();
00409 void startObjectBundle();
00410 void addObjectMessage(TuioObject *tobj);
00411 void sendObjectBundle(long fseq);
00412
00413 bool full_update;
00414 int update_interval;
00415 bool periodic_update;
00416
00417 long currentFrame;
00418 TuioTime currentFrameTime;
00419 bool updateObject, updateCursor;
00420 long lastCursorUpdate, lastObjectUpdate;
00421
00422 long sessionID;
00423 bool verbose;
00424
00425 #ifndef WIN32
00426 pthread_t thread;
00427 #else
00428 HANDLE thread;
00429 #endif
00430 bool connected;
00431 };
00432 };
00433 #endif