plz help me about CTimeOutTimer..

Login to reply to this topic.
Mon, 2005-05-02 04:33
Joined: 2005-03-08
Forum posts: 18
hi,

you probably know  the periodic example from  sdk examples..
whole day i ve worked on adding a new timer which is CTimeOutTimer to this periodic timer...

i wanna only make to add this CTimeOutTimer timer and after a duration write hello in the console.Also the priority of CTimeOutTimer must be higher than the CPeriodic timer...

This is the code for Cperiodic timer:

class TAppRunner
   {
public:
   TAppRunner();
   void NotifyFinished(); // notify an active object has finished
   void NotifyStarted(); // notify an active object has started
// private:
   TInt iActiveObjects; // count of active objects
   };

TAppRunner::TAppRunner()
   {
   iActiveObjects=0;
   }

void TAppRunner::NotifyStarted()
   {
   iActiveObjects++;
   }

void TAppRunner::NotifyFinished()
   {
   iActiveObjects--;
   if (iActiveObjects==0) CActiveScheduler::Stop();
   }


class CPeriodicRunner : public CBase
   {
public:
   // construct, add CPeriodic to active scheduler, and start it
   static CPeriodicRunner* NewL(TInt aTickInterval, TInt aTotalTicks, TAppRunner& aAppRunner);
   ~CPeriodicRunner(); // destruct and give statistics
protected:
   CPeriodicRunner(TInt aTickInterval, TInt aTotalTicks, TAppRunner& aAppRunner);
private:
   void ConstructL(); // second construction phase
   // functions for TCallBack protocol
   static TInt Tick(TAny* aObject); // directly called
   void DoTick(); // indirectly called
private:
   // constructor parameters
   TAppRunner& iAppRunner; // notify when started and finished
   TInt iTotalTicks; // number of ticks requested
   TInt iTickInterval; // the tick interval in microseconds
   // things set up by ConstructL
   TTime iStartTime; // when we were started
   CPeriodic* iPeriodic; // periodic timer active object
   // ticks left will be decremented as we go
   TInt iTicksLeft; // number of ticks before we expire
   TInt iTimerNumber; // indentifying number for the timer
   // seed for random delay generator
   TInt64 iDelaySeed;
   };

// protected C++ constructor
CPeriodicRunner::CPeriodicRunner(TInt aTickInterval, TInt aTotalTicks, TAppRunner& aAppRunner)
   : iAppRunner(aAppRunner), iTotalTicks(aTotalTicks), iTickInterval(aTickInterval)
   {}

// private second-phase constructor
void CPeriodicRunner::ConstructL()
   {
   iStartTime.HomeTime();
   iPeriodic=CPeriodic::NewL(0); // neutral priority
   iAppRunner.NotifyStarted();
   iTimerNumber = iAppRunner.iActiveObjects; // set idenfifying number for timer
   iTicksLeft = iTotalTicks;
   // variable (actually 1 second) delay and interval
   iPeriodic->Start(iTickInterval,iTickInterval,TCallBack(Tick, this));
   }

// construct, add CPeriodic to active scheduler, and start it
CPeriodicRunner* CPeriodicRunner::NewL(TInt aTickInterval, TInt aTotalTicks, TAppRunner& aAppRunner)
   {
   CPeriodicRunner* self=new (ELeave) CPeriodicRunner(aTickInterval, aTotalTicks, aAppRunner);
   CleanupStack::PushL(self);
   self->ConstructL();
   CleanupStack::Pop();
   return self;
   }

// destruct and give statistics
CPeriodicRunner::~CPeriodicRunner()
   {
   TTimeIntervalMicroSeconds elapsedTime;
   TTime currentTime;
   // set current time
   currentTime.HomeTime(); // set currentTime to now
   // find and show elapsed time & ticks
   elapsedTime = currentTime.MicroSecondsFrom(iStartTime);
   // NOTE - Int64() returns a const reference.
   //        GetTInt() is a non const function - hence the need to
   //        copy the returned TInt64.
   TInt64 a = elapsedTime.Int64();
   _LIT(KFormat1,"Periodic timer %d finished: %dus for %d %dus ticks\n");
   console->Printf(KFormat1,iTimerNumber,a.GetTInt(),iTotalTicks,iTickInterval);
   //  cancel any outstanding request; delete owned CPeriodic object
   iPeriodic->Cancel();
   delete iPeriodic;
   // tell app runner we've finished (if we're last, scheduler will stop)
   iAppRunner.NotifyFinished();
   }

// private
TInt CPeriodicRunner::Tick(TAny* aObject)
   {
   ((CPeriodicRunner*)aObject)->DoTick(); // cast, and call non-static function
   return 1;
   }

// private
void CPeriodicRunner::DoTick()
   {
   iTicksLeft--;
   _LIT(KFormat2,"Periodic timer %d: %d ticks done\n");
   console->Printf(KFormat2, iTimerNumber, iTotalTicks - iTicksLeft);
   if(iTicksLeft==0)
      {
      delete this;
      }
   RandomDelay(iDelaySeed,iTimerNumber); // a random delay to mess up the timing
   }


////////////////////////////////////////////////////////////////


where i must add the decleration of CTimeOutTimer, and where i must call the timeout funtion that  write hello in console???

i ve examine many examples such as scketengine,animation...
But i did not get it...As the examples are used in GUI app, but i use these timers in exe...

plz help me...

Tue, 2005-09-06 13:40
Joined: 2004-06-18
Forum posts: 20
Re: plz help me about CTimeOutTimer..
The class u want to write hello, have to be an observer of CTimeOutTimer -> MTimeOutNotifier, so the class implements the method iTimerExpired() where u write your hello. This means that u create an CTimeOutTimer and give the timeout class the reference to the hello class when creating the timeout objet. In the RunL u simply call iTimerExpired of the hello class and write hello. The priority for the timeout can u decide when creating the timeout object.

Christian
Thu, 2007-12-20 13:39
Joined: 2007-10-26
Forum posts: 36
Re: plz help me about CTimeOutTimer..

Can u help me in writing the code for setting expiry time for any app.

Thu, 2007-12-20 14:12
NewLC AdministratorSymbian AccreditedForum Nokia Champion
Joined: 2003-01-14
Forum posts: 1918
Re: plz help me about CTimeOutTimer..

This has probably nothing to do with a timeout timer.

Such generic question cannot been answered through a forum. Think by yourself, take a look at other applications or hire a consultant to help you.


Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant

  • Login to reply to this topic.