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.
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
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    37
/*
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    38
* Surcharg� par alexandre.bastien@iri.centrepompidou.fr
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    39
*/
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    40
static inline void call(TuioEvent type, long sid, int fid, float x, float y, float z, float a)
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    41
{
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    42
	TuioEventData data;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    43
	data.type = type;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    44
	data.sid = sid;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    45
	data.fid = fid;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    46
	data.x = x;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    47
	data.y = y;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    48
	data.z = z;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    49
	data.a = a;
27
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
    50
	data.code = "";
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
    51
	tuio_callback(data);
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
    52
}
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
    53
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
    54
/*
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
    55
* Ajout� par alexandre.bastien@iri.centrepompidou.fr
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
    56
*/
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
    57
static inline void call(TuioEvent type, long sid, const char* code)
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
    58
{
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
    59
	TuioEventData data;
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
    60
	data.type = type;
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
    61
	data.sid = sid;
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
    62
	data.code = code;
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    63
	tuio_callback(data);
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    64
}
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    65
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    66
class Listener : public TuioListener
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    67
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    68
public:
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    69
	Listener() { };
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    70
	~Listener() { };
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    71
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    72
	void addTuioObject(TuioObject *object)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    73
	{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    74
		call(TE_OBJECT_ADD,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    75
			object->getSessionID(), object->getFiducialID(),
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    76
			object->getX(), object->getY(), object->getAngle());
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    77
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    78
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    79
	void updateTuioObject(TuioObject *object)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    80
	{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    81
		call(TE_OBJECT_UPDATE,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    82
			object->getSessionID(), object->getFiducialID(),
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    83
			object->getX(), object->getY(), object->getAngle());
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    84
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    85
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    86
	void removeTuioObject(TuioObject *object)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    87
	{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    88
		call(TE_OBJECT_REMOVE,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    89
			object->getSessionID(), object->getFiducialID(),
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    90
			object->getX(), object->getY(), object->getAngle());
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    91
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    92
	
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    93
	/*
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    94
	* Modifi� par alexandre.bastien@iri.centrepompidou.fr
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    95
	*/
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    96
	void addTuioCursor(TuioCursor *cursor)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    97
	{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    98
		call(TE_CURSOR_ADD,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    99
			cursor->getSessionID(), cursor->getFingerID(),
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   100
			cursor->getX(), cursor->getY(), cursor->getZ(), 0);
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   101
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   102
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   103
	/*
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   104
	* Modifi� par alexandre.bastien@iri.centrepompidou.fr
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   105
	*/
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   106
	void updateTuioCursor(TuioCursor *cursor)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   107
	{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   108
		call(TE_CURSOR_UPDATE,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   109
			cursor->getSessionID(), cursor->getFingerID(),
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   110
			cursor->getX(), cursor->getY(), cursor->getZ(), 0);
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   111
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   112
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   113
	/*
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   114
	* Modifi� par alexandre.bastien@iri.centrepompidou.fr
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   115
	*/
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   116
	void removeTuioCursor(TuioCursor *cursor)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   117
	{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   118
		call(TE_CURSOR_REMOVE,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   119
			cursor->getSessionID(), cursor->getFingerID(),
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   120
			cursor->getX(), cursor->getY(), cursor->getZ(), 0);
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   121
	}
27
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   122
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   123
	/*
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   124
	* Ajout� par alexandre.bastien@iri.centrepompidou.fr
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   125
	*/
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   126
	void addTuioString(TuioString *string)
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   127
	{
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   128
		call(TE_STRING_ADD, string->getSessionID(), string->getCode());
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   129
	}
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   130
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   131
	/*
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   132
	* Ajout� par alexandre.bastien@iri.centrepompidou.fr
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   133
	*/
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   134
	void updateTuioString(TuioString *string)
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   135
	{
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   136
		call(TE_STRING_UPDATE, string->getSessionID(), string->getCode());
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   137
	}
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   138
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   139
	/*
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   140
	* Ajout� par alexandre.bastien@iri.centrepompidou.fr
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   141
	*/
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   142
	void removeTuioString(TuioString *string)
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   143
	{
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   144
		call(TE_STRING_REMOVE, string->getSessionID(), string->getCode());
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   145
	}
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   146
	
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   147
	void refresh(long timestamp) 
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   148
	{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   149
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   150
};
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   151
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   152
static TuioClient* client = 0;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   153
static Listener* listener = 0;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   154
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   155
void tuio_start(int port)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   156
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   157
	if (!client) {
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   158
		listener = new Listener();
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   159
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   160
		client = new TuioClient(port);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   161
		client->addTuioListener(listener);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   162
		client->start();
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   163
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   164
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   165
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   166
void tuio_stop()
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   167
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   168
	client->stop();
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   169
	delete listener;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   170
	delete client;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   171
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   172
	client = 0;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   173
	listener = 0;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   174
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   175
27
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   176
void t()
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   177
{
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   178
	std::cout << "t" << std::endl;
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   179
}