*
* @author Martin Kaltenbrunner
- * @version 1.5
+ * @version 1.1.6
*/
class LIBDECL TuioDispatcher {
diff --git a/TUIO/TuioListener.h b/TUIO/TuioListener.h
index d70592d..099f880 100644
--- a/TUIO/TuioListener.h
+++ b/TUIO/TuioListener.h
@@ -1,23 +1,20 @@
/*
- TUIO C++ Library - part of the reacTIVision project
- http://reactivision.sourceforge.net/
+ TUIO C++ Library
+ Copyright (c) 2005-2016 Martin Kaltenbrunner
- Copyright (c) 2005-2009 Martin Kaltenbrunner
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3.0 of the License, or (at your option) any later version.
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
+ This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library.
+*/
#ifndef INCLUDED_TUIOLISTENER_H
#define INCLUDED_TUIOLISTENER_H
@@ -43,7 +40,7 @@ namespace TUIO {
*
*
* @author Martin Kaltenbrunner
- * @version 1.5
+ * @version 1.1.6
*/
class LIBDECL TuioListener {
diff --git a/TUIO/TuioManager.cpp b/TUIO/TuioManager.cpp
index 9053c08..db16a61 100644
--- a/TUIO/TuioManager.cpp
+++ b/TUIO/TuioManager.cpp
@@ -1,22 +1,19 @@
/*
- TUIO Server Component - part of the reacTIVision project
- http://reactivision.sourceforge.net/
-
- Copyright (C) 2005-2009 Martin Kaltenbrunner
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ TUIO C++ Library
+ Copyright (c) 2005-2016 Martin Kaltenbrunner
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3.0 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library.
*/
#include "TuioManager.h"
@@ -61,6 +58,7 @@ TuioObject* TuioManager::addTuioObject(int f_id, float x, float y, float a) {
void TuioManager::addExternalTuioObject(TuioObject *tobj) {
if (tobj==NULL) return;
+ tobj->setSessionID(sessionID++);
objectList.push_back(tobj);
updateObject = true;
@@ -103,15 +101,16 @@ void TuioManager::updateExternalTuioObject(TuioObject *tobj) {
void TuioManager::removeTuioObject(TuioObject *tobj) {
if (tobj==NULL) return;
- objectList.remove(tobj);
- delete tobj;
- updateObject = true;
for (std::list::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->removeTuioObject(tobj);
if (verbose)
std::cout << "del obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << ")" << std::endl;
+
+ objectList.remove(tobj);
+ delete tobj;
+ updateObject = true;
}
void TuioManager::removeExternalTuioObject(TuioObject *tobj) {
@@ -158,6 +157,7 @@ TuioCursor* TuioManager::addTuioCursor(float x, float y) {
void TuioManager::addExternalTuioCursor(TuioCursor *tcur) {
if (tcur==NULL) return;
+ tcur->setSessionID(sessionID++);
cursorList.push_back(tcur);
updateCursor = true;
@@ -170,7 +170,7 @@ void TuioManager::addExternalTuioCursor(TuioCursor *tcur) {
void TuioManager::updateTuioCursor(TuioCursor *tcur,float x, float y) {
if (tcur==NULL) return;
- if (tcur->getTuioTime()==currentFrameTime) return;
+ //if (tcur->getTuioTime()==currentFrameTime) return;
tcur->update(currentFrameTime,x,y);
updateCursor = true;
@@ -280,13 +280,31 @@ TuioBlob* TuioManager::addTuioBlob(float x, float y, float a, float w, float h,
(*listener)->addTuioBlob(tblb);
if (verbose)
- std::cout << "add blb " << tblb->getBlobID() << " (" << tblb->getSessionID() << ") " << tblb->getX() << " " << tblb->getY() << tblb->getAngle() << " " << tblb->getWidth() << tblb->getHeight() << " " << tblb->getArea() << std::endl;
+ std::cout << "add blb " << tblb->getBlobID() << " (" << tblb->getSessionID() << ") " << tblb->getX() << " " << tblb->getY() << " " << tblb->getAngle() << " " << tblb->getWidth() << " " << tblb->getHeight() << " " << tblb->getArea() << std::endl;
return tblb;
}
void TuioManager::addExternalTuioBlob(TuioBlob *tblb) {
if (tblb==NULL) return;
+
+ int blobID = (int)blobList.size();
+ if (blobID <= maxBlobID) {
+ std::list::iterator closestBlob = freeBlobList.begin();
+
+ for(std::list::iterator iter = freeBlobList.begin();iter!= freeBlobList.end(); iter++) {
+ if((*iter)->getDistance(tblb->getX(),tblb->getY())<(*closestBlob)->getDistance(tblb->getX(),tblb->getY())) closestBlob = iter;
+ }
+
+ TuioBlob *freeBlob = (*closestBlob);
+ blobID = (*closestBlob)->getBlobID();
+ freeBlobList.erase(closestBlob);
+ delete freeBlob;
+ } else maxBlobID = blobID;
+
+ tblb->setSessionID(sessionID++);
+ tblb->setBlobID(blobID);
+
blobList.push_back(tblb);
updateBlob = true;
@@ -294,7 +312,7 @@ void TuioManager::addExternalTuioBlob(TuioBlob *tblb) {
(*listener)->addTuioBlob(tblb);
if (verbose)
- std::cout << "add blb " << tblb->getBlobID() << " (" << tblb->getSessionID() << ") " << tblb->getX() << " " << tblb->getY() << tblb->getAngle() << " " << tblb->getWidth() << tblb->getHeight() << " " << tblb->getArea() << std::endl;
+ std::cout << "add blb " << tblb->getBlobID() << " (" << tblb->getSessionID() << ") " << tblb->getX() << " " << tblb->getY() << " " << tblb->getAngle() << " " << tblb->getWidth() << " " << tblb->getHeight() << " " << tblb->getArea() << std::endl;
}
void TuioManager::updateTuioBlob(TuioBlob *tblb,float x, float y, float a, float w, float h, float f) {
@@ -569,8 +587,8 @@ void TuioManager::stopUntouchedMovingBlobs() {
tblb->stop(currentFrameTime);
updateBlob = true;
if (verbose)
- std::cout << "set blb " << tblb->getSessionID() << tblb->getX() << " " << tblb->getY() << " " << tblb->getWidth() << " " << tblb->getHeight() << " " << tblb->getAngle()
- << " " << tblb->getXSpeed() << " " << tblb->getYSpeed()<< " " << tblb->getMotionAccel() << " " << std::endl;
+ std::cout << "set blb " << tblb->getBlobID() << " (" << tblb->getSessionID() << ") " << tblb->getX() << " " << tblb->getY() << " " << tblb->getAngle() << " " << tblb->getWidth() << " " << tblb->getHeight() << " " << tblb->getArea()
+ << " " << tblb->getXSpeed() << " " << tblb->getYSpeed() << " " << tblb->getRotationSpeed() << " " << tblb->getMotionAccel()<< " " << tblb->getRotationAccel() << " " << std::endl;
}
}
}
diff --git a/TUIO/TuioManager.h b/TUIO/TuioManager.h
index 10fe477..3eabbde 100644
--- a/TUIO/TuioManager.h
+++ b/TUIO/TuioManager.h
@@ -1,23 +1,20 @@
/*
- TUIO Server Component - part of the reacTIVision project
- http://reactivision.sourceforge.net/
+ TUIO C++ Library
+ Copyright (c) 2005-2016 Martin Kaltenbrunner
- Copyright (C) 2005-2009 Martin Kaltenbrunner
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3.0 of the License, or (at your option) any later version.
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
+ This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library.
+*/
#ifndef INCLUDED_TUIOMANAGER_H
#define INCLUDED_TUIOMANAGER_H
@@ -60,7 +57,7 @@ namespace TUIO {
*
*
* @author Martin Kaltenbrunner
- * @version 1.5
+ * @version 1.1.6
*/
class LIBDECL TuioManager : public TuioDispatcher {
@@ -348,6 +345,7 @@ namespace TUIO {
* @param verbose print verbose messages if set to true
*/
void setVerbose(bool verbose) { this->verbose=verbose; }
+ bool isVerbose() { return verbose; }
void setInversion(bool ix, bool iy, bool ia) {
invert_x = ix;
diff --git a/TUIO/TuioObject.cpp b/TUIO/TuioObject.cpp
index de9090a..9c818ca 100644
--- a/TUIO/TuioObject.cpp
+++ b/TUIO/TuioObject.cpp
@@ -1,23 +1,20 @@
/*
- TUIO C++ Library - part of the reacTIVision project
- http://reactivision.sourceforge.net/
+ TUIO C++ Library
+ Copyright (c) 2005-2016 Martin Kaltenbrunner
- Copyright (c) 2005-2009 Martin Kaltenbrunner
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3.0 of the License, or (at your option) any later version.
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
+ This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library.
+*/
#include "TuioObject.h"
@@ -26,27 +23,40 @@ using namespace TUIO;
TuioObject::TuioObject (TuioTime ttime, long si, int sym, float xp, float yp, float a):TuioContainer(ttime, si, xp, yp) {
symbol_id = sym;
angle = a;
+ angle_sum = a;
rotation_speed = 0.0f;
rotation_accel = 0.0f;
+
+ angleFilter = NULL;
+ angleThreshold = 0.0f;
}
TuioObject::TuioObject (long si, int sym, float xp, float yp, float a):TuioContainer(si, xp, yp) {
symbol_id = sym;
angle = a;
+ angle_sum = a;
rotation_speed = 0.0f;
rotation_accel = 0.0f;
+
+ angleFilter = NULL;
+ angleThreshold = 0.0f;
}
TuioObject::TuioObject (TuioObject *tobj):TuioContainer(tobj) {
symbol_id = tobj->getSymbolID();
angle = tobj->getAngle();
+ angle_sum = tobj->getAngleSum();
rotation_speed = 0.0f;
rotation_accel = 0.0f;
+
+ angleFilter = NULL;
+ angleThreshold = 0.0f;
}
void TuioObject::update (TuioTime ttime, float xp, float yp, float a, float xs, float ys, float rs, float ma, float ra) {
TuioContainer::update(ttime,xp,yp,xs,ys,ma);
angle = a;
+ angle_sum = a;
rotation_speed = rs;
rotation_accel = ra;
if ((rotation_accel!=0) && (state==TUIO_STOPPED)) state = TUIO_ROTATING;
@@ -56,6 +66,7 @@ void TuioObject::update (TuioTime ttime, float xp, float yp, float a, float xs,
void TuioObject::update (float xp, float yp, float a, float xs, float ys, float rs, float ma, float ra) {
TuioContainer::update(xp,yp,xs,ys,ma);
angle = a;
+ angle_sum = a;
rotation_speed = rs;
rotation_accel = ra;
if ((rotation_accel!=0) && (state==TUIO_STOPPED)) state = TUIO_ROTATING;
@@ -67,11 +78,21 @@ void TuioObject::update (TuioTime ttime, float xp, float yp, float a) {
TuioTime diffTime = currentTime - lastPoint.getTuioTime();
float dt = diffTime.getTotalMilliseconds()/1000.0f;
- float last_angle = angle;
float last_rotation_speed = rotation_speed;
- angle = a;
- double da = (angle-last_angle)/(2*M_PI);
+ float prev_angle = angle_sum;
+ float da = a-angle;
+ if (da > M_PI/2.0f) angle_sum += (da-2*M_PI);
+ else if (da < M_PI/-2.0f) angle_sum += (da+2*M_PI);
+ else angle_sum += da;
+
+ if (angleFilter) angle_sum = angleFilter->filter(angle_sum,dt);
+ if (fabs(angle_sum-prev_angle) 0.75f) da-=1.0f;
else if (da < -0.75f) da+=1.0f;
@@ -88,6 +109,7 @@ void TuioObject::stop (TuioTime ttime) {
void TuioObject::update (TuioObject *tobj) {
TuioContainer::update(tobj);
angle = tobj->getAngle();
+ angle_sum = tobj->getAngleSum();
rotation_speed = tobj->getRotationSpeed();
rotation_accel = tobj->getRotationAccel();
if ((rotation_accel!=0) && (state==TUIO_STOPPED)) state = TUIO_ROTATING;
@@ -101,6 +123,10 @@ float TuioObject::getAngle() const{
return angle;
}
+float TuioObject::getAngleSum() const{
+ return angle_sum;
+}
+
float TuioObject::getAngleDegrees() const{
return (float)(angle/M_PI*180);
}
@@ -117,3 +143,23 @@ bool TuioObject::isMoving() const{
if ((state==TUIO_ACCELERATING) || (state==TUIO_DECELERATING) || (state==TUIO_ROTATING)) return true;
else return false;
}
+
+void TuioObject::addAngleThreshold(float thresh) {
+ angleThreshold = thresh;
+}
+
+void TuioObject::removeAngleThreshold() {
+ angleThreshold = 0.0f;
+}
+
+void TuioObject::addAngleFilter(float mcut, float beta) {
+
+ if (angleFilter) delete angleFilter;
+ angleFilter = new OneEuroFilter(60.0f, mcut, beta, 1.0f);
+}
+
+void TuioObject::removeAngleFilter() {
+
+ if (angleFilter) delete angleFilter;
+ angleFilter = NULL;
+}
diff --git a/TUIO/TuioObject.h b/TUIO/TuioObject.h
index 183c6f2..b027c79 100644
--- a/TUIO/TuioObject.h
+++ b/TUIO/TuioObject.h
@@ -1,23 +1,20 @@
/*
- TUIO C++ Library - part of the reacTIVision project
- http://reactivision.sourceforge.net/
+ TUIO C++ Library
+ Copyright (c) 2005-2016 Martin Kaltenbrunner
- Copyright (c) 2005-2009 Martin Kaltenbrunner
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3.0 of the License, or (at your option) any later version.
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
+ This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library.
+*/
#ifndef INCLUDED_TUIOOBJECT_H
#define INCLUDED_TUIOOBJECT_H
@@ -30,7 +27,7 @@ namespace TUIO {
* The TuioObject class encapsulates /tuio/2Dobj TUIO objects.
*
* @author Martin Kaltenbrunner
- * @version 1.5
+ * @version 1.1.6
*/
class LIBDECL TuioObject: public TuioContainer {
@@ -43,6 +40,10 @@ namespace TUIO {
* The rotation angle value.
*/
float angle;
+ /**
+ * The accumulated angle value.
+ */
+ float angle_sum;
/**
* The rotation speed value.
*/
@@ -52,6 +53,9 @@ namespace TUIO {
*/
float rotation_accel;
+ float angleThreshold;
+ OneEuroFilter *angleFilter;
+
public:
using TuioContainer::update;
@@ -91,7 +95,9 @@ namespace TUIO {
/**
* The destructor is doing nothing in particular.
*/
- ~TuioObject() {};
+ virtual ~TuioObject() {
+ if (angleFilter) delete angleFilter;
+ };
/**
* Takes a TuioTime argument and assigns it along with the provided
@@ -165,6 +171,12 @@ namespace TUIO {
*/
float getAngle() const;
+ /**
+ * Returns the accumulated rotation angle of this TuioObject.
+ * @return the accumulated rotation angle of this TuioObject
+ */
+ float getAngleSum() const;
+
/**
* Returns the rotation angle in degrees of this TuioObject.
* @return the rotation angle in degrees of this TuioObject
@@ -188,6 +200,14 @@ namespace TUIO {
* @return true of this TuioObject is moving
*/
bool isMoving() const;
+
+ void addAngleThreshold(float thresh);
+
+ void removeAngleThreshold();
+
+ void addAngleFilter(float mcut, float beta);
+
+ void removeAngleFilter();
};
}
#endif
diff --git a/TUIO/TuioPoint.cpp b/TUIO/TuioPoint.cpp
index 42f58a8..0b0761c 100644
--- a/TUIO/TuioPoint.cpp
+++ b/TUIO/TuioPoint.cpp
@@ -1,23 +1,20 @@
/*
- TUIO C++ Library - part of the reacTIVision project
- http://reactivision.sourceforge.net/
+ TUIO C++ Library
+ Copyright (c) 2005-2016 Martin Kaltenbrunner
- Copyright (c) 2005-2009 Martin Kaltenbrunner
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3.0 of the License, or (at your option) any later version.
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
+ This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library.
+*/
#include "TuioPoint.h"
@@ -28,6 +25,11 @@ TuioPoint::TuioPoint (float xp, float yp) {
ypos = yp;
currentTime = TuioTime::getSessionTime();
startTime = currentTime;
+
+ xposFilter = NULL;
+ yposFilter = NULL;
+
+ posThreshold = 0.0f;
}
TuioPoint::TuioPoint (TuioTime ttime, float xp, float yp) {
@@ -35,6 +37,11 @@ TuioPoint::TuioPoint (TuioTime ttime, float xp, float yp) {
ypos = yp;
currentTime = ttime;
startTime = currentTime;
+
+ xposFilter = NULL;
+ yposFilter = NULL;
+
+ posThreshold = 0.0f;
}
TuioPoint::TuioPoint (TuioPoint *tpoint) {
@@ -42,6 +49,11 @@ TuioPoint::TuioPoint (TuioPoint *tpoint) {
ypos = tpoint->getY();
currentTime = TuioTime::getSessionTime();
startTime = currentTime;
+
+ xposFilter = NULL;
+ yposFilter = NULL;
+
+ posThreshold = 0.0f;
}
void TuioPoint::update (TuioPoint *tpoint) {
@@ -52,16 +64,30 @@ void TuioPoint::update (TuioPoint *tpoint) {
void TuioPoint::update (float xp, float yp) {
xpos = xp;
ypos = yp;
-}
+}
void TuioPoint::update (TuioTime ttime, float xp, float yp) {
- xpos = xp;
- ypos = yp;
+
+ if (xposFilter && yposFilter) {
+ TuioTime diffTime = ttime - startTime;
+ float dt = diffTime.getTotalMilliseconds()/1000.0f;
+ xp = xposFilter->filter(xp,dt);
+ yp = yposFilter->filter(yp,dt);
+ //std::cout << dt << " " << xp << " " << xpos << " " << yp << " " << ypos << std::endl;
+ }
+
+ float dx = fabs(xpos - xp);
+ float dy = fabs(ypos - yp);
+ if ((dx>posThreshold) || (dy>posThreshold)) {
+ xpos = xp;
+ ypos = yp;
+ }
+
currentTime = ttime;
}
-float TuioPoint::getX() const{
+float TuioPoint::getX() const{
return xpos;
}
@@ -90,10 +116,10 @@ float TuioPoint::getAngle(float xp, float yp) const{
float side = xpos-xp;
float height = ypos-yp;
float distance = getDistance(xp,yp);
-
+
float angle = (float)(asin(side/distance)+M_PI/2);
if (height<0) angle = 2.0f*(float)M_PI-angle;
-
+
return angle;
}
@@ -109,7 +135,7 @@ float TuioPoint::getAngleDegrees(TuioPoint *tpoint) const{
return ((getAngle(tpoint)/(float)M_PI)*180.0f);
}
-int TuioPoint::getScreenX(int width) const{
+int TuioPoint::getScreenX(int width) const{
return (int)floor(xpos*width+0.5f);
}
@@ -117,7 +143,7 @@ int TuioPoint::getScreenY(int height) const{
return (int)floor(ypos*height+0.5f);
}
-TuioTime TuioPoint::getTuioTime() const{
+TuioTime TuioPoint::getTuioTime() const{
return currentTime;
}
@@ -125,3 +151,26 @@ TuioTime TuioPoint::getStartTime() const{
return startTime;
}
+void TuioPoint::addPositionThreshold(float thresh) {
+ posThreshold = thresh;
+}
+
+void TuioPoint::removePositionThreshold() {
+ posThreshold = 0.0f;
+}
+
+void TuioPoint::addPositionFilter(float mcut, float beta) {
+
+ if (xposFilter) delete xposFilter;
+ xposFilter = new OneEuroFilter(60.0f, mcut, beta, 1.0f);
+ if (yposFilter) delete yposFilter;
+ yposFilter = new OneEuroFilter(60.0f, mcut, beta, 1.0f);
+}
+
+void TuioPoint::removePositionFilter() {
+
+ if (xposFilter) delete xposFilter;
+ xposFilter = NULL;
+ if (yposFilter) delete yposFilter;
+ yposFilter = NULL;
+}
diff --git a/TUIO/TuioPoint.h b/TUIO/TuioPoint.h
index 9a5ec93..3415f07 100644
--- a/TUIO/TuioPoint.h
+++ b/TUIO/TuioPoint.h
@@ -1,28 +1,26 @@
/*
- TUIO C++ Library - part of the reacTIVision project
- http://reactivision.sourceforge.net/
+ TUIO C++ Library
+ Copyright (c) 2005-2016 Martin Kaltenbrunner
- Copyright (c) 2005-2009 Martin Kaltenbrunner
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3.0 of the License, or (at your option) any later version.
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
+ This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library.
+*/
#ifndef INCLUDED_TUIOPOINT_H
#define INCLUDED_TUIOPOINT_H
#include "TuioTime.h"
+#include "OneEuroFilter.h"
#include
#ifndef M_PI
@@ -30,16 +28,16 @@
#endif
namespace TUIO {
-
+
/**
* The TuioPoint class on the one hand is a simple container and utility class to handle TUIO positions in general,
* on the other hand the TuioPoint is the base class for the TuioCursor and TuioObject classes.
*
* @author Martin Kaltenbrunner
- * @version 1.5
+ * @version 1.1.6
*/
class LIBDECL TuioPoint {
-
+
protected:
/**
* X coordinate, representated as a floating point value in a range of 0..1
@@ -57,16 +55,20 @@ namespace TUIO {
* The creation time of this TuioPoint represented as TuioTime (time since session start)
*/
TuioTime startTime;
-
+
+ OneEuroFilter *xposFilter;
+ OneEuroFilter *yposFilter;
+ float posThreshold;
+
public:
/**
- * The default constructor takes no arguments and sets
+ * The default constructor takes no arguments and sets
* its coordinate attributes to zero and its time stamp to the current session time.
*/
TuioPoint (float xp, float yp);
-
+
/**
- * This constructor takes a TuioTime object and two floating point coordinate arguments and sets
+ * This constructor takes a TuioTime object and two floating point coordinate arguments and sets
* its coordinate attributes to these values and its time stamp to the provided TUIO time object.
*
* @param ttime the TuioTime to assign
@@ -74,37 +76,40 @@ namespace TUIO {
* @param yp the Y coordinate to assign
*/
TuioPoint (TuioTime ttime, float xp, float yp);
-
+
/**
- * This constructor takes a TuioPoint argument and sets its coordinate attributes
+ * This constructor takes a TuioPoint argument and sets its coordinate attributes
* to the coordinates of the provided TuioPoint and its time stamp to the current session time.
*
* @param tpoint the TuioPoint to assign
*/
TuioPoint (TuioPoint *tpoint);
-
+
/**
- * The destructor is doing nothing in particular.
+ * The destructor is doing nothing in particular.
*/
- ~TuioPoint(){};
-
+ virtual ~TuioPoint(){
+ if (xposFilter) delete xposFilter;
+ if (yposFilter) delete yposFilter;
+ };
+
/**
- * Takes a TuioPoint argument and updates its coordinate attributes
+ * Takes a TuioPoint argument and updates its coordinate attributes
* to the coordinates of the provided TuioPoint and leaves its time stamp unchanged.
*
* @param tpoint the TuioPoint to assign
*/
void update (TuioPoint *tpoint);
-
+
/**
* Takes two floating point coordinate arguments and updates its coordinate attributes
* to the coordinates of the provided TuioPoint and leaves its time stamp unchanged.
*
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
- */
- void update (float xp, float yp);
-
+ */
+ void update (float xp, float yp);
+
/**
* Takes a TuioTime object and two floating point coordinate arguments and updates its coordinate attributes
* to the coordinates of the provided TuioPoint and its time stamp to the provided TUIO time object.
@@ -208,6 +213,14 @@ namespace TUIO {
* @return the start time of this TuioPoint as TuioTime
*/
TuioTime getStartTime() const;
+
+ void addPositionThreshold(float thresh);
+
+ void removePositionThreshold();
+
+ void addPositionFilter(float mcut, float beta);
+
+ void removePositionFilter();
};
}
#endif
diff --git a/TUIO/TuioServer.cpp b/TUIO/TuioServer.cpp
index 4220237..c157e7d 100644
--- a/TUIO/TuioServer.cpp
+++ b/TUIO/TuioServer.cpp
@@ -1,22 +1,19 @@
/*
- TUIO Server Component - part of the reacTIVision project
- http://reactivision.sourceforge.net/
-
- Copyright (C) 2005-2009 Martin Kaltenbrunner
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ TUIO C++ Library
+ Copyright (c) 2005-2016 Martin Kaltenbrunner
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3.0 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library.
*/
#include "TuioServer.h"
@@ -26,48 +23,44 @@ using namespace TUIO;
using namespace osc;
TuioServer::TuioServer()
- :local_sender (true)
- ,full_update (false)
+ :full_update (false)
,periodic_update (false)
,objectProfileEnabled (true)
,cursorProfileEnabled (true)
,blobProfileEnabled (true)
,source_name (NULL)
{
- primary_sender = new UdpSender();
- initialize();
+ OscSender *oscsend = new UdpSender();
+ initialize(oscsend);
}
TuioServer::TuioServer(const char *host, int port)
-:local_sender (true)
-,full_update (false)
+:full_update (false)
,periodic_update (false)
,objectProfileEnabled (true)
,cursorProfileEnabled (true)
,blobProfileEnabled (true)
,source_name (NULL)
{
- primary_sender = new UdpSender(host,port);
- initialize();
+ OscSender *oscsend = new UdpSender(host,port);
+ initialize(oscsend);
}
TuioServer::TuioServer(OscSender *oscsend)
- :primary_sender (oscsend)
- ,local_sender (false)
- ,full_update (false)
+ :full_update (false)
,periodic_update (false)
,objectProfileEnabled (true)
,cursorProfileEnabled (true)
,blobProfileEnabled (true)
,source_name (NULL)
{
- initialize();
+ initialize(oscsend);
}
-void TuioServer::initialize() {
+void TuioServer::initialize(OscSender *oscsend) {
- senderList.push_back(primary_sender);
- int size = primary_sender->getBufferSize();
+ senderList.push_back(oscsend);
+ int size = oscsend->getBufferSize();
oscBuffer = new char[size];
oscPacket = new osc::OutboundPacketStream(oscBuffer,size);
fullBuffer = new char[size];
@@ -77,9 +70,9 @@ void TuioServer::initialize() {
cursorUpdateTime = TuioTime(currentFrameTime);
blobUpdateTime = TuioTime(currentFrameTime);
- sendEmptyCursorBundle();
- sendEmptyObjectBundle();
- sendEmptyBlobBundle();
+ if (cursorProfileEnabled) sendEmptyCursorBundle();
+ if (objectProfileEnabled) sendEmptyObjectBundle();
+ if (blobProfileEnabled) sendEmptyBlobBundle();
invert_x = false;
invert_y = false;
@@ -98,17 +91,18 @@ TuioServer::~TuioServer() {
removeUntouchedStoppedObjects();
removeUntouchedStoppedBlobs();
- sendEmptyCursorBundle();
- sendEmptyObjectBundle();
- sendEmptyBlobBundle();
-
+ if (cursorProfileEnabled) sendEmptyCursorBundle();
+ if (objectProfileEnabled) sendEmptyObjectBundle();
+ if (blobProfileEnabled) sendEmptyBlobBundle();
+
delete []oscBuffer;
delete oscPacket;
delete []fullBuffer;
delete fullPacket;
if (source_name) delete[] source_name;
- if( local_sender) delete primary_sender;
+ for (unsigned int i=0;isendOscPacket(packet);
}
+void TuioServer::setSourceName(const char *name, const char *ip) {
+ if (!source_name) source_name = new char[256];
+ sprintf(source_name,"%s@%s",name,ip);
+}
+
+
void TuioServer::setSourceName(const char *src) {
if (!source_name) source_name = new char[256];
- if (primary_sender->isLocal()) {
+ /*if (senderList[0]->isLocal()) {
sprintf(source_name,"%s",src);
- } else {
+ } else {*/
char hostname[64];
char *source_addr = NULL;
struct hostent *hp = NULL;
@@ -174,9 +174,9 @@ void TuioServer::setSourceName(const char *src) {
source_addr = inet_ntoa(*addr);
}
sprintf(source_name,"%s@%s",src,source_addr);
- }
+ //}
- //std::cout << "source: " << source_name << std::endl;
+ std::cout << "tuio/src " << source_name << std::endl;
}
void TuioServer::commitFrame() {
@@ -302,12 +302,14 @@ void TuioServer::startCursorBundle() {
if (source_name) (*oscPacket) << osc::BeginMessage( "/tuio/2Dcur") << "source" << source_name << osc::EndMessage;
(*oscPacket) << osc::BeginMessage( "/tuio/2Dcur") << "alive";
for (std::list::iterator tuioCursor = cursorList.begin(); tuioCursor!=cursorList.end(); tuioCursor++) {
- (*oscPacket) << (int32)((*tuioCursor)->getSessionID());
+ if ((*tuioCursor)->getTuioState()!=TUIO_ADDED) (*oscPacket) << (int32)((*tuioCursor)->getSessionID());
}
(*oscPacket) << osc::EndMessage;
}
void TuioServer::addCursorMessage(TuioCursor *tcur) {
+
+ if (tcur->getTuioState()==TUIO_ADDED) return;
float xpos = tcur->getX();
float xvel = tcur->getXSpeed();
@@ -405,13 +407,15 @@ void TuioServer::startBlobBundle() {
if (source_name) (*oscPacket) << osc::BeginMessage( "/tuio/2Dblb") << "source" << source_name << osc::EndMessage;
(*oscPacket) << osc::BeginMessage( "/tuio/2Dblb") << "alive";
for (std::list::iterator tuioBlob = blobList.begin(); tuioBlob!=blobList.end(); tuioBlob++) {
- (*oscPacket) << (int32)((*tuioBlob)->getSessionID());
+ if ((*tuioBlob)->getTuioState()!=TUIO_ADDED) (*oscPacket) << (int32)((*tuioBlob)->getSessionID());
}
(*oscPacket) << osc::EndMessage;
}
void TuioServer::addBlobMessage(TuioBlob *tblb) {
+ if (tblb->getTuioState()==TUIO_ADDED) return;
+
float xpos = tblb->getX();
float xvel = tblb->getXSpeed();
if (invert_x) {
diff --git a/TUIO/TuioServer.h b/TUIO/TuioServer.h
index 5fc5a73..66ad0a5 100644
--- a/TUIO/TuioServer.h
+++ b/TUIO/TuioServer.h
@@ -1,29 +1,29 @@
/*
- TUIO Server Component - part of the reacTIVision project
- http://reactivision.sourceforge.net/
+ TUIO C++ Library
+ Copyright (c) 2005-2016 Martin Kaltenbrunner
- Copyright (C) 2005-2009 Martin Kaltenbrunner
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3.0 of the License, or (at your option) any later version.
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
+ This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library.
+*/
#ifndef INCLUDED_TuioServer_H
#define INCLUDED_TuioServer_H
#include "TuioManager.h"
#include "UdpSender.h"
+#include "TcpSender.h"
+#include "WebSockSender.h"
+#include "FlashSender.h"
#include
#include
#include
@@ -66,7 +66,7 @@ namespace TUIO {
*
*
* @author Martin Kaltenbrunner
- * @version 1.5
+ * @version 1.1.6
*/
class LIBDECL TuioServer : public TuioManager {
@@ -172,9 +172,21 @@ namespace TUIO {
/**
* Defines the name of this TUIO source, which is transmitted within the /tuio/[profile] source message.
*
- * @param src the desired name of this TUIO source
+ * @param name the desired name of this TUIO source
*/
- void setSourceName(const char *src);
+ void setSourceName(const char *name);
+
+
+ /**
+ * Defines the name and IP address of this TUIO source, which is transmitted within the /tuio/[profile] source message.
+ *
+ * @param name the desired name of this TUIO source
+ * @param ip the local IP address
+ */
+ void setSourceName(const char *name, const char *ip);
+
+
+
void addOscSender(OscSender *sender);
void enableObjectProfile(bool flag) { objectProfileEnabled = flag; };
@@ -183,10 +195,7 @@ namespace TUIO {
private:
- void initialize();
-
- OscSender *primary_sender;
- bool local_sender;
+ void initialize(OscSender *oscsend);
std::vector senderList;
void deliverOscPacket(osc::OutboundPacketStream *packet);
diff --git a/TUIO/TuioTime.cpp b/TUIO/TuioTime.cpp
index 09f5941..f169c14 100644
--- a/TUIO/TuioTime.cpp
+++ b/TUIO/TuioTime.cpp
@@ -1,23 +1,20 @@
/*
- TUIO C++ Library - part of the reacTIVision project
- http://reactivision.sourceforge.net/
+ TUIO C++ Library
+ Copyright (c) 2005-2016 Martin Kaltenbrunner
- Copyright (c) 2005-2009 Martin Kaltenbrunner
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3.0 of the License, or (at your option) any later version.
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
+ This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library.
+*/
#include "TuioTime.h"
using namespace TUIO;
diff --git a/TUIO/TuioTime.h b/TUIO/TuioTime.h
index b9cc3f9..567c443 100644
--- a/TUIO/TuioTime.h
+++ b/TUIO/TuioTime.h
@@ -1,23 +1,20 @@
/*
- TUIO C++ Library - part of the reacTIVision project
- http://reactivision.sourceforge.net/
+ TUIO C++ Library
+ Copyright (c) 2005-2016 Martin Kaltenbrunner
- Copyright (c) 2005-2009 Martin Kaltenbrunner
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3.0 of the License, or (at your option) any later version.
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
+ This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library.
+*/
#ifndef INCLUDED_TUIOTIME_H
#define INCLUDED_TUIOTIME_H
@@ -46,7 +43,7 @@ namespace TUIO {
* The class also provides various addtional convience method, which allow some simple time arithmetics.
*
* @author Martin Kaltenbrunner
- * @version 1.5
+ * @version 1.1.6
*/
class LIBDECL TuioTime {
diff --git a/TUIO/UdpReceiver.cpp b/TUIO/UdpReceiver.cpp
deleted file mode 100644
index bbd7460..0000000
--- a/TUIO/UdpReceiver.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- TUIO C++ Library - part of the reacTIVision project
- http://reactivision.sourceforge.net/
-
- Copyright (c) 2005-2009 Martin Kaltenbrunner
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "UdpReceiver.h"
-
-using namespace TUIO;
-using namespace osc;
-
-#ifndef WIN32
-static void* ClientThreadFunc( void* obj )
-#else
-static DWORD WINAPI ClientThreadFunc( LPVOID obj )
-#endif
-{
- static_cast(obj)->socket->Run();
- return 0;
-};
-
-UdpReceiver::UdpReceiver(int port)
-: socket (NULL)
-, thread (NULL)
-, locked (false)
-{
- try {
- socket = new UdpListeningReceiveSocket(IpEndpointName( IpEndpointName::ANY_ADDRESS, port ), this );
- } catch (std::exception &e) {
- std::cerr << "could not bind to UDP port " << port << std::endl;
- socket = NULL;
- }
-
- if (socket!=NULL) {
- if (!socket->IsBound()) {
- delete socket;
- socket = NULL;
- } else std::cout << "listening to TUIO messages on UDP port " << port << std::endl;
- }
-}
-
-UdpReceiver::~UdpReceiver() {
- delete socket;
-}
-
-void UdpReceiver::connect(bool lk) {
-
- if (connected) return;
- if (socket==NULL) return;
-
- locked = lk;
- if (!locked) {
-#ifndef WIN32
- pthread_create(&thread , NULL, ClientThreadFunc, this);
-#else
- DWORD threadId;
- thread = CreateThread( 0, 0, ClientThreadFunc, this, 0, &threadId );
-#endif
- } else socket->Run();
-
- connected = true;
-}
-
-void UdpReceiver::disconnect() {
-
- if (!connected) return;
- if (socket==NULL) {
- connected = false;
- return;
- }
- socket->Break();
-
- if (!locked) {
-#ifdef WIN32
- if( thread ) CloseHandle( thread );
-#endif
- thread = 0;
- locked = false;
- }
-
- connected = false;
-}
-
-
diff --git a/TUIO/UdpReceiver.h b/TUIO/UdpReceiver.h
deleted file mode 100644
index 4f0da51..0000000
--- a/TUIO/UdpReceiver.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- TUIO C++ Library - part of the reacTIVision project
- http://reactivision.sourceforge.net/
-
- Copyright (c) 2005-2009 Martin Kaltenbrunner
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef INCLUDED_UDPRECEIVER_H
-#define INCLUDED_UDPRECEIVER_H
-
-#include "OscReceiver.h"
-#include "ip/UdpSocket.h"
-
-namespace TUIO {
-
- /**
- * The UdpReceiver provides the OscReceiver finctionality for the UDP transport method
- *
- * @author Martin Kaltenbrunner
- * @version 1.5
- */
- class LIBDECL UdpReceiver: public OscReceiver {
-
- public:
-
- /**
- * The UDP socket is only public to be accessible from the thread function
- */
- UdpListeningReceiveSocket *socket;
-
- /**
- * This constructor creates a UdpReceiver instance listening to the provided UDP port
- *
- * @param port the number of the UDP port to listen to, defaults to 3333
- */
- UdpReceiver (int port=3333);
-
- /**
- * The destructor is doing nothing in particular.
- */
- virtual ~UdpReceiver();
-
- /**
- * The UdpReceiver connects and starts receiving TUIO messages via UDP
- *
- * @param lock running in the background if set to false (default)
- */
- void connect(bool lock=false);
-
- /**
- * The UdpReceiver disconnects and stops receiving TUIO messages via UDP
- */
- void disconnect();
-
- private:
-
-#ifndef WIN32
- pthread_t thread;
-#else
- HANDLE thread;
-#endif
-
- bool locked;
- };
-};
-#endif /* INCLUDED_UDPRECEIVER_H */
diff --git a/TUIO/UdpSender.cpp b/TUIO/UdpSender.cpp
index d1b3e88..c4f8c10 100644
--- a/TUIO/UdpSender.cpp
+++ b/TUIO/UdpSender.cpp
@@ -1,24 +1,20 @@
/*
- TUIO C++ Library - part of the reacTIVision project
- http://reactivision.sourceforge.net/
+ TUIO C++ Library
+ Copyright (c) 2005-2016 Martin Kaltenbrunner
- Copyright (c) 2005-2009 Martin Kaltenbrunner
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3.0 of the License, or (at your option) any later version.
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
+ This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library.
+*/
#include "UdpSender.h"
@@ -30,9 +26,11 @@ UdpSender::UdpSender() {
long unsigned int ip = GetHostByName("localhost");
socket = new UdpTransmitSocket(IpEndpointName(ip, 3333));
buffer_size = MAX_UDP_SIZE;
+ std::cout << "TUIO/UDP messages to " << "127.0.0.1@3333" << std::endl;
} catch (std::exception &e) {
std::cout << "could not create UDP socket" << std::endl;
socket = NULL;
+ throw std::exception();
}
}
@@ -47,9 +45,11 @@ UdpSender::UdpSender(const char *host, int port) {
}
long unsigned int ip = GetHostByName(host);
socket = new UdpTransmitSocket(IpEndpointName(ip, port));
+ std::cout << "TUIO/UDP messages to " << host << "@" << port << std::endl;
} catch (std::exception &e) {
std::cout << "could not create UDP socket" << std::endl;
socket = NULL;
+ throw std::exception();
}
}
@@ -62,9 +62,11 @@ UdpSender::UdpSender(const char *host, int port, int size) {
socket = new UdpTransmitSocket(IpEndpointName(ip, port));
if (buffer_size>MAX_UDP_SIZE) buffer_size = MAX_UDP_SIZE;
else if (buffer_sizeSize() > buffer_size ) return false;
+ if ( bundle->Size() == 0 ) return false;
+
socket->Send( bundle->Data(), bundle->Size() );
return true;
}
diff --git a/TUIO/UdpSender.h b/TUIO/UdpSender.h
index 88bcb42..357f0f7 100644
--- a/TUIO/UdpSender.h
+++ b/TUIO/UdpSender.h
@@ -1,23 +1,20 @@
/*
- TUIO C++ Library - part of the reacTIVision project
- http://reactivision.sourceforge.net/
+ TUIO C++ Library
+ Copyright (c) 2005-2016 Martin Kaltenbrunner
- Copyright (c) 2005-2009 Martin Kaltenbrunner
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3.0 of the License, or (at your option) any later version.
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
+ This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library.
+*/
#ifndef INCLUDED_UDPSENDER_H
#define INCLUDED_UDPSENDER_H
@@ -35,7 +32,7 @@ namespace TUIO {
* The UdpSender implements the UDP transport method for OSC
*
* @author Martin Kaltenbrunner
- * @version 1.5
+ * @version 1.1.6
*/
class LIBDECL UdpSender : public OscSender {
@@ -69,7 +66,7 @@ namespace TUIO {
/**
* The destructor closes the socket.
*/
- ~UdpSender();
+ virtual ~UdpSender();
/**
* This method delivers the provided OSC data
@@ -87,6 +84,8 @@ namespace TUIO {
*/
bool isConnected ();
+ const char* tuio_type() { return "TUIO/UDP"; }
+
private:
UdpTransmitSocket *socket;
};
diff --git a/TUIO/WebSockSender.h b/TUIO/WebSockSender.h
new file mode 100644
index 0000000..66c8589
--- /dev/null
+++ b/TUIO/WebSockSender.h
@@ -0,0 +1,121 @@
+/*
+ TUIO C++ Library
+ Copyright (c) 2009-2016 Martin Kaltenbrunner
+ WebSockSender (c) 2015 Florian Echtler
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3.0 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library.
+*/
+
+#ifndef INCLUDED_WEBSOCKSENDER_H
+#define INCLUDED_WEBSOCKSENDER_H
+
+#if defined(_MSC_VER) && _MSC_VER < 1900
+#include
+#include
+#define snprintf c99_snprintf
+#define vsnprintf c99_vsnprintf
+
+__inline int c99_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap)
+{
+ int count = -1;
+
+ if (size != 0)
+ count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap);
+ if (count == -1)
+ count = _vscprintf(format, ap);
+
+ return count;
+}
+
+__inline int c99_snprintf(char *outBuf, size_t size, const char *format, ...)
+{
+ int count;
+ va_list ap;
+
+ va_start(ap, format);
+ count = c99_vsnprintf(outBuf, size, format, ap);
+ va_end(ap);
+
+ return count;
+}
+
+#endif
+
+
+/* All of these macros assume use on a 32-bit variable.
+ Additionally, SWAP assumes we're little-endian. */
+#define SWAP(a) ((((a) >> 24) & 0x000000ff) | (((a) >> 8) & 0x0000ff00) | \
+(((a) << 8) & 0x00ff0000) | (((a) << 24) & 0xff000000))
+#define ROL(a, b) (((a) << (b)) | ((a) >> (32 - (b))))
+#define ROR(a, b) ROL((a), (32 - (b)))
+#define SHA1_HASH_SIZE (160/8)
+
+#include "TcpSender.h"
+#include
+#include
+#include
+#include
+
+namespace TUIO {
+
+ /**
+ * The WebSockSender implements the WebSocket transport method for OSC
+ *
+ * @author Florian Echtler
+ * @version 2.0.a0
+ */
+ class LIBDECL WebSockSender : public TcpSender {
+
+ public:
+
+ /**
+ * The default constructor creates a WebSockSender that listens to the default HTTP-alt port 8080 on localhost
+ */
+ WebSockSender();
+
+ /**
+ * This constructor creates a WebSockSender that listens to the provided port
+ *
+ * @param port the listening WebSocket port number
+ */
+ WebSockSender(int port);
+
+ /**
+ * The destructor closes the socket.
+ */
+ virtual ~WebSockSender() {}
+
+ /**
+ * This method delivers the provided OSC data
+ *
+ * @param *bundle the OSC stream to deliver
+ * @return true if the data was delivered successfully
+ */
+ bool sendOscPacket (osc::OutboundPacketStream *bundle);
+
+ /**
+ * This method is called whenever a new client connects
+ *
+ * @param tcp_client the socket handle of the new client
+ */
+ void newClient( int tcp_client );
+
+ const char* tuio_type() { return "TUIO/WEB"; }
+ private:
+
+ void sha1( uint8_t digest[SHA1_HASH_SIZE], const uint8_t* inbuf, size_t length );
+ std::string base64( uint8_t* buffer, size_t size );
+ };
+}
+#endif /* INCLUDED_WEBSOCKSENDER_H */
diff --git a/TongsengApp/English.lproj/InfoPlist.strings b/TongsengApp/English.lproj/InfoPlist.strings
deleted file mode 100644
index 5e45963..0000000
Binary files a/TongsengApp/English.lproj/InfoPlist.strings and /dev/null differ
diff --git a/TongsengApp/English.lproj/MainMenu.xib b/TongsengApp/English.lproj/MainMenu.xib
index 08bd409..2b292b6 100644
--- a/TongsengApp/English.lproj/MainMenu.xib
+++ b/TongsengApp/English.lproj/MainMenu.xib
@@ -1,849 +1,170 @@
-
-
-
- 1050
- 9L30
- 677
- 949.54
- 353.00
-
-
-
-
- YES
-
- NSApplication
-
-
- FirstResponder
-
-
- NSApplication
-
-
- AMainMenu
-
- YES
-
-
- Tongseng
-
- 1048576
- 2147483647
-
- NSImage
- NSMenuCheckmark
-
-
- NSImage
- NSMenuMixedState
-
- submenuAction:
-
- TongsengApp
-
- YES
-
-
- About Tongseng
-
- 2147483647
-
-
-
-
-
- YES
- YES
-
-
- 2147483647
-
-
-
-
-
- Hide Tongseng
- h
- 1048576
- 2147483647
-
-
-
-
-
- Hide Others
- h
- 1572864
- 2147483647
-
-
-
-
-
- Show All
-
- 1048576
- 2147483647
-
-
-
-
-
- YES
- YES
-
-
- 1048576
- 2147483647
-
-
-
-
-
- Quit Tongseng
- q
- 1048576
- 2147483647
-
-
-
-
- _NSAppleMenu
-
-
-
- _NSMainMenu
-
-
- 7
- 2
- {{529, 292}, {269, 190}}
- 1954021376
- Tongseng
- NSWindow
-
- {3.40282e+38, 3.40282e+38}
-
-
- 256
-
- YES
-
-
- 12
-
- YES
-
-
- 256
-
- YES
-
-
- 268
- {{15, 57}, {72, 17}}
-
- YES
-
- 68288064
- 71304192
- Hostname:
-
- LucidaGrande
- 1.300000e+01
- 1044
-
-
-
- 6
- System
- controlColor
-
- 3
- MC42NjY2NjY2OQA
-
-
-
- 6
- System
- controlTextColor
-
- 3
- MAA
-
-
-
-
-
-
- 268
- {{15, 25}, {72, 17}}
-
- YES
-
- 68288064
- 71304192
- UDP port:
-
-
-
-
-
-
-
-
- 268
- {{92, 55}, {119, 22}}
-
- YES
-
- -1804468671
- 272630784
- localhost
-
-
- YES
-
- 6
- System
- textBackgroundColor
-
- 3
- MQA
-
-
-
- 6
- System
- textColor
-
-
-
-
-
-
- 268
- {{92, 23}, {119, 22}}
-
- YES
-
- -1804468671
- 272630784
- 3333
-
-
- YES
-
-
-
-
-
- {{1, 1}, {233, 98}}
-
-
-
- {{17, 16}, {235, 114}}
-
- {0, 0}
-
- 67239424
- 0
- Configuration
-
- LucidaGrande
- 1.100000e+01
- 3100
-
-
-
- 3
- MCAwLjgwMDAwMDAxAA
-
-
-
- 1
- 0
- 2
- NO
-
-
-
- 268
- {{14, 142}, {90, 32}}
-
- YES
-
- 67239424
- 134217728
- Start
-
-
- -2038284033
- 129
-
-
- 200
- 25
-
-
-
-
- 268
- {{109, 152}, {143, 17}}
-
- YES
-
- 68288064
- 4195328
- Tongseng is stopped
-
-
-
-
-
-
-
- {269, 190}
-
-
- {{0, 0}, {1280, 778}}
- {3.40282e+38, 3.40282e+38}
-
-
- NSFontManager
-
-
- TongsengController
-
-
-
-
- YES
-
-
- hide:
-
-
-
- 367
-
-
-
- hideOtherApplications:
-
-
-
- 368
-
-
-
- unhideAllApplications:
-
-
-
- 370
-
-
-
- terminate:
-
-
-
- 449
-
-
-
- startstop:
-
-
-
- 464
-
-
-
- _hostname
-
-
-
- 465
-
-
-
- _port
-
-
-
- 466
-
-
-
- _button
-
-
-
- 467
-
-
-
- _info
-
-
-
- 472
-
-
-
- delegate
-
-
-
- 481
-
-
-
- orderFrontStandardAboutPanel:
-
-
-
- 501
-
-
-
-
- YES
-
- 0
-
- YES
-
-
-
-
-
- -2
-
-
- RmlsZSdzIE93bmVyA
-
-
- -1
-
-
- First Responder
-
-
- -3
-
-
- Application
-
-
- 29
-
-
- YES
-
-
-
- MainMenu
-
-
- 56
-
-
- YES
-
-
-
-
-
- 57
-
-
- YES
-
-
-
-
-
-
-
-
-
-
-
- 134
-
-
-
-
- 150
-
-
-
-
- 136
-
-
- 1111
-
-
- 149
-
-
-
-
- 145
-
-
-
-
- 371
-
-
- YES
-
-
-
- Window (Window)
-
-
- 372
-
-
- YES
-
-
-
-
-
-
-
- 420
-
-
-
-
- 458
-
-
- YES
-
-
-
-
-
- 459
-
-
-
-
- 463
-
-
-
-
- 469
-
-
- YES
-
-
-
-
-
- 470
-
-
-
-
- 486
-
-
- YES
-
-
-
-
-
-
-
-
- 450
-
-
- YES
-
-
-
-
-
- 451
-
-
-
-
- 452
-
-
- YES
-
-
-
-
-
- 453
-
-
-
-
- 454
-
-
- YES
-
-
-
-
-
- 455
-
-
-
-
- 456
-
-
- YES
-
-
-
-
-
- 457
-
-
-
-
- 498
-
-
-
-
- 499
-
-
-
-
-
-
- YES
-
- YES
- -1.IBPluginDependency
- -2.IBPluginDependency
- -3.IBPluginDependency
- 134.IBPluginDependency
- 134.ImportedFromIB2
- 136.IBPluginDependency
- 136.ImportedFromIB2
- 145.IBPluginDependency
- 145.ImportedFromIB2
- 149.IBPluginDependency
- 149.ImportedFromIB2
- 150.IBPluginDependency
- 150.ImportedFromIB2
- 29.IBEditorWindowLastContentRect
- 29.IBPluginDependency
- 29.ImportedFromIB2
- 29.WindowOrigin
- 29.editorWindowContentRectSynchronizationRect
- 371.IBEditorWindowLastContentRect
- 371.IBWindowTemplateEditedContentRect
- 371.NSWindowTemplate.visibleAtLaunch
- 371.editorWindowContentRectSynchronizationRect
- 371.windowTemplate.maxSize
- 372.IBPluginDependency
- 420.IBPluginDependency
- 450.IBPluginDependency
- 451.IBPluginDependency
- 452.IBPluginDependency
- 453.IBPluginDependency
- 454.IBPluginDependency
- 455.IBPluginDependency
- 456.IBPluginDependency
- 457.IBPluginDependency
- 458.IBPluginDependency
- 459.IBPluginDependency
- 463.IBPluginDependency
- 469.IBPluginDependency
- 470.IBPluginDependency
- 486.IBPluginDependency
- 498.IBPluginDependency
- 499.IBPluginDependency
- 56.IBPluginDependency
- 56.ImportedFromIB2
- 57.IBEditorWindowLastContentRect
- 57.IBPluginDependency
- 57.ImportedFromIB2
- 57.editorWindowContentRectSynchronizationRect
-
-
- YES
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilderKit
- com.apple.InterfaceBuilderKit
- com.apple.InterfaceBuilder.CocoaPlugin
-
- com.apple.InterfaceBuilder.CocoaPlugin
-
- com.apple.InterfaceBuilder.CocoaPlugin
-
- com.apple.InterfaceBuilder.CocoaPlugin
-
- com.apple.InterfaceBuilder.CocoaPlugin
-
- {{88, 622}, {114, 20}}
- com.apple.InterfaceBuilder.CocoaPlugin
-
- {74, 862}
- {{6, 978}, {478, 20}}
- {{355, 419}, {269, 190}}
- {{355, 419}, {269, 190}}
-
- {{33, 99}, {480, 360}}
- {3.40282e+38, 3.40282e+38}
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
-
- {{100, 499}, {206, 123}}
- com.apple.InterfaceBuilder.CocoaPlugin
-
- {{23, 794}, {245, 183}}
-
-
-
- YES
-
- YES
-
-
- YES
-
-
-
-
- YES
-
- YES
-
-
- YES
-
-
-
- 501
-
-
-
- YES
-
- NSObject
-
- startstop:
- id
-
-
- IBUserSource
-
-
-
-
- TongsengController
- NSObject
-
- YES
-
- YES
- start:
- startstop:
- stop:
-
-
- YES
- id
- id
- id
-
-
-
- YES
-
- YES
- _button
- _hostname
- _info
- _port
-
-
- YES
- NSButton
- NSTextField
- NSTextField
- NSTextField
-
-
-
- IBProjectSource
- TongsengController.h
-
-
-
- TongsengController
- NSObject
-
- IBUserSource
-
-
-
-
-
- 0
- ../TongsengApp.xcodeproj
- 3
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/TongsengApp/Info.plist b/TongsengApp/Info.plist
index ce57a49..f5fa2ee 100644
--- a/TongsengApp/Info.plist
+++ b/TongsengApp/Info.plist
@@ -7,7 +7,7 @@
CFBundleExecutable${EXECUTABLE_NAME}CFBundleIconFile
-
+ TUIOCFBundleIdentifierid.web.fajran.${PRODUCT_NAME:identifier}CFBundleInfoDictionaryVersion
@@ -19,7 +19,7 @@
CFBundleSignature????CFBundleVersion
- 0.4
+ 0.5NSMainNibFileMainMenuNSPrincipalClass
diff --git a/TongsengApp/TUIO.icns b/TongsengApp/TUIO.icns
new file mode 100644
index 0000000..b1a9064
Binary files /dev/null and b/TongsengApp/TUIO.icns differ
diff --git a/TongsengApp/TongsengApp.xcodeproj/TemplateIcon.icns b/TongsengApp/TongsengApp.xcodeproj/TemplateIcon.icns
deleted file mode 100644
index 62cb701..0000000
Binary files a/TongsengApp/TongsengApp.xcodeproj/TemplateIcon.icns and /dev/null differ
diff --git a/TongsengApp/TongsengApp.xcodeproj/project.pbxproj b/TongsengApp/TongsengApp.xcodeproj/project.pbxproj
index d650e70..69d7c33 100644
--- a/TongsengApp/TongsengApp.xcodeproj/project.pbxproj
+++ b/TongsengApp/TongsengApp.xcodeproj/project.pbxproj
@@ -3,16 +3,14 @@
archiveVersion = 1;
classes = {
};
- objectVersion = 45;
+ objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD58140DA1D0A300B32029 /* MainMenu.xib */; };
- 3F45D5AA10A0FEEB00139241 /* TuioBlob.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F45D5A410A0FEEB00139241 /* TuioBlob.cpp */; };
3F45D5AB10A0FEEB00139241 /* TuioContainer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F45D5A510A0FEEB00139241 /* TuioContainer.cpp */; };
3F45D5AC10A0FEEB00139241 /* TuioCursor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F45D5A610A0FEEB00139241 /* TuioCursor.cpp */; };
3F45D5AD10A0FEEB00139241 /* TuioDispatcher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F45D5A710A0FEEB00139241 /* TuioDispatcher.cpp */; };
- 3F45D5AE10A0FEEB00139241 /* TuioObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F45D5A810A0FEEB00139241 /* TuioObject.cpp */; };
3F45D5AF10A0FEEB00139241 /* TuioPoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F45D5A910A0FEEB00139241 /* TuioPoint.cpp */; };
3F6CB36A10374F0C00CFF31E /* tongseng.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F6CB36810374F0C00CFF31E /* tongseng.cpp */; };
3F6CB3C010374FB900CFF31E /* NetworkingUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F6CB39010374FB900CFF31E /* NetworkingUtils.cpp */; };
@@ -25,29 +23,26 @@
3F6CB43A10375A6000CFF31E /* TongsengController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F6CB43810375A6000CFF31E /* TongsengController.m */; };
3FAF0802103963CD006DF045 /* TuioManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FAF0800103963CD006DF045 /* TuioManager.cpp */; };
3FAF0803103963CD006DF045 /* UdpSender.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FAF0801103963CD006DF045 /* UdpSender.cpp */; };
- 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
+ B26C5F031D12EDF500354F09 /* OneEuroFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B26C5F021D12EDF500354F09 /* OneEuroFilter.cpp */; };
+ B26C5F051D12EF5300354F09 /* TuioObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B26C5F041D12EF5300354F09 /* TuioObject.cpp */; };
+ B26C5F071D12EF5A00354F09 /* TuioBlob.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B26C5F061D12EF5A00354F09 /* TuioBlob.cpp */; };
+ B26C5F091D12F2E000354F09 /* TUIO.icns in Resources */ = {isa = PBXBuildFile; fileRef = B26C5F081D12F2E000354F09 /* TUIO.icns */; };
+ B2A01DF71D1C1D5900EF381B /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2A01DF61D1C1D5900EF381B /* CoreFoundation.framework */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
- 089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = ""; };
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = ""; };
- 13E42FB307B3F0F600E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = ""; };
1DDD58150DA1D0A300B32029 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = ""; };
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
- 29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = ""; };
- 29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; };
- 32CA4F630368D1EE00C91783 /* TongsengApp_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TongsengApp_Prefix.pch; sourceTree = ""; };
- 3F45D5A410A0FEEB00139241 /* TuioBlob.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TuioBlob.cpp; sourceTree = ""; };
3F45D5A510A0FEEB00139241 /* TuioContainer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TuioContainer.cpp; sourceTree = ""; };
3F45D5A610A0FEEB00139241 /* TuioCursor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TuioCursor.cpp; sourceTree = ""; };
3F45D5A710A0FEEB00139241 /* TuioDispatcher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TuioDispatcher.cpp; sourceTree = ""; };
- 3F45D5A810A0FEEB00139241 /* TuioObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TuioObject.cpp; sourceTree = ""; };
3F45D5A910A0FEEB00139241 /* TuioPoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TuioPoint.cpp; sourceTree = ""; };
- 3F6CB36810374F0C00CFF31E /* tongseng.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = tongseng.cpp; path = ../tongseng.cpp; sourceTree = SOURCE_ROOT; };
+ 3F6CB36810374F0C00CFF31E /* tongseng.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp.preprocessed; fileEncoding = 4; name = tongseng.cpp; path = ../tongseng.cpp; sourceTree = SOURCE_ROOT; };
3F6CB36910374F0C00CFF31E /* tongseng.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = tongseng.h; path = ../tongseng.h; sourceTree = SOURCE_ROOT; };
- 3F6CB36B10374F1600CFF31E /* mt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = mt.h; path = ../mt.h; sourceTree = SOURCE_ROOT; };
+ 3F6CB36B10374F1600CFF31E /* multitouch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = multitouch.h; path = ../multitouch.h; sourceTree = SOURCE_ROOT; };
3F6CB39010374FB900CFF31E /* NetworkingUtils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkingUtils.cpp; sourceTree = ""; };
3F6CB39210374FB900CFF31E /* UdpSocket.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UdpSocket.cpp; sourceTree = ""; };
3F6CB39E10374FB900CFF31E /* OscOutboundPacketStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OscOutboundPacketStream.cpp; sourceTree = ""; };
@@ -61,6 +56,11 @@
3FAF0801103963CD006DF045 /* UdpSender.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UdpSender.cpp; sourceTree = ""; };
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
8D1107320486CEB800E47090 /* Tongseng.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Tongseng.app; sourceTree = BUILT_PRODUCTS_DIR; };
+ B26C5F021D12EDF500354F09 /* OneEuroFilter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OneEuroFilter.cpp; sourceTree = ""; };
+ B26C5F041D12EF5300354F09 /* TuioObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TuioObject.cpp; sourceTree = ""; };
+ B26C5F061D12EF5A00354F09 /* TuioBlob.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TuioBlob.cpp; sourceTree = ""; };
+ B26C5F081D12F2E000354F09 /* TUIO.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = TUIO.icns; sourceTree = ""; };
+ B2A01DF61D1C1D5900EF381B /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = /System/Library/Frameworks/CoreFoundation.framework; sourceTree = ""; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -70,6 +70,7 @@
files = (
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */,
3F6CB41F103754BC00CFF31E /* MultitouchSupport.framework in Frameworks */,
+ B2A01DF71D1C1D5900EF381B /* CoreFoundation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -88,22 +89,13 @@
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = {
isa = PBXGroup;
children = (
+ B2A01DF61D1C1D5900EF381B /* CoreFoundation.framework */,
+ 3F6CB41E103754BC00CFF31E /* MultitouchSupport.framework */,
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
);
name = "Linked Frameworks";
sourceTree = "";
};
- 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */ = {
- isa = PBXGroup;
- children = (
- 3F6CB41E103754BC00CFF31E /* MultitouchSupport.framework */,
- 29B97324FDCFA39411CA2CEA /* AppKit.framework */,
- 13E42FB307B3F0F600E4EEF1 /* CoreData.framework */,
- 29B97325FDCFA39411CA2CEA /* Foundation.framework */,
- );
- name = "Other Frameworks";
- sourceTree = "";
- };
19C28FACFE9D520D11CA2CBB /* Products */ = {
isa = PBXGroup;
children = (
@@ -129,10 +121,9 @@
children = (
3F6CB3F31037541700CFF31E /* TUIO */,
3F6CB38710374FB900CFF31E /* oscpack */,
- 3F6CB36B10374F1600CFF31E /* mt.h */,
+ 3F6CB36B10374F1600CFF31E /* multitouch.h */,
3F6CB36810374F0C00CFF31E /* tongseng.cpp */,
3F6CB36910374F0C00CFF31E /* tongseng.h */,
- 32CA4F630368D1EE00C91783 /* TongsengApp_Prefix.pch */,
29B97316FDCFA39411CA2CEA /* main.m */,
);
name = "Other Sources";
@@ -141,8 +132,8 @@
29B97317FDCFA39411CA2CEA /* Resources */ = {
isa = PBXGroup;
children = (
+ B26C5F081D12F2E000354F09 /* TUIO.icns */,
8D1107310486CEB800E47090 /* Info.plist */,
- 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */,
1DDD58140DA1D0A300B32029 /* MainMenu.xib */,
);
name = Resources;
@@ -152,7 +143,6 @@
isa = PBXGroup;
children = (
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */,
- 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */,
);
name = Frameworks;
sourceTree = "";
@@ -196,11 +186,12 @@
3F6CB3F31037541700CFF31E /* TUIO */ = {
isa = PBXGroup;
children = (
- 3F45D5A410A0FEEB00139241 /* TuioBlob.cpp */,
+ B26C5F061D12EF5A00354F09 /* TuioBlob.cpp */,
+ B26C5F041D12EF5300354F09 /* TuioObject.cpp */,
+ B26C5F021D12EDF500354F09 /* OneEuroFilter.cpp */,
3F45D5A510A0FEEB00139241 /* TuioContainer.cpp */,
3F45D5A610A0FEEB00139241 /* TuioCursor.cpp */,
3F45D5A710A0FEEB00139241 /* TuioDispatcher.cpp */,
- 3F45D5A810A0FEEB00139241 /* TuioObject.cpp */,
3F45D5A910A0FEEB00139241 /* TuioPoint.cpp */,
3FAF0800103963CD006DF045 /* TuioManager.cpp */,
3FAF0801103963CD006DF045 /* UdpSender.cpp */,
@@ -237,9 +228,16 @@
/* Begin PBXProject section */
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
+ attributes = {
+ LastUpgradeCheck = 0730;
+ };
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "TongsengApp" */;
- compatibilityVersion = "Xcode 3.1";
+ compatibilityVersion = "Xcode 3.2";
+ developmentRegion = English;
hasScannedForEncodings = 1;
+ knownRegions = (
+ en,
+ );
mainGroup = 29B97314FDCFA39411CA2CEA /* TongsengApp */;
projectDirPath = "";
projectRoot = "";
@@ -254,7 +252,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */,
+ B26C5F091D12F2E000354F09 /* TUIO.icns in Resources */,
1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -271,32 +269,25 @@
3F6CB3C010374FB900CFF31E /* NetworkingUtils.cpp in Sources */,
3F6CB3C210374FB900CFF31E /* UdpSocket.cpp in Sources */,
3F6CB3C710374FB900CFF31E /* OscOutboundPacketStream.cpp in Sources */,
+ B26C5F031D12EDF500354F09 /* OneEuroFilter.cpp in Sources */,
3F6CB3CD10374FB900CFF31E /* OscTypes.cpp in Sources */,
3F6CB4061037541700CFF31E /* TuioServer.cpp in Sources */,
3F6CB4081037541700CFF31E /* TuioTime.cpp in Sources */,
3F6CB43A10375A6000CFF31E /* TongsengController.m in Sources */,
3FAF0802103963CD006DF045 /* TuioManager.cpp in Sources */,
3FAF0803103963CD006DF045 /* UdpSender.cpp in Sources */,
- 3F45D5AA10A0FEEB00139241 /* TuioBlob.cpp in Sources */,
+ B26C5F051D12EF5300354F09 /* TuioObject.cpp in Sources */,
3F45D5AB10A0FEEB00139241 /* TuioContainer.cpp in Sources */,
3F45D5AC10A0FEEB00139241 /* TuioCursor.cpp in Sources */,
3F45D5AD10A0FEEB00139241 /* TuioDispatcher.cpp in Sources */,
- 3F45D5AE10A0FEEB00139241 /* TuioObject.cpp in Sources */,
3F45D5AF10A0FEEB00139241 /* TuioPoint.cpp in Sources */,
+ B26C5F071D12EF5A00354F09 /* TuioBlob.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXVariantGroup section */
- 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */ = {
- isa = PBXVariantGroup;
- children = (
- 089C165DFE840E0CC02AAC07 /* English */,
- );
- name = InfoPlist.strings;
- sourceTree = "";
- };
1DDD58140DA1D0A300B32029 /* MainMenu.xib */ = {
isa = PBXVariantGroup;
children = (
@@ -321,8 +312,7 @@
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
- GCC_PRECOMPILE_PREFIX_HEADER = YES;
- GCC_PREFIX_HEADER = TongsengApp_Prefix.pch;
+ GCC_PRECOMPILE_PREFIX_HEADER = NO;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Applications";
PRODUCT_NAME = Tongseng;
@@ -339,8 +329,7 @@
"\"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks\"",
);
GCC_MODEL_TUNING = G5;
- GCC_PRECOMPILE_PREFIX_HEADER = YES;
- GCC_PREFIX_HEADER = TongsengApp_Prefix.pch;
+ GCC_PRECOMPILE_PREFIX_HEADER = NO;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Applications";
PRODUCT_NAME = Tongseng;
@@ -350,40 +339,37 @@
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
- ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
- GCC_C_LANGUAGE_STANDARD = c99;
+ ARCHS = "$(NATIVE_ARCH_ACTUAL)";
+ GCC_C_LANGUAGE_STANDARD = "compiler-default";
GCC_OPTIMIZATION_LEVEL = 0;
- GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = NO;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
../oscpack,
../TUIO,
);
- ONLY_ACTIVE_ARCH = NO;
- PREBINDING = NO;
- SDKROOT = "";
- VALID_ARCHS = i386;
+ MACOSX_DEPLOYMENT_TARGET = 10.6;
+ ONLY_ACTIVE_ARCH = YES;
+ SDKROOT = macosx;
+ VALID_ARCHS = "i386 x86_64";
};
name = Debug;
};
C01FCF5008A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
- ARCHS = (
- i386,
- x86_64,
- );
- GCC_C_LANGUAGE_STANDARD = c99;
- GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
+ GCC_C_LANGUAGE_STANDARD = "compiler-default";
+ GCC_WARN_ABOUT_RETURN_TYPE = NO;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
../oscpack,
../TUIO,
);
+ MACOSX_DEPLOYMENT_TARGET = 10.6;
ONLY_ACTIVE_ARCH = NO;
- PREBINDING = NO;
- SDKROOT = macosx10.5;
- VALID_ARCHS = "x86_64 i386";
+ SDKROOT = macosx;
+ VALID_ARCHS = "i386 x86_64";
};
name = Release;
};
diff --git a/TongsengApp/TongsengApp_Prefix.pch b/TongsengApp/TongsengApp_Prefix.pch
deleted file mode 100644
index 8988ad2..0000000
--- a/TongsengApp/TongsengApp_Prefix.pch
+++ /dev/null
@@ -1,7 +0,0 @@
-//
-// Prefix header for all source files of the 'TongsengApp' target in the 'TongsengApp' project
-//
-
-#ifdef __OBJC__
- #import
-#endif
diff --git a/TongsengApp/TongsengController.h b/TongsengApp/TongsengController.h
index f818a2b..0a599b6 100644
--- a/TongsengApp/TongsengController.h
+++ b/TongsengApp/TongsengController.h
@@ -4,6 +4,7 @@
IBOutlet NSTextField *_hostname;
IBOutlet NSTextField *_port;
IBOutlet NSTextField *_info;
+ IBOutlet NSPopUpButton *_device;
IBOutlet NSButton *_button;
bool _running;
}
diff --git a/TongsengApp/TongsengController.m b/TongsengApp/TongsengController.m
index 68806a0..9ef9f0b 100644
--- a/TongsengApp/TongsengController.m
+++ b/TongsengApp/TongsengController.m
@@ -1,4 +1,5 @@
#import "TongsengController.h"
+#import "multitouch.h"
#import "tongseng.h"
#import
@@ -10,6 +11,26 @@ - (id) init {
return self;
}
+- (void)awakeFromNib
+{
+
+ CFArrayRef devList = MTDeviceCreateList();
+ CFIndex dev_count = (CFIndex)CFArrayGetCount(devList);
+
+ if(dev_count > 1) {
+ for (int i=1;i<=dev_count;i++)
+ [_device addItemWithTitle:@"External"];
+ } else if(dev_count == 0) {
+ [_device removeAllItems];
+ [_device addItemWithTitle:@"None"];
+ [_button setEnabled:false];
+ [_hostname setEnabled:false];
+ [_port setEnabled:false];
+ [_device setEnabled:false];
+ [_info setStringValue:@"Tongseng is disabled"];
+ }
+}
+
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)app
{
[self stop:app];
@@ -25,12 +46,15 @@ - (IBAction)start:(id)sender {
const char *hostname = [[_hostname stringValue] UTF8String];
const char *strPort = [[_port stringValue] UTF8String];
const int port = atoi(strPort);
-
+ const int device = [_device indexOfSelectedItem];
+
tongseng_set_hostname_and_port(hostname, port);
+ tongseng_set_device(device);
tongseng_start();
[_hostname setEnabled:false];
[_port setEnabled:false];
+ [_device setEnabled:false];
[_info setStringValue:@"Tongseng is running"];
[_button setTitle:@"Stop"];
@@ -42,6 +66,7 @@ - (IBAction)stop:(id)sender {
[_hostname setEnabled:true];
[_port setEnabled:true];
+ [_device setEnabled:true];
[_info setStringValue:@"Tongseng is stopped"];
[_button setTitle:@"Start"];
diff --git a/main.cpp b/main.cpp
index 0022303..4317dbb 100644
--- a/main.cpp
+++ b/main.cpp
@@ -7,12 +7,14 @@ static bool running = false;
static bool verbose = false;
static std::string host("localhost");
static int port = 3333;
+static int device = 0;
static void show_help()
{
- std::cout << "Usage: tongseng [options] [host] [port]" << std::endl;
- std::cout << " -v verbose" << std::endl;
- std::cout << " -h show help" << std::endl;
+ std::cout << "Usage: tongseng -n [host] -p [port] -d [device]" << std::endl;
+ std::cout << " -l list devices" << std::endl;
+ std::cout << " -v verbose output" << std::endl;
+ std::cout << " -h show this help" << std::endl;
}
static void stop(int param)
@@ -22,40 +24,42 @@ static void stop(int param)
static void init(int argc, char** argv)
{
- int aflag = 0;
- int bflag = 0;
- char *cvalue = NULL;
- int index;
- int c;
+ char c;
- opterr = 0;
-
- while ((c = getopt(argc, argv, "v")) != -1) {
+ while ((c = getopt(argc, argv, "n:p:d:lvh")) != -1) {
switch (c) {
+ case 'n':
+ host = std::string(optarg);
+ break;
+ case 'p':
+ port = atoi(optarg);
+ break;
+ case 'd':
+ device = atoi(optarg);
+ break;
case 'v':
verbose = true;
break;
+ case 'l':
+ tongseng_list_devices();
+ exit(0);
case 'h':
show_help();
exit(0);
+ /*case '?':
+ if (optopt == 'n')
+ fprintf (stderr, "Option -n requires a host name.\n");
+ if (optopt == 'p')
+ fprintf (stderr, "Option -p requires a port number.\n");
+ if (optopt == 'd')
+ fprintf (stderr, "Option -d requires a device number.\n");
+ else if (isprint (optopt)) fprintf (stderr, "Unknown option '-%c'.\n", optopt);
+ else fprintf (stderr, "Unknown option character '\\x%x'.\n", optopt);*/
default:
show_help();
exit(1);
}
}
-
- for (index=optind, c=0; index < argc; index++, c++) {
- switch (c) {
- case 0:
- host = argv[index];
- break;
- case 1:
- port = atoi(argv[index]);
- break;
- default:
- break;
- }
- }
}
int main(int argc, char** argv)
@@ -63,6 +67,7 @@ int main(int argc, char** argv)
init(argc, argv);
std::cout << "Host: " << host << std::endl;
std::cout << "Port: " << port << std::endl;
+ std::cout << "Device: " << device << std::endl;
std::cout << "Verbose: " << verbose << std::endl;
std::cout << "Press Ctrl+C to end this program." << std::endl;
@@ -73,8 +78,10 @@ int main(int argc, char** argv)
tongseng_set_hostname_and_port(host.c_str(), port);
tongseng_set_verbose(verbose);
+ tongseng_set_device(device);
tongseng_start();
+
// Loop until the program is stopped.
running = true;
while (running) {
diff --git a/mt.h b/mt.h
deleted file mode 100644
index 7a5437d..0000000
--- a/mt.h
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright (C) 2009 Fajran Iman Rusadi
-
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-// Based on multitouch code from http://www.steike.com/code/multitouch/
-
-#ifndef MT_H_
-#define MT_H_
-
-#include
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct { float x,y; } mtPoint;
-typedef struct { mtPoint pos,vel; } mtReadout;
-
-typedef struct {
- int frame;
- double timestamp;
- int identifier, state, foo3, foo4;
- mtReadout normalized;
- float size;
- int zero1;
- float angle, majorAxis, minorAxis; // ellipsoid
- mtReadout mm;
- int zero2[2];
- float unk2;
-} Finger;
-
-typedef void* MTDeviceRef;
-typedef int (*MTContactCallbackFunction)(int,Finger*,int,double,int);
-
-MTDeviceRef MTDeviceCreateDefault();
-void MTRegisterContactFrameCallback(MTDeviceRef, MTContactCallbackFunction);
-void MTUnregisterContactFrameCallback(MTDeviceRef, MTContactCallbackFunction);
-void MTDeviceStart(MTDeviceRef, int);
-void MTDeviceStop(MTDeviceRef);
-void MTDeviceRelease(MTDeviceRef);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/multitouch.h b/multitouch.h
new file mode 100644
index 0000000..af325b9
--- /dev/null
+++ b/multitouch.h
@@ -0,0 +1,145 @@
+// Copyright (C) 2009 Fajran Iman Rusadi
+
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+#ifndef MULTITOUCH_H
+#define MULTITOUCH_H
+
+#ifdef __OBJC__
+#include
+#endif
+#include
+#include
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ typedef struct {
+ float x;
+ float y;
+ } MTPoint;
+
+ typedef struct {
+ MTPoint position;
+ MTPoint velocity;
+ } MTVector;
+
+ enum {
+ MTTouchStateNotTracking = 0,
+ MTTouchStateStartInRange = 1,
+ MTTouchStateHoverInRange = 2,
+ MTTouchStateMakeTouch = 3,
+ MTTouchStateTouching = 4,
+ MTTouchStateBreakTouch = 5,
+ MTTouchStateLingerInRange = 6,
+ MTTouchStateOutOfRange = 7
+ };
+ typedef uint32_t MTTouchState;
+
+ typedef struct {
+ int32_t frame;
+ double timestamp;
+ int32_t pathIndex; // "P" (~transducerIndex)
+ MTTouchState state;
+ int32_t fingerID; // "F" (~identity)
+ int32_t handID; // "H" (always 1)
+ MTVector normalizedVector;
+ float zTotal; // "ZTot" (~quality, multiple of 1/8 between 0 and 1)
+ int32_t field9; // always 0
+ float angle;
+ float majorAxis;
+ float minorAxis;
+ MTVector absoluteVector; // "mm"
+ int32_t field14; // always 0
+ int32_t field15; // always 0
+ float zDensity; // "ZDen" (~density)
+ } MTTouch;
+
+ typedef void* MTDeviceRef;
+
+ double MTAbsoluteTimeGetCurrent();
+ bool MTDeviceIsAvailable(); // true if can create default device
+
+ CFArrayRef MTDeviceCreateList(); // creates for driver types 0, 1, 4, 2, 3
+ MTDeviceRef MTDeviceCreateDefault();
+ MTDeviceRef MTDeviceCreateFromDeviceID(int64_t);
+ MTDeviceRef MTDeviceCreateFromService(io_service_t);
+ MTDeviceRef MTDeviceCreateFromGUID(uuid_t); // GUID's compared by pointer, not value!
+ void MTDeviceRelease(MTDeviceRef);
+
+ CFRunLoopSourceRef MTDeviceCreateMultitouchRunLoopSource(MTDeviceRef);
+ OSStatus MTDeviceScheduleOnRunLoop(MTDeviceRef, CFRunLoopRef, CFStringRef);
+
+ OSStatus MTDeviceStart(MTDeviceRef, int);
+ OSStatus MTDeviceStop(MTDeviceRef);
+ bool MTDeviceIsRunning(MTDeviceRef);
+
+ bool MTDeviceIsValid(MTDeviceRef);
+ bool MTDeviceIsBuiltIn(MTDeviceRef) __attribute__ ((weak_import)); // no 10.5
+ bool MTDeviceIsOpaqueSurface(MTDeviceRef);
+ io_service_t MTDeviceGetService(MTDeviceRef);
+ OSStatus MTDeviceGetSensorSurfaceDimensions(MTDeviceRef, int*, int*);
+ OSStatus MTDeviceGetFamilyID(MTDeviceRef, int*);
+ OSStatus MTDeviceGetDeviceID(MTDeviceRef, uint64_t*) __attribute__ ((weak_import)); // no 10.5
+ OSStatus MTDeviceGetDriverType(MTDeviceRef, int*);
+ OSStatus MTDeviceGetActualType(MTDeviceRef, int*);
+ OSStatus MTDeviceGetGUID(MTDeviceRef, uuid_t*);
+
+ typedef void (*MTFrameCallbackFunction)(MTDeviceRef device,
+ MTTouch touches[], size_t numTouches,
+ double timestamp, size_t frame);
+ void MTRegisterContactFrameCallback(MTDeviceRef, MTFrameCallbackFunction);
+ void MTUnregisterContactFrameCallback(MTDeviceRef, MTFrameCallbackFunction);
+
+ typedef void (*MTPathCallbackFunction)(MTDeviceRef device, long pathID, long state, MTTouch* touch);
+ MTPathCallbackFunction MTPathPrintCallback;
+ void MTRegisterPathCallback(MTDeviceRef, MTPathCallbackFunction);
+ void MTUnregisterPathCallback(MTDeviceRef, MTPathCallbackFunction);
+
+ /*
+ // callbacks never called (need different flags?)
+ typedef void (*MTImageCallbackFunction)(MTDeviceRef, void*, void*);
+ MTImageCallbackFunction MTImagePrintCallback;
+ void MTRegisterMultitouchImageCallback(MTDeviceRef, MTImageCallbackFunction);
+ */
+
+ /*
+ // these log error
+ void MTVibratorRunForDuration(MTDeviceRef,long);
+ void MTVibratorStop(MTDeviceRef);
+ */
+
+ inline const char*
+ MTTouchStateName(MTTouchState ps) {
+ switch (ps) {
+ case MTTouchStateNotTracking: return "NotTracking" ;
+ case MTTouchStateStartInRange: return "StartInRange" ;
+ case MTTouchStateHoverInRange: return "HoverInRange" ;
+ case MTTouchStateMakeTouch: return "MakeTouch" ;
+ case MTTouchStateTouching: return "Touching" ;
+ case MTTouchStateBreakTouch: return "BreakTouch" ;
+ case MTTouchStateLingerInRange: return "LingerInRange" ;
+ case MTTouchStateOutOfRange: return "OutOfRange" ;
+ default: return "Unknown" ;
+ }
+ }
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/oscpack/changes b/oscpack/changes
index 804df95..046c6b6 100644
--- a/oscpack/changes
+++ b/oscpack/changes
@@ -1,3 +1,94 @@
+April 9, 2013
+-------------
+
+Changes for the 1.1.0 release (vs 1.0.2) are listed below. Unless
+otherwise indicated these changes have been made since
+January 2013. The focus has been on general clean-up, fixing bugs,
+compiler errors and warnings, and fixing issues on 64 bit platforms.
+A few improvements such as support for OSC arrays, functions
+for setting broadcast and reuse socket options have been added.
+This update merges changes from the openFrameworks version
+of oscpack.
+
+ - Added support for arrays in messages (see OscUnitTests.cpp
+ for example usage). (patch thanks to Tim Blechmann)
+
+ - Fixed bugs relating to 64 bit usage (e.g. crashes in 64 bit
+ builds on OS X).
+
+ - Some member functions that previously used the "int" or
+ "unsigned long" type for parameters or return values now use
+ std::size_t (platform-defined) or
+ osc_bundle_element_size_t (a.k.a. int32).
+ This change was made to better support 64 bit platforms.
+ See SVN revision 70 for details.
+
+ - The previous point introduces a breaking change on Linux/x86_64
+ for callers of AsBlob() and AsBlobUnchecked():
+ The type of the second argument (the "size" argument) to
+ ReceivedMessageArgument::AsBlob() and
+ ReceivedMessageArgument::AsBlobUnchecked() has changed
+ from unsigned long & to osc_bundle_element_size_t (an int32).
+ You should declare your size argument variables as
+ osc_bundle_element_size_t to avoid incompatibilities between
+ 32 and 64 bit builds.
+
+ - Note that oscpack does not support packets larger than
+ 0x7FFFFFFC (see comments in class ReceivedPacket for
+ details).
+
+ - Oscpack defines an osc::Nil value used for sending the nil
+ message argument value. This conflicts with Objective-C.
+ Therefore osc::Nil is no longer defined in Obj-C++ code.
+ There is now an osc::OscNil value, which should be preferred.
+ osc::Nil is still available when writing C++.
+ (fix thanks to openFrameworks)
+
+ - Added UdpSocket::SetEnableBroadcast(). This needs to
+ be called to enable sending to the broadcast address on some
+ platforms (e.g. Mac OS X). (thanks to openFrameworks)
+
+ - Added UdpSocket::SetAllowReuse(). This is useful for
+ sharing sockets on some platforms (Mac?), and not so useful
+ on other platforms. (thanks to openFrameworks)
+
+ - Added IpEndpointName::IsMulticastAddress() (2010)
+
+ - Cleaned up C++ header usage and std:: namespace usage
+ to be more standards compliant (fixes issues on recent compilers
+ such as clang and gcc4.6).
+
+ - Improved host endianness detection. Should auto-detect
+ endianness on most platforms now.
+ (thanks to Tim Blechmann for help with this)
+
+ - Fixed two memory leaks: (1) in OscPrintReceivedElements.cpp
+ when printing time tag message arguments (thanks to Gwydion ap Dafydd).
+ (2) in the posix SocketReceiveMultiplexer::Run() method if an exception
+ was thrown while listening.
+
+ - Fixed bug in posix SocketReceiveMultiplexer::Run() that would cause
+ packets to stop being received if select() returned EINTR.
+ (thanks to Björn Wöldecke)
+
+ - Updated and improved Makefile to avoid redundant re-linking
+ (thanks to Douglas Mandell)
+
+ - Added CMakeLists.txt CMake build file (2010, thanks to David Doria)
+
+ - Switched license to plain MIT license with non binding request
+ for contribution of improvements (same as current PortAudio
+ boilerplate). See LICENSE file.
+
+Thanks to Tim Blechmann, Rob Canning, Gwydion ap Dafydd, David Doria,
+Christopher Delaney, Jon McCormack, Douglas Mandell, Björn Wöldecke,
+all the guys at openFrameworks, and everyone who reported bugs,
+submitted patches and helped out with testing this release.
+
+Thanks to Syneme at the University of Calgary for providing financial
+support for the 1.1.0 update.
+
+
September 28, 2005
------------------
@@ -11,14 +102,14 @@ spawn your own threads in a more complex application.
The list below summarises the changes if you are porting code from
the previous release.
- - there are no longer any threads in oscpack. if you need to
+ - There are no longer any threads in oscpack. if you need to
set up an asynchronous listener you can create your own thread
and call Run on an instance of SocketReceiveMultiplexer or
UdpListeningReceiveSocket (see ip/UdpSocket.h) yourself.
- - host byte order is now used for network (IP) addresses
+ - Host byte order is now used for network (IP) addresses
- - functions which used to take two parameters
+ - Functions which used to take two parameters
now take an instance of IpEndpointName (see
ip/IpEndpointName.h) this class has a number of convenient
constructors for converting numbers and strings to internet
diff --git a/oscpack/ip/IpEndpointName.cpp b/oscpack/ip/IpEndpointName.cpp
index 33fdd98..556da3a 100644
--- a/oscpack/ip/IpEndpointName.cpp
+++ b/oscpack/ip/IpEndpointName.cpp
@@ -1,8 +1,8 @@
/*
- oscpack -- Open Sound Control packet manipulation library
- http://www.audiomulch.com/~rossb/oscpack
+ oscpack -- Open Sound Control (OSC) packet manipulation library
+ http://www.rossbencina.com/code/oscpack
- Copyright (c) 2004-2005 Ross Bencina
+ Copyright (c) 2004-2013 Ross Bencina
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files
@@ -15,10 +15,6 @@
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
- Any person wishing to distribute modifications to the Software is
- requested to send the modifications to the original developer so that
- they can be incorporated into the canonical version.
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -27,9 +23,20 @@
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+
+/*
+ The text above constitutes the entire oscpack license; however,
+ the oscpack developer(s) also make the following non-binding requests:
+
+ Any person wishing to distribute modifications to the Software is
+ requested to send the modifications to the original developer so that
+ they can be incorporated into the canonical version. It is also
+ requested that these non-binding requests be included whenever the
+ above license is reproduced.
+*/
#include "IpEndpointName.h"
-#include
+#include
#include "NetworkingUtils.h"
@@ -43,9 +50,9 @@ unsigned long IpEndpointName::GetHostByName( const char *s )
void IpEndpointName::AddressAsString( char *s ) const
{
if( address == ANY_ADDRESS ){
- sprintf( s, "" );
+ std::sprintf( s, "" );
}else{
- sprintf( s, "%d.%d.%d.%d",
+ std::sprintf( s, "%d.%d.%d.%d",
(int)((address >> 24) & 0xFF),
(int)((address >> 16) & 0xFF),
(int)((address >> 8) & 0xFF),
@@ -58,9 +65,9 @@ void IpEndpointName::AddressAndPortAsString( char *s ) const
{
if( port == ANY_PORT ){
if( address == ANY_ADDRESS ){
- sprintf( s, ":" );
+ std::sprintf( s, ":" );
}else{
- sprintf( s, "%d.%d.%d.%d:",
+ std::sprintf( s, "%d.%d.%d.%d:",
(int)((address >> 24) & 0xFF),
(int)((address >> 16) & 0xFF),
(int)((address >> 8) & 0xFF),
@@ -68,9 +75,9 @@ void IpEndpointName::AddressAndPortAsString( char *s ) const
}
}else{
if( address == ANY_ADDRESS ){
- sprintf( s, ":%d", port );
+ std::sprintf( s, ":%d", port );
}else{
- sprintf( s, "%d.%d.%d.%d:%d",
+ std::sprintf( s, "%d.%d.%d.%d:%d",
(int)((address >> 24) & 0xFF),
(int)((address >> 16) & 0xFF),
(int)((address >> 8) & 0xFF),
diff --git a/oscpack/ip/IpEndpointName.h b/oscpack/ip/IpEndpointName.h
index c7b078e..4b3159a 100644
--- a/oscpack/ip/IpEndpointName.h
+++ b/oscpack/ip/IpEndpointName.h
@@ -1,8 +1,8 @@
/*
- oscpack -- Open Sound Control packet manipulation library
- http://www.audiomulch.com/~rossb/oscpack
+ oscpack -- Open Sound Control (OSC) packet manipulation library
+ http://www.rossbencina.com/code/oscpack
- Copyright (c) 2004-2005 Ross Bencina
+ Copyright (c) 2004-2013 Ross Bencina
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files
@@ -15,10 +15,6 @@
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
- Any person wishing to distribute modifications to the Software is
- requested to send the modifications to the original developer so that
- they can be incorporated into the canonical version.
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -27,8 +23,19 @@
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#ifndef INCLUDED_IPENDPOINTNAME_H
-#define INCLUDED_IPENDPOINTNAME_H
+
+/*
+ The text above constitutes the entire oscpack license; however,
+ the oscpack developer(s) also make the following non-binding requests:
+
+ Any person wishing to distribute modifications to the Software is
+ requested to send the modifications to the original developer so that
+ they can be incorporated into the canonical version. It is also
+ requested that these non-binding requests be included whenever the
+ above license is reproduced.
+*/
+#ifndef INCLUDED_OSCPACK_IPENDPOINTNAME_H
+#define INCLUDED_OSCPACK_IPENDPOINTNAME_H
class IpEndpointName{
@@ -54,6 +61,8 @@ class IpEndpointName{
unsigned long address;
int port;
+ bool IsMulticastAddress() const { return ((address >> 24) & 0xFF) >= 224 && ((address >> 24) & 0xFF) <= 239; }
+
enum { ADDRESS_STRING_LENGTH=17 };
void AddressAsString( char *s ) const;
@@ -71,4 +80,4 @@ inline bool operator!=( const IpEndpointName& lhs, const IpEndpointName& rhs )
return !(lhs == rhs);
}
-#endif /* INCLUDED_IPENDPOINTNAME_H */
+#endif /* INCLUDED_OSCPACK_IPENDPOINTNAME_H */
diff --git a/oscpack/ip/NetworkingUtils.h b/oscpack/ip/NetworkingUtils.h
index 0d6901c..516e9d2 100644
--- a/oscpack/ip/NetworkingUtils.h
+++ b/oscpack/ip/NetworkingUtils.h
@@ -1,8 +1,8 @@
/*
- oscpack -- Open Sound Control packet manipulation library
- http://www.audiomulch.com/~rossb/oscpack
+ oscpack -- Open Sound Control (OSC) packet manipulation library
+ http://www.rossbencina.com/code/oscpack
- Copyright (c) 2004-2005 Ross Bencina
+ Copyright (c) 2004-2013 Ross Bencina
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files
@@ -15,10 +15,6 @@
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
- Any person wishing to distribute modifications to the Software is
- requested to send the modifications to the original developer so that
- they can be incorporated into the canonical version.
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -27,8 +23,19 @@
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#ifndef INCLUDED_NETWORKINGUTILS_H
-#define INCLUDED_NETWORKINGUTILS_H
+
+/*
+ The text above constitutes the entire oscpack license; however,
+ the oscpack developer(s) also make the following non-binding requests:
+
+ Any person wishing to distribute modifications to the Software is
+ requested to send the modifications to the original developer so that
+ they can be incorporated into the canonical version. It is also
+ requested that these non-binding requests be included whenever the
+ above license is reproduced.
+*/
+#ifndef INCLUDED_OSCPACK_NETWORKINGUTILS_H
+#define INCLUDED_OSCPACK_NETWORKINGUTILS_H
// in general NetworkInitializer is only used internally, but if you're
@@ -46,4 +53,4 @@ class NetworkInitializer{
unsigned long GetHostByName( const char *name );
-#endif /* INCLUDED_NETWORKINGUTILS_H */
+#endif /* INCLUDED_OSCPACK_NETWORKINGUTILS_H */
diff --git a/oscpack/ip/PacketListener.h b/oscpack/ip/PacketListener.h
index 6647209..2a8cf63 100644
--- a/oscpack/ip/PacketListener.h
+++ b/oscpack/ip/PacketListener.h
@@ -1,8 +1,8 @@
/*
- oscpack -- Open Sound Control packet manipulation library
- http://www.audiomulch.com/~rossb/oscpack
+ oscpack -- Open Sound Control (OSC) packet manipulation library
+ http://www.rossbencina.com/code/oscpack
- Copyright (c) 2004-2005 Ross Bencina
+ Copyright (c) 2004-2013 Ross Bencina
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files
@@ -15,10 +15,6 @@
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
- Any person wishing to distribute modifications to the Software is
- requested to send the modifications to the original developer so that
- they can be incorporated into the canonical version.
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -27,8 +23,19 @@
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#ifndef INCLUDED_PACKETLISTENER_H
-#define INCLUDED_PACKETLISTENER_H
+
+/*
+ The text above constitutes the entire oscpack license; however,
+ the oscpack developer(s) also make the following non-binding requests:
+
+ Any person wishing to distribute modifications to the Software is
+ requested to send the modifications to the original developer so that
+ they can be incorporated into the canonical version. It is also
+ requested that these non-binding requests be included whenever the
+ above license is reproduced.
+*/
+#ifndef INCLUDED_OSCPACK_PACKETLISTENER_H
+#define INCLUDED_OSCPACK_PACKETLISTENER_H
class IpEndpointName;
@@ -40,4 +47,4 @@ class PacketListener{
const IpEndpointName& remoteEndpoint ) = 0;
};
-#endif /* INCLUDED_PACKETLISTENER_H */
+#endif /* INCLUDED_OSCPACK_PACKETLISTENER_H */
diff --git a/oscpack/ip/TimerListener.h b/oscpack/ip/TimerListener.h
index 82b1181..61e262b 100644
--- a/oscpack/ip/TimerListener.h
+++ b/oscpack/ip/TimerListener.h
@@ -1,8 +1,8 @@
/*
- oscpack -- Open Sound Control packet manipulation library
- http://www.audiomulch.com/~rossb/oscpack
+ oscpack -- Open Sound Control (OSC) packet manipulation library
+ http://www.rossbencina.com/code/oscpack
- Copyright (c) 2004-2005 Ross Bencina
+ Copyright (c) 2004-2013 Ross Bencina
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files
@@ -15,10 +15,6 @@
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
- Any person wishing to distribute modifications to the Software is
- requested to send the modifications to the original developer so that
- they can be incorporated into the canonical version.
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -27,8 +23,19 @@
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#ifndef INCLUDED_TIMERLISTENER_H
-#define INCLUDED_TIMERLISTENER_H
+
+/*
+ The text above constitutes the entire oscpack license; however,
+ the oscpack developer(s) also make the following non-binding requests:
+
+ Any person wishing to distribute modifications to the Software is
+ requested to send the modifications to the original developer so that
+ they can be incorporated into the canonical version. It is also
+ requested that these non-binding requests be included whenever the
+ above license is reproduced.
+*/
+#ifndef INCLUDED_OSCPACK_TIMERLISTENER_H
+#define INCLUDED_OSCPACK_TIMERLISTENER_H
class TimerListener{
@@ -37,4 +44,4 @@ class TimerListener{
virtual void TimerExpired() = 0;
};
-#endif /* INCLUDED_TIMERLISTENER_H */
+#endif /* INCLUDED_OSCPACK_TIMERLISTENER_H */
diff --git a/oscpack/ip/UdpSocket.h b/oscpack/ip/UdpSocket.h
index 6d9c26d..8bebb27 100644
--- a/oscpack/ip/UdpSocket.h
+++ b/oscpack/ip/UdpSocket.h
@@ -1,8 +1,8 @@
/*
- oscpack -- Open Sound Control packet manipulation library
- http://www.audiomulch.com/~rossb/oscpack
+ oscpack -- Open Sound Control (OSC) packet manipulation library
+ http://www.rossbencina.com/code/oscpack
- Copyright (c) 2004-2005 Ross Bencina
+ Copyright (c) 2004-2013 Ross Bencina
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files
@@ -15,10 +15,6 @@
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
- Any person wishing to distribute modifications to the Software is
- requested to send the modifications to the original developer so that
- they can be incorporated into the canonical version.
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -27,16 +23,24 @@
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#ifndef INCLUDED_UDPSOCKET_H
-#define INCLUDED_UDPSOCKET_H
-#ifndef INCLUDED_NETWORKINGUTILITIES_H
-#include "NetworkingUtils.h"
-#endif /* INCLUDED_NETWORKINGUTILITIES_H */
+/*
+ The text above constitutes the entire oscpack license; however,
+ the oscpack developer(s) also make the following non-binding requests:
+
+ Any person wishing to distribute modifications to the Software is
+ requested to send the modifications to the original developer so that
+ they can be incorporated into the canonical version. It is also
+ requested that these non-binding requests be included whenever the
+ above license is reproduced.
+*/
+#ifndef INCLUDED_OSCPACK_UDPSOCKET_H
+#define INCLUDED_OSCPACK_UDPSOCKET_H
-#ifndef INCLUDED_IPENDPOINTNAME_H
+#include // size_t
+
+#include "NetworkingUtils.h"
#include "IpEndpointName.h"
-#endif /* INCLUDED_IPENDPOINTNAME_H */
class PacketListener;
@@ -80,26 +84,40 @@ class UdpSocket{
public:
- // ctor throws std::runtime_error if there's a problem
+ // Ctor throws std::runtime_error if there's a problem
// initializing the socket.
UdpSocket();
virtual ~UdpSocket();
- // the socket is created in an unbound, unconnected state
+ // Enable broadcast addresses (e.g. x.x.x.255)
+ // Sets SO_BROADCAST socket option.
+ void SetEnableBroadcast( bool enableBroadcast );
+
+ // Enable multiple listeners for a single port on same
+ // network interface*
+ // Sets SO_REUSEADDR (also SO_REUSEPORT on OS X).
+ // [*] The exact behavior of SO_REUSEADDR and
+ // SO_REUSEPORT is undefined for some common cases
+ // and may have drastically different behavior on different
+ // operating systems.
+ void SetAllowReuse( bool allowReuse );
+
+
+ // The socket is created in an unbound, unconnected state
// such a socket can only be used to send to an arbitrary
// address using SendTo(). To use Send() you need to first
// connect to a remote endpoint using Connect(). To use
// ReceiveFrom you need to first bind to a local endpoint
// using Bind().
- // retrieve the local endpoint name when sending to 'to'
- IpEndpointName LocalEndpointFor( const IpEndpointName& remoteEndpoint ) const;
+ // Retrieve the local endpoint name when sending to 'to'
+ IpEndpointName LocalEndpointFor( const IpEndpointName& remoteEndpoint ) const;
// Connect to a remote endpoint which is used as the target
// for calls to Send()
void Connect( const IpEndpointName& remoteEndpoint );
- void Send( const char *data, int size );
- void SendTo( const IpEndpointName& remoteEndpoint, const char *data, int size );
+ void Send( const char *data, std::size_t size );
+ void SendTo( const IpEndpointName& remoteEndpoint, const char *data, std::size_t size );
// Bind a local endpoint to receive incoming data. Endpoint
@@ -107,7 +125,7 @@ class UdpSocket{
void Bind( const IpEndpointName& localEndpoint );
bool IsBound() const;
- int ReceiveFrom( IpEndpointName& remoteEndpoint, char *data, int size );
+ std::size_t ReceiveFrom( IpEndpointName& remoteEndpoint, char *data, std::size_t size );
};
@@ -155,4 +173,4 @@ class UdpListeningReceiveSocket : public UdpSocket{
};
-#endif /* INCLUDED_UDPSOCKET_H */
+#endif /* INCLUDED_OSCPACK_UDPSOCKET_H */
diff --git a/oscpack/ip/posix/NetworkingUtils.cpp b/oscpack/ip/posix/NetworkingUtils.cpp
index 3b1da79..51daca3 100644
--- a/oscpack/ip/posix/NetworkingUtils.cpp
+++ b/oscpack/ip/posix/NetworkingUtils.cpp
@@ -1,8 +1,8 @@
/*
- oscpack -- Open Sound Control packet manipulation library
- http://www.audiomulch.com/~rossb/oscpack
+ oscpack -- Open Sound Control (OSC) packet manipulation library
+ http://www.rossbencina.com/code/oscpack
- Copyright (c) 2004-2005 Ross Bencina
+ Copyright (c) 2004-2013 Ross Bencina
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files
@@ -15,10 +15,6 @@
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
- Any person wishing to distribute modifications to the Software is
- requested to send the modifications to the original developer so that
- they can be incorporated into the canonical version.
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -27,13 +23,24 @@
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+
+/*
+ The text above constitutes the entire oscpack license; however,
+ the oscpack developer(s) also make the following non-binding requests:
+
+ Any person wishing to distribute modifications to the Software is
+ requested to send the modifications to the original developer so that
+ they can be incorporated into the canonical version. It is also
+ requested that these non-binding requests be included whenever the
+ above license is reproduced.
+*/
#include "ip/NetworkingUtils.h"
#include
#include
#include
-#include
-#include
+
+#include
@@ -49,7 +56,7 @@ unsigned long GetHostByName( const char *name )
struct hostent *h = gethostbyname( name );
if( h ){
struct in_addr a;
- memcpy( &a, h->h_addr_list[0], h->h_length );
+ std::memcpy( &a, h->h_addr_list[0], h->h_length );
result = ntohl(a.s_addr);
}
diff --git a/oscpack/ip/posix/UdpSocket.cpp b/oscpack/ip/posix/UdpSocket.cpp
index f5feb00..4fa6204 100644
--- a/oscpack/ip/posix/UdpSocket.cpp
+++ b/oscpack/ip/posix/UdpSocket.cpp
@@ -1,8 +1,8 @@
/*
- oscpack -- Open Sound Control packet manipulation library
- http://www.audiomulch.com/~rossb/oscpack
+ oscpack -- Open Sound Control (OSC) packet manipulation library
+ http://www.rossbencina.com/code/oscpack
- Copyright (c) 2004-2005 Ross Bencina
+ Copyright (c) 2004-2013 Ross Bencina
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files
@@ -15,10 +15,6 @@
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
- Any person wishing to distribute modifications to the Software is
- requested to send the modifications to the original developer so that
- they can be incorporated into the canonical version.
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -27,16 +23,18 @@
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include "ip/UdpSocket.h"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include // for memset
+/*
+ The text above constitutes the entire oscpack license; however,
+ the oscpack developer(s) also make the following non-binding requests:
+
+ Any person wishing to distribute modifications to the Software is
+ requested to send the modifications to the original developer so that
+ they can be incorporated into the canonical version. It is also
+ requested that these non-binding requests be included whenever the
+ above license is reproduced.
+*/
+#include "ip/UdpSocket.h"
#include
#include
@@ -48,19 +46,30 @@
#include
#include // for sockaddr_in
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include // for memset
+#include
+#include
+
#include "ip/PacketListener.h"
#include "ip/TimerListener.h"
#if defined(__APPLE__) && !defined(_SOCKLEN_T)
-// pre system 10.3 didn have socklen_t
+// pre system 10.3 didn't have socklen_t
typedef ssize_t socklen_t;
#endif
static void SockaddrFromIpEndpointName( struct sockaddr_in& sockAddr, const IpEndpointName& endpoint )
{
- memset( (char *)&sockAddr, 0, sizeof(sockAddr ) );
+ std::memset( (char *)&sockAddr, 0, sizeof(sockAddr ) );
sockAddr.sin_family = AF_INET;
sockAddr.sin_addr.s_addr =
@@ -107,9 +116,7 @@ class UdpSocket::Implementation{
throw std::runtime_error("unable to create udp socket\n");
}
- int on=1;
- setsockopt(socket_, SOL_SOCKET, SO_BROADCAST, (char*)&on, sizeof(on));
- memset( &sendToAddr_, 0, sizeof(sendToAddr_) );
+ std::memset( &sendToAddr_, 0, sizeof(sendToAddr_) );
sendToAddr_.sin_family = AF_INET;
}
@@ -118,6 +125,24 @@ class UdpSocket::Implementation{
if (socket_ != -1) close(socket_);
}
+ void SetEnableBroadcast( bool enableBroadcast )
+ {
+ int broadcast = (enableBroadcast) ? 1 : 0; // int on posix
+ setsockopt(socket_, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast));
+ }
+
+ void SetAllowReuse( bool allowReuse )
+ {
+ int reuseAddr = (allowReuse) ? 1 : 0; // int on posix
+ setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR, &reuseAddr, sizeof(reuseAddr));
+
+#ifdef __APPLE__
+ // needed also for OS X - enable multiple listeners for a single port on same network interface
+ int reusePort = (allowReuse) ? 1 : 0; // int on posix
+ setsockopt(socket_, SOL_SOCKET, SO_REUSEPORT, &reusePort, sizeof(reusePort));
+#endif
+ }
+
IpEndpointName LocalEndpointFor( const IpEndpointName& remoteEndpoint ) const
{
assert( isBound_ );
@@ -134,7 +159,7 @@ class UdpSocket::Implementation{
// get the address
struct sockaddr_in sockAddr;
- memset( (char *)&sockAddr, 0, sizeof(sockAddr ) );
+ std::memset( (char *)&sockAddr, 0, sizeof(sockAddr ) );
socklen_t length = sizeof(sockAddr);
if (getsockname(socket_, (struct sockaddr *)&sockAddr, &length) < 0) {
throw std::runtime_error("unable to getsockname\n");
@@ -151,7 +176,7 @@ class UdpSocket::Implementation{
// unconnect from the remote address
struct sockaddr_in unconnectSockAddr;
- memset( (char *)&unconnectSockAddr, 0, sizeof(unconnectSockAddr ) );
+ std::memset( (char *)&unconnectSockAddr, 0, sizeof(unconnectSockAddr ) );
unconnectSockAddr.sin_family = AF_UNSPEC;
// address fields are zero
int connectResult = connect(socket_, (struct sockaddr *)&unconnectSockAddr, sizeof(unconnectSockAddr));
@@ -174,14 +199,14 @@ class UdpSocket::Implementation{
isConnected_ = true;
}
- void Send( const char *data, int size )
+ void Send( const char *data, std::size_t size )
{
assert( isConnected_ );
send( socket_, data, size, 0 );
}
- void SendTo( const IpEndpointName& remoteEndpoint, const char *data, int size )
+ void SendTo( const IpEndpointName& remoteEndpoint, const char *data, std::size_t size )
{
sendToAddr_.sin_addr.s_addr = htonl( remoteEndpoint.address );
sendToAddr_.sin_port = htons( remoteEndpoint.port );
@@ -203,14 +228,14 @@ class UdpSocket::Implementation{
bool IsBound() const { return isBound_; }
- int ReceiveFrom( IpEndpointName& remoteEndpoint, char *data, int size )
+ std::size_t ReceiveFrom( IpEndpointName& remoteEndpoint, char *data, std::size_t size )
{
assert( isBound_ );
struct sockaddr_in fromAddr;
socklen_t fromAddrLen = sizeof(fromAddr);
- int result = recvfrom(socket_, data, size, 0,
+ ssize_t result = recvfrom(socket_, data, size, 0,
(struct sockaddr *) &fromAddr, (socklen_t*)&fromAddrLen);
if( result < 0 )
return 0;
@@ -218,7 +243,7 @@ class UdpSocket::Implementation{
remoteEndpoint.address = ntohl(fromAddr.sin_addr.s_addr);
remoteEndpoint.port = ntohs(fromAddr.sin_port);
- return result;
+ return (std::size_t)result;
}
int Socket() { return socket_; }
@@ -234,6 +259,16 @@ UdpSocket::~UdpSocket()
delete impl_;
}
+void UdpSocket::SetEnableBroadcast( bool enableBroadcast )
+{
+ impl_->SetEnableBroadcast( enableBroadcast );
+}
+
+void UdpSocket::SetAllowReuse( bool allowReuse )
+{
+ impl_->SetAllowReuse( allowReuse );
+}
+
IpEndpointName UdpSocket::LocalEndpointFor( const IpEndpointName& remoteEndpoint ) const
{
return impl_->LocalEndpointFor( remoteEndpoint );
@@ -244,12 +279,12 @@ void UdpSocket::Connect( const IpEndpointName& remoteEndpoint )
impl_->Connect( remoteEndpoint );
}
-void UdpSocket::Send( const char *data, int size )
+void UdpSocket::Send( const char *data, std::size_t size )
{
impl_->Send( data, size );
}
-void UdpSocket::SendTo( const IpEndpointName& remoteEndpoint, const char *data, int size )
+void UdpSocket::SendTo( const IpEndpointName& remoteEndpoint, const char *data, std::size_t size )
{
impl_->SendTo( remoteEndpoint, data, size );
}
@@ -264,7 +299,7 @@ bool UdpSocket::IsBound() const
return impl_->IsBound();
}
-int UdpSocket::ReceiveFrom( IpEndpointName& remoteEndpoint, char *data, int size )
+std::size_t UdpSocket::ReceiveFrom( IpEndpointName& remoteEndpoint, char *data, std::size_t size )
{
return impl_->ReceiveFrom( remoteEndpoint, data, size );
}
@@ -370,106 +405,123 @@ class SocketReceiveMultiplexer::Implementation{
void Run()
{
break_ = false;
-
- // configure the master fd_set for select()
-
- fd_set masterfds, tempfds;
- FD_ZERO( &masterfds );
- FD_ZERO( &tempfds );
-
- // in addition to listening to the inbound sockets we
- // also listen to the asynchronous break pipe, so that AsynchronousBreak()
- // can break us out of select() from another thread.
- FD_SET( breakPipe_[0], &masterfds );
- int fdmax = breakPipe_[0];
-
- for( std::vector< std::pair< PacketListener*, UdpSocket* > >::iterator i = socketListeners_.begin();
- i != socketListeners_.end(); ++i ){
-
- if( fdmax < i->second->impl_->Socket() )
- fdmax = i->second->impl_->Socket();
- FD_SET( i->second->impl_->Socket(), &masterfds );
- }
-
-
- // configure the timer queue
- double currentTimeMs = GetCurrentTimeMs();
-
- // expiry time ms, listener
- std::vector< std::pair< double, AttachedTimerListener > > timerQueue_;
- for( std::vector< AttachedTimerListener >::iterator i = timerListeners_.begin();
- i != timerListeners_.end(); ++i )
- timerQueue_.push_back( std::make_pair( currentTimeMs + i->initialDelayMs, *i ) );
- std::sort( timerQueue_.begin(), timerQueue_.end(), CompareScheduledTimerCalls );
-
- const int MAX_BUFFER_SIZE = 4098;
- char *data = new char[ MAX_BUFFER_SIZE ];
- IpEndpointName remoteEndpoint;
-
- struct timeval timeout;
-
- while( !break_ ){
- tempfds = masterfds;
-
- struct timeval *timeoutPtr = 0;
- if( !timerQueue_.empty() ){
- double timeoutMs = timerQueue_.front().first - GetCurrentTimeMs();
- if( timeoutMs < 0 )
- timeoutMs = 0;
-
- // 1000000 microseconds in a second
- timeout.tv_sec = (long)(timeoutMs * .001);
- timeout.tv_usec = (long)((timeoutMs - (timeout.tv_sec * 1000)) * 1000);
- timeoutPtr = &timeout;
- }
-
- if( select( fdmax + 1, &tempfds, 0, 0, timeoutPtr ) < 0 && errno != EINTR ){
- if (!break_) throw std::runtime_error("select failed\n");
- else break;
- }
-
- if ( FD_ISSET( breakPipe_[0], &tempfds ) ){
- // clear pending data from the asynchronous break pipe
- char c;
- ssize_t ret;
- ret = read( breakPipe_[0], &c, 1 );
- }
-
- if( break_ )
- break;
-
- for( std::vector< std::pair< PacketListener*, UdpSocket* > >::iterator i = socketListeners_.begin();
- i != socketListeners_.end(); ++i ){
-
- if( FD_ISSET( i->second->impl_->Socket(), &tempfds ) ){
-
- int size = i->second->ReceiveFrom( remoteEndpoint, data, MAX_BUFFER_SIZE );
- if( size > 0 ){
- i->first->ProcessPacket( data, size, remoteEndpoint );
- if( break_ )
- break;
- }
- }
- }
-
- // execute any expired timers
- currentTimeMs = GetCurrentTimeMs();
- bool resort = false;
- for( std::vector< std::pair< double, AttachedTimerListener > >::iterator i = timerQueue_.begin();
- i != timerQueue_.end() && i->first <= currentTimeMs; ++i ){
-
- i->second.listener->TimerExpired();
- if( break_ )
- break;
-
- i->first += i->second.periodMs;
- resort = true;
- }
- if( resort )
- std::sort( timerQueue_.begin(), timerQueue_.end(), CompareScheduledTimerCalls );
- }
-
- delete [] data;
+ char *data = 0;
+
+ try{
+
+ // configure the master fd_set for select()
+
+ fd_set masterfds, tempfds;
+ FD_ZERO( &masterfds );
+ FD_ZERO( &tempfds );
+
+ // in addition to listening to the inbound sockets we
+ // also listen to the asynchronous break pipe, so that AsynchronousBreak()
+ // can break us out of select() from another thread.
+ FD_SET( breakPipe_[0], &masterfds );
+ int fdmax = breakPipe_[0];
+
+ for( std::vector< std::pair< PacketListener*, UdpSocket* > >::iterator i = socketListeners_.begin();
+ i != socketListeners_.end(); ++i ){
+
+ if( fdmax < i->second->impl_->Socket() )
+ fdmax = i->second->impl_->Socket();
+ FD_SET( i->second->impl_->Socket(), &masterfds );
+ }
+
+
+ // configure the timer queue
+ double currentTimeMs = GetCurrentTimeMs();
+
+ // expiry time ms, listener
+ std::vector< std::pair< double, AttachedTimerListener > > timerQueue_;
+ for( std::vector< AttachedTimerListener >::iterator i = timerListeners_.begin();
+ i != timerListeners_.end(); ++i )
+ timerQueue_.push_back( std::make_pair( currentTimeMs + i->initialDelayMs, *i ) );
+ std::sort( timerQueue_.begin(), timerQueue_.end(), CompareScheduledTimerCalls );
+
+ const int MAX_BUFFER_SIZE = 4098;
+ data = new char[ MAX_BUFFER_SIZE ];
+ IpEndpointName remoteEndpoint;
+
+ struct timeval timeout;
+
+ while( !break_ ){
+ tempfds = masterfds;
+
+ struct timeval *timeoutPtr = 0;
+ if( !timerQueue_.empty() ){
+ double timeoutMs = timerQueue_.front().first - GetCurrentTimeMs();
+ if( timeoutMs < 0 )
+ timeoutMs = 0;
+
+ long timoutSecondsPart = (long)(timeoutMs * .001);
+ timeout.tv_sec = (time_t)timoutSecondsPart;
+ // 1000000 microseconds in a second
+ timeout.tv_usec = (suseconds_t)((timeoutMs - (timoutSecondsPart * 1000)) * 1000);
+ timeoutPtr = &timeout;
+ }
+
+ if( select( fdmax + 1, &tempfds, 0, 0, timeoutPtr ) < 0 ){
+ if( break_ ){
+ break;
+ }else if( errno == EINTR ){
+ // on returning an error, select() doesn't clear tempfds.
+ // so tempfds would remain all set, which would cause read( breakPipe_[0]...
+ // below to block indefinitely. therefore if select returns EINTR we restart
+ // the while() loop instead of continuing on to below.
+ continue;
+ }else{
+ throw std::runtime_error("select failed\n");
+ }
+ }
+
+ if( FD_ISSET( breakPipe_[0], &tempfds ) ){
+ // clear pending data from the asynchronous break pipe
+ char c;
+ read( breakPipe_[0], &c, 1 );
+ }
+
+ if( break_ )
+ break;
+
+ for( std::vector< std::pair< PacketListener*, UdpSocket* > >::iterator i = socketListeners_.begin();
+ i != socketListeners_.end(); ++i ){
+
+ if( FD_ISSET( i->second->impl_->Socket(), &tempfds ) ){
+
+ std::size_t size = i->second->ReceiveFrom( remoteEndpoint, data, MAX_BUFFER_SIZE );
+ if( size > 0 ){
+ i->first->ProcessPacket( data, (int)size, remoteEndpoint );
+ if( break_ )
+ break;
+ }
+ }
+ }
+
+ // execute any expired timers
+ currentTimeMs = GetCurrentTimeMs();
+ bool resort = false;
+ for( std::vector< std::pair< double, AttachedTimerListener > >::iterator i = timerQueue_.begin();
+ i != timerQueue_.end() && i->first <= currentTimeMs; ++i ){
+
+ i->second.listener->TimerExpired();
+ if( break_ )
+ break;
+
+ i->first += i->second.periodMs;
+ resort = true;
+ }
+ if( resort )
+ std::sort( timerQueue_.begin(), timerQueue_.end(), CompareScheduledTimerCalls );
+ }
+
+ delete [] data;
+ }catch(...){
+ if( data )
+ delete [] data;
+ throw;
+ }
}
void Break()
@@ -482,8 +534,7 @@ class SocketReceiveMultiplexer::Implementation{
break_ = true;
// Send a termination message to the asynchronous break pipe, so select() will return
- ssize_t ret;
- ret = write( breakPipe_[1], "!", 1 );
+ write( breakPipe_[1], "!", 1 );
}
};
diff --git a/oscpack/ip/win32/NetworkingUtils.cpp b/oscpack/ip/win32/NetworkingUtils.cpp
index 071a758..ded5305 100644
--- a/oscpack/ip/win32/NetworkingUtils.cpp
+++ b/oscpack/ip/win32/NetworkingUtils.cpp
@@ -1,8 +1,8 @@
/*
- oscpack -- Open Sound Control packet manipulation library
- http://www.audiomulch.com/~rossb/oscpack
+ oscpack -- Open Sound Control (OSC) packet manipulation library
+ http://www.rossbencina.com/code/oscpack
- Copyright (c) 2004-2005 Ross Bencina
+ Copyright (c) 2004-2013 Ross Bencina
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files
@@ -15,10 +15,6 @@
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
- Any person wishing to distribute modifications to the Software is
- requested to send the modifications to the original developer so that
- they can be incorporated into the canonical version.
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -27,12 +23,23 @@
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+
+/*
+ The text above constitutes the entire oscpack license; however,
+ the oscpack developer(s) also make the following non-binding requests:
+
+ Any person wishing to distribute modifications to the Software is
+ requested to send the modifications to the original developer so that
+ they can be incorporated into the canonical version. It is also
+ requested that these non-binding requests be included whenever the
+ above license is reproduced.
+*/
#include "ip/NetworkingUtils.h"
#include // this must come first to prevent errors with MSVC7
#include
-#include
-#include
+
+#include
static LONG initCount_ = 0;
@@ -80,7 +87,7 @@ unsigned long GetHostByName( const char *name )
struct hostent *h = gethostbyname( name );
if( h ){
struct in_addr a;
- memcpy( &a, h->h_addr_list[0], h->h_length );
+ std::memcpy( &a, h->h_addr_list[0], h->h_length );
result = ntohl(a.s_addr);
}
diff --git a/oscpack/ip/win32/UdpSocket.cpp b/oscpack/ip/win32/UdpSocket.cpp
index 6f59bef..f4543fb 100644
--- a/oscpack/ip/win32/UdpSocket.cpp
+++ b/oscpack/ip/win32/UdpSocket.cpp
@@ -1,8 +1,8 @@
/*
- oscpack -- Open Sound Control packet manipulation library
- http://www.audiomulch.com/~rossb/oscpack
+ oscpack -- Open Sound Control (OSC) packet manipulation library
+ http://www.rossbencina.com/code/oscpack
- Copyright (c) 2004-2005 Ross Bencina
+ Copyright (c) 2004-2013 Ross Bencina
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files
@@ -15,10 +15,6 @@
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
- Any person wishing to distribute modifications to the Software is
- requested to send the modifications to the original developer so that
- they can be incorporated into the canonical version.
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -27,17 +23,35 @@
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include "ip/UdpSocket.h"
+
+/*
+ The text above constitutes the entire oscpack license; however,
+ the oscpack developer(s) also make the following non-binding requests:
+
+ Any person wishing to distribute modifications to the Software is
+ requested to send the modifications to the original developer so that
+ they can be incorporated into the canonical version. It is also
+ requested that these non-binding requests be included whenever the
+ above license is reproduced.
+*/
#include // this must come first to prevent errors with MSVC7
#include
#include // for timeGetTime()
-#include
+#ifndef WINCE
+#include
+#endif
+
#include
+#include
+#include // for memset
#include
-#include
-#include
+#include
+
+#include "ip/UdpSocket.h" // usually I'd include the module header first
+ // but this is causing conflicts with BCB4 due to
+ // std::size_t usage.
#include "ip/NetworkingUtils.h"
#include "ip/PacketListener.h"
@@ -49,7 +63,7 @@ typedef int socklen_t;
static void SockaddrFromIpEndpointName( struct sockaddr_in& sockAddr, const IpEndpointName& endpoint )
{
- memset( (char *)&sockAddr, 0, sizeof(sockAddr ) );
+ std::memset( (char *)&sockAddr, 0, sizeof(sockAddr ) );
sockAddr.sin_family = AF_INET;
sockAddr.sin_addr.s_addr =
@@ -98,9 +112,7 @@ class UdpSocket::Implementation{
throw std::runtime_error("unable to create udp socket\n");
}
- int on=1;
- setsockopt(socket_, SOL_SOCKET, SO_BROADCAST, (char*)&on, sizeof(on));
- memset( &sendToAddr_, 0, sizeof(sendToAddr_) );
+ std::memset( &sendToAddr_, 0, sizeof(sendToAddr_) );
sendToAddr_.sin_family = AF_INET;
}
@@ -109,6 +121,22 @@ class UdpSocket::Implementation{
if (socket_ != INVALID_SOCKET) closesocket(socket_);
}
+ void SetEnableBroadcast( bool enableBroadcast )
+ {
+ char broadcast = (char)((enableBroadcast) ? 1 : 0); // char on win32
+ setsockopt(socket_, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast));
+ }
+
+ void SetAllowReuse( bool allowReuse )
+ {
+ // Note: SO_REUSEADDR is non-deterministic for listening sockets on Win32. See MSDN article:
+ // "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE"
+ // http://msdn.microsoft.com/en-us/library/ms740621%28VS.85%29.aspx
+
+ char reuseAddr = (char)((allowReuse) ? 1 : 0); // char on win32
+ setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR, &reuseAddr, sizeof(reuseAddr));
+ }
+
IpEndpointName LocalEndpointFor( const IpEndpointName& remoteEndpoint ) const
{
assert( isBound_ );
@@ -125,7 +153,7 @@ class UdpSocket::Implementation{
// get the address
struct sockaddr_in sockAddr;
- memset( (char *)&sockAddr, 0, sizeof(sockAddr ) );
+ std::memset( (char *)&sockAddr, 0, sizeof(sockAddr ) );
socklen_t length = sizeof(sockAddr);
if (getsockname(socket_, (struct sockaddr *)&sockAddr, &length) < 0) {
throw std::runtime_error("unable to getsockname\n");
@@ -164,19 +192,19 @@ class UdpSocket::Implementation{
isConnected_ = true;
}
- void Send( const char *data, int size )
+ void Send( const char *data, std::size_t size )
{
assert( isConnected_ );
- send( socket_, data, size, 0 );
+ send( socket_, data, (int)size, 0 );
}
- void SendTo( const IpEndpointName& remoteEndpoint, const char *data, int size )
+ void SendTo( const IpEndpointName& remoteEndpoint, const char *data, std::size_t size )
{
sendToAddr_.sin_addr.s_addr = htonl( remoteEndpoint.address );
sendToAddr_.sin_port = htons( (short)remoteEndpoint.port );
- sendto( socket_, data, size, 0, (sockaddr*)&sendToAddr_, sizeof(sendToAddr_) );
+ sendto( socket_, data, (int)size, 0, (sockaddr*)&sendToAddr_, sizeof(sendToAddr_) );
}
void Bind( const IpEndpointName& localEndpoint )
@@ -193,14 +221,14 @@ class UdpSocket::Implementation{
bool IsBound() const { return isBound_; }
- int ReceiveFrom( IpEndpointName& remoteEndpoint, char *data, int size )
+ std::size_t ReceiveFrom( IpEndpointName& remoteEndpoint, char *data, std::size_t size )
{
assert( isBound_ );
struct sockaddr_in fromAddr;
socklen_t fromAddrLen = sizeof(fromAddr);
- int result = recvfrom(socket_, data, size, 0,
+ int result = recvfrom(socket_, data, (int)size, 0,
(struct sockaddr *) &fromAddr, (socklen_t*)&fromAddrLen);
if( result < 0 )
return 0;
@@ -224,6 +252,16 @@ UdpSocket::~UdpSocket()
delete impl_;
}
+void UdpSocket::SetEnableBroadcast( bool enableBroadcast )
+{
+ impl_->SetEnableBroadcast( enableBroadcast );
+}
+
+void UdpSocket::SetAllowReuse( bool allowReuse )
+{
+ impl_->SetAllowReuse( allowReuse );
+}
+
IpEndpointName UdpSocket::LocalEndpointFor( const IpEndpointName& remoteEndpoint ) const
{
return impl_->LocalEndpointFor( remoteEndpoint );
@@ -234,12 +272,12 @@ void UdpSocket::Connect( const IpEndpointName& remoteEndpoint )
impl_->Connect( remoteEndpoint );
}
-void UdpSocket::Send( const char *data, int size )
+void UdpSocket::Send( const char *data, std::size_t size )
{
impl_->Send( data, size );
}
-void UdpSocket::SendTo( const IpEndpointName& remoteEndpoint, const char *data, int size )
+void UdpSocket::SendTo( const IpEndpointName& remoteEndpoint, const char *data, std::size_t size )
{
impl_->SendTo( remoteEndpoint, data, size );
}
@@ -254,7 +292,7 @@ bool UdpSocket::IsBound() const
return impl_->IsBound();
}
-int UdpSocket::ReceiveFrom( IpEndpointName& remoteEndpoint, char *data, int size )
+std::size_t UdpSocket::ReceiveFrom( IpEndpointName& remoteEndpoint, char *data, std::size_t size )
{
return impl_->ReceiveFrom( remoteEndpoint, data, size );
}
@@ -284,7 +322,9 @@ extern "C" /*static*/ void InterruptSignalHandler( int );
/*static*/ void InterruptSignalHandler( int )
{
multiplexerInstanceToAbortWithSigInt_->AsynchronousBreak();
- signal( SIGINT, SIG_DFL );
+#ifndef WINCE
+ signal( SIGINT, SIG_DFL );
+#endif
}
@@ -299,8 +339,12 @@ class SocketReceiveMultiplexer::Implementation{
double GetCurrentTimeMs() const
{
+#ifndef WINCE
return timeGetTime(); // FIXME: bad choice if you want to run for more than 40 days
- }
+#else
+ return 0;
+#endif
+ }
public:
Implementation()
@@ -407,9 +451,9 @@ class SocketReceiveMultiplexer::Implementation{
if( waitResult != WAIT_TIMEOUT ){
for( int i = waitResult - WAIT_OBJECT_0; i < (int)socketListeners_.size(); ++i ){
- int size = socketListeners_[i].second->ReceiveFrom( remoteEndpoint, data, MAX_BUFFER_SIZE );
+ std::size_t size = socketListeners_[i].second->ReceiveFrom( remoteEndpoint, data, MAX_BUFFER_SIZE );
if( size > 0 ){
- socketListeners_[i].first->ProcessPacket( data, size, remoteEndpoint );
+ socketListeners_[i].first->ProcessPacket( data, (int)size, remoteEndpoint );
if( break_ )
break;
}
@@ -505,9 +549,13 @@ void SocketReceiveMultiplexer::RunUntilSigInt()
{
assert( multiplexerInstanceToAbortWithSigInt_ == 0 ); /* at present we support only one multiplexer instance running until sig int */
multiplexerInstanceToAbortWithSigInt_ = this;
- signal( SIGINT, InterruptSignalHandler );
+#ifndef WINCE
+ signal( SIGINT, InterruptSignalHandler );
+#endif
impl_->Run();
+#ifndef WINCE
signal( SIGINT, SIG_DFL );
+#endif
multiplexerInstanceToAbortWithSigInt_ = 0;
}
diff --git a/oscpack/license b/oscpack/license
index 23c9609..7b11e28 100644
--- a/oscpack/license
+++ b/oscpack/license
@@ -1,7 +1,7 @@
-oscpack -- Open Sound Control packet manipulation library
-http://www.audiomulch.com/~rossb/code/oscpack
+oscpack -- Open Sound Control (OSC) packet manipulation library
+http://www.rossbencina.com/code/oscpack
-Copyright (c) 2004 Ross Bencina
+Copyright (c) 2004-2013 Ross Bencina
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files
@@ -14,10 +14,6 @@ subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
-Any person wishing to distribute modifications to the Software is
-requested to send the modifications to the original developer so that
-they can be incorporated into the canonical version.
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -26,3 +22,13 @@ ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+###
+
+The text above constitutes the entire oscpack license; however,
+the oscpack developer(s) also make the following non-binding requests:
+
+Any person wishing to distribute modifications to the Software is
+requested to send the modifications to the original developer so that
+they can be incorporated into the canonical version. It is also
+requested that these non-binding requests be included whenever the
+above license is reproduced.
\ No newline at end of file
diff --git a/oscpack/osc/MessageMappingOscPacketListener.h b/oscpack/osc/MessageMappingOscPacketListener.h
index 017bf05..fc7f75a 100644
--- a/oscpack/osc/MessageMappingOscPacketListener.h
+++ b/oscpack/osc/MessageMappingOscPacketListener.h
@@ -1,8 +1,8 @@
/*
- oscpack -- Open Sound Control packet manipulation library
- http://www.audiomulch.com/~rossb/oscpack
+ oscpack -- Open Sound Control (OSC) packet manipulation library
+ http://www.rossbencina.com/code/oscpack
- Copyright (c) 2004-2005 Ross Bencina
+ Copyright (c) 2004-2013 Ross Bencina
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files
@@ -15,10 +15,6 @@
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
- Any person wishing to distribute modifications to the Software is
- requested to send the modifications to the original developer so that
- they can be incorporated into the canonical version.
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -27,10 +23,21 @@
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#ifndef INCLUDED_MESSAGEMAPPINGOSCPACKETLISTENER_H
-#define INCLUDED_MESSAGEMAPPINGOSCPACKETLISTENER_H
-#include
+/*
+ The text above constitutes the entire oscpack license; however,
+ the oscpack developer(s) also make the following non-binding requests:
+
+ Any person wishing to distribute modifications to the Software is
+ requested to send the modifications to the original developer so that
+ they can be incorporated into the canonical version. It is also
+ requested that these non-binding requests be included whenever the
+ above license is reproduced.
+*/
+#ifndef INCLUDED_OSCPACK_MESSAGEMAPPINGOSCPACKETLISTENER_H
+#define INCLUDED_OSCPACK_MESSAGEMAPPINGOSCPACKETLISTENER_H
+
+#include
#include