|
1 /* |
|
2 * Copyright (c) 2002-2008 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: Support for Emergency Calls. |
|
15 * Pressed keys are tracked in a buffer and CEmergencyNumberUtils |
|
16 * is used to find out if the buffer matches to emergency number. |
|
17 * Observers, if registered are called to notify them. |
|
18 * |
|
19 * |
|
20 */ |
|
21 |
|
22 |
|
23 #if !defined(__AKNECS_H__) |
|
24 #define __AKNECS_H__ |
|
25 |
|
26 // INCLUDES |
|
27 #include <babitflags.h> |
|
28 #include <eikapp.h> |
|
29 #include <eikdef.h> |
|
30 #include "AknWsEventObserver.h" |
|
31 |
|
32 class CPhCltEmergencyCall; |
|
33 class CPhCltEmergencyCallObserver; |
|
34 |
|
35 |
|
36 // CONSTANTS |
|
37 |
|
38 // Maximum length of an emergency number |
|
39 const TInt KAknEcsMaxMatchingLength = 6; |
|
40 |
|
41 // Separator character for the emergency number string |
|
42 _LIT( KAknEcsSeparator, " "); |
|
43 |
|
44 // Maximum time in Microseconds between keys in a valid emergency call entry: |
|
45 const TInt KEcsInterKeyTimeout = 4000000; |
|
46 |
|
47 // Deprecated |
|
48 const TInt KAknMaxEmergencyNumberString = 200; |
|
49 |
|
50 // FORWARD DECLARATIONS |
|
51 |
|
52 // Forward declarations; Full declaration comes later |
|
53 class MAknEcsObserver; |
|
54 class CAknMatchingCharacterQueue; |
|
55 |
|
56 |
|
57 // CLASS DECLARATIONS |
|
58 |
|
59 /** |
|
60 * Central coordinating object in the emergency call system |
|
61 * Objects of this class own the number queue and own the interface object to the stored |
|
62 * emergency numbers. |
|
63 * |
|
64 * A phone client session is also open while constructed |
|
65 * |
|
66 */ |
|
67 class CAknEcsDetector : public CBase, public MAknWsEventObserver |
|
68 { |
|
69 |
|
70 public: |
|
71 |
|
72 /** |
|
73 * Enumeration to carry the state of the Ecs detector |
|
74 */ |
|
75 enum TState |
|
76 { |
|
77 ENotFullyConstructed, |
|
78 EEmpty, |
|
79 ENoMatch, |
|
80 EPartialMatch, // Not in use. |
|
81 ECompleteMatch, |
|
82 ECompleteMatchThenSendKey, |
|
83 ECallAttempted |
|
84 }; |
|
85 |
|
86 public: |
|
87 /** |
|
88 * C++ destructor |
|
89 */ |
|
90 IMPORT_C virtual ~CAknEcsDetector(); |
|
91 |
|
92 /** |
|
93 * Two phase constructor for Ecs detector |
|
94 * Static method. |
|
95 */ |
|
96 IMPORT_C static CAknEcsDetector* NewL(); |
|
97 |
|
98 // From MAknWsEventObserver |
|
99 /** |
|
100 * Handle and event coming from the AppUi. Default implementation handles all keys |
|
101 * and updates the Status(), CurrentMatch(), and IndexOfCurrentMatch() |
|
102 * |
|
103 */ |
|
104 IMPORT_C virtual void HandleWsEventL(const TWsEvent& aEvent,CCoeControl* aDestination ); |
|
105 |
|
106 /** |
|
107 * Add a character to the emergency call buffer. This should be fed with both numberic |
|
108 * key presses and the Send key. |
|
109 * |
|
110 * @param aNewChar New character to emergency call buffer. |
|
111 */ |
|
112 IMPORT_C void AddChar( TText aNewChar ); |
|
113 |
|
114 /** |
|
115 * Set the entire contents of the emergency call buffer. A reset is performed first, and then |
|
116 * the characters in the passed descriptor are added to the buffer. |
|
117 * Emergency number is matched only if there is not other content in the string. |
|
118 * |
|
119 * @param aNewBuffer Emergency call buffer. |
|
120 */ |
|
121 IMPORT_C void SetBuffer( const TDesC& aNewBuffer ); |
|
122 |
|
123 /** |
|
124 * Reset the buffer to a just initialized state. |
|
125 */ |
|
126 IMPORT_C void Reset(); |
|
127 |
|
128 /** |
|
129 * Returns the current state of the Ecs Detector |
|
130 * |
|
131 * @return The state of the object |
|
132 */ |
|
133 IMPORT_C TState State(); |
|
134 |
|
135 /** |
|
136 * Returns a pointer to the current matching number. |
|
137 * |
|
138 * @return A ptr descriptor into the currently matching text |
|
139 */ |
|
140 IMPORT_C TPtrC CurrentMatch() const; |
|
141 |
|
142 /** |
|
143 * Sets the obserever of the EcsDetector |
|
144 */ |
|
145 IMPORT_C void SetObserver( MAknEcsObserver* aNewObserver ); |
|
146 |
|
147 /** |
|
148 * This method attaches the Ecs Detector to the current appui and the registers itself for |
|
149 * receiving all key presses parasitically. |
|
150 * This method is called when there is no requirement for the ECS to keep synchronized with a |
|
151 * visual buffer |
|
152 * |
|
153 * @return Success of the connection |
|
154 */ |
|
155 IMPORT_C TBool ConnectToEventSource(); |
|
156 |
|
157 /** |
|
158 * Closes the connection to the appui object opened by a previous call to ConnectToEventSource |
|
159 */ |
|
160 IMPORT_C void CloseEventSource(); |
|
161 |
|
162 /** |
|
163 * It is called whenever status is retrieved (by the client). |
|
164 * |
|
165 * @param aStatus It is the status of the phone. |
|
166 */ |
|
167 virtual void HandlePhoneStatusL( const TInt aStatus ); |
|
168 |
|
169 /** |
|
170 * Returns an index to the current character buffer where the emergency number |
|
171 * match begins. This value is between 0 and KAknEcsMaxMatchingLength, even if |
|
172 * there have been a large number characters input to the FIFO. Thus, it does not |
|
173 * take account of characters that have fallen out of the FIFO. |
|
174 * |
|
175 * The main use case for this is to allow clients to tell if the number was matched |
|
176 * from the beginning of the buffer (value 0). Note that for emergency numbers of |
|
177 * length KAknEcsMaxMatchingLength will ALWAYS return 0 if there is a complete match. |
|
178 * |
|
179 * @return the index in the current buffer where the match starts |
|
180 */ |
|
181 TInt IndexOfCurrentMatch() const; |
|
182 |
|
183 protected: |
|
184 |
|
185 /** |
|
186 * Enumeration for the bit indices of iFlags |
|
187 * Used for substates or state modifiers |
|
188 */ |
|
189 enum TBitFlagIndices |
|
190 { |
|
191 EEventSourceConnected = 0, |
|
192 ETestMode |
|
193 }; |
|
194 |
|
195 /** |
|
196 * C++ constructor |
|
197 */ |
|
198 IMPORT_C CAknEcsDetector(); // Use NewL to construct |
|
199 |
|
200 /** |
|
201 * 2nd stage construction. All memory allocation is performed in this routine |
|
202 */ |
|
203 IMPORT_C void ConstructL(); // Use NewL to construct |
|
204 |
|
205 /** |
|
206 * Calls the observer |
|
207 */ |
|
208 IMPORT_C virtual void ReportEvent( TState aNewState ); |
|
209 |
|
210 /** |
|
211 * Internal routine to set the state |
|
212 */ |
|
213 IMPORT_C void SetState( TState newState ); |
|
214 |
|
215 /** |
|
216 * Framework method that may be re-implemented in order to perform some check or put up UI |
|
217 * before the phone call is made |
|
218 * Implementation must not leave; |
|
219 * |
|
220 * @return Whether or not to continue with the emergency call |
|
221 */ |
|
222 IMPORT_C virtual TBool OfferEmergencyCall(); |
|
223 |
|
224 /** |
|
225 * Static method that can be used as a cancel callback to the detector |
|
226 * |
|
227 * @return Integer return for CPeriodic callbacks; 1 to continue periodic callbacks |
|
228 */ |
|
229 static TInt CancelMatch( TAny* aAny ); |
|
230 |
|
231 private: |
|
232 /** |
|
233 * Utility routine to determine the new state of the module. |
|
234 */ |
|
235 void DetermineState(); |
|
236 |
|
237 /** |
|
238 * Wraps up the code to capture whatever keys are necessary when the emergency number |
|
239 */ |
|
240 void CaptureKeys(); |
|
241 |
|
242 /** |
|
243 * Uncaptures Send key (if necessary) |
|
244 */ |
|
245 void RelinquishCapturedKeys(); |
|
246 |
|
247 /** |
|
248 * Wraps up the code that acutally sets off the emergency call |
|
249 */ |
|
250 void AttemptEmergencyCall(); |
|
251 |
|
252 public: |
|
253 /** |
|
254 * This callback is called by a CIdle object to state that the call has been |
|
255 * attempted. This is called outside the event loop in order allow self-deletion of the |
|
256 * client object. |
|
257 * |
|
258 * State is set to CallAttempted by this method. |
|
259 * |
|
260 * @param aSelf |
|
261 */ |
|
262 static TInt CallAttemptedCallback(TAny* aSelf); |
|
263 |
|
264 private: |
|
265 // Constituent object: the character queue |
|
266 CAknMatchingCharacterQueue* iQueue; |
|
267 |
|
268 // Internal state of the detector |
|
269 TState iState; |
|
270 |
|
271 TBuf<KAknEcsMaxMatchingLength> iSpare_3; |
|
272 |
|
273 // Timer for match timeout |
|
274 CPeriodic* iKeyTimeoutTimer; |
|
275 |
|
276 // The observer |
|
277 MAknEcsObserver* iObserver; |
|
278 |
|
279 // A reference to the control environment |
|
280 CCoeEnv* iCoeEnv; |
|
281 |
|
282 // Flags |
|
283 TBitFlags16 iFlags; |
|
284 |
|
285 // To hold a captured key handle |
|
286 TInt iCapturedKey; |
|
287 |
|
288 /** Phone client interface of emergency call. */ |
|
289 CPhCltEmergencyCall* iPhCltEmergencyCall; |
|
290 |
|
291 // Idle object for causing a delayed call attempted state |
|
292 CIdle* iIdler; |
|
293 |
|
294 /** Pointer to emergency call observer object */ |
|
295 CPhCltEmergencyCallObserver* iEmergencyCallObserver; |
|
296 |
|
297 TInt iSpare_2; |
|
298 }; |
|
299 |
|
300 // |
|
301 // MAknEcsObserver |
|
302 // |
|
303 // This interface is used to handle changes in state of the Emergency call detector. |
|
304 // |
|
305 // |
|
306 class MAknEcsObserver |
|
307 { |
|
308 public: |
|
309 /** |
|
310 * This event handler method provides a pointer to the detector and gives its state. |
|
311 * It is called at least every changed of state. It may be called repeatedly on the same state |
|
312 */ |
|
313 virtual void HandleEcsEvent(CAknEcsDetector* aDetector, CAknEcsDetector::TState aUpdatedState) = 0; |
|
314 }; |
|
315 |
|
316 #endif // __AKNECS_H__ |