OHJ-5500 Mobiiliohjelmointi, 5op

Exercise 6 - Active objects

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

Emulator



Download  application (zip file) that is used as a basis for the exercise.  The goal of the exercise if to create an CActive object and get circles moving by pressing start-command.

Part 1
Download Player application and study how the active objects are used. How active object is created and how the  methods RunL, DoCancel, RunError are implemented?  Where it is added to the control of the CActiveScheduler? How the two phase construction has been implemented of this active object?

Part 2
Try out creating your own active object.
  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.