front_idill/extern/fajran-npTuioClient/src/client.cpp
author bastiena
Thu, 19 Apr 2012 11:53:06 +0200
changeset 29 fcf435874395
parent 28 9ccef81f02ab
permissions -rw-r--r--
Middleware : Connection between middleware and front idill established with websockets.
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
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    18
/*
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    19
    Modified by alexandre.bastien@iri.centrepompidou.fr to manage TUIO strings.
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    20
*/
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    21
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    22
#include "client.h"
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    23
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    24
#include <TuioClient.h>
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    25
#include <TuioListener.h>
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    26
#include <TuioObject.h>
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    27
#include <TuioCursor.h>
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    28
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    29
static inline void call(TuioEvent type, long sid, int fid, float x, float y, float a)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    30
{
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    31
    TuioEventData data;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    32
    data.type = type;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    33
    data.sid = sid;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    34
    data.fid = fid;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    35
    data.x = x;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    36
    data.y = y;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    37
    data.a = a;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    38
    tuio_callback(data);
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    39
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    40
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    41
/*
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    42
* Surchargé par alexandre.bastien@iri.centrepompidou.fr
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    43
*/
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    44
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
    45
{
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    46
    TuioEventData data;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    47
    data.type = type;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    48
    data.sid = sid;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    49
    data.fid = fid;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    50
    data.x = x;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    51
    data.y = y;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    52
    data.z = z;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    53
    data.a = a;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    54
    data.code = "";
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    55
    tuio_callback(data);
27
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
    56
}
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
    57
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
    58
/*
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    59
* Ajouté par alexandre.bastien@iri.centrepompidou.fr
27
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
    60
*/
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
    61
static inline void call(TuioEvent type, long sid, const char* code)
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
    62
{
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    63
    TuioEventData data;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    64
    data.type = type;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    65
    data.sid = sid;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    66
    data.code = code;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    67
    tuio_callback(data);
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    68
}
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    69
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    70
class Listener : public TuioListener
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    71
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    72
public:
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    73
    Listener() { };
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    74
    ~Listener() { };
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    75
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    76
    void addTuioObject(TuioObject *object)
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    77
    {
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    78
        call(TE_OBJECT_ADD,
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    79
            object->getSessionID(), object->getFiducialID(),
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    80
            object->getX(), object->getY(), object->getAngle());
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    81
    }
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    82
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    83
    void updateTuioObject(TuioObject *object)
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    84
    {
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    85
        call(TE_OBJECT_UPDATE,
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    86
            object->getSessionID(), object->getFiducialID(),
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    87
            object->getX(), object->getY(), object->getAngle());
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    88
    }
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    89
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    90
    void removeTuioObject(TuioObject *object)
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    91
    {
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    92
        call(TE_OBJECT_REMOVE,
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    93
            object->getSessionID(), object->getFiducialID(),
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    94
            object->getX(), object->getY(), object->getAngle());
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    95
    }
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    96
    
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    97
    /*
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    98
    * Modifié par alexandre.bastien@iri.centrepompidou.fr
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
    99
    */
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   100
    void addTuioCursor(TuioCursor *cursor)
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   101
    {
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   102
        call(TE_CURSOR_ADD,
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   103
            cursor->getSessionID(), cursor->getFingerID(),
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   104
            cursor->getX(), cursor->getY(), cursor->getZ(), 0);
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   105
    }
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   106
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   107
    /*
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   108
    * Modifié par alexandre.bastien@iri.centrepompidou.fr
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   109
    */
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   110
    void updateTuioCursor(TuioCursor *cursor)
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   111
    {
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   112
        call(TE_CURSOR_UPDATE,
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   113
            cursor->getSessionID(), cursor->getFingerID(),
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   114
            cursor->getX(), cursor->getY(), cursor->getZ(), 0);
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   115
    }
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   116
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   117
    /*
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   118
    * Modifié par alexandre.bastien@iri.centrepompidou.fr
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   119
    */
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   120
    void removeTuioCursor(TuioCursor *cursor)
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   121
    {
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   122
        call(TE_CURSOR_REMOVE,
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   123
            cursor->getSessionID(), cursor->getFingerID(),
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   124
            cursor->getX(), cursor->getY(), cursor->getZ(), 0);
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   125
    }
27
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   126
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   127
    /*
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   128
    * Ajouté par alexandre.bastien@iri.centrepompidou.fr
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   129
    */
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   130
    void addTuioString(TuioString *string)
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   131
    {
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   132
        call(TE_STRING_ADD, string->getSessionID(), string->getCode());
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   133
    }
27
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   134
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   135
    /*
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   136
    * Ajouté par alexandre.bastien@iri.centrepompidou.fr
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   137
    */
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   138
    void updateTuioString(TuioString *string)
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   139
    {
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   140
        call(TE_STRING_UPDATE, string->getSessionID(), string->getCode());
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   141
    }
27
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   142
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   143
    /*
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   144
    * Ajouté par alexandre.bastien@iri.centrepompidou.fr
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   145
    */
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   146
    void removeTuioString(TuioString *string)
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   147
    {
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   148
        call(TE_STRING_REMOVE, string->getSessionID(), string->getCode());
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   149
    }
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   150
    
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   151
    void refresh(long timestamp) 
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   152
    {
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   153
    }
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   154
};
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   155
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   156
static TuioClient* client = 0;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   157
static Listener* listener = 0;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   158
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   159
void tuio_start(int port)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   160
{
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   161
    if (!client) {
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   162
        listener = new Listener();
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   163
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   164
        client = new TuioClient(port);
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   165
        client->addTuioListener(listener);
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   166
        client->start();
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   167
    }
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   168
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   169
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   170
void tuio_stop()
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   171
{
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   172
    client->stop();
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   173
    delete listener;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   174
    delete client;
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   175
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   176
    client = 0;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   177
    listener = 0;
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   178
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   179
27
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   180
void t()
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   181
{
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 27
diff changeset
   182
    std::cout << "t" << std::endl;
27
6c08d4d7219e Middleware :
bastiena
parents: 24
diff changeset
   183
}