front_idill/extern/fajran-npTuioClient/src/client.cpp
author bastiena
Fri, 06 Apr 2012 10:44:54 +0200
changeset 21 e4e5f02787a1
child 24 2bdf5d51d434
permissions -rw-r--r--
Front IDILL : Added Communication extern named fajran-npTuioClient It contains the project generating a dll used as a browser plugin.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     1
//   
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     2
// Copyright (C) 2009  Fajran Iman Rusadi
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     3
//
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     4
// This program is free software: you can redistribute it and/or modify
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     5
// it under the terms of the GNU General Public License as published by
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     6
// the Free Software Foundation, either version 3 of the License, or
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     7
// (at your option) any later version.
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     8
//
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     9
// This program is distributed in the hope that it will be useful,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    12
// GNU General Public License for more details.
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    13
//
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    14
// You should have received a copy of the GNU General Public License
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    15
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    16
//
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    17
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    18
#include "client.h"
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    19
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    20
#include <TuioClient.h>
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    21
#include <TuioListener.h>
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    22
#include <TuioObject.h>
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    23
#include <TuioCursor.h>
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    24
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    25
static inline void call(TuioEvent type, long sid, int fid, float x, float y, float a)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    26
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    27
	TuioEventData data;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    28
	data.type = type;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    29
	data.sid = sid;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    30
	data.fid = fid;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    31
	data.x = x;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    32
	data.y = y;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    33
	data.a = a;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    34
	tuio_callback(data);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    35
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    36
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    37
class Listener : public TuioListener
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    38
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    39
public:
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    40
	Listener() { };
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    41
	~Listener() { };
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    42
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    43
	void addTuioObject(TuioObject *object)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    44
	{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    45
		call(TE_OBJECT_ADD,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    46
			object->getSessionID(), object->getFiducialID(),
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    47
			object->getX(), object->getY(), object->getAngle());
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    48
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    49
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    50
	void updateTuioObject(TuioObject *object)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    51
	{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    52
		call(TE_OBJECT_UPDATE,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    53
			object->getSessionID(), object->getFiducialID(),
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    54
			object->getX(), object->getY(), object->getAngle());
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    55
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    56
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    57
	void removeTuioObject(TuioObject *object)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    58
	{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    59
		call(TE_OBJECT_REMOVE,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    60
			object->getSessionID(), object->getFiducialID(),
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    61
			object->getX(), object->getY(), object->getAngle());
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    62
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    63
	
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    64
	void addTuioCursor(TuioCursor *cursor)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    65
	{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    66
		call(TE_CURSOR_ADD,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    67
			cursor->getSessionID(), cursor->getFingerID(),
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    68
			cursor->getX(), cursor->getY(), 0);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    69
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    70
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    71
	void updateTuioCursor(TuioCursor *cursor)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    72
	{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    73
		call(TE_CURSOR_UPDATE,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    74
			cursor->getSessionID(), cursor->getFingerID(),
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    75
			cursor->getX(), cursor->getY(), 0);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    76
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    77
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    78
	void removeTuioCursor(TuioCursor *cursor)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    79
	{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    80
		call(TE_CURSOR_REMOVE,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    81
			cursor->getSessionID(), cursor->getFingerID(),
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    82
			cursor->getX(), cursor->getY(), 0);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    83
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    84
	
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    85
	void refresh(long timestamp) 
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    86
	{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    87
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    88
};
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    89
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    90
static TuioClient* client = 0;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    91
static Listener* listener = 0;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    92
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    93
void tuio_start(int port)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    94
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    95
	if (!client) {
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    96
		listener = new Listener();
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    97
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    98
		client = new TuioClient(port);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    99
		client->addTuioListener(listener);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   100
		client->start();
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   101
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   102
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   103
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   104
void tuio_stop()
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   105
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   106
	client->stop();
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   107
	delete listener;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   108
	delete client;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   109
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   110
	client = 0;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   111
	listener = 0;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   112
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   113