|
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 the License "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "consolealarmalertsession.h" |
|
17 |
|
18 // System includes |
|
19 |
|
20 #include "e32svr.h" |
|
21 // User includes |
|
22 #include "asaltdefs.h" |
|
23 //#include "..\..\Test\ConsoleANTestClient.h" |
|
24 // |
|
25 #include "consolealarmalertsession.h" |
|
26 #include "consolealarmalertconsole.h" |
|
27 #include "consolealarmalertledflasher.h" |
|
28 #include "consolealarmalertserver.h" //for inter-session communication |
|
29 |
|
30 // Type definitions |
|
31 |
|
32 // Constants |
|
33 const TInt KSlot0 = 0; |
|
34 const TInt KSlot1 = 1; |
|
35 const TInt KSlot2 = 2; |
|
36 |
|
37 // Enumerations |
|
38 |
|
39 // Classes referenced |
|
40 |
|
41 |
|
42 /////////////////////////////////////////////////////////////////////////////////////// |
|
43 // ----> CConsoleAlarmAlertSession (source) |
|
44 /////////////////////////////////////////////////////////////////////////////////////// |
|
45 |
|
46 //************************************************************************************* |
|
47 CConsoleAlarmAlertSession::CConsoleAlarmAlertSession(CConsoleAlarmAlertServer* aServer) |
|
48 : iServer(aServer), iInstructionSet(NULL), iInstructionSetFound(EFalse) |
|
49 { |
|
50 } |
|
51 |
|
52 |
|
53 //************************************************************************************* |
|
54 CConsoleAlarmAlertSession::~CConsoleAlarmAlertSession() |
|
55 { |
|
56 CConsoleAlarmAlertSession* session = iServer->WaitingSession(); |
|
57 session = NULL; |
|
58 delete iSoundLEDFlasher; |
|
59 delete iSoundCallbackTimer; |
|
60 delete iConsole; |
|
61 } |
|
62 |
|
63 |
|
64 //************************************************************************************* |
|
65 void CConsoleAlarmAlertSession::ConstructL() |
|
66 { |
|
67 iSoundLEDFlasher = CConsoleAlarmAlertLEDFlasher::NewL(); |
|
68 iSoundCallbackTimer = CPeriodic::NewL(CActive::EPriorityIdle); |
|
69 iConsole = new(ELeave) CConsoleAlarmAlertConsole(*this); |
|
70 } |
|
71 |
|
72 |
|
73 //************************************************************************************* |
|
74 CConsoleAlarmAlertSession* CConsoleAlarmAlertSession::NewL(CConsoleAlarmAlertServer* aServer) |
|
75 { |
|
76 CConsoleAlarmAlertSession* self = new(ELeave) CConsoleAlarmAlertSession(aServer); |
|
77 CleanupStack::PushL(self); |
|
78 self->ConstructL(); |
|
79 CleanupStack::Pop(self); |
|
80 return self; |
|
81 } |
|
82 |
|
83 |
|
84 /////////////////////////////////////////////////////////////////////////////////////// |
|
85 /////////////////////////////////////////////////////////////////////////////////////// |
|
86 /////////////////////////////////////////////////////////////////////////////////////// |
|
87 |
|
88 |
|
89 //************************************************************************************* |
|
90 TTime CConsoleAlarmAlertSession::DeferTime() const |
|
91 { |
|
92 return iDeferTime; |
|
93 } |
|
94 |
|
95 |
|
96 //************************************************************************************* |
|
97 void CConsoleAlarmAlertSession::Notify(TASAltAlertServerResponse aFlag) |
|
98 { |
|
99 if (iHasMessage) |
|
100 { |
|
101 iMsgPtr.Complete(aFlag); |
|
102 iHasMessage = EFalse; |
|
103 } |
|
104 } |
|
105 |
|
106 |
|
107 //************************************************************************************* |
|
108 void CConsoleAlarmAlertSession::Notify(TASAltAlertServerResponse aFlag, const TTime& aDeferTime) |
|
109 { |
|
110 if (iHasMessage) |
|
111 { |
|
112 TPckgC<TTime> time(aDeferTime); |
|
113 TRAPD(err, iMsgPtr.WriteL(KSlot0, time)); |
|
114 __ASSERT_DEBUG(err == KErrNone, User::Invariant()); |
|
115 Notify(aFlag); |
|
116 } |
|
117 } |
|
118 |
|
119 |
|
120 /////////////////////////////////////////////////////////////////////////////////////// |
|
121 /////////////////////////////////////////////////////////////////////////////////////// |
|
122 /////////////////////////////////////////////////////////////////////////////////////// |
|
123 |
|
124 |
|
125 //************************************************************************************* |
|
126 void CConsoleAlarmAlertSession::ServiceL(const RMessage2& aMessage) |
|
127 { |
|
128 iMsgComplete = ETrue; |
|
129 const TInt function = aMessage.Function(); |
|
130 |
|
131 //see if the server holds a set of instructions to be followed, |
|
132 //rather than waiting for user input. |
|
133 if(!iInstructionSetFound) //go look for it now. |
|
134 { |
|
135 //we will enter into this code only once |
|
136 const CServer2* tmpServ = Server(); |
|
137 const CConsoleAlarmAlertServer* specific = reinterpret_cast<const CConsoleAlarmAlertServer*>(tmpServ); |
|
138 iInstructionSet = const_cast<CConsoleAlarmAlertServer*>(specific)->ResponseArray(); |
|
139 iInstructionSetFound = ETrue; |
|
140 } |
|
141 |
|
142 // |
|
143 switch(function) |
|
144 { |
|
145 case EASAltOpCodeNotify: |
|
146 { |
|
147 __ASSERT_ALWAYS(!iHasMessage, User::Invariant()); |
|
148 iMsgComplete = EFalse; |
|
149 iMsgPtr = aMessage; |
|
150 iHasMessage = ETrue; |
|
151 CConsoleAlarmAlertSession* session = iServer->WaitingSession(); |
|
152 session = this; |
|
153 break; |
|
154 } |
|
155 |
|
156 case EASAltOpCodeNotifyCancel: |
|
157 if (iHasMessage) |
|
158 { |
|
159 iHasMessage=EFalse; |
|
160 iMsgPtr.Complete(KErrCancel); |
|
161 } |
|
162 break; |
|
163 |
|
164 case EASAltOpCodeVisible: |
|
165 { |
|
166 TBool isVisible = aMessage.Int0(); |
|
167 iConsole->SetVisibility(isVisible); |
|
168 iServer->SetNotifying(isVisible); |
|
169 break; |
|
170 } |
|
171 |
|
172 case EASAltOpCodeSetState: |
|
173 iConsole->SetAlertState(aMessage.Int0()); |
|
174 break; |
|
175 |
|
176 case EASAltOpCodeSetAlarm: |
|
177 SetAlarmL(aMessage); |
|
178 iConsole->iTimeInterval=0; |
|
179 iConsole->UpdateDisplay(); |
|
180 break; |
|
181 |
|
182 case EASAltOpCodeGetUserTime: |
|
183 GetUserTimeL(aMessage); |
|
184 break; |
|
185 |
|
186 case EASAltOpCodeSetDeferTime: |
|
187 SetDeferTimeL(aMessage); |
|
188 iConsole->UpdateDisplay(); |
|
189 break; |
|
190 |
|
191 case EASAltOpCodeLogon: |
|
192 __ASSERT_ALWAYS(!iLoggedOn, User::Invariant()); |
|
193 iMsgComplete=EFalse; |
|
194 iLoggedOn=ETrue; |
|
195 break; |
|
196 |
|
197 case EASAltOpCodeStartPlayingSound: |
|
198 { |
|
199 iSoundLEDFlasher->Start(); |
|
200 TCallBack callback(SoundPlaybackCallbackL, this); |
|
201 iSoundCallbackTimer->Start(TTimeIntervalMicroSeconds32(0), TTimeIntervalMicroSeconds32(3000000), callback); |
|
202 break; |
|
203 } |
|
204 |
|
205 case EASAltOpCodeStopPlayingSound: |
|
206 iSoundLEDFlasher->Stop(); |
|
207 iSoundCallbackTimer->Cancel(); |
|
208 break; |
|
209 |
|
210 #if 0 |
|
211 //Test code |
|
212 case EASAltTestOpCodeAcknowledgeAlarm: |
|
213 if (iServer->WaitingSession()) |
|
214 iServer->WaitingSession()->Notify(EASAltAlertServerResponseClear); |
|
215 break; |
|
216 |
|
217 case EASAltTestOpCodeGetAttachment: |
|
218 { |
|
219 if (iServer->Attachment() != NULL) |
|
220 { |
|
221 const TDes8& data = iServer->Attachment()->Des(); |
|
222 const TInt maxLength = static_cast<TInt>(aMessage.Int0()); |
|
223 if (data.Size() > maxLength) |
|
224 User::Panic(_L("Client's buffer is too short"), KErrOverflow); |
|
225 else |
|
226 { |
|
227 if (data.Length() == 0) |
|
228 { |
|
229 _LIT8(KEmpty,"Empty"); |
|
230 aMessage.WriteL(KSlot1, KEmpty); |
|
231 } |
|
232 else |
|
233 { |
|
234 aMessage.WriteL(KSlot1, data); |
|
235 } |
|
236 iServer->SetAttachment(NULL); |
|
237 } |
|
238 } |
|
239 } |
|
240 break; |
|
241 |
|
242 case EASAltTestOpCodeGetIsNotifying: |
|
243 { |
|
244 TPckgC<TBool> ret = iServer->IsNotifying(); |
|
245 aMessage.WriteL(KSlot0, ret); |
|
246 break; |
|
247 } |
|
248 #endif |
|
249 default: |
|
250 User::Invariant(); |
|
251 break; |
|
252 } |
|
253 |
|
254 if (iMsgComplete) |
|
255 aMessage.Complete(KErrNone); |
|
256 } |
|
257 |
|
258 |
|
259 /////////////////////////////////////////////////////////////////////////////////////// |
|
260 /////////////////////////////////////////////////////////////////////////////////////// |
|
261 /////////////////////////////////////////////////////////////////////////////////////// |
|
262 |
|
263 |
|
264 //************************************************************************************* |
|
265 TBool CConsoleAlarmAlertSession::CmdL() |
|
266 { |
|
267 return KErrNone; |
|
268 } |
|
269 |
|
270 |
|
271 /////////////////////////////////////////////////////////////////////////////////////// |
|
272 /////////////////////////////////////////////////////////////////////////////////////// |
|
273 /////////////////////////////////////////////////////////////////////////////////////// |
|
274 |
|
275 |
|
276 //************************************************************************************* |
|
277 void CConsoleAlarmAlertSession::SetAlarmL(const RMessage2& aMessage) |
|
278 { |
|
279 TPckg<TASShdAlarm> pA(iAlarm); |
|
280 aMessage.ReadL(KSlot0, pA); |
|
281 if (iAlarm.HasAssociatedData()) |
|
282 { |
|
283 iAlarmAssociatedDataSize = aMessage.GetDesLength(2); |
|
284 TPckg<TAgnAlarmInfo> pB(iAlarmData); |
|
285 aMessage.ReadL(KSlot2, pB); |
|
286 |
|
287 //Storing the data in the server for the test session to read.. |
|
288 HBufC8* data = HBufC8::NewLC(iAlarmAssociatedDataSize); |
|
289 TPtr8 pData(data->Des()); |
|
290 aMessage.ReadL(KSlot2, pData); |
|
291 iServer->SetAttachment(data); //Server takes an ownership |
|
292 CleanupStack::Pop(data); |
|
293 } |
|
294 else |
|
295 iAlarmAssociatedDataSize = 0; |
|
296 } |
|
297 |
|
298 |
|
299 //************************************************************************************* |
|
300 void CConsoleAlarmAlertSession::GetUserTimeL(const RMessage2& aMessage) |
|
301 { |
|
302 TTime time; |
|
303 time.HomeTime(); |
|
304 time+=TTimeIntervalMinutes(iConsole->GetTimeInterval()); |
|
305 TPtrC8 pTime((TUint8 *)&time,sizeof(TTime)); |
|
306 aMessage.WriteL(KSlot0,pTime); |
|
307 } |
|
308 |
|
309 |
|
310 //************************************************************************************* |
|
311 void CConsoleAlarmAlertSession::SetDeferTimeL(const RMessage2& aMessage) |
|
312 { |
|
313 TPckg<TTime> pTime(iDeferTime); |
|
314 aMessage.ReadL(KSlot0, pTime); |
|
315 } |
|
316 |
|
317 |
|
318 //************************************************************************************* |
|
319 TBool CConsoleAlarmAlertSession::SoundPlaybackCallbackL(TAny* /*aSelf*/) |
|
320 { |
|
321 // _LIT(KPlayingSound, "Playing sound"); |
|
322 // User::InfoPrint(KPlayingSound); |
|
323 return ETrue; |
|
324 } |
|
325 |
|
326 //************************************************************************************** |
|
327 TAny * CConsoleAlarmAlertSession::InstructionSet() |
|
328 { |
|
329 return iInstructionSet; |
|
330 } |