void BaseTween::testRelaunch()
 {
     if (!isIterationStep && repeatCnt >= 0 && step < 0 && currentTime+deltaTime >= 0)
     {
         assert(step == -1);
         isIterationStep = true;
         step = 0;
         float delta = 0-currentTime;
         deltaTime -= delta;
         currentTime = 0;
         callCallback(TweenCallback::BEGIN);
         callCallback(TweenCallback::START);
         updateOverride(step, step-1, isIterationStep, delta);
         
     }
     else if (!isIterationStep && repeatCnt >= 0 && step > repeatCnt*2 && currentTime+deltaTime < 0)
     {
         assert(step == repeatCnt*2 + 1);
         isIterationStep = true;
         step = repeatCnt*2;
         float delta = 0-currentTime;
         deltaTime -= delta;
         currentTime = duration;
         callCallback(TweenCallback::BACK_BEGIN);
         callCallback(TweenCallback::BACK_START);
         updateOverride(step, step+1, isIterationStep, delta);
     }
 }
 void BaseTween::initialize() {
     if (currentTime+deltaTime >= delayStart)
     {
         initializeOverride();
         isInitializedFlag = true;
         isIterationStep = true;
         step = 0;
         deltaTime -= delayStart-currentTime;
         currentTime = 0;
         callCallback(TweenCallback::BEGIN);
         callCallback(TweenCallback::START);
     }
 }
