00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <e32base.h>
00033 #include <e32cons.h>
00034 #include <asshdalarm.h>
00035 #include <asclisession.h>
00036
00037
00038 #include "AlarmServerExample.h"
00039
00040
00041 static CConsoleBase* gConsole;
00042
00043 _LIT(KConsoleStars,"\n*************************");
00044
00045 CExampleAlarmServer* CExampleAlarmServer::NewL()
00046 {
00047 CExampleAlarmServer* self = new (ELeave) CExampleAlarmServer();
00048 CleanupStack::PushL(self);
00049 self->ConstructL();
00050 CleanupStack::Pop(self);
00051 return self;
00052 }
00053
00054 void CExampleAlarmServer::ConstructL()
00055 {
00056
00057 User::LeaveIfError(iAlarmServerSession.Connect());
00058 }
00059
00060 CExampleAlarmServer::~CExampleAlarmServer()
00061 {
00062 iAlarmServerSession.Close();
00063 }
00064
00065
00066 void CExampleAlarmServer::DisplayNotificationType(TAlarmChangeEvent aAlarmChangeEvent, TAlarmId )
00067 {
00068 switch (aAlarmChangeEvent)
00069 {
00070 case EAlarmChangeEventUndefined:
00071 _LIT(KConsoleMsg, "\nAn undefined alarm event has occurred.");
00072 gConsole->Printf(KConsoleMsg);
00073 break;
00074 case EAlarmChangeEventState:
00075 _LIT(KConsoleMsg1, "\nAn alarm has changed state.");
00076 gConsole->Printf(KConsoleMsg1);
00077 break;
00078 case EAlarmChangeEventStatus:
00079 _LIT(KConsoleMsg2, "\nAn alarm has changed status.");
00080 gConsole->Printf(KConsoleMsg2);
00081 break;
00082 case EAlarmChangeEventCharacteristics:
00083 _LIT(KConsoleMsg3, "\nAn alarm has changed characteristics..");
00084 gConsole->Printf(KConsoleMsg3);
00085 break;
00086 case EAlarmChangeEventAlarmDeletion:
00087 _LIT(KConsoleMsg4, "\nAn alarm has been deleted from the queue.");
00088 gConsole->Printf(KConsoleMsg4);
00089 break;
00090 case EAlarmChangeEventAlarmAddition:
00091 _LIT(KConsoleMsg5, "\nAn alarm has been added to the queue.");
00092 gConsole->Printf(KConsoleMsg5);
00093 break;
00094 case EAlarmChangeEventTimerExpired:
00095 _LIT(KConsoleMsg6, "\nAn alarm has expired.");
00096 gConsole->Printf(KConsoleMsg6);
00097 break;
00098 case EAlarmChangeEventSoundPlaying:
00099 _LIT(KConsoleMsg7, "\nThe sound for an alarm has just started playing.");
00100 gConsole->Printf(KConsoleMsg7);
00101 break;
00102 case EAlarmChangeEventSoundStopped:
00103 _LIT(KConsoleMsg8, "\nThe sound for an alarm has just stopped playing.");
00104 gConsole->Printf(KConsoleMsg8);
00105 break;
00106 case EAlarmChangeEventPlayIntervalsChanged:
00107 _LIT(KConsoleMsg9, "\nThe sound intervals associated with sound timing have changed.");
00108 gConsole->Printf(KConsoleMsg9);
00109 break;
00110 case EAlarmChangeEventGlobalSoundStateChanged:
00111 _LIT(KConsoleMsg10, "\nThe global sound state (on/off) has changed.");
00112 gConsole->Printf(KConsoleMsg10);
00113 break;
00114 case EAlarmChangeEventHeadQueueItemChanged:
00115 _LIT(KConsoleMsg11, "\nThe next alarm at the head of the alarm queue has changed.");
00116 gConsole->Printf(KConsoleMsg11);
00117 break;
00118 case EAlarmChangeEventSystemDateTimeChanged:
00119 _LIT(KConsoleMsg12, "\nThe system date or time has changed, or the days defined as workdays have changed.");
00120 gConsole->Printf(KConsoleMsg12);
00121 break;
00122 case EAlarmChangeEventAlarmUIVisible:
00123 _LIT(KConsoleMsg13, "\nThe alarm alert server has been instructed to show the 'alarm expired' display.");
00124 gConsole->Printf(KConsoleMsg13);
00125 break;
00126 case EAlarmChangeEventAlarmUIInvisible:
00127 _LIT(KConsoleMsg14, "\nThe alarm alert server has been instructed to hide the 'alarm expired' display.");
00128 gConsole->Printf(KConsoleMsg14);
00129 break;
00130 case EAlarmChangeEventSoundSilence:
00131 _LIT(KConsoleMsg15, "\nAlarm sounds have been temporarily silenced, the current alarm has been paused or re-enabled.");
00132 gConsole->Printf(KConsoleMsg15);
00133 break;
00134 case EAlarmChangeEventAlarmData:
00135 _LIT(KConsoleMsg16, "\nThe data associated with an alarm has changed.");
00136 gConsole->Printf(KConsoleMsg16);
00137 break;
00138 case EAlarmChangeEventRestoreStarted:
00139 _LIT(KConsoleMsg17, "\nA restore from backup of the alarm server has started. Alarms cannot be added/deleted until this has finished.");
00140 gConsole->Printf(KConsoleMsg17);
00141 break;
00142 case EAlarmChangeEventRestoreFailed:
00143 _LIT(KConsoleMsg18, "\nA restore from backup of the alarm server has failed. Alarms can be added/deleted again.");
00144 gConsole->Printf(KConsoleMsg18);
00145 break;
00146 case EAlarmChangeEventRestoreCompleted:
00147 _LIT(KConsoleMsg19, "\nA restore from backup of the alarm server has completed. The alarm queue has changed.");
00148 gConsole->Printf(KConsoleMsg19);
00149 break;
00150 case EAlarmChangeEventLast:
00151 _LIT(KConsoleMsg20, "\nLast change event (anchor). This is always at the end of the list.");
00152 gConsole->Printf(KConsoleMsg20);
00153 break;
00154 }
00155 }
00156
00157
00158
00159
00160 void CExampleAlarmServer::WaitForAlarmToBeCleared()
00161 {
00162 TAlarmChangeEvent alarmChangeEvent;
00163 do
00164 {
00165 TRequestStatus status;
00166 TAlarmId alarmId;
00167 iAlarmServerSession.NotifyChange(status, alarmId);
00168 User::WaitForRequest(status);
00169 alarmChangeEvent = static_cast<TAlarmChangeEvent>(status.Int());
00170 DisplayNotificationType(alarmChangeEvent,alarmId);
00171 }
00172
00173 while (alarmChangeEvent != EAlarmChangeEventAlarmUIInvisible);
00174 }
00175
00176
00177
00178 void CExampleAlarmServer::SetFloatingAlarmL()
00179 {
00180
00181
00182
00183
00184
00185
00186
00187
00188 _LIT(KConsoleMsg, "\nPress any key to add a floating alarm");
00189 gConsole->Printf(KConsoleMsg);
00190 _LIT(KConsoleMsg2,"\nWhen notification occurs, press Clear to continue");
00191 gConsole->Printf(KConsoleMsg2);
00192 gConsole->Getch();
00193 gConsole->Printf(KConsoleStars);
00194
00195 TASShdAlarm alarm;
00196 alarm.Category() = KASCliCategoryClock;
00197
00198 alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
00199 _LIT(KAlarmMessage,"\nThis is a floating alarm.");
00200 alarm.Message() = KAlarmMessage;
00201
00202 alarm.NextDueTime().HomeTime();
00203
00204
00205
00206 alarm.NextDueTime() -= TTimeIntervalSeconds(2);
00207
00208
00209 User::LeaveIfError(iAlarmServerSession.AlarmAdd(alarm));
00210
00211 WaitForAlarmToBeCleared();
00212 }
00213
00214
00215 void CExampleAlarmServer::DisplayAlarmState(TAlarmState aState)
00216 {
00217 switch (aState)
00218 {
00219 case EAlarmStateInPreparation:
00220 _LIT(KConsoleMsg1, "\nThe alarm state is not currently known by the alarm server..");
00221 gConsole->Printf(KConsoleMsg1);
00222 break;
00223 case EAlarmStateQueued:
00224 _LIT(KConsoleMsg2, "\nThe alarm is in the queue.");
00225 gConsole->Printf(KConsoleMsg2);
00226 break;
00227 case EAlarmStateSnoozed:
00228 _LIT(KConsoleMsg3, "\nThe alarm is snoozed. When the snooze period is over, the alarm expires again.");
00229 gConsole->Printf(KConsoleMsg3);
00230 break;
00231 case EAlarmStateWaitingToNotify:
00232 _LIT(KConsoleMsg4, "\nThe alarm is waiting to be notified.");
00233 gConsole->Printf(KConsoleMsg4);
00234 break;
00235 case EAlarmStateNotifying:
00236 _LIT(KConsoleMsg5, "\nThe alarm is currently notifying");
00237 gConsole->Printf(KConsoleMsg5);
00238 break;
00239 case EAlarmStateNotified:
00240 _LIT(KConsoleMsg6, "\nThe alarm has already notified and has been dismissed.");
00241 gConsole->Printf(KConsoleMsg6);
00242 break;
00243 }
00244 }
00245
00246
00247
00248
00249
00250
00251 void CExampleAlarmServer::AddFetchDeleteFixedAlarmL()
00252 {
00253 gConsole->Printf(KConsoleStars);
00254 _LIT(KConsoleMsg, "\nPress any key to add a fixed alarm");
00255 gConsole->Printf(KConsoleMsg);
00256 gConsole->Getch();
00257
00258 TASShdAlarm alarm;
00259 TAlarmCategory alarmCategory = KASCliCategoryClock;
00260 alarm.Category()=alarmCategory;
00261 _LIT(KAlarmMessage, "This is a fixed alarm");
00262 alarm.Message() = KAlarmMessage;
00263 _LIT(KAlarmSound, "Chimes");
00264 alarm.SoundName() = KAlarmSound;
00265
00266 alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
00267
00268 TTime time;
00269
00270 time.UniversalTime();
00271
00272 time += TTimeIntervalSeconds(2);
00273 alarm.SetUtcNextDueTime(time);
00274
00275
00276 User::LeaveIfError(iAlarmServerSession.AlarmAdd(alarm));
00277
00278
00279 const TAlarmId id = alarm.Id();
00280 TAlarmCategory category;
00281 User::LeaveIfError(iAlarmServerSession.GetAlarmCategory(id, category));
00282 User::LeaveIfError(iAlarmServerSession.GetAlarmDetails(id, alarm));
00283
00284 TAlarmState state = alarm.State();
00285 DisplayAlarmState(state);
00286
00287 TAlarmMessage message = alarm.Message();
00288 TBuf<256> messageBuf;
00289 messageBuf.Copy(message);
00290 _LIT(KConsoleMessage,"\nThe alarm's message is....:");
00291 gConsole->Printf(KConsoleMessage);
00292 gConsole->Printf(messageBuf);
00293
00294 TAlarmSoundName soundName = alarm.SoundName();
00295 messageBuf.Copy(soundName);
00296 _LIT(KConsoleSoundName,"\nThe alarm's sound name is ....:");
00297 gConsole->Printf(KConsoleSoundName);
00298 gConsole->Printf(messageBuf);
00299
00300 _LIT(KDeleteMsg, "\n\nPress any key to finish");
00301 gConsole->Printf(KDeleteMsg);
00302 gConsole->Getch();
00303
00304 User::LeaveIfError(iAlarmServerSession.AlarmDelete(id));
00305 }
00306
00307
00308 void CExampleAlarmServer::EgAlarmServerL()
00309 {
00310 SetFloatingAlarmL();
00311 AddFetchDeleteFixedAlarmL();
00312 }
00313
00314 static void DoExampleL()
00315 {
00316
00317 _LIT(KConsoleMessageDisplay, "Alarm Server Example");
00318 gConsole = Console::NewL(KConsoleMessageDisplay,TSize(KConsFullScreen,KConsFullScreen));
00319 CleanupStack::PushL(gConsole);
00320 gConsole->Printf(KConsoleMessageDisplay);
00321 gConsole->Printf(KConsoleStars);
00322
00323 CExampleAlarmServer* egAlarmServer= CExampleAlarmServer::NewL();
00324 TRAPD(err, egAlarmServer->EgAlarmServerL());
00325 if (err)
00326 {
00327 _LIT(KFailed,"\n\nExample failed: leave code=%d");
00328 gConsole->Printf(KFailed, err);
00329 gConsole->Getch();
00330 }
00331 delete egAlarmServer;
00332 CleanupStack::PopAndDestroy(gConsole);
00333 }
00334
00335
00336 TInt E32Main()
00337 {
00338 __UHEAP_MARK;
00339
00340 CActiveScheduler* scheduler=new CActiveScheduler;
00341
00342 if (scheduler)
00343 {
00344 CActiveScheduler::Install(scheduler);
00345
00346 CTrapCleanup* cleanup=CTrapCleanup::New();
00347 if (cleanup)
00348 {
00349 TRAP_IGNORE(DoExampleL());
00350 delete cleanup;
00351 }
00352 delete scheduler;
00353 }
00354 __UHEAP_MARKEND;
00355 return KErrNone;
00356 }