root / TUIO_CPP / TUIO / differ @ 91

View | Annotate | Download (35.7 KB)

1
2,5d1
2
< Modified by: Thiago de Freitas Oliveira Araújo
3
< NUI GROUP - Google Summer of Code 2009
4
< Handling hand format
5
< 
6
8c4
7
< 
8
---
9
>  
10
10c6
11
< 
12
---
13
>  
14
15c11
15
< 
16
---
17
>  
18
20c16
19
< 
20
---
21
>  
22
37,38c33,34
23
<     static_cast<TuioClient*>(obj)->socket->Run();
24
<     return 0;
25
---
26
> 	static_cast<TuioClient*>(obj)->socket->Run();
27
> 	return 0;
28
41,45c37,40
29
< void TuioClient::lockObjectList()
30
< {
31
<     if (!connected) return;
32
< #ifndef WIN32
33
<     pthread_mutex_lock(&objectMutex);
34
---
35
> void TuioClient::lockObjectList() {
36
> 	if(!connected) return;
37
> #ifndef WIN32	
38
> 	pthread_mutex_lock(&objectMutex);
39
47,48c42,43
40
<     WaitForSingleObject(objectMutex, INFINITE);
41
< #endif
42
---
43
> 	WaitForSingleObject(objectMutex, INFINITE);
44
> #endif		
45
51,55c46,49
46
< void TuioClient::unlockObjectList()
47
< {
48
<     if (!connected) return;
49
< #ifndef WIN32
50
<     pthread_mutex_unlock(&objectMutex);
51
---
52
> void TuioClient::unlockObjectList() {
53
> 	if(!connected) return;
54
> #ifndef WIN32	
55
> 	pthread_mutex_unlock(&objectMutex);
56
57c51
57
<     ReleaseMutex(objectMutex);
58
---
59
> 	ReleaseMutex(objectMutex);
60
61,65c55,58
61
< void TuioClient::lockCursorList()
62
< {
63
<     if (!connected) return;
64
< #ifndef WIN32
65
<     pthread_mutex_lock(&cursorMutex);
66
---
67
> void TuioClient::lockCursorList() {
68
> 	if(!connected) return;
69
> #ifndef WIN32	
70
> 	pthread_mutex_lock(&cursorMutex);
71
67,68c60,61
72
<     WaitForSingleObject(cursorMutex, INFINITE);
73
< #endif
74
---
75
> 	WaitForSingleObject(cursorMutex, INFINITE);
76
> #endif		
77
71,75c64,67
78
< void TuioClient::unlockCursorList()
79
< {
80
<     if (!connected) return;
81
< #ifndef WIN32
82
<     pthread_mutex_unlock(&cursorMutex);
83
---
84
> void TuioClient::unlockCursorList() {
85
> 	if(!connected) return;
86
> #ifndef WIN32	
87
> 	pthread_mutex_unlock(&cursorMutex);
88
77,78c69,70
89
<     ReleaseMutex(cursorMutex);
90
< #endif
91
---
92
> 	ReleaseMutex(cursorMutex);
93
> #endif		
94
81,88c73,93
95
< void TuioClient::lockHandList()
96
< {
97
<     if (!connected) return;
98
< #ifndef WIN32
99
<     pthread_mutex_lock(&handMutex);
100
< #else
101
<     WaitForSingleObject(handMutex, INFINITE);
102
< #endif
103
---
104
> TuioClient::TuioClient(int port)
105
> : socket      (NULL)
106
> , currentFrame(-1)
107
> , maxCursorID (-1)
108
> , thread      (NULL)
109
> , locked      (false)
110
> , connected     (false)
111
> {
112
> 	try {
113
> 		socket = new UdpListeningReceiveSocket(IpEndpointName( IpEndpointName::ANY_ADDRESS, port ), this );
114
> 	} catch (std::exception &e) { 
115
> 		std::cerr << "could not bind to UDP port " << port << std::endl;
116
> 		socket = NULL;
117
> 	}
118
> 	
119
> 	if (socket!=NULL) {
120
> 		if (!socket->IsBound()) {
121
> 			delete socket;
122
> 			socket = NULL;
123
> 		} else std::cout << "listening to TUIO messages on UDP port " << port << std::endl;
124
> 	}	
125
91,98c96,97
126
< void TuioClient::unlockHandList()
127
< {
128
<     if (!connected) return;
129
< #ifndef WIN32
130
<     pthread_mutex_unlock(&handMutex);
131
< #else
132
<     ReleaseMutex(handMutex);
133
< #endif
134
---
135
> TuioClient::~TuioClient() {	
136
> 	delete socket;
137
101,127c100,112
138
< TuioClient::TuioClient(int port)
139
<         : socket      (NULL)
140
<         , currentFrame(-1)
141
<         , maxCursorID (-1)
142
<         , thread      (NULL)
143
<         , locked      (false)
144
<         , connected     (false)
145
< {
146
<     try
147
<     {
148
<         socket = new UdpListeningReceiveSocket(IpEndpointName( IpEndpointName::ANY_ADDRESS, port ), this );
149
<     }
150
<     catch (std::exception &e)
151
<     {
152
<         std::cerr << "could not bind to UDP port " << port << std::endl;
153
<         socket = NULL;
154
<     }
155
< 
156
<     if (socket!=NULL)
157
<     {
158
<         if (!socket->IsBound())
159
<         {
160
<             delete socket;
161
<             socket = NULL;
162
<         }
163
<         else std::cout << "listening to TUIO messages on UDP port " << port << std::endl;
164
<     }
165
---
166
> void TuioClient::ProcessBundle( const ReceivedBundle& b, const IpEndpointName& remoteEndpoint) {
167
> 	
168
> 	try {
169
> 		for( ReceivedBundle::const_iterator i = b.ElementsBegin(); i != b.ElementsEnd(); ++i ){
170
> 			if( i->IsBundle() )
171
> 				ProcessBundle( ReceivedBundle(*i), remoteEndpoint);
172
> 			else
173
> 				ProcessMessage( ReceivedMessage(*i), remoteEndpoint);
174
> 		}
175
> 	} catch (MalformedBundleException& e) {
176
> 		std::cerr << "malformed OSC bundle" << std::endl << e.what() << std::endl;
177
> 	}
178
> 	
179
130,133c115,139
180
< TuioClient::~TuioClient()
181
< {
182
<     delete socket;
183
< }
184
---
185
> void TuioClient::ProcessMessage( const ReceivedMessage& msg, const IpEndpointName& remoteEndpoint) {
186
> 	try {
187
> 		ReceivedMessageArgumentStream args = msg.ArgumentStream();
188
> 		ReceivedMessage::const_iterator arg = msg.ArgumentsBegin();
189
> 		
190
> 		if( strcmp( msg.AddressPattern(), "/tuio/2Dobj" ) == 0 ){
191
> 			
192
> 			const char* cmd;
193
> 			args >> cmd;
194
> 			
195
> 			if (strcmp(cmd,"set")==0) {	
196
> 												
197
> 				int32 s_id, c_id;
198
> 				float xpos, ypos, angle, xspeed, yspeed, rspeed, maccel, raccel;
199
> 				args >> s_id >> c_id >> xpos >> ypos >> angle >> xspeed >> yspeed >> rspeed >> maccel >> raccel;
200
> 				
201
> 				lockObjectList();
202
> 				std::list<TuioObject*>::iterator tobj;
203
> 				for (tobj=objectList.begin(); tobj!= objectList.end(); tobj++)
204
> 					if((*tobj)->getSessionID()==(long)s_id) break;
205
> 				
206
> 				if (tobj == objectList.end()) {
207
> 					
208
> 					TuioObject *addObject = new TuioObject((long)s_id,(int)c_id,xpos,ypos,angle);
209
> 					frameObjects.push_back(addObject);
210
135,136c141
211
< void TuioClient::ProcessBundle( const ReceivedBundle& b, const IpEndpointName& remoteEndpoint)
212
< {
213
---
214
> 				} else if ( ((*tobj)->getX()!=xpos) || ((*tobj)->getY()!=ypos) || ((*tobj)->getAngle()!=angle) || ((*tobj)->getXSpeed()!=xspeed) || ((*tobj)->getYSpeed()!=yspeed) || ((*tobj)->getRotationSpeed()!=rspeed) || ((*tobj)->getMotionAccel()!=maccel) || ((*tobj)->getRotationAccel()!=raccel) ) {
215
138,151c143,148
216
<     try
217
<     {
218
<         for ( ReceivedBundle::const_iterator i = b.ElementsBegin(); i != b.ElementsEnd(); ++i )
219
<         {
220
<             if ( i->IsBundle() )
221
<                 ProcessBundle( ReceivedBundle(*i), remoteEndpoint);
222
<             else
223
<                 ProcessMessage( ReceivedMessage(*i), remoteEndpoint);
224
<         }
225
<     }
226
<     catch (MalformedBundleException& e)
227
<     {
228
<         std::cerr << "malformed OSC bundle" << std::endl << e.what() << std::endl;
229
<     }
230
---
231
> 					TuioObject *updateObject = new TuioObject((long)s_id,(*tobj)->getSymbolID(),xpos,ypos,angle);
232
> 					updateObject->update(xpos,ypos,angle,xspeed,yspeed,rspeed,maccel,raccel);
233
> 					frameObjects.push_back(updateObject);
234
> 					
235
> 				}
236
> 				unlockObjectList();
237
153c150,193
238
< }
239
---
240
> 			} else if (strcmp(cmd,"alive")==0) {
241
> 				
242
> 				int32 s_id;
243
> 				objectBuffer.clear();
244
> 				while(!args.Eos()) {
245
> 					args >> s_id;
246
> 					objectBuffer.push_back((long)s_id);
247
> 					
248
> 					std::list<long>::iterator iter;
249
> 					iter = find(aliveObjectList.begin(), aliveObjectList.end(), (long)s_id); 
250
> 					if (iter != aliveObjectList.end()) aliveObjectList.erase(iter);
251
> 				}
252
> 				
253
> 				lockObjectList();
254
> 				for (std::list<long>::iterator alive_iter=aliveObjectList.begin(); alive_iter != aliveObjectList.end(); alive_iter++) {
255
> 					std::list<TuioObject*>::iterator tobj;
256
> 					for (tobj=objectList.begin(); tobj!=objectList.end(); tobj++) {
257
> 						TuioObject *deleteObject = (*tobj);
258
> 						if(deleteObject->getSessionID()==*alive_iter) {
259
> 							deleteObject->remove(currentTime);
260
> 							frameObjects.push_back(deleteObject);
261
> 							break;
262
> 						}
263
> 					}
264
> 				}
265
> 				unlockObjectList();
266
> 				
267
> 			} else if (strcmp(cmd,"fseq")==0) {
268
> 				
269
> 				int32 fseq;
270
> 				args >> fseq;
271
> 				bool lateFrame = false;
272
> 				if (fseq>0) {
273
> 					if (fseq>currentFrame) currentTime = TuioTime::getSessionTime();
274
> 					if ((fseq>=currentFrame) || ((currentFrame-fseq)>100)) currentFrame = fseq;
275
> 					else lateFrame = true;
276
> 				} else if ((TuioTime::getSessionTime().getTotalMilliseconds()-currentTime.getTotalMilliseconds())>100) {
277
> 					currentTime = TuioTime::getSessionTime();
278
> 				}
279
> 			
280
> 				if (!lateFrame) {
281
> 					
282
> 					for (std::list<TuioObject*>::iterator iter=frameObjects.begin(); iter != frameObjects.end(); iter++) {
283
> 						TuioObject *tobj = (*iter);
284
155,322c195,202
285
< void TuioClient::ProcessMessage( const ReceivedMessage& msg, const IpEndpointName& remoteEndpoint)
286
< {
287
<     try
288
<     {
289
<         ReceivedMessageArgumentStream args = msg.ArgumentStream();
290
<         ReceivedMessage::const_iterator arg = msg.ArgumentsBegin();
291
< 
292
<         if ( strcmp( msg.AddressPattern(), "/tuio/2Dobj" ) == 0 )
293
<         {
294
< 
295
<             const char* cmd;
296
<             args >> cmd;
297
< 
298
<             if (strcmp(cmd,"set")==0)
299
<             {
300
< 
301
<                 int32 s_id, c_id;
302
<                 float xpos, ypos, angle, xspeed, yspeed, rspeed, maccel, raccel;
303
<                 args >> s_id >> c_id >> xpos >> ypos >> angle >> xspeed >> yspeed >> rspeed >> maccel >> raccel;
304
< 
305
<                 lockObjectList();
306
<                 std::list<TuioObject*>::iterator tobj;
307
<                 for (tobj=objectList.begin(); tobj!= objectList.end(); tobj++)
308
<                     if ((*tobj)->getSessionID()==(long)s_id) break;
309
< 
310
<                 if (tobj == objectList.end())
311
<                 {
312
< 
313
<                     TuioObject *addObject = new TuioObject((long)s_id,(int)c_id,xpos,ypos,angle);
314
<                     frameObjects.push_back(addObject);
315
< 
316
<                 }
317
<                 else if ( ((*tobj)->getX()!=xpos) || ((*tobj)->getY()!=ypos) || ((*tobj)->getAngle()!=angle) || ((*tobj)->getXSpeed()!=xspeed) || ((*tobj)->getYSpeed()!=yspeed) || ((*tobj)->getRotationSpeed()!=rspeed) || ((*tobj)->getMotionAccel()!=maccel) || ((*tobj)->getRotationAccel()!=raccel) )
318
<                 {
319
< 
320
<                     TuioObject *updateObject = new TuioObject((long)s_id,(*tobj)->getSymbolID(),xpos,ypos,angle);
321
<                     updateObject->update(xpos,ypos,angle,xspeed,yspeed,rspeed,maccel,raccel);
322
<                     frameObjects.push_back(updateObject);
323
< 
324
<                 }
325
<                 unlockObjectList();
326
< 
327
<             }
328
<             else if (strcmp(cmd,"alive")==0)
329
<             {
330
< 
331
<                 int32 s_id;
332
<                 objectBuffer.clear();
333
<                 while (!args.Eos())
334
<                 {
335
<                     args >> s_id;
336
<                     objectBuffer.push_back((long)s_id);
337
< 
338
<                     std::list<long>::iterator iter;
339
<                     iter = find(aliveObjectList.begin(), aliveObjectList.end(), (long)s_id);
340
<                     if (iter != aliveObjectList.end()) aliveObjectList.erase(iter);
341
<                 }
342
< 
343
<                 lockObjectList();
344
<                 for (std::list<long>::iterator alive_iter=aliveObjectList.begin(); alive_iter != aliveObjectList.end(); alive_iter++)
345
<                 {
346
<                     std::list<TuioObject*>::iterator tobj;
347
<                     for (tobj=objectList.begin(); tobj!=objectList.end(); tobj++)
348
<                     {
349
<                         TuioObject *deleteObject = (*tobj);
350
<                         if (deleteObject->getSessionID()==*alive_iter)
351
<                         {
352
<                             deleteObject->remove(currentTime);
353
<                             frameObjects.push_back(deleteObject);
354
<                             break;
355
<                         }
356
<                     }
357
<                 }
358
<                 unlockObjectList();
359
< 
360
<             }
361
<             else if (strcmp(cmd,"fseq")==0)
362
<             {
363
< 
364
<                 int32 fseq;
365
<                 args >> fseq;
366
<                 bool lateFrame = false;
367
<                 if (fseq>0)
368
<                 {
369
<                     if (fseq>currentFrame) currentTime = TuioTime::getSessionTime();
370
<                     if ((fseq>=currentFrame) || ((currentFrame-fseq)>100)) currentFrame = fseq;
371
<                     else lateFrame = true;
372
<                 }
373
<                 else if ((TuioTime::getSessionTime().getTotalMilliseconds()-currentTime.getTotalMilliseconds())>100)
374
<                 {
375
<                     currentTime = TuioTime::getSessionTime();
376
<                 }
377
< 
378
<                 if (!lateFrame)
379
<                 {
380
< 
381
<                     for (std::list<TuioObject*>::iterator iter=frameObjects.begin(); iter != frameObjects.end(); iter++)
382
<                     {
383
<                         TuioObject *tobj = (*iter);
384
< 
385
<                         TuioObject *frameObject;
386
<                         switch (tobj->getTuioState())
387
<                         {
388
<                         case TUIO_REMOVED:
389
<                             frameObject = tobj;
390
<                             frameObject->remove(currentTime);
391
< 
392
<                             for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
393
<                                 (*listener)->removeTuioObject(frameObject);
394
< 
395
<                             lockObjectList();
396
<                             for (std::list<TuioObject*>::iterator delobj=objectList.begin(); delobj!=objectList.end(); delobj++)
397
<                             {
398
<                                 if ((*delobj)->getSessionID()==frameObject->getSessionID())
399
<                                 {
400
<                                     objectList.erase(delobj);
401
<                                     break;
402
<                                 }
403
<                             }
404
<                             unlockObjectList();
405
< 
406
<                             break;
407
<                         case TUIO_ADDED:
408
<                             frameObject = new TuioObject(currentTime,tobj->getSessionID(),tobj->getSymbolID(),tobj->getX(),tobj->getY(),tobj->getAngle());
409
<                             lockObjectList();
410
<                             objectList.push_back(frameObject);
411
<                             unlockObjectList();
412
< 
413
<                             for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
414
<                                 (*listener)->addTuioObject(frameObject);
415
< 
416
<                             break;
417
<                         default:
418
<                             frameObject = getTuioObject(tobj->getSessionID());
419
<                             if ( (tobj->getX()!=frameObject->getX() && tobj->getXSpeed()==0) || (tobj->getY()!=frameObject->getY() && tobj->getYSpeed()==0) )
420
<                                 frameObject->update(currentTime,tobj->getX(),tobj->getY(),tobj->getAngle());
421
<                             else
422
<                                 frameObject->update(currentTime,tobj->getX(),tobj->getY(),tobj->getAngle(),tobj->getXSpeed(),tobj->getYSpeed(),tobj->getRotationSpeed(),tobj->getMotionAccel(),tobj->getRotationAccel());
423
< 
424
<                             for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
425
<                                 (*listener)->updateTuioObject(frameObject);
426
< 
427
<                         }
428
<                         delete tobj;
429
<                     }
430
< 
431
<                     for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
432
<                         (*listener)->refresh(currentTime);
433
< 
434
<                     aliveObjectList = objectBuffer;
435
< 
436
<                 }
437
<                 else
438
<                 {
439
<                     for (std::list<TuioObject*>::iterator iter=frameObjects.begin(); iter != frameObjects.end(); iter++)
440
<                     {
441
<                         TuioObject *tobj = (*iter);
442
<                         delete tobj;
443
<                     }
444
<                 }
445
< 
446
<                 frameObjects.clear();
447
<             }
448
<         }
449
<      
450
< /*
451
< begin
452
< */
453
---
454
> 						TuioObject *frameObject;
455
> 						switch (tobj->getTuioState()) {
456
> 							case TUIO_REMOVED:
457
> 								frameObject = tobj;
458
> 								frameObject->remove(currentTime);
459
> 
460
> 								for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
461
> 									(*listener)->removeTuioObject(frameObject);
462
324c204,252
463
< else if( strcmp( msg.AddressPattern(), "/tuio/2Dcur" ) == 0 ) {
464
---
465
> 								lockObjectList();
466
> 								for (std::list<TuioObject*>::iterator delobj=objectList.begin(); delobj!=objectList.end(); delobj++) {
467
> 									if((*delobj)->getSessionID()==frameObject->getSessionID()) {
468
> 										objectList.erase(delobj);
469
> 										break;
470
> 									}
471
> 								}
472
> 								unlockObjectList();
473
> 								
474
> 								break;
475
> 							case TUIO_ADDED:
476
> 								frameObject = new TuioObject(currentTime,tobj->getSessionID(),tobj->getSymbolID(),tobj->getX(),tobj->getY(),tobj->getAngle());
477
> 								lockObjectList();
478
> 								objectList.push_back(frameObject);
479
> 								unlockObjectList();
480
> 	
481
> 								for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
482
> 									(*listener)->addTuioObject(frameObject);
483
> 								
484
> 								break;
485
> 							default:
486
> 								frameObject = getTuioObject(tobj->getSessionID());
487
> 								if ( (tobj->getX()!=frameObject->getX() && tobj->getXSpeed()==0) || (tobj->getY()!=frameObject->getY() && tobj->getYSpeed()==0) )
488
> 									frameObject->update(currentTime,tobj->getX(),tobj->getY(),tobj->getAngle());
489
> 								else
490
> 									frameObject->update(currentTime,tobj->getX(),tobj->getY(),tobj->getAngle(),tobj->getXSpeed(),tobj->getYSpeed(),tobj->getRotationSpeed(),tobj->getMotionAccel(),tobj->getRotationAccel());
491
> 								
492
> 								for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
493
> 									(*listener)->updateTuioObject(frameObject);
494
> 								
495
> 						}
496
> 						delete tobj;
497
> 					}
498
> 					
499
> 					for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
500
> 						(*listener)->refresh(currentTime);
501
> 					
502
> 					aliveObjectList = objectBuffer;
503
> 					
504
> 				} else {
505
> 					for (std::list<TuioObject*>::iterator iter=frameObjects.begin(); iter != frameObjects.end(); iter++) {
506
> 						TuioObject *tobj = (*iter);
507
> 						delete tobj;
508
> 					}
509
> 				}
510
> 				
511
> 				frameObjects.clear();
512
> 			}
513
> 		} else if( strcmp( msg.AddressPattern(), "/tuio/2Dcur" ) == 0 ) {
514
502,730c430,432
515
< 
516
< 
517
< 	
518
< ///////////////////////////////////////////////////////
519
< 
520
< else if ( strcmp( msg.AddressPattern(), "/tuio/2Dhnd" ) == 0 )
521
<     {
522
< 
523
< 		std::cout << "listening to Hand TUIO messages" << std::endl;
524
< /*
525
<         const char* cmd;
526
<         args >> cmd;
527
< 
528
<         if (strcmp(cmd,"set")==0)
529
<         {
530
< 
531
<             int32 s_id;
532
<             float xpos, ypos, xspeed, yspeed, maccel;
533
<             args >> s_id >> xpos >> ypos >> xspeed >> yspeed >> maccel;
534
< 
535
<             lockHandList();
536
<             std::list<TuioHand*>::iterator thand;
537
<             for (thand=handList.begin(); thand!= handList.end(); thand++)
538
<                 if ((*thand)->getSessionID()==(long)s_id) break;
539
< 
540
<             if (thand==handList.end())
541
<             {
542
< 
543
<                 TuioHand *addHand = new TuioHand((long)s_id,-1,xpos,ypos);
544
<                 frameHands.push_back(addHand);
545
< 
546
<             }
547
<             else if ( ((*thand)->getX()!=xpos) || ((*thand)->getY()!=ypos) || ((*thand)->getXSpeed()!=xspeed) || ((*thand)->getYSpeed()!=yspeed) || ((*thand)->getMotionAccel()!=maccel) )
548
<             {
549
< 
550
<                 TuioHand *updateHand = new TuioHand((long)s_id,(*thand)->getHandID(),xpos,ypos);
551
<                 updateHand->update(xpos,ypos,xspeed,yspeed,maccel);
552
<                 frameHands.push_back(updateHand);
553
< 
554
<             }
555
<             unlockHandList();
556
< 
557
<         }
558
<         else if (strcmp(cmd,"alive")==0)
559
<         {
560
< 
561
<             int32 s_id;
562
<             handBuffer.clear();
563
<             while (!args.Eos())
564
<             {
565
<                 args >> s_id;
566
<                 handBuffer.push_back((long)s_id);
567
< 
568
<                 std::list<long>::iterator iter;
569
<                 iter = find(aliveHandList.begin(), aliveHandList.end(), (long)s_id);
570
<                 if (iter != aliveHandList.end()) aliveHandList.erase(iter);
571
<             }
572
< 
573
<             lockHandList();
574
<             for (std::list<long>::iterator alive_iter=aliveHandList.begin(); alive_iter != aliveHandList.end(); alive_iter++)
575
<             {
576
<                 std::list<TuioHand*>::iterator thand;
577
<                 for (thand=handList.begin(); thand != handList.end(); thand++)
578
<                 {
579
<                     TuioHand *deleteHand = (*thand);
580
<                     if (deleteHand->getSessionID()==*alive_iter)
581
<                     {
582
< 
583
<                         deleteHand->remove(currentTime);
584
<                         frameHands.push_back(deleteHand);
585
<                         break;
586
<                     }
587
<                 }
588
<             }
589
<             unlockHandList();
590
< 
591
<         }
592
<         else if ( strcmp( cmd, "fseq" ) == 0 )
593
<         {
594
< 
595
<             int32 fseq;
596
<             args >> fseq;
597
<             bool lateFrame = false;
598
<             if (fseq>0)
599
<             {
600
<                 if (fseq>currentFrame) currentTime = TuioTime::getSessionTime();
601
<                 if ((fseq>=currentFrame) || ((currentFrame-fseq)>100)) currentFrame = fseq;
602
<                 else lateFrame = true;
603
<             }
604
<             else if ((TuioTime::getSessionTime().getTotalMilliseconds()-currentTime.getTotalMilliseconds())>100)
605
<             {
606
<                 currentTime = TuioTime::getSessionTime();
607
<             }
608
< 
609
<             if (!lateFrame)
610
<             {
611
< 
612
<                 for (std::list<TuioHand*>::iterator iter=frameHands.begin(); iter != frameHands.end(); iter++)
613
<                 {
614
<                     TuioHand *thand = (*iter);
615
< 
616
<                     int c_id = -1;
617
<                     TuioHand *frameHand;
618
<                     switch (thand->getTuioState())
619
<                     {
620
<                     case TUIO_REMOVED:
621
<                         frameHand = thand;
622
<                         frameHand->remove(currentTime);
623
< 
624
<                         for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
625
<                             (*listener)->removeTuioHand(frameHand);
626
< 
627
<                         lockHandList();
628
<                         for (std::list<TuioHand*>::iterator delhand=handList.begin(); delhand!=handList.end(); delhand++)
629
<                         {
630
<                             if ((*delhand)->getSessionID()==frameHand->getSessionID())
631
<                             {
632
<                                 handList.erase(delhand);
633
<                                 break;
634
<                             }
635
<                         }
636
< 
637
<                         if (frameHand->getHandID()==maxHandID)
638
<                         {
639
<                             maxHandID = -1;
640
<                             delete frameHand;
641
< 
642
<                             if (handList.size()>0)
643
<                             {
644
<                                 std::list<TuioHand*>::iterator clist;
645
<                                 for (clist=handList.begin(); clist != handList.end(); clist++)
646
<                                 {
647
<                                     c_id = (*clist)->getHandID();
648
<                                     if (c_id>maxHandID) maxHandID=c_id;
649
<                                 }
650
< 
651
<                                 freeHandBuffer.clear();
652
<                                 for (std::list<TuioHand*>::iterator flist=freeHandList.begin(); flist != freeHandList.end(); flist++)
653
<                                 {
654
<                                     TuioHand *freeHand = (*flist);
655
<                                     if (freeHand->getHandID()>maxHandID) delete freeHand;
656
<                                     else freeHandBuffer.push_back(freeHand);
657
<                                 }
658
<                                 freeHandList = freeHandBuffer;
659
< 
660
<                             }
661
<                             else
662
<                             {
663
<                                 for (std::list<TuioHand*>::iterator flist=freeHandList.begin(); flist != freeHandList.end(); flist++)
664
<                                 {
665
<                                     TuioHand *freeHand = (*flist);
666
<                                     delete freeHand;
667
<                                 }
668
<                                 freeHandList.clear();
669
<                             }
670
<                         }
671
<                         else if (frameHand->getHandID()<maxHandID)
672
<                         {
673
<                             freeHandList.push_back(frameHand);
674
<                         }
675
<                         unlockHandList();
676
< 
677
<                         break;
678
<                     case TUIO_ADDED:
679
< 
680
<                         c_id = (int)handList.size();
681
<                         if (((int)(handList.size())<=maxHandID) && ((int)(freeHandList.size())>0))
682
<                         {
683
<                             std::list<TuioHand*>::iterator closestHand = freeHandList.begin();
684
< 
685
<                             for (std::list<TuioHand*>::iterator iter = freeHandList.begin();iter!= freeHandList.end(); iter++)
686
<                             {
687
<                                 if ((*iter)->getDistance(thand)<(*closestHand)->getDistance(thand)) closestHand = iter;
688
<                             }
689
< 
690
<                             TuioHand *freeHand = (*closestHand);
691
<                             c_id = freeHand->getHandID();
692
<                             freeHandList.erase(closestHand);
693
<                             delete freeHand;
694
<                         }
695
<                         else maxHandID = c_id;
696
< 
697
<                         frameHand = new TuioHand(currentTime,thand->getSessionID(),c_id,thand->getX(),thand->getY());
698
<                         lockHandList();
699
<                         handList.push_back(frameHand);
700
<                         unlockHandList();
701
< 
702
<                         for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
703
<                             (*listener)->addTuioHand(frameHand);
704
<                         delete thand;
705
<                         break;
706
<                     default:
707
< 
708
<                         frameHand = getTuioHand(thand->getSessionID());
709
<                         if ( (thand->getX()!=frameHand->getX() && thand->getXSpeed()==0) || (thand->getY()!=frameHand->getY() && thand->getYSpeed()==0) )
710
<                             frameHand->update(currentTime,thand->getX(),thand->getY());
711
<                         else
712
<                             frameHand->update(currentTime,thand->getX(),thand->getY(),thand->getXSpeed(),thand->getYSpeed(),thand->getMotionAccel());
713
< 
714
<                         for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
715
<                             (*listener)->updateTuioHand(frameHand);
716
<                         delete thand;
717
<                     }
718
<                 }
719
< 
720
<                 for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
721
<                     (*listener)->refresh(currentTime);
722
< 
723
<                 aliveHandList = handBuffer;
724
<             }
725
<             else
726
<             {
727
<                 for (std::list<TuioHand*>::iterator iter=frameHands.begin(); iter != frameHands.end(); iter++)
728
<                 {
729
<                     TuioHand *thand = (*iter);
730
<                     delete thand;
731
<                 }
732
<             }
733
< 
734
<             frameHands.clear();
735
<         }
736
<         std::cout << "End of the Hand TUIO messages" << std::endl;
737
<    */ }
738
< }
739
< ////////////////////////////////
740
< catch ( Exception& e )
741
< {
742
<     std::cerr << "error parsing TUIO message: "<< msg.AddressPattern() <<  " - " << e.what() << std::endl;
743
< }
744
---
745
> 	} catch( Exception& e ){
746
> 		std::cerr << "error parsing TUIO message: "<< msg.AddressPattern() <<  " - " << e.what() << std::endl;
747
> 	}
748
733,737c435,438
749
< void TuioClient::ProcessPacket( const char *data, int size, const IpEndpointName& remoteEndpoint )
750
< {
751
<     ReceivedPacket p( data, size );
752
<     if (p.IsBundle()) ProcessBundle( ReceivedBundle(p), remoteEndpoint);
753
<     else ProcessMessage( ReceivedMessage(p), remoteEndpoint);
754
---
755
> void TuioClient::ProcessPacket( const char *data, int size, const IpEndpointName& remoteEndpoint ) {
756
> 	ReceivedPacket p( data, size );
757
> 	if(p.IsBundle()) ProcessBundle( ReceivedBundle(p), remoteEndpoint);
758
> 	else ProcessMessage( ReceivedMessage(p), remoteEndpoint);
759
740,741c441
760
< void TuioClient::connect(bool lk)
761
< {
762
---
763
> void TuioClient::connect(bool lk) {
764
743,749c443,448
765
< #ifndef WIN32
766
<     /*pthread_mutexattr_settype(&attr_p, PTHREAD_MUTEX_RECURSIVE);
767
<     pthread_mutex_init(&cursorMutex,&attr_p);
768
<     pthread_mutex_init(&objectMutex,&attr_p);*/
769
<     pthread_mutex_init(&cursorMutex,NULL);
770
<     pthread_mutex_init(&objectMutex,NULL);
771
<     pthread_mutex_init(&handMutex,NULL);
772
---
773
> #ifndef WIN32	
774
> 	/*pthread_mutexattr_settype(&attr_p, PTHREAD_MUTEX_RECURSIVE);
775
> 	pthread_mutex_init(&cursorMutex,&attr_p);
776
> 	pthread_mutex_init(&objectMutex,&attr_p);*/
777
> 	pthread_mutex_init(&cursorMutex,NULL);
778
> 	pthread_mutex_init(&objectMutex,NULL);	
779
751,762c450,459
780
<     cursorMutex = CreateMutex(NULL,FALSE,"cursorMutex");
781
<     objectMutex = CreateMutex(NULL,FALSE,"objectMutex");
782
<     handMutex = CreateMutex(NULL,FALSE,"objectMutex");
783
< #endif
784
< 
785
<     if (socket==NULL) return;
786
<     TuioTime::initSession();
787
<     currentTime.reset();
788
< 
789
<     locked = lk;
790
<     if (!locked)
791
<     {
792
---
793
> 	cursorMutex = CreateMutex(NULL,FALSE,"cursorMutex");
794
> 	objectMutex = CreateMutex(NULL,FALSE,"objectMutex");
795
> #endif		
796
> 		
797
> 	if (socket==NULL) return;
798
> 	TuioTime::initSession();
799
> 	currentTime.reset();
800
> 	
801
> 	locked = lk;
802
> 	if (!locked) {
803
764c461
804
<         pthread_create(&thread , NULL, ClientThreadFunc, this);
805
---
806
> 		pthread_create(&thread , NULL, ClientThreadFunc, this);
807
766,767c463,464
808
<         DWORD threadId;
809
<         thread = CreateThread( 0, 0, ClientThreadFunc, this, 0, &threadId );
810
---
811
> 		DWORD threadId;
812
> 		thread = CreateThread( 0, 0, ClientThreadFunc, this, 0, &threadId );
813
769,775c466,470
814
<     }
815
<     else socket->Run();
816
< 
817
<     connected = true;
818
<     unlockCursorList();
819
<     unlockObjectList();
820
<     unlockHandList();
821
---
822
> 	} else socket->Run();
823
> 	
824
> 	connected = true;
825
> 	unlockCursorList();
826
> 	unlockObjectList();
827
778,785c473,478
828
< void TuioClient::disconnect()
829
< {
830
< 
831
<     if (socket==NULL) return;
832
<     socket->Break();
833
< 
834
<     if (!locked)
835
<     {
836
---
837
> void TuioClient::disconnect() {
838
> 	
839
> 	if (socket==NULL) return;
840
> 	socket->Break();
841
> 	
842
> 	if (!locked) {
843
787c480
844
<         if ( thread ) CloseHandle( thread );
845
---
846
> 		if( thread ) CloseHandle( thread );
847
789,796c482,488
848
<         thread = 0;
849
<         locked = false;
850
<     }
851
< 
852
< #ifndef WIN32
853
<     pthread_mutex_destroy(&cursorMutex);
854
<     pthread_mutex_destroy(&objectMutex);
855
<     pthread_mutex_destroy(&handMutex);
856
---
857
> 		thread = 0;
858
> 		locked = false;
859
> 	}
860
> 	
861
> #ifndef WIN32	
862
> 	pthread_mutex_destroy(&cursorMutex);
863
> 	pthread_mutex_destroy(&objectMutex);
864
798,800c490,491
865
<     CloseHandle(cursorMutex);
866
<     CloseHandle(objectMutex);
867
<     CloseHandle(handMutex);
868
---
869
> 	CloseHandle(cursorMutex);
870
> 	CloseHandle(objectMutex);
871
803,833c494,495
872
<     aliveObjectList.clear();
873
<     aliveCursorList.clear();
874
<     aliveHandList.clear();
875
< 
876
<     for (std::list<TuioObject*>::iterator iter=objectList.begin(); iter != objectList.end(); iter++)
877
<         delete (*iter);
878
<     objectList.clear();
879
< 
880
<     for (std::list<TuioCursor*>::iterator iter=cursorList.begin(); iter != cursorList.end(); iter++)
881
<         delete (*iter);
882
<     cursorList.clear();
883
< 
884
<         for (std::list<TuioHand*>::iterator iter=handList.begin(); iter != handList.end(); iter++)
885
<         delete (*iter);
886
<     cursorList.clear();
887
< 
888
<     for (std::list<TuioCursor*>::iterator iter=freeCursorList.begin(); iter != freeCursorList.end(); iter++)
889
<         delete(*iter);
890
<     freeCursorList.clear();
891
< 
892
<         for (std::list<TuioHand*>::iterator iter=freeHandList.begin(); iter != freeHandList.end(); iter++)
893
<         delete(*iter);
894
<     freeHandList.clear();
895
< 
896
<     connected = false;
897
< }
898
< 
899
< void TuioClient::addTuioListener(TuioListener *listener)
900
< {
901
<     listenerList.push_back(listener);
902
< }
903
---
904
> 	aliveObjectList.clear();
905
> 	aliveCursorList.clear();
906
835,839c497,499
907
< void TuioClient::removeTuioListener(TuioListener *listener)
908
< {
909
<     std::list<TuioListener*>::iterator result = find(listenerList.begin(),listenerList.end(),listener);
910
<     if (result!=listenerList.end()) listenerList.remove(listener);
911
< }
912
---
913
> 	for (std::list<TuioObject*>::iterator iter=objectList.begin(); iter != objectList.end(); iter++)
914
> 		delete (*iter);
915
> 	objectList.clear();
916
841,854c501,507
917
< TuioObject* TuioClient::getTuioObject(long s_id)
918
< {
919
<     lockObjectList();
920
<     for (std::list<TuioObject*>::iterator iter=objectList.begin(); iter != objectList.end(); iter++)
921
<     {
922
<         if ((*iter)->getSessionID()==s_id)
923
<         {
924
<             unlockObjectList();
925
<             return (*iter);
926
<         }
927
<     }
928
<     unlockObjectList();
929
<     return NULL;
930
< }
931
---
932
> 	for (std::list<TuioCursor*>::iterator iter=cursorList.begin(); iter != cursorList.end(); iter++)
933
> 		delete (*iter);
934
> 	cursorList.clear();
935
> 	
936
> 	for (std::list<TuioCursor*>::iterator iter=freeCursorList.begin(); iter != freeCursorList.end(); iter++)
937
> 		delete(*iter);
938
> 	freeCursorList.clear();
939
856,868c509
940
< TuioCursor* TuioClient::getTuioCursor(long s_id)
941
< {
942
<     lockCursorList();
943
<     for (std::list<TuioCursor*>::iterator iter=cursorList.begin(); iter != cursorList.end(); iter++)
944
<     {
945
<         if ((*iter)->getSessionID()==s_id)
946
<         {
947
<             unlockCursorList();
948
<             return (*iter);
949
<         }
950
<     }
951
<     unlockCursorList();
952
<     return NULL;
953
---
954
> 	connected = false;
955
871,889c512,513
956
< 
957
< 
958
< /*
959
< 
960
< */
961
< 
962
< TuioHand* TuioClient::getTuioHand(long s_id)
963
< {
964
<     lockHandList();
965
<     for (std::list<TuioHand*>::iterator iter=handList.begin(); iter != handList.end(); iter++)
966
<     {
967
<         if ((*iter)->getSessionID()==s_id)
968
<         {
969
<             unlockHandList();
970
<             return (*iter);
971
<         }
972
<     }
973
<     unlockHandList();
974
<     return NULL;
975
---
976
> void TuioClient::addTuioListener(TuioListener *listener) {
977
> 	listenerList.push_back(listener);
978
891,892d514
979
< /*
980
< */
981
894,899c516,518
982
< std::list<TuioObject*> TuioClient::getTuioObjects()
983
< {
984
<     lockObjectList();
985
<     std::list<TuioObject*> listBuffer = objectList;
986
<     unlockObjectList();
987
<     return listBuffer;
988
---
989
> void TuioClient::removeTuioListener(TuioListener *listener) {
990
> 	std::list<TuioListener*>::iterator result = find(listenerList.begin(),listenerList.end(),listener);
991
> 	if (result!=listenerList.end()) listenerList.remove(listener);
992
902,907c521,530
993
< std::list<TuioCursor*> TuioClient::getTuioCursors()
994
< {
995
<     lockCursorList();
996
<     std::list<TuioCursor*> listBuffer = cursorList;
997
<     unlockCursorList();
998
<     return listBuffer;
999
---
1000
> TuioObject* TuioClient::getTuioObject(long s_id) {
1001
> 	lockObjectList();
1002
> 	for (std::list<TuioObject*>::iterator iter=objectList.begin(); iter != objectList.end(); iter++) {
1003
> 		if((*iter)->getSessionID()==s_id) {
1004
> 			unlockObjectList();
1005
> 			return (*iter);
1006
> 		}
1007
> 	}	
1008
> 	unlockObjectList();
1009
> 	return NULL;
1010
910,915c533,556
1011
< std::list<TuioHand*> TuioClient::getTuioHands()
1012
< {
1013
<     lockHandList();
1014
<     std::list<TuioHand*> listBuffer = handList;
1015
<     unlockHandList();
1016
<     return listBuffer;
1017
---
1018
> TuioCursor* TuioClient::getTuioCursor(long s_id) {
1019
> 	lockCursorList();
1020
> 	for (std::list<TuioCursor*>::iterator iter=cursorList.begin(); iter != cursorList.end(); iter++) {
1021
> 		if((*iter)->getSessionID()==s_id) {
1022
> 			unlockCursorList();
1023
> 			return (*iter);
1024
> 		}
1025
> 	}	
1026
> 	unlockCursorList();
1027
> 	return NULL;
1028
> }
1029
> 
1030
> std::list<TuioObject*> TuioClient::getTuioObjects() {
1031
> 	lockObjectList();
1032
> 	std::list<TuioObject*> listBuffer = objectList;
1033
> 	unlockObjectList();
1034
> 	return listBuffer;
1035
> }
1036
> 
1037
> std::list<TuioCursor*> TuioClient::getTuioCursors() {
1038
> 	lockCursorList();
1039
> 	std::list<TuioCursor*> listBuffer = cursorList;
1040
> 	unlockCursorList();
1041
> 	return listBuffer;
1042
917d557
1043
<