|
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 assign service. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CPbk2AssignService.h" |
|
20 |
|
21 // Phonebook 2 |
|
22 #include "CPbk2SingleContactDataAssigner.h" |
|
23 #include "CPbk2MultiContactDataAssigner.h" |
|
24 #include "CPbk2ContactAttributeAssigner.h" |
|
25 #include "TPbk2ServerMessageDataRetriever.h" |
|
26 #include "CPbk2ServerAppAppUi.h" |
|
27 #include <MPbk2ApplicationServices.h> |
|
28 |
|
29 // Virtual Phonebook |
|
30 #include <MVPbkContactLinkArray.h> |
|
31 |
|
32 // System includes |
|
33 #include <AiwContactAssignDataTypes.h> |
|
34 |
|
35 using namespace AiwContactAssign; |
|
36 |
|
37 |
|
38 /// Unnamed namespace for local definitions |
|
39 namespace { |
|
40 |
|
41 _LIT(KPanicText, "CPbk2AssignService"); |
|
42 |
|
43 enum TPanicCode |
|
44 { |
|
45 EInvalidRequest, |
|
46 EInvalidAssignType |
|
47 }; |
|
48 |
|
49 // RMessage IPC-argument slot order |
|
50 const TInt KResponseSlot = 0; |
|
51 const TInt KPackedResultsSlot = 0; |
|
52 const TInt KExtraResultsSlot = 1; |
|
53 const TInt KResultSizeSlot = 0; |
|
54 const TInt KAssignInstructionsSlot = 2; |
|
55 |
|
56 const TInt KExitAcceptedSlot = 0; // ok to exit protocol |
|
57 const TInt KExitCommandIdSlot = 1; // ok to exit protocol |
|
58 const TInt KCompleteExitCommandIdSlot = 0; // ok to exit protocol |
|
59 |
|
60 |
|
61 // Assign types |
|
62 enum TAssignType |
|
63 { |
|
64 EInvalidType, |
|
65 ESingleContactDataAssign, |
|
66 EMultipleContactDataAssign, |
|
67 EContactAttributeAssign, |
|
68 }; |
|
69 |
|
70 /** |
|
71 * Retrieves assign type from given message. |
|
72 * |
|
73 * @param aMessage Message. |
|
74 * @return Assign type. |
|
75 */ |
|
76 TAssignType AssignTypeL( const RMessage2& aMessage ) |
|
77 { |
|
78 TAssignType result = EInvalidType; |
|
79 |
|
80 TAiwContactAssignDataBasePckg dataPckg; |
|
81 aMessage.ReadL( KAssignInstructionsSlot, dataPckg ); |
|
82 |
|
83 switch ( TAiwContactAssignDataBase::AssignDataTypeFromBuffer |
|
84 ( dataPckg ) ) |
|
85 { |
|
86 case EAiwSingleContactAssignV1: |
|
87 { |
|
88 result = ESingleContactDataAssign; |
|
89 |
|
90 // Perform additional check for multiple preselected contacts |
|
91 TPbk2ServerMessageDataRetriever dataRetriever; |
|
92 CPbk2ServerAppAppUi& appUi = static_cast<CPbk2ServerAppAppUi&> |
|
93 ( *CEikonEnv::Static()->EikAppUi() ); |
|
94 MVPbkContactLinkArray* preselectedContacts = |
|
95 dataRetriever.GetPreselectedContactLinksL |
|
96 ( aMessage, |
|
97 appUi.ApplicationServices().ContactManager() ); |
|
98 if ( preselectedContacts && preselectedContacts->Count() > 1 ) |
|
99 { |
|
100 // Multiple preselected contacts found, switch to |
|
101 // multi assign mode |
|
102 result = EMultipleContactDataAssign; |
|
103 } |
|
104 delete preselectedContacts; |
|
105 break; |
|
106 } |
|
107 case EAiwMultipleContactAssignV1: |
|
108 { |
|
109 result = EMultipleContactDataAssign; |
|
110 break; |
|
111 } |
|
112 case EAiwContactAttributeAssignV1: |
|
113 { |
|
114 result = EContactAttributeAssign; |
|
115 break; |
|
116 } |
|
117 default: |
|
118 { |
|
119 aMessage.Panic( KPanicText, EInvalidAssignType ); |
|
120 break; |
|
121 } |
|
122 } |
|
123 return result; |
|
124 } |
|
125 |
|
126 } /// namespace |
|
127 |
|
128 |
|
129 // -------------------------------------------------------------------------- |
|
130 // CPbk2AssignService::CPbk2AssignService |
|
131 // -------------------------------------------------------------------------- |
|
132 // |
|
133 CPbk2AssignService::CPbk2AssignService( const RMessage2& aExitMsg ) : |
|
134 iExitMsg( aExitMsg ) |
|
135 { |
|
136 } |
|
137 |
|
138 // -------------------------------------------------------------------------- |
|
139 // CPbk2AssignService::~CPbk2AssignService |
|
140 // -------------------------------------------------------------------------- |
|
141 // |
|
142 CPbk2AssignService::~CPbk2AssignService() |
|
143 { |
|
144 if ( !iAssignCompleteMsg.IsNull() ) |
|
145 { |
|
146 iAssignCompleteMsg.Complete( KErrServerTerminated ); |
|
147 } |
|
148 |
|
149 delete iUiService; |
|
150 } |
|
151 |
|
152 // -------------------------------------------------------------------------- |
|
153 // CPbk2AssignService::NewL |
|
154 // -------------------------------------------------------------------------- |
|
155 // |
|
156 CPbk2AssignService* CPbk2AssignService::NewL( const RMessage2& aExitMsg ) |
|
157 { |
|
158 CPbk2AssignService* self = |
|
159 new ( ELeave ) CPbk2AssignService( aExitMsg ); |
|
160 return self; |
|
161 } |
|
162 |
|
163 // -------------------------------------------------------------------------- |
|
164 // CPbk2AssignService::LaunchServiceL |
|
165 // -------------------------------------------------------------------------- |
|
166 // |
|
167 void CPbk2AssignService::LaunchServiceL( const RMessage2& aMessage ) |
|
168 { |
|
169 if ( ( iAssignCompleteMsg.Handle() != KNullHandle ) && |
|
170 ( iExitMsg.Handle() == KNullHandle ) ) |
|
171 { |
|
172 aMessage.Panic( KPanicText, EInvalidRequest ); |
|
173 } |
|
174 |
|
175 delete iUiService; |
|
176 iUiService = NULL; |
|
177 |
|
178 switch ( AssignTypeL( aMessage ) ) |
|
179 { |
|
180 case ESingleContactDataAssign: |
|
181 { |
|
182 iUiService = CPbk2SingleContactDataAssigner::NewL |
|
183 ( aMessage, *this ); |
|
184 break; |
|
185 } |
|
186 case EMultipleContactDataAssign: |
|
187 { |
|
188 iUiService = CPbk2MultiContactDataAssigner::NewL |
|
189 ( aMessage, *this ); |
|
190 break; |
|
191 } |
|
192 case EContactAttributeAssign: |
|
193 { |
|
194 iUiService = CPbk2ContactAttributeAssigner::NewL |
|
195 ( aMessage, *this ); |
|
196 break; |
|
197 } |
|
198 default: |
|
199 { |
|
200 aMessage.Panic( KPanicText, EInvalidRequest ); |
|
201 break; |
|
202 } |
|
203 } |
|
204 |
|
205 iAssignCompleteMsg = aMessage; |
|
206 iUiService->LaunchServiceL(); |
|
207 } |
|
208 |
|
209 // -------------------------------------------------------------------------- |
|
210 // CPbk2AssignService::CancelService |
|
211 // -------------------------------------------------------------------------- |
|
212 // |
|
213 void CPbk2AssignService::CancelService( const RMessage2& aMessage ) |
|
214 { |
|
215 // If iAssignCompleteMsg is already completed do nothing |
|
216 if ( !iAssignCompleteMsg.IsNull() ) |
|
217 { |
|
218 iUiService->CancelService(); |
|
219 } |
|
220 |
|
221 aMessage.Complete( KErrNone ); |
|
222 } |
|
223 |
|
224 // -------------------------------------------------------------------------- |
|
225 // CPbk2AssignService::GetResultsL |
|
226 // -------------------------------------------------------------------------- |
|
227 // |
|
228 void CPbk2AssignService::GetResultsL( const RMessage2& aMessage ) |
|
229 { |
|
230 if ( iUiService ) |
|
231 { |
|
232 MPbk2UiService::TServiceResults results; |
|
233 iUiService->ServiceResults(&results); |
|
234 if ( results.iLinkArray ) |
|
235 { |
|
236 HBufC8* packedResults = results.iLinkArray->PackLC(); |
|
237 TPckg<TInt> extraData(results.iExtraData); |
|
238 TRAP_IGNORE( |
|
239 aMessage.WriteL(KPackedResultsSlot, *packedResults ); |
|
240 aMessage.WriteL(KExtraResultsSlot, extraData ); |
|
241 ); |
|
242 CleanupStack::PopAndDestroy(); // packedResults |
|
243 } |
|
244 } |
|
245 aMessage.Complete( KErrNone ); |
|
246 } |
|
247 |
|
248 // -------------------------------------------------------------------------- |
|
249 // CPbk2AssignService::GetResultSizeL |
|
250 // -------------------------------------------------------------------------- |
|
251 // |
|
252 void CPbk2AssignService::GetResultSizeL( const RMessage2& aMessage ) |
|
253 { |
|
254 if ( iUiService ) |
|
255 { |
|
256 MPbk2UiService::TServiceResults results; |
|
257 iUiService->ServiceResults(&results); |
|
258 if ( results.iLinkArray ) |
|
259 { |
|
260 HBufC8* packedResults = results.iLinkArray->PackLC(); |
|
261 TPtr8 ptr = packedResults->Des(); |
|
262 TPckg<TInt> buffer( ptr.Size() ); |
|
263 TRAP_IGNORE( aMessage.WriteL( |
|
264 KResultSizeSlot, buffer ) ); |
|
265 CleanupStack::PopAndDestroy(); // packedResults |
|
266 } |
|
267 } |
|
268 aMessage.Complete( KErrNone ); |
|
269 } |
|
270 |
|
271 // -------------------------------------------------------------------------- |
|
272 // CPbk2AssignService::TryExitServiceL |
|
273 // -------------------------------------------------------------------------- |
|
274 // |
|
275 void CPbk2AssignService::TryExitServiceL( const RMessage2& aMessage ) |
|
276 { |
|
277 TBool accepted = EFalse; |
|
278 TPckg<TBool> acceptedPkg( accepted ); |
|
279 aMessage.ReadL( KExitAcceptedSlot, acceptedPkg ); |
|
280 |
|
281 if ( iUiService && accepted ) |
|
282 { |
|
283 TInt exitId = KErrNotFound; |
|
284 TPckg<TInt> exitPkg( exitId ); |
|
285 aMessage.ReadL( KExitCommandIdSlot, exitPkg ); |
|
286 |
|
287 iUiService->ExitServiceL( exitId ); |
|
288 } |
|
289 |
|
290 aMessage.Complete( KErrNone ); |
|
291 } |
|
292 |
|
293 // -------------------------------------------------------------------------- |
|
294 // CPbk2AssignService::TryAcceptServiceL |
|
295 // -------------------------------------------------------------------------- |
|
296 // |
|
297 void CPbk2AssignService::TryAcceptServiceL( const RMessage2& aMessage ) |
|
298 { |
|
299 // Accept protocol not supported in assign |
|
300 aMessage.Complete( KErrNotSupported ); |
|
301 } |
|
302 |
|
303 // -------------------------------------------------------------------------- |
|
304 // CPbk2AssignService::ServiceComplete |
|
305 // -------------------------------------------------------------------------- |
|
306 // |
|
307 void CPbk2AssignService::ServiceComplete() |
|
308 { |
|
309 if ( !iAssignCompleteMsg.IsNull() ) |
|
310 { |
|
311 TPckg<TBool> complete( EFalse ); |
|
312 TRAP_IGNORE( iAssignCompleteMsg.WriteL( KResponseSlot, complete ) ); |
|
313 iAssignCompleteMsg.Complete( KErrNone ); |
|
314 } |
|
315 } |
|
316 |
|
317 // -------------------------------------------------------------------------- |
|
318 // CPbk2AssignService::ServiceCanceled |
|
319 // -------------------------------------------------------------------------- |
|
320 // |
|
321 void CPbk2AssignService::ServiceCanceled() |
|
322 { |
|
323 if ( !iAssignCompleteMsg.IsNull() ) |
|
324 { |
|
325 TPckg<TBool> cancel( ETrue ); |
|
326 TRAP_IGNORE( iAssignCompleteMsg.WriteL( KResponseSlot, cancel ) ); |
|
327 iAssignCompleteMsg.Complete( KErrCancel ); |
|
328 } |
|
329 } |
|
330 |
|
331 // -------------------------------------------------------------------------- |
|
332 // CPbk2AssignService::ServiceAborted |
|
333 // -------------------------------------------------------------------------- |
|
334 // |
|
335 void CPbk2AssignService::ServiceAborted() |
|
336 { |
|
337 if ( !iAssignCompleteMsg.IsNull() ) |
|
338 { |
|
339 iAssignCompleteMsg.Complete( KErrAbort ); |
|
340 |
|
341 // There is nothing to do if ProcessCommandL leaves. |
|
342 // Of course it shouldn't leave in practice because it's |
|
343 // exit command. |
|
344 TRAP_IGNORE( ExitApplicationL() ); |
|
345 } |
|
346 } |
|
347 |
|
348 // -------------------------------------------------------------------------- |
|
349 // CPbk2AssignService::ServiceError |
|
350 // -------------------------------------------------------------------------- |
|
351 // |
|
352 void CPbk2AssignService::ServiceError( TInt aErrorCode ) |
|
353 { |
|
354 if ( !iAssignCompleteMsg.IsNull() ) |
|
355 { |
|
356 TPckg<TInt> error( aErrorCode ); |
|
357 TRAP_IGNORE( iAssignCompleteMsg.WriteL( KResponseSlot, error ) ); |
|
358 iAssignCompleteMsg.Complete( aErrorCode ); |
|
359 } |
|
360 } |
|
361 |
|
362 // -------------------------------------------------------------------------- |
|
363 // CPbk2AssignService::CompleteExitMessage |
|
364 // -------------------------------------------------------------------------- |
|
365 // |
|
366 void CPbk2AssignService::CompleteExitMessage( TInt aExitCommandId ) |
|
367 { |
|
368 TPckg<TInt> exitCommandId( aExitCommandId ); |
|
369 if ( iUiService && iExitMsg.Handle() != KNullHandle ) |
|
370 { |
|
371 TRAP_IGNORE( iExitMsg.WriteL( |
|
372 KCompleteExitCommandIdSlot, exitCommandId ) ); |
|
373 iExitMsg.Complete( KErrNone ); |
|
374 } |
|
375 } |
|
376 |
|
377 // -------------------------------------------------------------------------- |
|
378 // CPbk2AssignService::CompleteAcceptMsg |
|
379 // -------------------------------------------------------------------------- |
|
380 // |
|
381 void CPbk2AssignService::CompleteAcceptMsg |
|
382 ( const TDesC8& /*aMarkedEntries*/, const TDesC8& /*aLinkData*/ ) |
|
383 { |
|
384 // Not supported in assign |
|
385 } |
|
386 |
|
387 // -------------------------------------------------------------------------- |
|
388 // CPbk2AssignService::ExitApplicationL |
|
389 // -------------------------------------------------------------------------- |
|
390 // |
|
391 void CPbk2AssignService::ExitApplicationL() |
|
392 { |
|
393 // Exit application |
|
394 CEikonEnv* eikonEnv = CEikonEnv::Static(); |
|
395 if ( eikonEnv ) |
|
396 { |
|
397 CEikAppUi* appUi = eikonEnv->EikAppUi(); |
|
398 MEikCommandObserver* cmdObs = |
|
399 static_cast<MEikCommandObserver*>( appUi ); |
|
400 |
|
401 cmdObs->ProcessCommandL( EAknCmdExit ); |
|
402 } |
|
403 } |
|
404 |
|
405 // End of File |