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