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

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.
- Define your CActive based class in a new header file. The name
could be, for example, CAnimationAgent (engine project).
- Add the usual constructors, destructors, implement two
phased construction for the class.
- Remember to add the active object under the control of
the active scheduler in the end of ConstructL.
- Add the RTimer object as an attribute to the CAnimationAgent.
Remember to #include the correct header file for this
- 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!
- 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!
- 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.
- In RunL, call AnimObserver::Animate to make pieces move.
- 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.
- Remember to add the call to Cancel in the destructor of the
CAnimationAgent, also Close the RTimer in the destructor after
cancelling.
- Add the CAnimationAgent as an attribute (pointer) to the
CAeng class.
- Create the active object in the ConstructL of
the CAeng
- When the animation start, call the
StartAnimation.
- When animation is stopped, call Cancel of the CAnimation agent to
cancel the animation.