TuioClient locking

Hello All!

I am experiencing some behavior that I am sure not whats the reason behind and I was wondering if someone has some insights…

I am trying to write a very simple TUIO client that will receive cursor data and I am experiencing some kind of weird blocking between the drawing thread and the tuioClient. I am following the logic of the TuioDemo app that comes with the library for my client.

More specifically, the client will dump the very last set of data that received just before exiting the app but it wont print anything during runtime .

If I run the app with tuioClient->connect(true) [which locks the tuio client] I receive the data correctly but of course the drawing thread is being blocked.

I am working on ubuntu 10.04 64bit with OF 7.0.

What seems strange to me is that I am running the exact same code on a mac os x 10.6.8 and everything runs fine.

The code part is trivial and directly from the TuioDemo app but in any case here it is:

  
  
#ifndef TUIO_CONNECTION_H  
#define TUIO_CONNECTION_H  
  
  
#include "TuioListener.h"  
#include "TuioClient.h"  
#include "TuioObject.h"  
#include "TuioCursor.h"  
#include "TuioPoint.h"  
  
#include "ofMain.h"  
  
using namespace TUIO;  
  
class TuioConnection : public TuioListener {  
public:  
	TuioConnection(int port);  
	~TuioConnection()  
	{  
		tuioClient->disconnect();  
		delete tuioClient;  
	}  
	  
	void addTuioObject(TuioObject *tobj);  
	void updateTuioObject(TuioObject *tobj);  
	void removeTuioObject(TuioObject *tobj);  
	  
	void addTuioCursor(TuioCursor *tcursor);  
	void updateTuioCursor(TuioCursor *tcursor);  
	void removeTuioCursor(TuioCursor *tcursor);  
	  
	void refresh(TUIO::TuioTime);  
	  
	void drawCursor();  
	  
	TuioClient *tuioClient;  
	  
	bool verbose;  
	  
};  
  
#endif   
  
  
#endif  
  
  

  
  
  
#include "tuioConnection.h"  
  
TuioConnection::TuioConnection(int port) : verbose(true)  
{  
	tuioClient = new TuioClient(port);  
	tuioClient->addTuioListener(this);  
	tuioClient->connect();  
}  
  
void TuioConnection::addTuioObject(TuioObject *tobj) {  
	if (verbose)  
		std::cout << "add obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << ") "<< tobj->getX() << " " << tobj->getY() << " " << tobj->getAngle() << std::endl;  
	  
}  
  
void TuioConnection::updateTuioObject(TuioObject *tobj) {  
	  
	if (verbose) 	  
		std::cout << "set obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << ") "<< tobj->getX() << " " << tobj->getY() << " " << tobj->getAngle()   
		<< " " << tobj->getMotionSpeed() << " " << tobj->getRotationSpeed() << " " << tobj->getMotionAccel() << " " << tobj->getRotationAccel() << std::endl;  
	  
}  
  
void TuioConnection::removeTuioObject(TuioObject *tobj) {  
	  
	if (verbose)  
		std::cout << "del obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << ")" << std::endl;  
}  
  
void TuioConnection::addTuioCursor(TuioCursor *tcur) {  
	  
	if (verbose)   
		std::cout << "add cur " << tcur->getCursorID() << " (" <<  tcur->getSessionID() << ") " << tcur->getX() << " " << tcur->getY() << std::endl;  
	  
}  
  
void TuioConnection::updateTuioCursor(TuioCursor *tcur) {  
	  
	if (verbose) 	  
		std::cout << "set cur " << tcur->getCursorID() << " (" <<  tcur->getSessionID() << ") " << tcur->getX() << " " << tcur->getY()   
		<< " " << tcur->getMotionSpeed() << " " << tcur->getMotionAccel() << " " << std::endl;  
}  
  
void TuioConnection::removeTuioCursor(TuioCursor *tcur) {  
	  
	if (verbose)  
		std::cout << "del cur " << tcur->getCursorID() << " (" <<  tcur->getSessionID() << ")" << std::endl;  
}  
  
void TuioConnection::refresh(TuioTime frameTime) {  
	//drawObjects();  
}  
  
