1 /* |
|
2 * Copyright (c) 2002-2007 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: CCntParserServer implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "clientserver.h" |
|
20 #include "cntparserserver.h" |
|
21 #include "cntparserserversession.h" |
|
22 #include "irmcconsts.h" |
|
23 |
|
24 #include "debug.h" |
|
25 |
|
26 #include <cntdb.h> |
|
27 |
|
28 //------------------------------------------------------------ |
|
29 // RunServer |
|
30 //------------------------------------------------------------ |
|
31 TInt CCntParserServer::RunServer() |
|
32 { |
|
33 LOGGER_ENTERFN( "CCntParserServer::RunServer" ); |
|
34 |
|
35 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
36 TInt ret( KErrNoMemory ); |
|
37 if( cleanup ) |
|
38 { |
|
39 TRAP( ret, CCntParserServer::RunServerL() ); |
|
40 delete cleanup; |
|
41 } |
|
42 if( ret != KErrNone ) |
|
43 { |
|
44 // Signal the client that server creation failed |
|
45 RProcess::Rendezvous( ret ); |
|
46 } |
|
47 LOGGER_LEAVEFN( "CCntParserServer::RunServer" ); |
|
48 return ret; |
|
49 } |
|
50 //------------------------------------------------------------ |
|
51 // RunServerL |
|
52 //------------------------------------------------------------ |
|
53 void CCntParserServer::RunServerL() |
|
54 { |
|
55 // Create and install the active scheduler we need |
|
56 LOGGER_ENTERFN( "CCntParserServer::RunServerL" ); |
|
57 CActiveScheduler *as=new (ELeave)CActiveScheduler; |
|
58 CleanupStack::PushL( as ); |
|
59 CActiveScheduler::Install( as ); |
|
60 |
|
61 // Create server |
|
62 CCntParserServer::NewL(); |
|
63 |
|
64 // Initialisation complete, now signal the client |
|
65 User::LeaveIfError( RThread().RenameMe( KTxtServer ) ); |
|
66 RProcess::Rendezvous( KErrNone ); |
|
67 |
|
68 // Ready to run |
|
69 CActiveScheduler::Start(); |
|
70 |
|
71 // Cleanup the scheduler |
|
72 CleanupStack::PopAndDestroy( as ); |
|
73 LOGGER_LEAVEFN( "CCntParserServer::RunServerL" ); |
|
74 } |
|
75 //------------------------------------------------------------ |
|
76 // E32Main() |
|
77 //------------------------------------------------------------ |
|
78 TInt E32Main() |
|
79 { |
|
80 return CCntParserServer::RunServer(); |
|
81 } |
|
82 //------------------------------------------------------------ |
|
83 // PanicServer(TCntParserServerPanic aPanic) |
|
84 //------------------------------------------------------------ |
|
85 GLDEF_C void PanicServer(TCntParserServerPanic aPanic) |
|
86 { |
|
87 LOGGER_WRITE( "PANIC SERVER!" ); |
|
88 _LIT(KTxtServerPanic,"Parser server panic"); |
|
89 User::Panic( KTxtServerPanic, aPanic ); |
|
90 } |
|
91 |
|
92 |
|
93 //********************************** |
|
94 //CCntParserServer |
|
95 //********************************** |
|
96 |
|
97 //------------------------------------------------------------ |
|
98 // CCntParserServer::CCntParserServer() |
|
99 //------------------------------------------------------------ |
|
100 CCntParserServer::CCntParserServer() : CServer2( EPriorityStandard ) |
|
101 { |
|
102 } |
|
103 //------------------------------------------------------------ |
|
104 // CCntParserServer::~CCntParserServer() |
|
105 //------------------------------------------------------------ |
|
106 EXPORT_C CCntParserServer::~CCntParserServer() |
|
107 { |
|
108 if( iCollector ) |
|
109 { |
|
110 iCollector->Cancel(); |
|
111 } |
|
112 delete iCollector; |
|
113 delete iCurrentDatabase; |
|
114 LOGGER_WRITE( "CntParserServer: DELETED!" ); |
|
115 } |
|
116 //------------------------------------------------------------ |
|
117 // CCntParserServer* CCntParserServer::NewL() |
|
118 //------------------------------------------------------------ |
|
119 EXPORT_C CCntParserServer* CCntParserServer::NewL() |
|
120 { |
|
121 LOGGER_WRITE( "CntParserServer: NEW" ); |
|
122 CCntParserServer* pS=new (ELeave) CCntParserServer(); |
|
123 CleanupStack::PushL(pS); |
|
124 pS->StartL( KCntParserName ); |
|
125 CleanupStack::Pop( pS ); |
|
126 LOGGER_WRITE( "CntParserServer: Created" ); |
|
127 return pS; |
|
128 } |
|
129 //------------------------------------------------------------ |
|
130 // CCntParserServer::NewSessionL(const TVersion &aVersion, const RMessage2& /*aMsg*/) const |
|
131 //------------------------------------------------------------ |
|
132 CSession2* CCntParserServer::NewSessionL(const TVersion &aVersion, const RMessage2& /*aMsg*/) const |
|
133 { |
|
134 LOGGER_WRITE( "CntParserServer: NEW SessionL" ); |
|
135 // check we're the right version |
|
136 TVersion v( KCntParserMajorVersionNumber,KCntParserMinorVersionNumber,KCntParserBuildVersionNumber ); |
|
137 if ( !User::QueryVersionSupported( v,aVersion ) ) |
|
138 User::Leave( KErrNotSupported ); |
|
139 CCntParserServerSession* self=CCntParserServerSession::NewL( (CCntParserServer*)this ); |
|
140 return self; |
|
141 } |
|
142 //------------------------------------------------------------ |
|
143 // CCntParserServer::IncreaseSessionCountL() |
|
144 //------------------------------------------------------------ |
|
145 void CCntParserServer::IncreaseSessionCountL() |
|
146 { |
|
147 LOGGER_WRITE( "CntParserServer: Increase Session Count" ); |
|
148 iSessionCount++; |
|
149 if( iSessionCount == 1 ) //If first session, prepare collector |
|
150 { |
|
151 PrepareCollectorL(); |
|
152 } |
|
153 } |
|
154 //------------------------------------------------------------ |
|
155 // CCntParserServer::DecreaseSessionCount() |
|
156 //------------------------------------------------------------ |
|
157 void CCntParserServer::DecreaseSessionCount() |
|
158 { |
|
159 LOGGER_WRITE( "CntParserServer: Decrease Session Count" ); |
|
160 iSessionCount--; |
|
161 if( iSessionCount==0 ) //if last session is disconnected, delete server |
|
162 { |
|
163 Stop(); |
|
164 } |
|
165 } |
|
166 //------------------------------------------------------------ |
|
167 // CCntParserServer::ContactsParsed() |
|
168 //------------------------------------------------------------ |
|
169 TInt CCntParserServer::ContactsParsed() |
|
170 { |
|
171 return iCollector->CurrentItem(); |
|
172 } |
|
173 //------------------------------------------------------------ |
|
174 // CCntParserServer::TotalNumOfContacts() |
|
175 //------------------------------------------------------------ |
|
176 TInt CCntParserServer::TotalNumOfContacts() |
|
177 { |
|
178 //After the PrepareCollector is called, the number of contacts can be returned |
|
179 return iCollector->Count(); |
|
180 } |
|
181 //------------------------------------------------------------ |
|
182 // CCntParserServer::ContactsSaved() |
|
183 //------------------------------------------------------------ |
|
184 TInt CCntParserServer::ContactsSaved() |
|
185 { |
|
186 return iCollector->ContactsSaved(); |
|
187 } |
|
188 //------------------------------------------------------------ |
|
189 // CCntParserServer::PrepareCollectorL() |
|
190 //------------------------------------------------------------ |
|
191 void CCntParserServer::PrepareCollectorL() |
|
192 { |
|
193 LOGGER_WRITE( "CntParserServer: Prepare collectorL: Open Contact Database" ); |
|
194 |
|
195 TFileName dbFile; |
|
196 TFileName defaultDb; |
|
197 |
|
198 CContactDatabase::GetDefaultNameL( defaultDb ); |
|
199 |
|
200 LOGGER_WRITE( "CntParserServer: Prepare collectorL: GetDefault" ); |
|
201 |
|
202 iCurrentDatabase=CContactDatabase::OpenL(); |
|
203 |
|
204 LOGGER_WRITE( "CntParserServer: Prepare collectorL: OpenDefault" ); |
|
205 |
|
206 iCurrentDatabase->GetCurrentDatabase( dbFile ); //Get selected database |
|
207 |
|
208 LOGGER_WRITE( "CntParserServer: Prepare collectorL: CompareDefault" ); |
|
209 |
|
210 if( dbFile.CompareF(defaultDb)!=0 && dbFile!=KNullDesC16 /*&& dbFile.CompareF(KSimDummyDatabase)!=0*/) //If the selected database is not the default and something is selected |
|
211 { |
|
212 LOGGER_WRITE( "CntParserServer: Prepare collectorL: Close Default" ); |
|
213 delete iCurrentDatabase; |
|
214 iCurrentDatabase = NULL; |
|
215 |
|
216 LOGGER_WRITE( "CntParserServer: Prepare collectorL: OpenSelected" ); |
|
217 iCurrentDatabase=CContactDatabase::OpenL( dbFile ); //open the selected one |
|
218 } |
|
219 |
|
220 LOGGER_WRITE( "CntParserServer: Prepare collectorL: Is everything ok?" ); |
|
221 if( !iCurrentDatabase ) |
|
222 { |
|
223 User::Leave( KErrNotFound ); |
|
224 } |
|
225 |
|
226 LOGGER_WRITE( "CntParserServer: Prepare collectorL: Create Collector" ); |
|
227 iCollector = CCntParserCollector::NewL( this,iCurrentDatabase ); |
|
228 |
|
229 iRequests = 0; |
|
230 } |
|
231 //------------------------------------------------------------ |
|
232 // CCntParserServer::CreateIrMCL2PhoneBookL() |
|
233 //------------------------------------------------------------ |
|
234 TInt CCntParserServer::CreateIrMCL2PhoneBookL(const TDesC& path, TInt aMaxNumberOfContacts,TBool aForced) |
|
235 { |
|
236 LOGGER_WRITE( "CntParserServer: CreateIrMCL2PhoneBookL" ); |
|
237 |
|
238 TInt err( KErrNone ); |
|
239 |
|
240 iRequests++; |
|
241 if( iRequests == 1 ) |
|
242 { |
|
243 LOGGER_WRITE( "CntParserServer: CreateIrMCL2PhoneBookL: Ready to call collector" ); |
|
244 |
|
245 err = iCollector->CreateIrMCL2FileL( path,aMaxNumberOfContacts,aForced ); |
|
246 if( err==KPBNotUpdated ) |
|
247 { |
|
248 iRequests = 0; //If the file exists (no parsing), then more requests can be made |
|
249 } |
|
250 } |
|
251 else |
|
252 { |
|
253 return KErrNotReady; |
|
254 } |
|
255 return err; |
|
256 } |
|
257 //------------------------------------------------------------ |
|
258 // CCntParserServer::CompletePhoneBookRequests() |
|
259 //------------------------------------------------------------ |
|
260 void CCntParserServer::CompletePhoneBookRequests(TInt aErr) //Goes through all the sessions and completes the request |
|
261 { |
|
262 LOGGER_WRITE( "CntParserServer: Complete phonebook request" ); |
|
263 iSessionIter.SetToFirst(); |
|
264 while( iSessionIter!=NULL ) //Go through all sessions |
|
265 { |
|
266 ( (CCntParserServerSession*) (iSessionIter++) )->CompletePhoneBookRequest( aErr ); |
|
267 } |
|
268 iRequests = 0; //Collector is ready to start again.. |
|
269 } |
|
270 //------------------------------------------------------------ |
|
271 // CCntParserServer::CancelPhoneBookRequest() |
|
272 //------------------------------------------------------------ |
|
273 void CCntParserServer::CancelPhoneBookRequest() |
|
274 { |
|
275 if( iRequests == 1 ) |
|
276 { |
|
277 iCollector->Cancel(); |
|
278 } |
|
279 iRequests--; |
|
280 } |
|
281 //------------------------------------------------------------ |
|
282 // CCntParserServer::CancelAllPhoneBookRequests() |
|
283 //------------------------------------------------------------ |
|
284 void CCntParserServer::CancelAllPhoneBookRequests() |
|
285 { |
|
286 iCollector->Cancel(); |
|
287 iRequests = 0; |
|
288 } |
|
289 //------------------------------------------------------------ |
|
290 // CCntParserServer::Disconnect() |
|
291 //------------------------------------------------------------ |
|
292 void CCntParserServer::Disconnect() |
|
293 { |
|
294 LOGGER_WRITE( "CntParserServer: Disconnect" ); |
|
295 } |
|
296 //------------------------------------------------------------ |
|
297 // CCntParserServer::Stop() |
|
298 //------------------------------------------------------------ |
|
299 void CCntParserServer::Stop() |
|
300 { |
|
301 LOGGER_ENTERFN( "CntParserServer::Stop()" ); |
|
302 if( iCollector ) |
|
303 { |
|
304 iCollector->Cancel(); |
|
305 } |
|
306 delete iCollector; |
|
307 iCollector = NULL; |
|
308 delete iCurrentDatabase; |
|
309 iCurrentDatabase = NULL; |
|
310 CActiveScheduler::Stop(); |
|
311 LOGGER_LEAVEFN( "CntParserServer::Stop()" ); |
|
312 } |
|
313 //------------------------------------------------------------ |
|
314 // CCntParserServer::SetRequests() |
|
315 //------------------------------------------------------------ |
|
316 void CCntParserServer::SetRequests(TInt aRequests) |
|
317 { |
|
318 iRequests=aRequests; |
|
319 } |
|
320 |
|
321 |
|
322 |
|