分类: C/C++
2009-08-05 10:17:17
#include "AlarmListener.h" #include _LIT(KAlarmMessage,"\nMY Alarm."); CAlarmListener* CAlarmListener::NewLC( MAlarmObserver& aObserver ) { CAlarmListener* self = new (ELeave) CAlarmListener(aObserver); CleanupStack::PushL(self); self->ConstructL(); return self; } CAlarmListener* CAlarmListener::NewL( MAlarmObserver& aObserver ) { CAlarmListener* self = CAlarmListener::NewLC(aObserver); CleanupStack::Pop(self); return self; } CAlarmListener::CAlarmListener( MAlarmObserver& aObserver ) : CActive(EPriorityStandard) // Standard priority , iObserver(aObserver) { } void CAlarmListener::ConstructL() { User::LeaveIfError(iAlarmServerSession.Connect()); CActiveScheduler::Add(this); // Add to scheduler } CAlarmListener::~CAlarmListener() { Cancel(); iAlarmServerSession.Close(); } void CAlarmListener::DoCancel() { iAlarmServerSession.NotifyChangeCancel(); } void CAlarmListener::StartL() { Cancel(); // Cancel any request, just to be sure iAlarmServerSession.NotifyChange(this->iStatus,iAlarmId); SetActive(); // Tell scheduler a request is active } void CAlarmListener::RunL() { TAlarmChangeEvent alarmChangeEvent = static_cast switch (alarmChangeEvent) { case EAlarmChangeEventTimerExpired: { TASShdAlarm alarmplaying; iAlarmServerSession.GetAlarmDetails(iAlarmId,alarmplaying); if(alarmplaying.Message().CompareF(KAlarmMessage) == 0) { TInt dState; TTime duetime = alarmplaying.NextDueTime(); TTime hometime; hometime.HomeTime(); if(hometime < duetime) { iAlarmServerSession.NotifyChange(this->iStatus,iAlarmId); SetActive(); return; } if(alarmplaying.RepeatDefinition() == EAlarmRepeatDefintionRepeatOnce) { User::LeaveIfError(iAlarmServerSession.AlarmDelete(iAlarmId)); iObserver.ResponseTimerExpiredL(EMyAlarmOnce); } else if(alarmplaying.RepeatDefinition() == EAlarmRepeatDefintionRepeatDaily) { User::LeaveIfError(iAlarmServerSession.AlarmDelete(iAlarmId)); iObserver.ResponseTimerExpiredL(EMyAlarmRepeat); TASShdAlarm alarm; alarm.Category() = KASCliCategoryClock; alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatDaily; alarm.Message() = KAlarmMessage; TTime temptime = alarmplaying.NextDueTime(); temptime += TTimeIntervalDays(1); alarm.NextDueTime() = temptime; User::LeaveIfError(iAlarmServerSession.AlarmAdd(alarm)); } } break; } default: break; } iAlarmServerSession.NotifyChange(this->iStatus,iAlarmId); SetActive(); // Tell scheduler a request is active } |