TInt DExampleChannel::DoCancel(TUint /*aMask*/)
{
    if (iAsyncGetValueStatus)
    {
        iAsyncGetValueTimer.Cancel();
        iAsyncGetValueDfc.Cancel();
        Kern::RequestComplete(iClient, iAsyncGetValueStatus, KErrCancel);
    }

    if (iAsyncGetValue2Status)
    {
        iAsyncGetValue2Timer.Cancel();
        iAsyncGetValue2Dfc.Cancel();
        Kern::RequestComplete(iClient, iAsyncGetValue2Status, KErrCancel);
    }

    if (iReadStatus)
    {
        iReadTimer.Cancel();
        iCompleteReadDfc.Cancel();
        Kern::RequestComplete(iClient, iReadStatus, KErrCancel);
    }

    if (iWriteStatus)
    {
        iWriteTimer.Cancel();
        iCompleteWriteDfc.Cancel();
        Kern::RequestComplete(iClient, iWriteStatus, KErrCancel);
    }

    return KErrNone;
}
Example #2
0
//============================================================================
//		NThreadUtilities::DelayFunctor : Delay a functor.
//----------------------------------------------------------------------------
void NThreadUtilities::DelayFunctor(const NFunctor &theFunctor, NTime theDelay, bool onMainThread)
{	NTimer		*theTimer;



	// Invoke immediately
	//
	// If we're to invoke on a new thread, or are already on the main
	// thread, we can invoke the functor directly without any delay.
	//
	// If we can't (we have a delay or we're not the main thread but
	// the functor must execute on the main thread), we fall through
	// to the timer case.
	if (NMathUtilities::IsZero(theDelay))
		{
		if (!onMainThread)
			{
			DetachFunctor(theFunctor);
			return;
			}
		
		else if (NThread::IsMain())
			{
			theFunctor();
			return;
			}
		}



	// Invoke with a delay
	theTimer = new NTimer;
	if (theTimer != NULL)
		theTimer->AddTimer(BindFunction(NThreadUtilities::DelayedFunctor, theTimer, theFunctor, onMainThread), theDelay);
}
void
ActivateRadar()
{
    radarActive = true;
    radarTimer.reset();
    ConsoleInterface::postMessage(Color::unitAqua, false, 0, "YOU GOT AN ENEMY RADAR POWERUP" );
}
Example #4
0
TInt DMediaDriverFlashWin32::DoWrite()
	{
	if (iReadReq)
		return 1;	// read in progress so defer write

	if (iState==EErasePending)
		{
		iTimer.Cancel();
		iState = ESuspended;
		}
	if (iState==EIdle || iState==ESuspended)
		{
		// can start the write now
		__KTRACE_OPT(KLOCDRV,Kern::Printf("Flash:Write Pos=%08x Length=%08x RemDesOff=%08x",
											(TInt)iWriteReq->Pos(),(TInt)iWriteReq->Length(),iWriteReq->RemoteDesOffset()));
		if (iState==EIdle)
			iState=EWriting;
		TInt pos = (TInt)iWriteReq->Pos();
		TInt end = pos + (TInt)iWriteReq->Length();
		pos &= ~(iWriteBlockSize-1);
		end = (end + iWriteBlockSize-1) & ~(iWriteBlockSize-1);
		StartTimer(((end-pos)/iWriteBlockSize) * iWriteTime);
		}
	else if (iState==EErase)
		{
		// erase in progress - suspend it
		SuspendErase();
		}
	else if (iState==EEraseNoSuspend)
		iState=ESuspendPending;
	// wait for suspend to complete
	return KErrNone;
	}
Example #5
0
TInt DMediaDriverFlashWin32::DoRead()
	{
	if (iWriteReq)
		return 1;	// write in progress so defer read
	
	__KTRACE_OPT(KLOCDRV,Kern::Printf("Flash:DoRead"));

	if (iState==EErasePending)
		{
		iTimer.Cancel();
		iState = ESuspended;
		}
	if (iState==EIdle || iState==ESuspended)
		{
		// can do the read now
		TInt pos=(TInt)iReadReq->Pos();
		TInt len=(TInt)iReadReq->Length();

		TPtrC8 des(iBase+pos,len);
		TInt r=iReadReq->WriteRemote(&des,0);
		Complete(EReqRead,r);
		if (iState==ESuspended)
			StartErase();
		}
	else if (iState==EErase)
		{
		// erase in progress - suspend it
		SuspendErase();
		}
	else if (iState==EEraseNoSuspend)
		iState=ESuspendPending;
	// wait for suspend to complete
	return KErrNone;
	}
