front_idill/extern/fajran-npTuioClient/src/client.cpp
author bastiena
Thu, 12 Apr 2012 13:09:46 +0200
changeset 27 6c08d4d7219e
parent 24 2bdf5d51d434
child 28 9ccef81f02ab
permissions -rw-r--r--
Middleware : GPL License added. Front Processing : GPL License added. Front IDILL : extern altered to send TUIO cursors from Middleware to Front. implemented as a plugin.

//   
// 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 3 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, see <http://www.gnu.org/licenses/>.
//

#include "client.h"

#include <TuioClient.h>
#include <TuioListener.h>
#include <TuioObject.h>
#include <TuioCursor.h>

static inline void call(TuioEvent type, long sid, int fid, float x, float y, float a)
{
	TuioEventData data;
	data.type = type;
	data.sid = sid;
	data.fid = fid;
	data.x = x;
	data.y = y;
	data.a = a;
	tuio_callback(data);
}

/*
* Surcharg� par alexandre.bastien@iri.centrepompidou.fr
*/
static inline void call(TuioEvent type, long sid, int fid, float x, float y, float z, float a)
{
	TuioEventData data;
	data.type = type;
	data.sid = sid;
	data.fid = fid;
	data.x = x;
	data.y = y;
	data.z = z;
	data.a = a;
	data.code = "";
	tuio_callback(data);
}

/*
* Ajout� par alexandre.bastien@iri.centrepompidou.fr
*/
static inline void call(TuioEvent type, long sid, const char* code)
{
	TuioEventData data;
	data.type = type;
	data.sid = sid;
	data.code = code;
	tuio_callback(data);
}

class Listener : public TuioListener
{
public:
	Listener() { };
	~Listener() { };

	void addTuioObject(TuioObject *object)
	{
		call(TE_OBJECT_ADD,
			object->getSessionID(), object->getFiducialID(),
			object->getX(), object->getY(), object->getAngle());
	}

	void updateTuioObject(TuioObject *object)
	{
		call(TE_OBJECT_UPDATE,
			object->getSessionID(), object->getFiducialID(),
			object->getX(), object->getY(), object->getAngle());
	}

	void removeTuioObject(TuioObject *object)
	{
		call(TE_OBJECT_REMOVE,
			object->getSessionID(), object->getFiducialID(),
			object->getX(), object->getY(), object->getAngle());
	}
	
	/*
	* Modifi� par alexandre.bastien@iri.centrepompidou.fr
	*/
	void addTuioCursor(TuioCursor *cursor)
	{
		call(TE_CURSOR_ADD,
			cursor->getSessionID(), cursor->getFingerID(),
			cursor->getX(), cursor->getY(), cursor->getZ(), 0);
	}

	/*
	* Modifi� par alexandre.bastien@iri.centrepompidou.fr
	*/
	void updateTuioCursor(TuioCursor *cursor)
	{
		call(TE_CURSOR_UPDATE,
			cursor->getSessionID(), cursor->getFingerID(),
			cursor->getX(), cursor->getY(), cursor->getZ(), 0);
	}

	/*
	* Modifi� par alexandre.bastien@iri.centrepompidou.fr
	*/
	void removeTuioCursor(TuioCursor *cursor)
	{
		call(TE_CURSOR_REMOVE,
			cursor->getSessionID(), cursor->getFingerID(),
			cursor->getX(), cursor->getY(), cursor->getZ(), 0);
	}

	/*
	* Ajout� par alexandre.bastien@iri.centrepompidou.fr
	*/
	void addTuioString(TuioString *string)
	{
		call(TE_STRING_ADD, string->getSessionID(), string->getCode());
	}

	/*
	* Ajout� par alexandre.bastien@iri.centrepompidou.fr
	*/
	void updateTuioString(TuioString *string)
	{
		call(TE_STRING_UPDATE, string->getSessionID(), string->getCode());
	}

	/*
	* Ajout� par alexandre.bastien@iri.centrepompidou.fr
	*/
	void removeTuioString(TuioString *string)
	{
		call(TE_STRING_REMOVE, string->getSessionID(), string->getCode());
	}
	
	void refresh(long timestamp) 
	{
	}
};

static TuioClient* client = 0;
static Listener* listener = 0;

void tuio_start(int port)
{
	if (!client) {
		listener = new Listener();

		client = new TuioClient(port);
		client->addTuioListener(listener);
		client->start();
	}
}

void tuio_stop()
{
	client->stop();
	delete listener;
	delete client;

	client = 0;
	listener = 0;
}

void t()
{
	std::cout << "t" << std::endl;
}