|
1 // Copyright (c) 2000-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 #ifndef __WATCHERBASE_H__ |
|
17 #define __WATCHERBASE_H__ |
|
18 |
|
19 // System includes |
|
20 #include <e32base.h> |
|
21 #include <etelext.h> |
|
22 #include <etelmm.h> |
|
23 #include <etel.h> |
|
24 |
|
25 // User includes |
|
26 #include "phoneonoff.h" |
|
27 #include "ModemChangeObserver.h" |
|
28 |
|
29 // Test code hooks (when this file is embedded inside an EXE) |
|
30 #include "WatcherTestHooks.h" |
|
31 |
|
32 /** |
|
33 Constants |
|
34 @internalComponent |
|
35 */ |
|
36 const TInt KErrorRetryCount = 3; |
|
37 const TInt KErrorRetryPausePeriod = 60; // Seconds |
|
38 const TInt KWatcherBaseModemNotDetected = -2017; |
|
39 |
|
40 const TUint KPhonePropertyKey = 0; //-- Phone properties key |
|
41 |
|
42 #ifdef WATCHER_TESTING |
|
43 |
|
44 //-- These UIds used for debugging purposes only by T_WATCHERS test. |
|
45 |
|
46 //-- Changing property with this Uid (to any value) informs that CTelPhoneWatcher has re-read modem table from Commdb in |
|
47 //-- CTelPhoneWatcher::DoRetrieveTSYNameL(). |
|
48 const TUid KUidTestProp_ModemTableRefreshed = {0x11111111}; |
|
49 |
|
50 //-- Property with this Uid is changed in CTelPhoneWatcher::HandleModemChangedL() |
|
51 //-- when the Commdb modem record has been changed |
|
52 const TUid KUidTestProp_ModemRecordChanged = {0xDEADBEEF}; |
|
53 |
|
54 //-- Property with this Uid is used in CIndicatorWatcher::HandleIndicatorUpdateL() |
|
55 //-- to simulate call state change by t_watchers test |
|
56 const TUid KUidTestProp_CallStateChange = {0x12341234}; |
|
57 |
|
58 //-- Property with this Uid is used to disable and reset phone watchers |
|
59 const TUid KUidTestProp_WatchersDisable = {0xFABBBABE}; |
|
60 |
|
61 #endif |
|
62 |
|
63 // |
|
64 // ------> CWatcherBase (header) |
|
65 // |
|
66 class CWatcherBase : public CActive |
|
67 /** |
|
68 @internalComponent |
|
69 */ |
|
70 { |
|
71 // |
|
72 public: // DESTRUCT |
|
73 // |
|
74 IMPORT_C ~CWatcherBase(); |
|
75 |
|
76 // |
|
77 protected: // CONSTRUCT |
|
78 // |
|
79 IMPORT_C CWatcherBase(TInt aPriority = CActive::EPriorityStandard); |
|
80 IMPORT_C virtual void ConstructL(); |
|
81 |
|
82 // |
|
83 #ifdef WATCHER_TESTING |
|
84 public: // NEW FUNCTIONS |
|
85 #else |
|
86 protected: // NEW FUNCTIONS |
|
87 #endif |
|
88 // |
|
89 IMPORT_C void SuspendFor(TInt aTimeInSeconds); |
|
90 IMPORT_C void SetDisabled(const TDesC& aLogEntry, TInt aError); |
|
91 IMPORT_C void RequestNextState(); |
|
92 IMPORT_C void WaitForPhoneToPowerUpL(); |
|
93 // |
|
94 virtual void HandleStateEventL(TInt aCompletionCode) = 0; |
|
95 virtual void HandleConnectionToChangeNotifierEstablishedL() { } |
|
96 virtual void HandleCancel() = 0; |
|
97 virtual void Reset() { } |
|
98 |
|
99 // |
|
100 protected: // INLINE MUTATORS |
|
101 // |
|
102 |
|
103 enum TWatcherPanic |
|
104 { |
|
105 EGeneral, |
|
106 EUnexpectedState, |
|
107 EUnexpectedActiveState |
|
108 }; |
|
109 void WatcherBasePanic(TWatcherPanic aPanicNumber); |
|
110 |
|
111 inline TInt ErrorCountIncrement() { return ++iErrorCount; } |
|
112 inline void ErrorCountReset() { iErrorCount = 0; } |
|
113 |
|
114 // |
|
115 private: // FROM CActive |
|
116 // |
|
117 IMPORT_C void RunL(); |
|
118 IMPORT_C void DoCancel(); |
|
119 IMPORT_C TInt RunError(TInt aError); |
|
120 |
|
121 // |
|
122 private: // INTERNAL STATE |
|
123 // |
|
124 enum TBaseState |
|
125 { |
|
126 EBaseStateConnectingToPropertyNotifier, |
|
127 EBaseStatePassive, |
|
128 EBaseStateSuspending, |
|
129 EBaseStateDisabled, |
|
130 EBaseStateWaitingForPhoneToPowerUp, |
|
131 // |
|
132 EBaseStateLast |
|
133 }; |
|
134 inline TBaseState& State() { return iBaseState; } |
|
135 |
|
136 // |
|
137 private: // STATEMACHINE |
|
138 // |
|
139 |
|
140 // Error count |
|
141 TInt iErrorCount; |
|
142 |
|
143 // Our current state |
|
144 TBaseState iBaseState; |
|
145 |
|
146 // Retry timer |
|
147 RTimer iTimer; |
|
148 |
|
149 RProperty iPhonePowerProperty; |
|
150 }; |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 // |
|
157 // ------> CPhoneWatcher (header) |
|
158 // |
|
159 class CPhoneWatcher : public CWatcherBase, public MPhoneOnOffObserver, public MModemChangeObserver |
|
160 /** |
|
161 @internalComponent |
|
162 */ |
|
163 { |
|
164 // |
|
165 public: // DESTRUCT |
|
166 // |
|
167 IMPORT_C ~CPhoneWatcher(); |
|
168 |
|
169 // |
|
170 protected: // CONSTRUCT |
|
171 // |
|
172 IMPORT_C CPhoneWatcher(TInt aPriority = CActive::EPriorityStandard); |
|
173 IMPORT_C void ConstructL(); |
|
174 |
|
175 // |
|
176 protected: // NEW |
|
177 // |
|
178 virtual void HandlePhoneStateEventL(TInt aCompletionCode) = 0; |
|
179 virtual void ReleasePhoneResources() { } |
|
180 |
|
181 // |
|
182 protected: // INLINE MUTATORS |
|
183 // |
|
184 inline RMobilePhone& Phone() { return iPhone; } |
|
185 inline RTelServer& ETel() { return iETelServer; } |
|
186 |
|
187 // |
|
188 protected: // FROM CWatcherBase |
|
189 // |
|
190 IMPORT_C void HandleStateEventL(TInt aCompletionCode); |
|
191 IMPORT_C void Reset(); |
|
192 |
|
193 // |
|
194 protected: // FROM MPhoneOnOffObserver |
|
195 // |
|
196 IMPORT_C void PhoneIsOff(); |
|
197 |
|
198 // |
|
199 private: // FROM MModemChangeObserver |
|
200 // |
|
201 IMPORT_C void HandleModemChangedL(); |
|
202 |
|
203 // |
|
204 private: // STANDARD SETUP STATE-MACHINE STEPS |
|
205 // |
|
206 TInt RetrieveTSYName(); |
|
207 TInt ConnectToETelServer(); |
|
208 TInt LoadPhoneModule(); |
|
209 TInt ConnectToPhone(); |
|
210 |
|
211 // |
|
212 private: // INTERNAL |
|
213 // |
|
214 enum TPhoneState |
|
215 { |
|
216 EPhoneStateRetrievingTsyName = 0, |
|
217 EPhoneStateConnectingToETel, |
|
218 EPhoneStateLoadingPhoneModule, |
|
219 EPhoneStateConnectingToPhone, |
|
220 EPhoneStatePassive |
|
221 }; |
|
222 inline TPhoneState& PhoneState() { return iPhoneState; } |
|
223 void DoRetrieveTSYNameL(); |
|
224 |
|
225 // |
|
226 private: // STATE MACHINE MEMBER DATA |
|
227 // |
|
228 TName iTSYName; |
|
229 TPhoneState iPhoneState; |
|
230 // |
|
231 RMobilePhone iPhone; |
|
232 RTelServer iETelServer; |
|
233 |
|
234 // Waits to be informed when the phone is turned on or off. |
|
235 CPhoneOnOff* iPhoneWait; |
|
236 |
|
237 // Waits to be informed when the CommsDb modem changes. |
|
238 CModemChangeObserver* iModemChangeObserver; |
|
239 }; |
|
240 |
|
241 |
|
242 #endif |