Example #6
0
void DmacSim::StartEmulation()
	{
	__DMA_ASSERTA(StartStop==EDmaSimIdle);
	new (&Timer) NTimer(&TickCB, 0);
	__e32_atomic_store_ord32(&StartStop, EDmaSimStarted);
	__DMA_ASSERTA(Timer.OneShot(KPeriod, EFalse) == KErrNone);
	}
bool
EnemyRadarPowerUp::isRadarActive()
{
    if ( radarActive && radarTimer.isTimeOut() )
    {
        radarActive = false;
    }
    return radarActive;
}
TInt DExampleChannel::StartAsyncGetValue(TInt* aValue, TRequestStatus* aStatus)
{
    iAsyncGetValueDest = aValue;
    iAsyncGetValueStatus = aStatus;

    // queue a timer to simulate an asynchronous operation
    iAsyncGetValueTimer.OneShot(KAsyncDelay, iAsyncGetValueDfc);
    return KErrNone;
}
TInt DExampleChannel::StartAsyncGetValue2(TInt* aValue1, TInt* aValue2, TRequestStatus* aStatus)
{
    iAsyncGetValue2Dest1 = aValue1;
    iAsyncGetValue2Dest2 = aValue2;
    iAsyncGetValue2Status = aStatus;

    // queue a timer to simulate an asynchronous operation
    iAsyncGetValue2Timer.OneShot(KAsyncDelay, iAsyncGetValue2Dfc);
    return KErrNone;
}
Example #10
0
void DmacSim::TickCB(TAny*)
	{
	TInt orig = (TInt)__e32_atomic_ior_acq32(&StartStop, EDmaSimInISR);
	if (orig >= 0)
		{
		DmacSb::DoTransfer();
		DmacDb::DoTransfer();
		DmacSg::DoTransfer();
		}
	orig = (TInt)__e32_atomic_and_rel32(&StartStop, (TUint32)~EDmaSimInISR);
	if (orig < 0)
		{
		__e32_atomic_store_rel32(&StartStop, EDmaSimIdle);
		return;
		}
	TInt r = Timer.Again(KPeriod);
	if (r == KErrArgument)
		r = Timer.OneShot(KPeriod);
	__DMA_ASSERTA(r == KErrNone);
	}
Example #11
0
void DmacSim::StopEmulation()
	{
	TInt orig = __e32_atomic_tas_ord32(&StartStop, (TInt)EDmaSimStarted, (TInt)EDmaSimStopping, 0);
	if (orig == EDmaSimIdle)
		return;		// wasn't running
	// loop until we succeed in cancelling the timer or the timer callback
	// notices that we are shutting down
	while (!Timer.Cancel() && __e32_atomic_load_acq32(&StartStop)!=EDmaSimIdle)
		{}
	__e32_atomic_store_ord32(&StartStop, EDmaSimIdle);
	}
bool
DedicatedGameManager::mainLoop()
{
    if ( heartbeat )
        heartbeat->checkHeartbeat();

    static NTimer aktimer(10000); //all 10 sec only
    if (aktimer.isTimeOut())
    {
        aktimer.reset();
        PlayerState * player = 0;
        unsigned long max_players;
        max_players = PlayerInterface::getMaxPlayers();
        for (unsigned long i = 0; i < max_players; i++)
        {
            player = PlayerInterface::getPlayer((unsigned short) i);
            if ( player->isActive() )
            {
                if ( player->checkAutokick() )
                {
                    char chat_string[256];
                    sprintf(chat_string, "Server kicked '%s' due to inactivity",player->getName().c_str());
                    LOGGER.info("DED: %s", chat_string);
                    ChatInterface::serversay(chat_string);
                    SERVER->kickClient((PlayerID)i);

                }
            }

        }
        if (VoteManager::checkVoteTimer())
        {
            VoteManager::checkPlayersVote();
        }
    }
    return BaseGameManager::mainLoop();
}
Example #13
0
TInt DBMLChannel::RequestNTimerJitterInterrupt()
	{
	if (!iStarted)
		{
		return KErrNotReady;
		}
	if (iPendingInterruptRequest) 
		{
		return KErrInUse;
		}
	iPendingInterruptRequest = ETrue;
	iNTimerShotCount = 0;
	iNTimer.OneShot(1);
	return KErrNone;
	}
