|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This class takes care of accessory events that should be |
|
15 * handled in alarm. I.e. stopping alarm using accessory end key. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include "alarmremconeventshandler.h" |
|
22 |
|
23 #include "AlmAlarmControl.h" |
|
24 #include <remconinterfaceselector.h> |
|
25 #include <RemConCallHandlingTarget.h> |
|
26 #include <RemConExtensionApi.h> |
|
27 |
|
28 |
|
29 // ======== MEMBER FUNCTIONS ======== |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // ?description_if_needed |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 CAlarmRemConEventsHandler* CAlarmRemConEventsHandler::NewL(CAlmAlarmControl& aAlarmUI) |
|
36 { |
|
37 TRACE_ENTRY_POINT; |
|
38 CAlarmRemConEventsHandler* self = new( ELeave )CAlarmRemConEventsHandler( aAlarmUI ); |
|
39 CleanupStack::PushL( self ); |
|
40 self->ConstructL(); |
|
41 CleanupStack::Pop( self ); |
|
42 TRACE_EXIT_POINT; |
|
43 return self; |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // ?description_if_needed |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 CAlarmRemConEventsHandler::~CAlarmRemConEventsHandler() |
|
51 { |
|
52 TRACE_ENTRY_POINT; |
|
53 // cancel the AO and delete all data |
|
54 Cancel(); |
|
55 Cleanup(); |
|
56 TRACE_EXIT_POINT; |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // from base class CActive |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 void CAlarmRemConEventsHandler::DoCancel() |
|
64 { |
|
65 TRACE_ENTRY_POINT; |
|
66 Cleanup(); |
|
67 TRACE_EXIT_POINT; |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // from base class CActive |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 TInt CAlarmRemConEventsHandler::RunError(TInt /*aError*/) |
|
75 { |
|
76 TRACE_ENTRY_POINT; |
|
77 Cleanup(); |
|
78 TRACE_EXIT_POINT; |
|
79 return KErrNone; |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // from base class CActive |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 void CAlarmRemConEventsHandler::RunL() |
|
87 { |
|
88 TRACE_ENTRY_POINT; |
|
89 TBool sendResponse( EFalse ); |
|
90 |
|
91 switch( iState ) |
|
92 { |
|
93 case EStateIdle: |
|
94 case EStateWaitingCommand: |
|
95 // do nothing |
|
96 break; |
|
97 |
|
98 case EStateHandleEndCallCommand: |
|
99 { |
|
100 // stop the alarm after sending the response |
|
101 iState = EStateStopAlarm; |
|
102 sendResponse = ETrue; |
|
103 } |
|
104 break; |
|
105 |
|
106 case EStateIgnoreCommand: |
|
107 { |
|
108 // command was ignored, keep waiting for more commands |
|
109 iState = EStateWaitingCommand; |
|
110 sendResponse = ETrue; |
|
111 } |
|
112 break; |
|
113 |
|
114 case EStateStopAlarm: |
|
115 { |
|
116 // stop the alarm and keep waiting for more commands |
|
117 iState = EStateWaitingCommand; |
|
118 iAlarmUI.ExternalStopAlarm(); |
|
119 } |
|
120 break; |
|
121 |
|
122 default: |
|
123 { |
|
124 ASSERT( EFalse ); |
|
125 } |
|
126 } |
|
127 |
|
128 if( sendResponse ) |
|
129 { |
|
130 // send the response |
|
131 TInt status = iStatus.Int(); |
|
132 SetActive(); |
|
133 iRemConCallHandlingTarget->SendResponse( iStatus, iRemConOperationID, status ); |
|
134 } |
|
135 TRACE_EXIT_POINT; |
|
136 } |
|
137 |
|
138 // --------------------------------------------------------------------------- |
|
139 // From MRemConCallHandlingTargetObserver. |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 void CAlarmRemConEventsHandler::EndCall() |
|
143 { |
|
144 TRACE_ENTRY_POINT; |
|
145 HandleRemConCommand( ERemConExtEndCall ); |
|
146 TRACE_EXIT_POINT; |
|
147 } |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // From MRemConCallHandlingTargetObserver. |
|
151 // --------------------------------------------------------------------------- |
|
152 // |
|
153 void CAlarmRemConEventsHandler::AnswerEndCall() |
|
154 { |
|
155 TRACE_ENTRY_POINT; |
|
156 HandleRemConCommand( ERemConExtAnswerEnd ); |
|
157 TRACE_EXIT_POINT; |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // From MRemConCallHandlingTargetObserver. |
|
162 // --------------------------------------------------------------------------- |
|
163 // |
|
164 void CAlarmRemConEventsHandler::AnswerCall() |
|
165 { |
|
166 TRACE_ENTRY_POINT; |
|
167 HandleRemConCommand( ERemConExtAnswerCall ); |
|
168 TRACE_EXIT_POINT; |
|
169 } |
|
170 |
|
171 // --------------------------------------------------------------------------- |
|
172 // From MRemConCallHandlingTargetObserver. |
|
173 // --------------------------------------------------------------------------- |
|
174 // |
|
175 void CAlarmRemConEventsHandler::VoiceDial(const TBool /*aActivate*/) |
|
176 { |
|
177 TRACE_ENTRY_POINT; |
|
178 HandleRemConCommand( ERemConExtVoiceDial ); |
|
179 TRACE_EXIT_POINT; |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // From MRemConCallHandlingTargetObserver. |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 void CAlarmRemConEventsHandler::LastNumberRedial() |
|
187 { |
|
188 TRACE_ENTRY_POINT; |
|
189 HandleRemConCommand( ERemConExtLastNumberRedial ); |
|
190 TRACE_EXIT_POINT; |
|
191 } |
|
192 |
|
193 // --------------------------------------------------------------------------- |
|
194 // From MRemConCallHandlingTargetObserver. |
|
195 // --------------------------------------------------------------------------- |
|
196 // |
|
197 void CAlarmRemConEventsHandler::DialCall(const TDesC8& /*aTelNumber*/) |
|
198 { |
|
199 TRACE_ENTRY_POINT; |
|
200 HandleRemConCommand( ERemConExtDialCall ); |
|
201 TRACE_EXIT_POINT; |
|
202 } |
|
203 |
|
204 // --------------------------------------------------------------------------- |
|
205 // From MRemConCallHandlingTargetObserver. |
|
206 // --------------------------------------------------------------------------- |
|
207 // |
|
208 void CAlarmRemConEventsHandler::MultipartyCalling(const TDesC8& /*aData*/) |
|
209 { |
|
210 TRACE_ENTRY_POINT; |
|
211 HandleRemConCommand( ERemConExt3WaysCalling ); |
|
212 TRACE_EXIT_POINT; |
|
213 } |
|
214 |
|
215 // --------------------------------------------------------------------------- |
|
216 // From MRemConCallHandlingTargetObserver. |
|
217 // --------------------------------------------------------------------------- |
|
218 // |
|
219 void CAlarmRemConEventsHandler::GenerateDTMF(const TChar /*aChar*/) |
|
220 { |
|
221 TRACE_ENTRY_POINT; |
|
222 HandleRemConCommand( ERemConExtGenerateDTMF ); |
|
223 TRACE_EXIT_POINT; |
|
224 } |
|
225 |
|
226 // --------------------------------------------------------------------------- |
|
227 // From MRemConCallHandlingTargetObserver. |
|
228 // --------------------------------------------------------------------------- |
|
229 // |
|
230 void CAlarmRemConEventsHandler::SpeedDial(const TInt /*aIndex*/) |
|
231 { |
|
232 TRACE_ENTRY_POINT; |
|
233 HandleRemConCommand( ERemConExtSpeedDial ); |
|
234 TRACE_EXIT_POINT; |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // Default constructor |
|
239 // --------------------------------------------------------------------------- |
|
240 // |
|
241 CAlarmRemConEventsHandler::CAlarmRemConEventsHandler(CAlmAlarmControl& aAlarmUI) |
|
242 : CActive( CActive::EPriorityStandard ), |
|
243 iState( EStateIdle ), |
|
244 iRemConOperationID( -1 ), |
|
245 iAlarmUI( aAlarmUI ) |
|
246 { |
|
247 TRACE_ENTRY_POINT; |
|
248 /** no implementation **/ |
|
249 TRACE_EXIT_POINT; |
|
250 } |
|
251 |
|
252 // --------------------------------------------------------------------------- |
|
253 // ?description_if_needed |
|
254 // --------------------------------------------------------------------------- |
|
255 // |
|
256 void CAlarmRemConEventsHandler::ConstructL() |
|
257 { |
|
258 TRACE_ENTRY_POINT; |
|
259 CActiveScheduler::Add( this ); |
|
260 TRACE_EXIT_POINT; |
|
261 } |
|
262 |
|
263 // --------------------------------------------------------------------------- |
|
264 // ?description_if_needed |
|
265 // --------------------------------------------------------------------------- |
|
266 // |
|
267 void CAlarmRemConEventsHandler::HandleRemConCommand(TInt aCommand) |
|
268 { |
|
269 TRACE_ENTRY_POINT; |
|
270 ASSERT( iState == EStateWaitingCommand && IsAdded() && !IsActive() ); |
|
271 |
|
272 // there shouldn't be new commands while we're still handling the previous one |
|
273 if( iState == EStateWaitingCommand ) |
|
274 { |
|
275 iRemConOperationID = aCommand; |
|
276 |
|
277 switch( iRemConOperationID ) |
|
278 { |
|
279 case ERemConExtEndCall: |
|
280 case ERemConExtAnswerEnd: |
|
281 // handle message (stop the alarm) |
|
282 iState = EStateHandleEndCallCommand; |
|
283 break; |
|
284 |
|
285 case ERemConExtAnswerCall: |
|
286 case ERemConExtVoiceDial: |
|
287 case ERemConExtLastNumberRedial: |
|
288 case ERemConExtDialCall: |
|
289 case ERemConExt3WaysCalling: |
|
290 case ERemConExtGenerateDTMF: |
|
291 case ERemConExtSpeedDial: |
|
292 // no event handling...just send the response |
|
293 iState = EStateIgnoreCommand; |
|
294 break; |
|
295 |
|
296 default: |
|
297 ASSERT( EFalse ); |
|
298 } |
|
299 // start the AO |
|
300 CompleteSelf(); |
|
301 } |
|
302 TRACE_EXIT_POINT; |
|
303 } |
|
304 |
|
305 // --------------------------------------------------------------------------- |
|
306 // ?description_if_needed |
|
307 // --------------------------------------------------------------------------- |
|
308 // |
|
309 void CAlarmRemConEventsHandler::CompleteSelf() |
|
310 { |
|
311 TRACE_ENTRY_POINT; |
|
312 TRequestStatus* pStat = &iStatus; |
|
313 User::RequestComplete( pStat, KErrNone ); |
|
314 |
|
315 if( IsAdded() && !IsActive() ) |
|
316 { |
|
317 SetActive(); |
|
318 } |
|
319 TRACE_EXIT_POINT; |
|
320 } |
|
321 |
|
322 // --------------------------------------------------------------------------- |
|
323 // ?description_if_needed |
|
324 // --------------------------------------------------------------------------- |
|
325 // |
|
326 void CAlarmRemConEventsHandler::StartL() |
|
327 { |
|
328 TRACE_ENTRY_POINT; |
|
329 if( !iRemConInterfaceSelector && !iRemConCallHandlingTarget ) |
|
330 { |
|
331 // create the RemCon interface selector |
|
332 CRemConInterfaceSelector* selector = CRemConInterfaceSelector::NewL(); |
|
333 CleanupStack::PushL( selector ); |
|
334 |
|
335 // create the RemCon target |
|
336 CRemConCallHandlingTarget* target = CRemConCallHandlingTarget::NewL( *selector, *this ); |
|
337 CleanupStack::PushL( target ); |
|
338 |
|
339 // open a target session to RemCon |
|
340 selector->OpenTargetL(); |
|
341 CleanupStack::Pop( 2, selector ); |
|
342 |
|
343 // RemCon initialisation ok |
|
344 iRemConCallHandlingTarget = target; |
|
345 iRemConInterfaceSelector = selector; |
|
346 |
|
347 iState = EStateWaitingCommand; |
|
348 } |
|
349 TRACE_EXIT_POINT; |
|
350 } |
|
351 |
|
352 // --------------------------------------------------------------------------- |
|
353 // ?description_if_needed |
|
354 // --------------------------------------------------------------------------- |
|
355 // |
|
356 void CAlarmRemConEventsHandler::Stop() |
|
357 { |
|
358 TRACE_ENTRY_POINT; |
|
359 Cancel(); |
|
360 Cleanup(); |
|
361 TRACE_EXIT_POINT; |
|
362 } |
|
363 |
|
364 // --------------------------------------------------------------------------- |
|
365 // ?description_if_needed |
|
366 // --------------------------------------------------------------------------- |
|
367 // |
|
368 void CAlarmRemConEventsHandler::Cleanup() |
|
369 { |
|
370 TRACE_ENTRY_POINT; |
|
371 iState = EStateIdle; |
|
372 iRemConOperationID = -1; |
|
373 iRemConCallHandlingTarget = NULL; // owned by iRemConInterfaceSelector |
|
374 delete iRemConInterfaceSelector; |
|
375 iRemConInterfaceSelector = NULL; |
|
376 TRACE_EXIT_POINT; |
|
377 } |
|
378 |
|
379 |
|
380 // End of File |