|
1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "ASAltEventHandler.h" |
|
17 |
|
18 // User includes |
|
19 #include <asaltdefs.h> |
|
20 #include "ASAltClientSession.h" |
|
21 #include "ASAltAlarmAlertObserver.h" |
|
22 #include "ASSrvStaticUtils.h" |
|
23 #include "ASAltRequestQuietPeriodEnd.h" |
|
24 |
|
25 // |
|
26 // ----> CASAltEventHandler (source) |
|
27 // |
|
28 |
|
29 //************************************************************************************* |
|
30 CASAltEventHandler::CASAltEventHandler(RASAltClientSession& aSession, MASAltAlarmAlertObserver& aObserver) |
|
31 : CActive(EPriorityUserInput), iSession(aSession), iObserver(aObserver) |
|
32 { |
|
33 CActiveScheduler::Add(this); |
|
34 } |
|
35 |
|
36 |
|
37 //************************************************************************************* |
|
38 CASAltEventHandler::~CASAltEventHandler() |
|
39 { |
|
40 Cancel(); |
|
41 delete iRequestQuietPeriodEnd; |
|
42 } |
|
43 |
|
44 |
|
45 //************************************************************************************* |
|
46 void CASAltEventHandler::ConstructL() |
|
47 { |
|
48 iRequestQuietPeriodEnd=CASAltRequestQuietPeriodEnd::NewL(iSession,iObserver); |
|
49 RequestEvents(); |
|
50 } |
|
51 |
|
52 |
|
53 //************************************************************************************* |
|
54 CASAltEventHandler* CASAltEventHandler::NewL(RASAltClientSession& aSession, MASAltAlarmAlertObserver& aObserver) |
|
55 { |
|
56 CASAltEventHandler* self = new(ELeave) CASAltEventHandler(aSession, aObserver); |
|
57 CleanupStack::PushL(self); |
|
58 self->ConstructL(); |
|
59 CleanupStack::Pop(self); |
|
60 return self; |
|
61 } |
|
62 |
|
63 |
|
64 // |
|
65 // |
|
66 // |
|
67 |
|
68 |
|
69 //************************************************************************************* |
|
70 /** |
|
71 * Request events from the Alarm Alert Server |
|
72 */ |
|
73 void CASAltEventHandler::RequestEvents() |
|
74 { |
|
75 __ASSERT_DEBUG(!IsActive(), ASSrvStaticUtils::Fault(ASSrvStaticUtils::EASSrvFaultAlarmAlertServerResponseReaderAlreadyActive)); |
|
76 |
|
77 Session().NotifyOnResponse(iStatus, iTimeValueFromAlarmAlertServer, iAlarmId); |
|
78 SetActive(); |
|
79 } |
|
80 |
|
81 |
|
82 // |
|
83 // |
|
84 // |
|
85 |
|
86 |
|
87 //************************************************************************************* |
|
88 void CASAltEventHandler::RunL() |
|
89 { |
|
90 const TInt response = iStatus.Int(); |
|
91 if ( response == KErrCancel |
|
92 || response == KErrServerTerminated) // if Alarm Alert Server dies, don't ask |
|
93 // for any further information from it |
|
94 return; |
|
95 |
|
96 // Request any further events from the server. Do this now so that |
|
97 // we don't miss anything whilst processing this event. |
|
98 RequestEvents(); |
|
99 |
|
100 switch(response) |
|
101 { |
|
102 // The Alarm Alert Server requested that alarm of the returned alarm id be silenced |
|
103 case EASAltAlertServerResponseSilence: |
|
104 Observer().ASAltSilenceCurrentAlarm(iAlarmId); |
|
105 break; |
|
106 |
|
107 // Clear the current alarm and setup ready for the next pending alarm |
|
108 case EASAltAlertServerResponseClear: |
|
109 Observer().ASAltAcknowledgeAlarm(MASAltAlarmAlertObserver::EAcknowledgeCurrentAlarm, iAlarmId); |
|
110 break; |
|
111 |
|
112 // Clears all alarms in the due que |
|
113 case EASAltAlertServerResponseClearAll: |
|
114 Observer().ASAltAcknowledgeAlarm(MASAltAlarmAlertObserver::EAcknowledgeAllAlarms, iAlarmId); |
|
115 break; |
|
116 |
|
117 // The Alarm Alert Server requested that all alarms are quiet until the specified time |
|
118 case EASAltAlertServerResponseQuietPeriod: |
|
119 { |
|
120 iRequestQuietPeriodEnd->RequestQuietPeriodEnd(); |
|
121 } |
|
122 break; |
|
123 |
|
124 // The Alarm Alert Server requested that sound playing is paused until |
|
125 // the specified time. When requested, we also need to reset the cycle |
|
126 // count back to zero (since the user requested this snooze, rather |
|
127 // than it being an automatic one). |
|
128 case EASAltAlertServerResponsePauseSound: |
|
129 Observer().ASAltPauseSoundUntil(iTimeValueFromAlarmAlertServer, iAlarmId); |
|
130 break; |
|
131 |
|
132 // The Alarm Alert Server requested that the alarm is snoozed until the specified time |
|
133 case EASAltAlertServerResponseSnooze: |
|
134 Observer().ASAltSnoozeAlarmUntil(iTimeValueFromAlarmAlertServer, iAlarmId); |
|
135 break; |
|
136 |
|
137 case KErrServerBusy: |
|
138 // Simply try again |
|
139 break; |
|
140 |
|
141 default: |
|
142 __ASSERT_DEBUG(EFalse, ASSrvStaticUtils::Fault(ASSrvStaticUtils::EASSrvFaultInvalidAlarmAlertServerResponse)); |
|
143 break; |
|
144 } |
|
145 } |
|
146 |
|
147 //************************************************************************************* |
|
148 void CASAltEventHandler::DoCancel() |
|
149 { |
|
150 if (Session().Handle() == KNullHandle) |
|
151 { |
|
152 TRequestStatus* status = &iStatus; |
|
153 User::RequestComplete(status, KErrCancel); |
|
154 } |
|
155 else |
|
156 { |
|
157 Session().NotifyOnResponseCancel(); |
|
158 } |
|
159 } |
|
160 |
|
161 |
|
162 // |
|
163 // |
|
164 // |
|
165 |