void Msg35::gotReply ( UdpSlot *slot ) {
	// get the reply
	char *reply     = slot->m_readBuf;
	int32_t  replySize = slot->m_readBufSize;
	// don't let UdpServer free the send buffer
	slot->m_sendBufAlloc = NULL;
	// bitch if bad reply
	if ( ! g_errno && replySize != 1 ) g_errno = EBADREPLYSIZE;
	// on error we will try sending the request again via call to sync()
	if ( g_errno ) {
		log("merge: Received error reply when getting merge token: "
		    "%s.", mstrerror(g_errno));
		return;
	}
	// . sometimes we get it right away, without waiting
	// . get the client #
	int32_t n = reply[0];
	// -1 means we're waiting
	if ( n == -1 ) return;
	// debug msg
	log(LOG_DEBUG,"merge: msg35: Got merge token in reply.");
	// returns false and sets g_errno on error, true otherwise
	callCallback ( n );
}
void Msg35::handleRequest ( UdpSlot *slot ) {
	int32_t  requestSize = slot->m_readBufSize;
	char *request     = slot->m_readBuf;
	// . get request code
	// . REQUEST_GETTOKEN
	// . REQUEST_GIVETOKEN
	// . REQUEST_RELEASETOKEN
	// . REQUEST_SYNC

	// this is from manager to client, giving the token to the client
	if ( requestSize == 2 && *request == REQUEST_GIVETOKEN ) {
		// get the client #
		int32_t n = request[1];
		// debug msg
		log(LOG_INFO,"merge: Received merge token after waiting.");
		// . call the callback
		// . returns false and sets g_errno on error, true otherwise
		// . let manager know we received the token
		// . m_callback should call releaseToken() when done with it
		if ( ! callCallback ( n ) ) 
			g_udpServer.sendErrorReply ( slot , EBADREQUEST );
		else
			g_udpServer.sendReply_ass  ( NULL, 0, NULL, 0, slot );
		return;
	}
	// this is asking for the token, from the client to the manager
	if ( requestSize == 11 && *request == REQUEST_GETTOKEN ) {
		char *p          = request + 1;
		int32_t  hostId     = *(int32_t *)p ; p += 4;
		int32_t  timestamp  = *(int32_t *)p ; p += 4;
		char  priority   = *p         ; p += 1;
		int32_t  clientSlot = *p         ; p += 1;
		// see if a repeat request
		for ( int32_t i = 0 ; i < m_topUsedServer ; i++ ) {
			ServerWait *s = &m_serverWaits[i];
			if ( s->m_isEmpty                  ) continue;
			if ( s->m_hostId     != hostId     ) continue;
			if ( s->m_clientSlot != clientSlot ) continue;
			// it might be a priority update
			s->m_priority = priority;
			// we might have just sent them the token, they
			// released it and called again for another slot,
			// but we clean out the serverWait when we do that
			// right? ... ? well we remove the request from the
			// server table BEFORE sending the GIVETOKEN so that
			// these repeats should not happen legitimately
			log(LOG_LOGIC,"merge: msg35: Got repeat request "
			    "for token.");
			char *p = s->m_buf;
			*p = -1;
			g_udpServer.sendReply_ass  ( p , 1, NULL , 0 , slot );
			return;
		}
		// add him to our queue
		int32_t w = addServerWait ( hostId , priority , clientSlot ,
					 timestamp );
		// return error if failed
		if ( w < 0 ) {
			g_udpServer.sendErrorReply ( slot , EBUFTOOSMALL );
			return;
		}
		// otherwise, see if we can give him the token right now
		ServerWait *s = &m_serverWaits[w];
		p = s->m_buf;
		// if nobody has token now, give it to our client now
		if ( m_serverTokeni == -1 ) {
			*p = clientSlot;
			m_serverTokeni = w;
			// always exit discrepancy mode on token re-assignment
			m_discrepancyHid = -1;
		}
		// otherwise, he has to wait for it to be released from another
		else 
			*p = -1;
		g_udpServer.sendReply_ass  ( p , 1, NULL , 0 , slot );
		return;
	}
	// this is asking to release token, from the client to the manager
	if ( requestSize == 1 && *request == REQUEST_RELEASETOKEN ) {
		// TODO: mdw: ensure we think releaser has the token?
		int32_t w = m_serverTokeni;
		// ensure someone is actually holding the token
		if ( w < 0 ) {
			log(LOG_LOGIC,"merge: msg35: Host released token "
			    "to us, but he did not hold it anyway.");
			g_udpServer.sendReply_ass  ( NULL, 0, NULL, 0, slot );
			return;
		}
		// free the token
		m_serverTokeni = -1;
		// always exit discrepancy mode on token re-assignment
		m_discrepancyHid = -1;
		// empty the slot
		removeServerWait ( w );
		// send acknowledgement, empty reply
		g_udpServer.sendReply_ass  ( NULL, 0 , NULL , 0 , slot );
		// give the token to the next in line, if any
		giveToken();
		return;
	}
	// this is asking us to sync with the client, from client to manager
	if ( requestSize >= 1 && *request == REQUEST_SYNC ) {
		// get hostid of the requesting client
		int32_t hid = *(int32_t *)(&request[1]);
		// mark the sync as received for this hostId so that once
		// we get syncs from all hostids in our group we can give
		// the token to one
		if ( ! m_allReceived ) {
			int32_t numHosts;
			//Host **h = g_hostdb.getTokenGroup (g_hostdb.m_hostId,
			//				    &numHosts ) ;
			Host **h = NULL;
			//Host **h = getTokenGroup(&numHosts);
			if ( numHosts > 16 ) {
				log(LOG_LOGIC,
				    "merge: msg35: too many hosts in group.");
				char *xx = NULL; *xx = 0;
				numHosts = 16;
			}
			int32_t count = 0;
			for ( int32_t i = 0 ; i < numHosts ; i++ ) {
				if ( h[i]->m_hostId == hid ) m_flags[i] = true;
				if ( m_flags[i] ) count++;
			}
			if ( count == numHosts ) m_allReceived = true;
		}
		// clear out all his token requests from our table
		for ( int32_t i = 0 ; i <= m_topUsedServer ; i++ )
			if ( m_serverWaits[i].m_hostId == hid )
				removeServerWait ( i );
		// . client's version of who has the token relative to his tble
		// . is -1 if nobody in his table has it
		int32_t clientTokeni = *(int32_t *)(&request[5]);
		// does this guy think he has the token?
		int32_t newi = -1;
		// add the server waits back in for this hostid
		char *p = &request[9];
		char *pend = request + requestSize;
		while ( p + 6 <= pend ) {
			int32_t timestamp  = *(int32_t *)p ; p += 4;
			char priority   = *p         ; p += 1;
			char clientSlot = *p         ; p += 1;
			if ( clientSlot < 0 ) {
				log(LOG_LOGIC,"merge: msg35: bad clientSlot.");
				continue;
			}
			int32_t a = addServerWait ( hid, priority, clientSlot ,
						 timestamp );
			// if this request is reported by client to have the
			// token now, then remember its slot # in OUR table,
			// slot # "newi"
			if ( a >= 0 && clientSlot == clientTokeni )
				newi = a;
		}
		// sanity check
		if ( p != pend )
			log(LOG_LOGIC,"merge: msg35: p != pend, bad engineer."
			    "diff = %"INT32".",
			    (int32_t)(pend - p));
			
		// . what HOSTID do we think has the token? 
		// . set tokenHid to -1 if we don't think anybody has it
		int32_t tokenHid = -1;
		if ( m_serverTokeni >= 0 ) 
			tokenHid = m_serverWaits[m_serverTokeni].m_hostId;
		// . if we do not think client has the token but he says he
		//   does then believe him, maybe we just came online
		// . if this info is not accurate it will be corrected in
		//   call to sync()
		if  ( tokenHid != hid && newi >= 0 ) {
			log("merge: HostId #%"INT32" claims he "
			    "has the merge token. Giving it to him.",hid);
			m_serverTokeni = newi;
			// always exit discrepancy mode on token re-assignment
			m_discrepancyHid = -1;
		}
		// if we think he's got the token and he does too, we might
		// have assigned it to a different bucket when re-adding the
		// requests using addServerWait() above
		else if ( tokenHid == hid && newi >= 0 ) {
			m_serverTokeni = newi;
			// always exit discrepancy mode on token re-assignment
			m_discrepancyHid = -1;
		}
		// if we think he has the token but he says he does not
		// then it may be because we just sent it to him, so wait 
		// until HIS next sync before actually updating m_serverTokeni
		else if ( tokenHid == hid && newi == -1 ) {
			// if we are already in discrepancy for someone else...
			if ( m_discrepancyHid >= 0 && 
			     m_discrepancyHid != hid ) {
				log(LOG_INFO,
				    "merge: Host #%"INT32" says he "
				    "does not have the merge token, "
				    "but already in "
				    "discrepancy mode for host #%"INT32". "
				    "Reassigning.", hid, m_discrepancyHid);
				// we need to re-assign to prevent token lockup
				m_discrepancyHid = hid;
			}
			// if we aren't already in discrepancy mode... enter it
			else if ( m_discrepancyHid != hid ) {
				log(LOG_INFO,"merge: Entering "
				    "discrepancy mode for host #%"INT32"",hid);
				// this is >= 0 when in discrepancy mode
				m_discrepancyHid = hid;
			}
			// . if we were already in discrepancy mode for him
			//   and this is his follow up sync, AND he STILL 
			//   claims not to have the token, then believe him 
			//   this time
			// . it may be the case that he did have it, but 
			//   released it right after and we ran into this
			//   situation again... but if that was the case then
			//   our m_serverTokeni would have been changed
			//   and anytime that happens we exit discrepancy mode
			else {
				log(LOG_INFO,
				    "merge: Leaving discrepancy mode. "
				    "Merge token unassigned.");
				// leave the mode
				m_discrepancyHid = -1;
				// unassign the token
				m_serverTokeni = -1;
			}
		}

		// send acknowledgement, empty reply
		g_udpServer.sendReply_ass  ( NULL, 0 , NULL , 0 , slot );
		// call giveToken() in case we need to give it because it
		// was unassigned due to a discrepancy
		giveToken();
		return;
	}

	// bitch and return if a bad request
	log(LOG_LOGIC, "merge: Received bad merge token related request "
	    "of %"INT32" bytes.",requestSize );
	g_udpServer.sendErrorReply ( slot , EBADREQUESTSIZE );
}
	void AnimationTask::execute(unsigned long timeDelta)
	{
		double deltaSec;
		std::list<memUInt> finishedAnimations;
		std::list<memUInt>::iterator finishedAnimationsIter;
		AnimationMapIterator iter;
		Value val;

		if (getState() != TS_RUNNING)
		{
			setState(TS_RUNNING);
		}

		// Dispatch all waiting messages of this task
		NotificationManager::getSingleton().dispatchQueuedNotifications((memUInt) this);

		deltaSec = ((double) timeDelta) / MICROSECONDS_IN_SECOND;

		{
			Poco::ScopedRWLock lock(mRWLockActiveAnimations, false);
			// Update animations
			for (iter = activeAnimations.begin(); iter != activeAnimations.end(); ++iter)
			{
				AnimationMapValueEntry entry = iter->second;
				Ogre::AnimationState *animationState = entry.first;

				// Check if the animation has ended, and add it to a list of animations to be removed from the active list
				if ((animationState->hasEnded()) || (!animationState->getEnabled()))
				{
					finishedAnimations.push_back(iter->first);
					animationState->setEnabled(false);

					// If the animation has a stop callback, call it
					callCallback(animationState, &mStopCallbacks);
				}
				else
				{
					// Add the time since the last update to the animation
					animationState->addTime(deltaSec);

					// Check if this animation is just starting, if it is call its start callback
					if (mStartingAnimations.erase(reinterpret_cast<memUInt>(animationState)) == 1)
					{
						callCallback(animationState, &mStartCallbacks);
					}
				}
			}
		}

		mStartingAnimations.clear();

		{
			Poco::ScopedRWLock lock(mRWLockActiveAnimations, true);
			Poco::ScopedRWLock lockCallbacks(mRWLockCallbacks, true);

			// Remove the animations that have ended from the list of active animations
			for (finishedAnimationsIter = finishedAnimations.begin(); finishedAnimationsIter != finishedAnimations.end(); ++finishedAnimationsIter)
			{
				memUInt animationAddress = *finishedAnimationsIter;
				activeAnimations.erase(animationAddress);

				// Remove any callbacks associated with this animation
				mStartCallbacks.erase(animationAddress);
				mStopCallbacks.erase(animationAddress);
			}
		}
	}
 void BaseTween::updateStep()
 {
     while (isValid(step))
     {
         if (!isIterationStep && currentTime+deltaTime <= 0)
         {
             isIterationStep = true;
             step -= 1;
             
             float delta = 0-currentTime;
             deltaTime -= delta;
             currentTime = duration;
             
             if (isReverse(step)) forceStartValues();
             else forceEndValues();
             callCallback(TweenCallback::BACK_START);
             updateOverride(step, step+1, isIterationStep, delta);
             
         }
         else if (!isIterationStep && currentTime+deltaTime >= repeatDelay)
         {
             isIterationStep = true;
             step += 1;
             
             float delta = repeatDelay-currentTime;
             deltaTime -= delta;
             currentTime = 0;
             
             if (isReverse(step)) forceEndValues(); else forceStartValues();
             callCallback(TweenCallback::START);
             updateOverride(step, step-1, isIterationStep, delta);
             
         }
         else if (isIterationStep && currentTime+deltaTime < 0)
         {
             isIterationStep = false;
             step -= 1;
             
             float delta = 0-currentTime;
             deltaTime -= delta;
             currentTime = 0;
             
             updateOverride(step, step+1, isIterationStep, delta);
             callCallback(TweenCallback::BACK_END);
             
             if (step < 0 && repeatCnt >= 0) callCallback(TweenCallback::BACK_COMPLETE);
             else currentTime = repeatDelay;
             
         }
         else if (isIterationStep && currentTime+deltaTime > duration)
         {
             isIterationStep = false;
             step += 1;
             
             float delta = duration-currentTime;
             deltaTime -= delta;
             currentTime = duration;
             
             updateOverride(step, step-1, isIterationStep, delta);
             callCallback(TweenCallback::END);
             
             if (step > repeatCnt*2 && repeatCnt >= 0) callCallback(TweenCallback::COMPLETE);
             currentTime = 0;
             
         }
         else if (isIterationStep)
         {
             float delta = deltaTime;
             deltaTime -= delta;
             currentTime += delta;
             updateOverride(step, step, isIterationStep, delta);
             break;
             
         }
         else
         {
             float delta = deltaTime;
             deltaTime -= delta;
             currentTime += delta;
             break;
         }
     }
 }
Example #7
0
void Connection::closeConnectionError(int error)
{
	closeConnection();
	m_state = STATE_ERROR;
	callCallback(error);
}