void
WorldInputCmdProcessor::evalRightMButtonEvents(const MouseEvent& event)
{
    static NTimer mtimer(75);
    if (event.event == MouseEvent::EVENT_DOWN )
    {
        right_mouse_scroll=true;
        right_mouse_scroll_moved = false;
        right_mouse_scroll_pos=event.pos;
        right_mouse_scrolled_pos.x=right_mouse_scrolled_pos.y=0;
        mtimer.reset();
    }
    
    if (right_mouse_scroll && event.event == MouseEvent::EVENT_UP )
    {
        right_mouse_scroll=false;
        if ( ! right_mouse_scroll_moved && mtimer.isTimeOut() )
        {
            // simple right click on the same position after timeout
            working_list.unGroup();
        }
        return;
    }
}
Example #15
0
TInt DPowerManager::PowerDown()
	{ // called by ExecHandler 
	__KTRACE_OPT(KPOWER,Kern::Printf(">PowerManger::PowerDown(0x%x) Enter", iPowerController->iTargetState));
	__ASSERT_CRITICAL;

	Lock();


	if (iPowerController->iTargetState == EPwActive)
		{
		Unlock();
		return KErrNotReady;
		}

    __PM_ASSERT(iHandlers);
	NFastSemaphore shutdownSem(0);
	NTimer ntimer;
	TDfc dfc(ShutDownTimeoutFn, &shutdownSem);
#ifndef _DEBUG_POWER	
	iPendingShutdownCount = 0;
#endif	
	DPowerHandler* ph = iHandlers;
	//Power down in reverse order of handle registration.
	do
		{
#ifdef _DEBUG_POWER
		__PM_ASSERT(!(ph->iStatus & DPowerHandler::EDone));
#endif
		ph->iSem = &shutdownSem; 
		ph->PowerDown(iPowerController->iTargetState);
#ifndef _DEBUG_POWER		
		iPendingShutdownCount++; 
#else
		if(iPslShutdownTimeoutMs>0)
			{
		    // Fire shut down timeout timer			
			ntimer.OneShot(iPslShutdownTimeoutMs, dfc);
			}

		NKern::FSWait(&shutdownSem);	// power down drivers one after another to simplify debug
		__e32_atomic_and_ord32(&(ph->iStatus), ~DPowerHandler::EDone);

		// timeout condition
		if(iPslShutdownTimeoutMs>0 && ph->iSem)
			{
			__e32_atomic_store_ord_ptr(&ph->iSem, 0);
			}
		ntimer.Cancel();
#endif		
		ph = ph->iPrev;
		}while(ph != iHandlers);

#ifndef _DEBUG_POWER
	if(iPslShutdownTimeoutMs>0)
		{
		// Fire shut down timeout timer
		ntimer.OneShot(iPslShutdownTimeoutMs, dfc);
		}

	ph = iHandlers;
	do
		{
		NKern::FSWait(&shutdownSem);
		if(__e32_atomic_load_acq32(&iPendingShutdownCount)==ESHUTDOWN_TIMEOUT)
			{
			iPendingShutdownCount = 0;
			NKern::Lock();
			shutdownSem.Reset(); // iPendingShutdownCount could be altered while ShutDownTimeoutFn is running
		       			     // reset it to make sure shutdownSem is completely clean.	
			NKern::Unlock();
			break;
			}
		__e32_atomic_add_ord32(&iPendingShutdownCount, (TUint)(~0x0)); // iPendingShutDownCount--;
		ph = ph->iPrev;
		}while(ph != iHandlers);

	ntimer.Cancel();
	
#endif

	TTickQ::Wait();

	iPowerController->PowerDown(K::SecondQ->WakeupTime());
	__PM_ASSERT(iPowerController->iTargetState != EPwOff);
	iPowerController->iTargetState = EPwActive;

	K::SecondQ->WakeUp();
	TTickQ::Signal();

	NFastSemaphore powerupSem(0);

	ph = iHandlers->iNext;
	//Power up in same order of handle registration.
	do
		{
#ifdef _DEBUG_POWER
		__PM_ASSERT(!(ph->iStatus & DPowerHandler::EDone));
#endif
		ph->iSem = &powerupSem;
		ph->PowerUp();
#ifdef _DEBUG_POWER
		NKern::FSWait(&powerupSem);	// power down drivers one after another to simplify debug
		__PM_ASSERT(!ph->iSem);
		__PM_ASSERT(ph->iStatus & DPowerHandler::EDone);
		ph->iStatus &= ~DPowerHandler::EDone;
#endif
		ph = ph->iNext;
		}while(ph != iHandlers->iNext);

#ifndef _DEBUG_POWER
	ph = iHandlers->iNext;
	do
		{
		NKern::FSWait(&powerupSem);
		ph = ph->iNext;
		}while(ph != iHandlers->iNext);
#endif

	// complete wakeup notification request if any
	NotifyWakeupEvent(KErrNone); 

	Unlock();

	__KTRACE_OPT(KPOWER,Kern::Printf("<PowerManger::PowerDown() Leave"));

	return KErrNone;
	}	
Example #16
0
TInt DNE1Keypad::DoCreate()
	{
	iKeyboardTimer.OneShot(KKeybPollTime, ETrue);
	return KErrNone;
	}