void TuioConnection::drawCursor()  
{  
	glClear(GL_COLOR_BUFFER_BIT);  
	char id[3];  
	  
	// draw the cursors  
	std::list<TuioCursor*> cursorList = tuioClient->getTuioCursors();  
	//std::cout<<cursorList.size()<<std::endl;  
	tuioClient->lockCursorList();  
	for (std::list<TuioCursor*>::iterator iter = cursorList.begin(); iter!=cursorList.end(); iter++) {  
		TuioCursor *tuioCursor = (*iter);  
		std::list<TuioPoint> path = tuioCursor->getPath();  
		if (path.size()>0) {  
			  
			TuioPoint last_point = path.front();  
			glBegin(GL_LINES);  
			glColor3f(0.0, 0.0, 1.0);  
			  
			for (std::list<TuioPoint>::iterator point = path.begin(); point!=path.end(); point++) {  
				glVertex3f(last_point.getX()*ofGetWidth(), last_point.getY()*ofGetHeight(), 0.0f);  
				glVertex3f(point->getX()*ofGetWidth(), point->getY()*ofGetHeight(), 0.0f);  
				last_point.update(point->getX(),point->getY());  
				  
			} glEnd();  
			  
			// draw the finger tip  
			glColor3f(0.75, 0.75, 0.75);  
			glPushMatrix();  
			glTranslatef(last_point.getX()*ofGetWidth(), last_point.getY()*ofGetHeight(), 0.0);  
			glBegin(GL_TRIANGLE_FAN);  
			for(double a = 0.0f; a <= 2*M_PI; a += 0.2f) {  
				glVertex2d(cos(a) * ofGetHeight()/100.0f, sin(a) * ofGetHeight()/100.0f);  
			} glEnd();  
			glPopMatrix();  
			  
			glColor3f(0.0, 0.0, 0.0);  
			glRasterPos2f(tuioCursor->getScreenX(ofGetWidth()),tuioCursor->getScreenY(ofGetHeight()));  
			sprintf(id,"%d",tuioCursor->getCursorID());  
			ofDrawBitmapString(id,last_point.getX()*ofGetWidth(), last_point.getY()*ofGetHeight());  
		}  
	}  
	tuioClient->unlockCursorList();  
}  
  
  

  
  
#pragma once  
  
#include "ofMain.h"  
#include "tuioConnection.h"  
  
class testApp : public ofBaseApp{  
  
	public:  
		void setup();  
		void update();  
		void draw();  
  
		void keyPressed  (int key);  
		void keyReleased(int key);  
		void mouseMoved(int x, int y );  
		void mouseDragged(int x, int y, int button);  
		void mousePressed(int x, int y, int button);  
		void mouseReleased(int x, int y, int button);  
		void windowResized(int w, int h);  
		void dragEvent(ofDragInfo dragInfo);  
		void gotMessage(ofMessage msg);  
  
TuioConnection *tuio;  
ofImage background; //EDIT  
		  
};  
  
  

  
  
#include "testApp.h"  
  
//--------------------------------------------------------------  
void testApp::setup(){  
  
tuio = new TuioConnection(3333);  
background.loadImage("timeline.jpg") //EDIT  
}  
  
//--------------------------------------------------------------  
void testApp::update(){  
  
}  
  
//--------------------------------------------------------------  
void testApp::draw(){  
 ofBackground(255,255,255);  
 timeLine.draw(); //EDIT : If I comment both timeLine.draw() and ofDrawBitmapString everything works as expected -- if not the tuio stuff are being blocked.   
 ofDrawBitmapString("fps : " + ofToString(ofGetFrameRate()) , 100, 100);//EDIT : This is also causing problems when uncommented  
 tuio->drawCursor();  
}  
  
//--------------------------------------------------------------  
void testApp::keyPressed(int key){  
  
}  
  
//--------------------------------------------------------------  
void testApp::keyReleased(int key){  
  
}  
  
//--------------------------------------------------------------  
void testApp::mouseMoved(int x, int y ){  
  
}  
  
//--------------------------------------------------------------  
void testApp::mouseDragged(int x, int y, int button){  
  
}  
  
//--------------------------------------------------------------  
void testApp::mousePressed(int x, int y, int button){  
  
}  
  
//--------------------------------------------------------------  
void testApp::mouseReleased(int x, int y, int button){  
  
}  
  
//--------------------------------------------------------------  
void testApp::windowResized(int w, int h){  
  
}  
  
//--------------------------------------------------------------  
void testApp::gotMessage(ofMessage msg){  
  
}  
  
//--------------------------------------------------------------  
void testApp::dragEvent(ofDragInfo dragInfo){   
  
}  
  

Thanks in advance for any insights!

Petros

EDIT:

Sorry, actually my previous post was not complete — In addition to the above code I am also doing some drawing which involves loading an image and then drawing it which seems to cause this whole issue ( in addition I noticed that a call to ofDrawBitmapString also gives the same results as trying to draw the loaded image i.e blocking the tuio events). Also the osx version that I mentioned doesnt do any drawing so probably thats why I didnt experience any issues now that I am thinking about it…

Still confused…

When running the app with gdb in order to examine the call stack everything works as expected which makes me wonder even more for the nature of this bug…

Any ideas ???

P.

Hi !

I had some time to get back on this weird bug today again and I realized that problem arises because of using a different version of poco instead of the one that ships with OF.

More specifically I am using Poco version 1.4.2 for linux 64 bit – I am not sure which version OF uses (I couldnt find any details about it) but it seems that with the 1.4.2 version something related to the way events are handled and the way that OF notifies draw causes the draw function to block any incoming tuio events whenever trying to do something as simple as :

  
  
void testApp::setup(){  
background.loadImage("bg.jpg");  
tuioClient.connect(7777);  
}  
  
void testApp::draw(){  
background.draw(0,0);  
tuioClient.drawCursors();  
}  
  

If I link with the version of Poco that ships with OF everything runs as expected…

I dont know if it worths getting any deeper on this but I thought that at least it worths mentioning…

P.S Would somebody know which version of Poco is shipped with OF??