示例#1
0
void TUIOInputDevice::processAlive(ReceivedMessageArgumentStream& args, 
        Event::Source source)
{
    std::set<int> liveTUIOIDs;
    int32 tuioID;
    while (!args.Eos()) {
        args >> tuioID;
        liveTUIOIDs.insert(tuioID);
    }

    // Create up events for all ids not in live list.
    set<int> deadTUIOIDs;
    getDeadIDs(liveTUIOIDs, deadTUIOIDs, source);
    set<int>::iterator it;
    for (it = deadTUIOIDs.begin(); it != deadTUIOIDs.end(); ++it) {
        int id = *it;
        TouchStatusPtr pTouchStatus = getTouchStatus(id);
        CursorEventPtr pOldEvent = pTouchStatus->getLastEvent();
        CursorEventPtr pUpEvent = pOldEvent->cloneAs(Event::CURSOR_UP);
        pTouchStatus->pushEvent(pUpEvent);
        removeTouchStatus(id);
    }
}
示例#2
0
void test1()
{
    const char s[] = "/test\0\0\0,fiT\0\0\0\0\0\0\0\0\0\0\0A";
    char *buffer = NewMessageBuffer( s, sizeof(s)-1 );

    // test argument iterator interface
    bool unexpectedExceptionCaught = false;
    try{
        ReceivedMessage m( ReceivedPacket(buffer, sizeof(s)-1) );

        assertEqual( std::strcmp( m.AddressPattern(), "/test" ), 0 );
        assertEqual( std::strcmp( m.TypeTags(), "fiT" ), 0 );
        
        ReceivedMessage::const_iterator i = m.ArgumentsBegin();
        ++i;
        ++i;
        ++i;
        assertEqual( i, m.ArgumentsEnd() );

        i = m.ArgumentsBegin();
        float f = (i++)->AsFloat();
        (void)f;
        int n = (i++)->AsInt32();
        (void)n;
        bool b = (i++)->AsBool();
        (void)b;
        
        i = m.ArgumentsBegin();
        bool exceptionThrown = false;
        try{
            int n = (i++)->AsInt32();
            (void)n;
        }catch( Exception& ){
            exceptionThrown = true;
        }
        assertEqual( exceptionThrown, true );

    }catch( Exception& e ){
        std::cout << "unexpected exception: " << e.what() << "\n";
        unexpectedExceptionCaught = true;
    }
    assertEqual( unexpectedExceptionCaught, false );


    // test argument stream interface
    unexpectedExceptionCaught = false;
    try{
        ReceivedMessage m( ReceivedPacket(buffer, sizeof(s)-1) );
        ReceivedMessageArgumentStream args = m.ArgumentStream();
        assertEqual( args.Eos(), false );

        float f;
        int32 n;
        bool b;
        args >> f >> n >> b;

        (void) f;
        (void) n;
        (void) b;
        
        assertEqual( args.Eos(), true );

    }catch( Exception& e ){
        std::cout << "unexpected exception: " << e.what() << "\n";
        unexpectedExceptionCaught = true;
    }
    assertEqual( unexpectedExceptionCaught, false );
}
void TuioClient::ProcessMessage( const ReceivedMessage& msg, const IpEndpointName& remoteEndpoint) {
	try {
		ReceivedMessageArgumentStream args = msg.ArgumentStream();
		ReceivedMessage::const_iterator arg = msg.ArgumentsBegin();
		
		if( strcmp( msg.AddressPattern(), "/tuio/2Dobj" ) == 0 ){
			
			const char* cmd;
			args >> cmd;
			
			if (strcmp(cmd,"set")==0) {	
				
				if (currentTime.getTotalMilliseconds()==0)
					currentTime = TuioTime::getSessionTime();
								
				int32 s_id, c_id;
				float xpos, ypos, angle, xspeed, yspeed, rspeed, maccel, raccel;
				args >> s_id >> c_id >> xpos >> ypos >> angle >> xspeed >> yspeed >> rspeed >> maccel >> raccel;
				
				lockObjectList();
				std::list<TuioObject*>::iterator tobj;
				for (tobj=objectList.begin(); tobj!= objectList.end(); tobj++)
					if((*tobj)->getSessionID()==(long)s_id) break;
				
				if (tobj == objectList.end()) {
					TuioObject *addObject = new TuioObject(currentTime,(long)s_id,(int)c_id,xpos,ypos,angle);
					objectList.push_back(addObject);
					
					for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
						(*listener)->addTuioObject(addObject);
					
				} 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) ) {

					TuioObject *updateObject = new TuioObject(currentTime,(long)s_id,(*tobj)->getSymbolID(),xpos,ypos,angle);
					updateObject->update(currentTime,xpos,ypos,angle,xspeed,yspeed,rspeed,maccel,raccel);
					frameObjects.push_back(updateObject);
				
					/*(*tobj)->update(currentTime,xpos,ypos,angle,xspeed,yspeed,rspeed,maccel,raccel);
					for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
						(*listener)->updateTuioObject((*tobj));*/
				}
				unlockObjectList();
			} else if (strcmp(cmd,"alive")==0) {
				
				int32 s_id;
				while(!args.Eos()) {
					args >> s_id;
					objectBuffer.push_back((long)s_id);
					
					std::list<long>::iterator iter;
					iter = find(aliveObjectList.begin(), aliveObjectList.end(), (long)s_id); 
					if (iter != aliveObjectList.end()) aliveObjectList.erase(iter);
				}
				
				std::list<long>::iterator alive_iter;
				for (alive_iter=aliveObjectList.begin(); alive_iter != aliveObjectList.end(); alive_iter++) {
					lockObjectList();
					std::list<TuioObject*>::iterator tobj;
					for (tobj=objectList.begin(); tobj!=objectList.end(); tobj++) {
						TuioObject *deleteObject = (*tobj);
						if(deleteObject->getSessionID()==*alive_iter) {
							objectList.erase(tobj);
							deleteObject->remove(currentTime);
							for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
								(*listener)->removeTuioObject(deleteObject);
							delete deleteObject;
							break;
						}
					}
					unlockObjectList();
				}
				aliveObjectList = objectBuffer;
				objectBuffer.clear();
			} else if (strcmp(cmd,"fseq")==0) {
				
				int32 fseq;
				args >> fseq;
				bool lateFrame = false;
				if (fseq>0) {
					if ((fseq>=currentFrame) || ((currentFrame-fseq)>100)) currentFrame = fseq;
					else lateFrame = true;
				}
			
				if (!lateFrame) {
					
					for (std::list<TuioObject*>::iterator iter=frameObjects.begin(); iter != frameObjects.end(); iter++) {
						TuioObject *tobj = (*iter);
						TuioObject *updateObject = getTuioObject(tobj->getSessionID());
						updateObject->update(currentTime,tobj->getX(),tobj->getY(),tobj->getAngle(),tobj->getXSpeed(),tobj->getYSpeed(),tobj->getRotationSpeed(),tobj->getMotionAccel(),tobj->getRotationAccel());
						
						for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
							(*listener)->updateTuioObject(updateObject);
						
						delete tobj;
					}
					
					for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
						(*listener)->refresh(currentTime);
					
					if (fseq>0) currentTime.reset();
				} else {
					for (std::list<TuioObject*>::iterator iter=frameObjects.begin(); iter != frameObjects.end(); iter++) {
						TuioObject *tobj = (*iter);
						delete tobj;
					}
				}
				
				frameObjects.clear();
				
				/*TuioTime ftime = TuioTime::getSystemTime();
				long ft = ftime.getSeconds()*1000000 + ftime.getMicroseconds();
				if (currentFrame>0) std:: cout << "received frame " << currentFrame << " " << ft  << std::endl;*/
			}