1 /* |
|
2 * Copyright (c) 2002 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: Recovery system. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32svr.h> |
|
21 |
|
22 #include "phoneui.pan" |
|
23 #include "cphonerecoverysystem.h" |
|
24 #include "ctelerecoverysystem.h" |
|
25 #include "cphonetimer.h" |
|
26 #include "phoneconstants.h" |
|
27 |
|
28 const TInt KEmptySlot = 0; |
|
29 const TInt KErrNoSpace = -1; |
|
30 |
|
31 // ================= MEMBER FUNCTIONS ======================= |
|
32 |
|
33 // --------------------------------------------------------- |
|
34 // CPhoneRecoverySystem::Instance |
|
35 // Initializes the singleton object |
|
36 // (other items were commented in a header). |
|
37 // --------------------------------------------------------- |
|
38 // |
|
39 EXPORT_C CPhoneRecoverySystem* CPhoneRecoverySystem::Instance() |
|
40 { |
|
41 CPhoneRecoverySystem* instance = static_cast<CPhoneRecoverySystem*> |
|
42 ( CCoeEnv::Static ( KUidRecoverySystemSingleton ) ); |
|
43 |
|
44 if ( !instance ) |
|
45 { |
|
46 TRAPD( err, instance = CPhoneRecoverySystem::NewL() ); |
|
47 if ( err ) |
|
48 { |
|
49 Panic( EPhoneUtilsCouldNotCreateSingleton ); |
|
50 } |
|
51 } |
|
52 return instance; |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------- |
|
56 // CPhoneRecoverySystem::CPhoneRecoverySystem |
|
57 // --------------------------------------------------------- |
|
58 // |
|
59 CPhoneRecoverySystem::CPhoneRecoverySystem() : |
|
60 CCoeStatic( KUidRecoverySystemSingleton, EThread ) |
|
61 { |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CPhoneRecoverySystem::NewL |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 CPhoneRecoverySystem* CPhoneRecoverySystem::NewL() |
|
69 { |
|
70 CPhoneRecoverySystem* self = new (ELeave) CPhoneRecoverySystem(); |
|
71 return self; |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CTeUtlFactoryImpl::CreateRecoverySystemL |
|
76 // |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 CTeleRecoverySystem* CPhoneRecoverySystem::CreateRecoverySystemL() |
|
80 { |
|
81 return CTeleRecoverySystem::NewL(); |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CPhoneRecoverySystem::~CPhoneRecoverySystem |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 CPhoneRecoverySystem::~CPhoneRecoverySystem() |
|
89 { |
|
90 RemoveAllIdsFromContainer(); |
|
91 delete iRecoverySystem; |
|
92 iRecoverySystem = NULL; |
|
93 } |
|
94 |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CPhoneRecoverySystem::AddL |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 EXPORT_C TRecoveryId CPhoneRecoverySystem::AddL( |
|
101 TCallBack aCallBack, |
|
102 TRecoveryPriority aPriority, |
|
103 CTeleRecoverySystem::TRecoveryState aState ) |
|
104 { |
|
105 if ( !iRecoverySystem ) |
|
106 { |
|
107 iRecoverySystem = CreateRecoverySystemL(); |
|
108 } |
|
109 |
|
110 TRecoveryId id = iRecoverySystem->AddL( |
|
111 aCallBack, |
|
112 aPriority, |
|
113 aState ); |
|
114 |
|
115 try |
|
116 { |
|
117 AddIdToContainer( id ); |
|
118 } |
|
119 catch( TInt exception ) |
|
120 { |
|
121 __ASSERT_DEBUG( EFalse, Panic( EPhoneUtilsBufferOverflow ) ); |
|
122 } |
|
123 |
|
124 return id; |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CPhoneRecoverySystem::Add |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 TRecoveryId CPhoneRecoverySystem::Add( |
|
132 TCallBack aCallBack, |
|
133 TRecoveryPriority aPriority, |
|
134 CTeleRecoverySystem::TRecoveryState aState ) |
|
135 { |
|
136 return iRecoverySystem->Add( |
|
137 aCallBack, |
|
138 aPriority, |
|
139 aState ); |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CPhoneRecoverySystem::Remove |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 EXPORT_C void CPhoneRecoverySystem::Remove( TRecoveryId aId ) |
|
147 { |
|
148 CPhoneRecoverySystem* instance = static_cast<CPhoneRecoverySystem*> |
|
149 ( CCoeEnv::Static( KUidRecoverySystemSingleton ) ); |
|
150 |
|
151 if ( instance ) |
|
152 { |
|
153 instance->RemoveId( aId ); |
|
154 } |
|
155 } |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // CPhoneRecoverySystem::RemoveId |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 void CPhoneRecoverySystem::RemoveId( TRecoveryId aId ) |
|
162 { |
|
163 if ( iRecoverySystem ) |
|
164 { |
|
165 iRecoverySystem->Remove( aId ); |
|
166 RemoveFromContainer( aId ); |
|
167 } |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CPhoneRecoverySystem::SetState |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 void CPhoneRecoverySystem::SetState( TRecoveryId aId, CTeleRecoverySystem::TRecoveryState aState ) |
|
175 { |
|
176 iRecoverySystem->SetState( |
|
177 aId, |
|
178 aState ); |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CPhoneRecoverySystem::ResetPending |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 void CPhoneRecoverySystem::ResetPending() |
|
186 { |
|
187 iRecoverySystem->ResetPending(); |
|
188 } |
|
189 |
|
190 // ----------------------------------------------------------------------------- |
|
191 // CPhoneRecoverySystem::RecoverNow |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 EXPORT_C TInt CPhoneRecoverySystem::RecoverNow( TRecoveryId aId, |
|
195 TRecoveryPriority aPriority, |
|
196 TBool aAllSteps ) |
|
197 { |
|
198 __ASSERT_DEBUG( iRecoverySystem, Panic( EPhoneUtilsInvariant ) ); |
|
199 |
|
200 if ( !iRecoverySystem ) |
|
201 { |
|
202 TRAPD( error, iRecoverySystem = CreateRecoverySystemL() ) |
|
203 if( error != KErrNone ) |
|
204 { |
|
205 return error; |
|
206 } |
|
207 } |
|
208 return iRecoverySystem->RecoverNow( aId, aPriority, aAllSteps ); |
|
209 } |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // CPhoneRecoverySystem::EnablePreconditionL |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 EXPORT_C void CPhoneRecoverySystem::EnablePreconditionL() |
|
216 { |
|
217 __ASSERT_DEBUG( iRecoverySystem, Panic( EPhoneUtilsInvariant ) ); |
|
218 |
|
219 if ( !iRecoverySystem ) |
|
220 { |
|
221 iRecoverySystem = CreateRecoverySystemL(); |
|
222 } |
|
223 |
|
224 iRecoverySystem->EnablePrecondition(); |
|
225 } |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // CPhoneRecoverySystem::AddIdToContainer |
|
229 // ----------------------------------------------------------------------------- |
|
230 // |
|
231 void CPhoneRecoverySystem::AddIdToContainer( TRecoveryId aId ) |
|
232 { |
|
233 __ASSERT_DEBUG( iIdContainer.Count() == KIdContainerSize, Panic( EPhoneUtilsInvariant ) ); |
|
234 for( TInt i = 0; i < KIdContainerSize; i++ ) |
|
235 { |
|
236 if( iIdContainer[ i ] == KEmptySlot ) |
|
237 { |
|
238 iIdContainer[ i ] = aId; |
|
239 return; |
|
240 } |
|
241 } |
|
242 |
|
243 // All slots checked, no space - throw exception |
|
244 throw KErrNoSpace; |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // CPhoneRecoverySystem::RemoveFromContainer |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 void CPhoneRecoverySystem::RemoveFromContainer( TRecoveryId aId ) |
|
252 { |
|
253 __ASSERT_DEBUG( iIdContainer.Count() == KIdContainerSize, Panic( EPhoneUtilsInvariant ) ); |
|
254 for( TInt i = 0; i < KIdContainerSize; i++ ) |
|
255 { |
|
256 if( iIdContainer[ i ] == aId ) |
|
257 { |
|
258 iIdContainer[ i ] = KEmptySlot; |
|
259 } |
|
260 } |
|
261 } |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CPhoneRecoverySystem::RemoveAllIdsFromContainer |
|
265 // ----------------------------------------------------------------------------- |
|
266 // |
|
267 void CPhoneRecoverySystem::RemoveAllIdsFromContainer() |
|
268 { |
|
269 __ASSERT_DEBUG( iIdContainer.Count() == KIdContainerSize, Panic( EPhoneUtilsInvariant ) ); |
|
270 for( TInt i = 0; i < KIdContainerSize; i++ ) |
|
271 { |
|
272 if( iIdContainer[ i ] != KEmptySlot ) |
|
273 { |
|
274 RemoveId( iIdContainer[ i ] ); |
|
275 } |
|
276 } |
|
277 } |
|
278 |
|
279 // End of File |
|