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.
- 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.