Prev: Advanced Concepts
Alarm Server Example
The concepts of this chapter are illustrated by developing a module accessing the Symbian "alarm server". The client API to this server is the Symbian class RASCliSession. AlarmModule.cpp contains the complete source of the module and is also part of the NMI SDK.
We call our module alarm. And again, after studying the services offered by the alarm server API, we specify it:
- Alarms are identified by integers (TAlarmId is a TInt).
- The module alarm should provide the following functions:
- alarm.add(msg,due,sound=null)→Number adds an alarm with message, due time and optional sound file and returns the id of the new alarm.
- alarm.all()→Array returns the ids of all known alarms.
- alarm.delete(id)→null deletes the alarm with the given id.
- alarm.get(id)→null returns some data about the alarm with the given id, as an array with the following members:
| Key | Contents |
| msg | The message text of the alarm. |
| due | The next due time of the alarm. |
| sound | The sound file played when the alarm expires. |
| enabled | Whether the alarm is enabled. |
| |
- alarm.on(id, enabled)→null enables or disables an alarm.
- alarm.wait(timeout=-1)→Number waits up to timeout milliseconds for the next alarm to expire and returns its id. If timeout is negative, it is ignored.
- The module should respect the permissions granted by the user: ReadApp for all alarm functions, WriteApp for the functions modifying alarm data.
From this spec, we can directly write the skeleton of our module:
#include "NativeModule.h"
#include <asclisession.h>
#include <asshdalarm.h>
class AlarmModule : public NativeModule {
private:
enum Functions {
AddFunction, AllFunction, DeleteFunction, GetFunction, OnFunction,
WaitFunction
};
RASCliSession session;
TASShdAlarm alarm;
// destroying the mod |