|
1 /* |
|
2 * Copyright (c) 2005-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: Phonebook 2 application server service class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CPbk2AppService.h" |
|
20 |
|
21 // Phonebook 2 |
|
22 #include "CPbk2AssignService.h" |
|
23 #include "CPbk2FetchService.h" |
|
24 #include <Pbk2ServerAppIPC.h> |
|
25 |
|
26 // Debug |
|
27 #include <Pbk2Debug.h> |
|
28 |
|
29 // -------------------------------------------------------------------------- |
|
30 // CPbk2AppService::CPbk2AppService |
|
31 // -------------------------------------------------------------------------- |
|
32 // |
|
33 CPbk2AppService::CPbk2AppService() |
|
34 { |
|
35 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
36 ("CPbk2AppService::CPbk2AppService()") ); |
|
37 } |
|
38 |
|
39 // -------------------------------------------------------------------------- |
|
40 // CPbk2AppService::~CPbk2AppService |
|
41 // -------------------------------------------------------------------------- |
|
42 // |
|
43 CPbk2AppService::~CPbk2AppService() |
|
44 { |
|
45 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
46 ("CPbk2AppService::~CPbk2AppService()") ); |
|
47 if ( !iAcceptMsg.IsNull() ) |
|
48 { |
|
49 iAcceptMsg.Complete( KErrServerTerminated ); |
|
50 } |
|
51 |
|
52 if ( !iExitMsg.IsNull() ) |
|
53 { |
|
54 iExitMsg.Complete( KErrServerTerminated ); |
|
55 } |
|
56 |
|
57 delete iFetchService; |
|
58 delete iAssignService; |
|
59 } |
|
60 |
|
61 // -------------------------------------------------------------------------- |
|
62 // CPbk2AppService::NewL |
|
63 // -------------------------------------------------------------------------- |
|
64 // |
|
65 CPbk2AppService* CPbk2AppService::NewL() |
|
66 { |
|
67 CPbk2AppService* self = new ( ELeave ) CPbk2AppService; |
|
68 return self; |
|
69 } |
|
70 |
|
71 // -------------------------------------------------------------------------- |
|
72 // CPbk2AppService::ServiceL |
|
73 // -------------------------------------------------------------------------- |
|
74 // |
|
75 void CPbk2AppService::ServiceL( const RMessage2& aMessage ) |
|
76 { |
|
77 TInt functionId = aMessage.Function(); |
|
78 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
79 ("CPbk2AppService::ServiceL(%d)"), functionId ); |
|
80 switch ( functionId ) |
|
81 { |
|
82 case EPbk2LaunchFetch: |
|
83 { |
|
84 // Launch fetch service |
|
85 delete iFetchService; |
|
86 iFetchService = NULL; |
|
87 iFetchService = CPbk2FetchService::NewL( iExitMsg, iAcceptMsg ); |
|
88 iFetchService->LaunchServiceL( aMessage ); |
|
89 break; |
|
90 } |
|
91 |
|
92 case EPbk2CancelFetch: |
|
93 { |
|
94 // Synchronous service |
|
95 // Cancel fetch service |
|
96 if ( iFetchService ) |
|
97 { |
|
98 iFetchService->CancelService( aMessage ); |
|
99 } |
|
100 // Complete message if it is not completed by service |
|
101 if ( !aMessage.IsNull() ) |
|
102 { |
|
103 aMessage.Complete( KErrNone ); |
|
104 } |
|
105 break; |
|
106 } |
|
107 |
|
108 case EPbk2LaunchAssign: // FALLTHROUGH |
|
109 case EPbk2LaunchAttributeAssign: // FALLTHROUGH |
|
110 case EPbk2LaunchAttributeUnassign: |
|
111 { |
|
112 // Launch assign contact service |
|
113 delete iAssignService; |
|
114 iAssignService = NULL; |
|
115 iAssignService = CPbk2AssignService::NewL( iExitMsg ); |
|
116 iAssignService->LaunchServiceL( aMessage ); |
|
117 break; |
|
118 } |
|
119 |
|
120 case EPbk2CancelAssign: |
|
121 { |
|
122 // Synchronous service |
|
123 // Cancel assign service |
|
124 if ( iAssignService ) |
|
125 { |
|
126 iAssignService->CancelService( aMessage ); |
|
127 } |
|
128 // Complete message if it is not completed by service |
|
129 if ( !aMessage.IsNull() ) |
|
130 { |
|
131 aMessage.Complete( KErrNone ); |
|
132 } |
|
133 break; |
|
134 } |
|
135 |
|
136 case EPbk2GetResults: |
|
137 { |
|
138 // Synchronous service |
|
139 if ( iFetchService ) |
|
140 { |
|
141 iFetchService->GetResultsL( aMessage ); |
|
142 } |
|
143 if ( iAssignService ) |
|
144 { |
|
145 iAssignService->GetResultsL( aMessage ); |
|
146 } |
|
147 // Complete message if it is not completed by service |
|
148 if ( !aMessage.IsNull() ) |
|
149 { |
|
150 aMessage.Complete( KErrNone ); |
|
151 } |
|
152 break; |
|
153 } |
|
154 |
|
155 case EPbk2GetResultSize: |
|
156 { |
|
157 // Synchronous service |
|
158 if ( iFetchService ) |
|
159 { |
|
160 iFetchService->GetResultSizeL( aMessage ); |
|
161 } |
|
162 if ( iAssignService ) |
|
163 { |
|
164 iAssignService->GetResultSizeL( aMessage ); |
|
165 } |
|
166 // Complete message if it is not completed by service |
|
167 if ( !aMessage.IsNull() ) |
|
168 { |
|
169 aMessage.Complete( KErrNone ); |
|
170 } |
|
171 break; |
|
172 } |
|
173 |
|
174 case EPbk2ExitRequest: |
|
175 { |
|
176 StoreExitRequest( aMessage ); |
|
177 break; |
|
178 } |
|
179 |
|
180 case EPbk2CancelExitRequest: |
|
181 { |
|
182 CancelExitRequest( aMessage ); |
|
183 break; |
|
184 } |
|
185 |
|
186 case EPbk2AcceptRequest: |
|
187 { |
|
188 StoreAcceptRequest( aMessage ); |
|
189 break; |
|
190 } |
|
191 |
|
192 case EPbk2CancelAcceptRequest: |
|
193 { |
|
194 CancelAcceptRequest( aMessage ); |
|
195 break; |
|
196 } |
|
197 |
|
198 case EPbk2ExitService: |
|
199 { |
|
200 // Synchronous service |
|
201 // After the client has received a completion |
|
202 // to EPbk2ExitRequest, it must send this |
|
203 // message to fulfill the protocol |
|
204 if ( iFetchService ) |
|
205 { |
|
206 iFetchService->TryExitServiceL( aMessage ); |
|
207 } |
|
208 if ( iAssignService ) |
|
209 { |
|
210 iAssignService->TryExitServiceL( aMessage ); |
|
211 } |
|
212 // Complete message if it is not completed by service |
|
213 if ( !aMessage.IsNull() ) |
|
214 { |
|
215 aMessage.Complete( KErrNone ); |
|
216 } |
|
217 break; |
|
218 } |
|
219 |
|
220 case EPbk2AcceptService: |
|
221 { |
|
222 // Synchronous service |
|
223 // After the client has received a completion |
|
224 // to EPbk2AcceptRequest, it must send this |
|
225 // message to fulfill the protocol |
|
226 if ( iFetchService ) |
|
227 { |
|
228 iFetchService->TryAcceptServiceL( aMessage ); |
|
229 } |
|
230 if ( iAssignService ) |
|
231 { |
|
232 iAssignService->TryAcceptServiceL( aMessage ); |
|
233 } |
|
234 // Complete message if it is not completed by service |
|
235 if ( !aMessage.IsNull() ) |
|
236 { |
|
237 aMessage.Complete( KErrNone ); |
|
238 } |
|
239 break; |
|
240 } |
|
241 |
|
242 default: |
|
243 { |
|
244 // Message not recognized, pass it to base class |
|
245 CAknAppServiceBase::ServiceL( aMessage ); |
|
246 break; |
|
247 } |
|
248 } |
|
249 } |
|
250 |
|
251 // -------------------------------------------------------------------------- |
|
252 // CPbk2AppService::SecurityCheckL |
|
253 // Security check performed when client sends a message requesting a service. |
|
254 // -------------------------------------------------------------------------- |
|
255 // |
|
256 CPolicyServer::TCustomResult CPbk2AppService::SecurityCheckL |
|
257 ( const RMessage2& aMsg, TInt& aAction, TSecurityInfo& aMissing ) |
|
258 { |
|
259 CPolicyServer::TCustomResult res = CPolicyServer::EFail; |
|
260 aAction = CPolicyServer::EPanicClient; |
|
261 |
|
262 TInt functionId = aMsg.Function(); |
|
263 |
|
264 switch ( functionId ) |
|
265 { |
|
266 case EPbk2LaunchFetch: |
|
267 case EPbk2CancelFetch: // FALLTHROUGH |
|
268 { |
|
269 // Fetch needs ReadUserData capability |
|
270 if ( aMsg.HasCapability( ECapabilityReadUserData ) ) |
|
271 { |
|
272 res = CPolicyServer::EPass; |
|
273 } |
|
274 break; |
|
275 } |
|
276 |
|
277 case EPbk2LaunchAssign: // FALLTHROUGH |
|
278 case EPbk2CancelAssign: // FALLTHROUGH |
|
279 case EPbk2LaunchAttributeAssign: // FALLTHROUGH |
|
280 case EPbk2LaunchAttributeUnassign: |
|
281 { |
|
282 // Assign needs ReadUserData and WriteUserData capabilities |
|
283 if ( aMsg.HasCapability( ECapabilityReadUserData ) && |
|
284 aMsg.HasCapability( ECapabilityWriteUserData ) ) |
|
285 { |
|
286 res = CPolicyServer::EPass; |
|
287 } |
|
288 break; |
|
289 } |
|
290 |
|
291 case EPbk2GetResults: // FALLTHROUGH |
|
292 case EPbk2GetResultSize: |
|
293 { |
|
294 // Result fetching needs ReadUserData capability |
|
295 if ( aMsg.HasCapability( ECapabilityReadUserData ) ) |
|
296 { |
|
297 res = CPolicyServer::EPass; |
|
298 } |
|
299 break; |
|
300 } |
|
301 |
|
302 case EPbk2AcceptService: // FALLTHROUGH |
|
303 case EPbk2AcceptRequest: |
|
304 { |
|
305 // Accepting needs ReadUserData capability |
|
306 if ( aMsg.HasCapability( ECapabilityReadUserData ) ) |
|
307 { |
|
308 res = CPolicyServer::EPass; |
|
309 } |
|
310 break; |
|
311 } |
|
312 |
|
313 case EPbk2ExitService: // FALLTHROUGH |
|
314 case EPbk2ExitRequest: // FALLTHROUGH |
|
315 case EPbk2CancelExitRequest: // FALLTHROUGH |
|
316 case EPbk2CancelAcceptRequest: |
|
317 { |
|
318 // No capabilities required |
|
319 res = CPolicyServer::EPass; |
|
320 break; |
|
321 } |
|
322 |
|
323 default: |
|
324 { |
|
325 // Call base class |
|
326 res = CAknAppServiceBase::SecurityCheckL |
|
327 ( aMsg, aAction, aMissing ); |
|
328 break; |
|
329 } |
|
330 } |
|
331 |
|
332 return res; |
|
333 } |
|
334 |
|
335 // -------------------------------------------------------------------------- |
|
336 // CPbk2AppService::StoreExitRequest |
|
337 // -------------------------------------------------------------------------- |
|
338 // |
|
339 void CPbk2AppService::StoreExitRequest( const RMessage2& aMessage ) |
|
340 { |
|
341 if ( iExitMsg.Handle() != KNullHandle ) |
|
342 { |
|
343 aMessage.Complete( KErrAlreadyExists ); |
|
344 } |
|
345 else |
|
346 { |
|
347 iExitMsg = aMessage; |
|
348 } |
|
349 } |
|
350 |
|
351 // -------------------------------------------------------------------------- |
|
352 // CPbk2AppService::CancelExitRequest |
|
353 // -------------------------------------------------------------------------- |
|
354 // |
|
355 void CPbk2AppService::CancelExitRequest( const RMessage2& aMessage ) |
|
356 { |
|
357 if ( iExitMsg.Handle() != KNullHandle ) |
|
358 { |
|
359 iExitMsg.Complete( KErrCancel ); |
|
360 } |
|
361 aMessage.Complete( KErrNone ); |
|
362 } |
|
363 |
|
364 // -------------------------------------------------------------------------- |
|
365 // CPbk2AppService::StoreAcceptRequest |
|
366 // -------------------------------------------------------------------------- |
|
367 // |
|
368 void CPbk2AppService::StoreAcceptRequest( const RMessage2& aMessage ) |
|
369 { |
|
370 if ( iAcceptMsg.Handle() != KNullHandle ) |
|
371 { |
|
372 aMessage.Complete( KErrAlreadyExists ); |
|
373 } |
|
374 else |
|
375 { |
|
376 iAcceptMsg = aMessage; |
|
377 } |
|
378 } |
|
379 |
|
380 // -------------------------------------------------------------------------- |
|
381 // CPbk2AppService::CancelAcceptRequest |
|
382 // -------------------------------------------------------------------------- |
|
383 // |
|
384 void CPbk2AppService::CancelAcceptRequest( const RMessage2& aMessage ) |
|
385 { |
|
386 if ( iAcceptMsg.Handle() != KNullHandle ) |
|
387 { |
|
388 iAcceptMsg.Complete( KErrCancel ); |
|
389 } |
|
390 aMessage.Complete( KErrNone ); |
|
391 } |
|
392 |
|
393 // End of File |