void DExampleChannel::SendFromWriteBuffer()
{
    // just queue a timer to simulate an asynchronous send operation
    iWriteTimer.OneShot(KAsyncDelay, iCompleteWriteDfc);
}
void DExampleChannel::ReceiveToReadBuffer()
{
    // just queue a timer to simulate an asynchronous receive operation
    // actually will return the previous contents of the buffer
    iReadTimer.OneShot(KAsyncDelay, iCompleteReadDfc);
}
void
WorldInputCmdProcessor::evalLeftMButtonEvents(const MouseEvent &event)
{
    iXY world_pos;
    unsigned char click_status;

    WorldViewInterface::clientXYtoWorldXY(world_win, event.pos, &world_pos);

    if ( (manual_control_state == true) ||
            KeyboardInterface::getKeyState( SDLK_LCTRL ) ||
            KeyboardInterface::getKeyState( SDLK_RCTRL )
       )
    {

        if (event.event == MouseEvent::EVENT_DOWN )
        {
            sendManualFireCommand( world_pos );
        }

    }
    else if (event.event == MouseEvent::EVENT_DOWN)
    {
        Objective *objective = 0;
        click_status = ObjectiveInterface::quearyObjectiveLocationStatus(
            world_pos, PlayerInterface::getLocalPlayerIndex(), &objective);
	
        if ( click_status == _player_occupied_objective_found )
        {
            selection_box_active = false;
            outpost_goal_selection = objective->objective_state.ID;
            output_pos_press = objective->objective_state.location; 
        }
        else
        {
            box_press = world_pos;
            box_release = world_pos;
            selection_box_active = true;
        }
    }
    else if(event.event == MouseEvent::EVENT_UP)
    {
        if (selection_box_active)
        {
            selection_box_active = false;
            box_release = world_pos;
            if(abs(box_release.x - box_press.x) > 3
		    && abs(box_release.y - box_press.y) > 3)
            {
                return;
            }
        }
        
        if (outpost_goal_selection != OBJECTIVE_NONE )
        {
            Objective *objective = 0;
            int cs = ObjectiveInterface::quearyObjectiveLocationStatus(
                    world_pos, PlayerInterface::getLocalPlayerIndex(),
                    &objective);
            
            if ( (cs == _player_occupied_objective_found) 
                    && outpost_goal_selection == objective->objective_state.ID
               )
            {
                // we've let go of the mouse on the building so we're
                //  not changing the spawn point
                selected_objective_id = objective->objective_state.ID;
                activateVehicleSelectionView( selected_objective_id );
            }
            else
            {
                TerminalOutpostOutputLocRequest term_mesg;
                
                term_mesg.output_loc_request.set( outpost_goal_selection,
                        world_pos);
                
                CLIENT->sendMessage(&term_mesg, sizeof(TerminalOutpostOutputLocRequest));

                if ( NetworkState::status == _network_state_client )
                {    
                    ObjectiveInterface::sendMessage( &(term_mesg.output_loc_request) );
                }
            }
            outpost_goal_selection = OBJECTIVE_NONE;
            return;
        }
        
        click_status = getCursorStatus(world_pos);
        switch(click_status)
        {
            case _cursor_player_unit:
            {
                static NTimer dclick_timer(200);
                static int click_times = 0;
                bool addunits = false;
                if( (KeyboardInterface::getKeyState(SDLK_LSHIFT) == true) ||
                        (KeyboardInterface::getKeyState(SDLK_RSHIFT) == true))
                {
                    addunits = true;
                }
                if ( ! dclick_timer.isTimeOut() )
                {
                    if ( click_times )
                    {
                        iRect wr;
                        WorldViewInterface::getViewWindow(&wr);
                        working_list.selectBounded(wr, addunits);
                        click_times=0;
                    }
                    else
                    {
                        working_list.selectSameTypeVisible(world_pos,addunits);
                        dclick_timer.reset();
                        click_times++;
                    }
                    break;
                }
                else if (addunits)
                {
                    working_list.addUnit(world_pos);
                }
                else
                {
                    working_list.selectUnit(world_pos );
                }

                current_selection_list_bits=0;
                current_selection_list_index = 0xFFFF;
                if (working_list.unit_list.size() > 0)
                {
                    UnitBase *unit = UnitInterface::getUnit(
                            working_list.unit_list[0]);
                    if(unit)
                        unit->soundSelected();
                }
                dclick_timer.reset();
                click_times=0;
                break;
            }
            case _cursor_move:
            case _cursor_blocked:
                if(outpost_goal_selection == OBJECTIVE_NONE)
                    sendMoveCommand(world_pos);
                break;

            case _cursor_enemy_unit:
                sendAttackCommand(world_pos);
                break;

            case _cursor_make_allie:
                sendAllianceRequest(world_pos, true);
                break;

            case _cursor_break_allie:
                sendAllianceRequest(world_pos, false);
                break;
        }
    }
}