Mobiiliohjelmointi/Mobile programming

 

Exercise 5 – Active Objects

 

The topic of this exercise is active objects. More information on active objects can be found from here as well as the many books on Symbian OS programming

Download application:  Animation for SDK 3rd FP1(zip file) that is used as a basis for the exercise. NOTE:  if you are using older Symbian SDK, here is same application : Animation for  SDK 2nd FP 3

The goal of the exercise if to create a CActive object and get circles moving by pressing start-command.

  1. Define your CActive based class in a new header file. The name could be, for example, CAnimationAgent (engine project)
  2. Add the usual constructors, destructors, implement two phased construction for the class.
  3. Remember to add the active object under the control of the active scheduler in the end of ConstructL.
  4. Add the RTimer object as an attribute to the CAnimationAgent. Remember to #include the correct header file for this
  5. Initialize the RTimer in the ConstructL of CAnimationAgent. This is done by calling RTimer::CreateLocal. This can fail, so you should check the return value and LeaveIfError!
  6. Add a method to start the animation. This could be, for example, StartAnimation(1).  Use RTimer::After to request the asynchronous service from the Kernel server. Remember to set the active object active after requesting the asynch service!
  7. Implement the RunL, DoCancel and RunError to the active object. Remember to request the timer service again - you wish to get repeating timers, not just one timer. Remember again to set the active object active after calling RTimer::After.
  8. In RunL, call AnimObserver::Animate to make pieces move.
  9. In DoCancel, cancel the outstanding timer request of RTimer. In RunError, there is not really much to do in this example, just return the error code and let the active scheduler handle the errors.
  10. Remember to add the call to Cancel in the destructor of the CAnimationAgent, also Close the RTimer in the destructor after cancelling.
  11. Add the CAnimationAgent as an attribute (pointer) to the CAeng class.
  12. Create the active object in the ConstructL of the CAeng
  13. When the animation start, call the StartAnimation.
  14. When animation is stopped, call Cancel of the CAnimation agent to cancel the animation.