1 /* |
|
2 * Copyright (c) 2006 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: CBSUpdater.cpp |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "e32base.h" |
|
22 |
|
23 #include "cbsupdater.h" |
|
24 #include "debugtrace.h" |
|
25 #include "mbsaccess.h" |
|
26 #include "bselementfactory.h" |
|
27 #include "mbselement.h" |
|
28 #include "bsserverdefs.h" |
|
29 |
|
30 // Two-phased constructor. |
|
31 CBSUpdater* CBSUpdater::NewL( const TDesC8& aApplicationId ) |
|
32 { |
|
33 CBSUpdater* self = new ( ELeave ) CBSUpdater() ; |
|
34 CleanupStack::PushL( self ); |
|
35 self->ConstructL( aApplicationId ); |
|
36 CleanupStack::Pop( self ); //self |
|
37 return self; |
|
38 } |
|
39 |
|
40 // Symbian OS default constructor can leave. |
|
41 void CBSUpdater::ConstructL( const TDesC8& aApplicationId ) |
|
42 { |
|
43 iApplicationId = aApplicationId.AllocL(); |
|
44 User::LeaveIfError( iClient.Connect() ); |
|
45 } |
|
46 |
|
47 // Destructor |
|
48 CBSUpdater::~CBSUpdater() |
|
49 { |
|
50 delete iApplicationId; |
|
51 delete iBrandId; |
|
52 iClient.Close(); |
|
53 } |
|
54 |
|
55 // C++ default constructor can NOT contain any code, that |
|
56 // might leave. |
|
57 // |
|
58 CBSUpdater::CBSUpdater() |
|
59 { |
|
60 } |
|
61 |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CBSUpdater::Close() |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 void CBSUpdater::Close() |
|
68 { |
|
69 delete this; |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CBSUpdater::StartTransactionL() |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 void CBSUpdater::StartTransactionL( const TDesC8& aBrandId, |
|
77 TLanguage aLanguageId, |
|
78 TUpdateTransactionType aType, /*EUpdateInstall*/ |
|
79 TInt aReserved) |
|
80 { |
|
81 if( iActive ) |
|
82 { |
|
83 User::Leave( KErrAlreadyExists ); |
|
84 } |
|
85 |
|
86 iActive = ETrue; |
|
87 HBufC8* tmp = aBrandId.AllocL(); |
|
88 delete iBrandId; |
|
89 iBrandId = tmp; |
|
90 iLanguageId = aLanguageId; |
|
91 iReserved = aReserved; |
|
92 iTxType = aType; |
|
93 |
|
94 TTransactionType operation = EBSTxAccess; |
|
95 switch( aType ) |
|
96 { |
|
97 case EUpdateInstall: |
|
98 { |
|
99 operation = EBSTxInstall; |
|
100 break; |
|
101 } |
|
102 case EUpdateAppend: |
|
103 { |
|
104 operation = EBSTxAppend; |
|
105 break; |
|
106 } |
|
107 case EUpdateReplace: |
|
108 { |
|
109 operation = EBSTxReplace; |
|
110 break; |
|
111 } |
|
112 case EUpdateUninstall: |
|
113 { |
|
114 operation = EBSTxUninstall; |
|
115 break; |
|
116 } |
|
117 default: |
|
118 break; |
|
119 } |
|
120 |
|
121 TRAPD( err, iClient.StartTransactionL( *iApplicationId, aBrandId, KNullDesC8, |
|
122 aLanguageId, operation, aReserved ) ); |
|
123 if( err ) |
|
124 { |
|
125 iActive = EFalse; |
|
126 User::Leave( err ); |
|
127 } |
|
128 |
|
129 } |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CBSUpdater::StopTransactionL() |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 TInt CBSUpdater::StopTransactionL() |
|
135 { |
|
136 if( !iActive ) |
|
137 { |
|
138 User::Leave( KErrNotFound ); |
|
139 } |
|
140 |
|
141 TInt returnValue = iClient.StopTransactionL( *iApplicationId, |
|
142 *iBrandId, |
|
143 iLanguageId, |
|
144 iReserved ); |
|
145 iActive = EFalse; |
|
146 return returnValue; |
|
147 } |
|
148 |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CBSUpdater::CancelTransactionL() |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 void CBSUpdater::CancelTransactionL() |
|
155 { |
|
156 if( !iActive ) |
|
157 { |
|
158 User::Leave( KErrNotFound ); |
|
159 } |
|
160 |
|
161 iClient.CancelTransactionL( *iApplicationId, *iBrandId, iLanguageId, iReserved ); |
|
162 iActive = EFalse; |
|
163 } |
|
164 |
|
165 |
|
166 |
|
167 //*** BRAND INSTALLING ***// |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CBSUpdater::InsertTextL() |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 void CBSUpdater::InsertTextL( const TDesC8& aId, |
|
173 const TDesC& aText ) |
|
174 { |
|
175 if( !iActive ) |
|
176 { |
|
177 User::Leave( KErrNotReady ); |
|
178 } |
|
179 if( iTxType != EUpdateInstall ) |
|
180 { |
|
181 User::Leave( KErrArgument ); |
|
182 } |
|
183 MBSElement* element = BSElementFactory::CreateBSElementL( aId, EBSText, aText ); |
|
184 CleanupClosePushL( *element ); |
|
185 InsertElementL( element ); |
|
186 CleanupStack::PopAndDestroy(); // element |
|
187 } |
|
188 |
|
189 |
|
190 // ----------------------------------------------------------------------------- |
|
191 // CBSUpdater::InsertBufferL() |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 void CBSUpdater::InsertBufferL( const TDesC8& aId, |
|
195 const TDesC8& aBuffer ) |
|
196 { |
|
197 if( !iActive ) |
|
198 { |
|
199 User::Leave( KErrNotReady ); |
|
200 } |
|
201 if( iTxType != EUpdateInstall ) |
|
202 { |
|
203 User::Leave( KErrArgument ); |
|
204 } |
|
205 MBSElement* element = BSElementFactory::CreateBSElementL( aId, EBSBuffer, aBuffer ); |
|
206 CleanupClosePushL( *element ); |
|
207 InsertElementL( element ); |
|
208 CleanupStack::PopAndDestroy(); // element |
|
209 } |
|
210 |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CBSUpdater::InsertIntL() |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 void CBSUpdater::InsertIntL( const TDesC8& aId, |
|
217 TInt aInt ) |
|
218 { |
|
219 if( !iActive ) |
|
220 { |
|
221 User::Leave( KErrNotReady ); |
|
222 } |
|
223 if( iTxType != EUpdateInstall ) |
|
224 { |
|
225 User::Leave( KErrArgument ); |
|
226 } |
|
227 MBSElement* element = BSElementFactory::CreateBSElementL( aId, EBSInt, aInt ); |
|
228 CleanupClosePushL( *element ); |
|
229 InsertElementL( element ); |
|
230 CleanupStack::PopAndDestroy(); // element |
|
231 } |
|
232 |
|
233 |
|
234 // ----------------------------------------------------------------------------- |
|
235 // CBSUpdater::InsertFileL() |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 void CBSUpdater::InsertFileL( const TDesC8& aId, |
|
239 const TDesC& aFileName ) |
|
240 { |
|
241 if( !iActive ) |
|
242 { |
|
243 User::Leave( KErrNotReady ); |
|
244 } |
|
245 if( iTxType != EUpdateInstall ) |
|
246 { |
|
247 User::Leave( KErrArgument ); |
|
248 } |
|
249 MBSElement* element = BSElementFactory::CreateBSElementL( aId, EBSFile, aFileName ); |
|
250 CleanupClosePushL( *element ); |
|
251 InsertElementL( element ); |
|
252 CleanupStack::PopAndDestroy(); // element |
|
253 } |
|
254 |
|
255 |
|
256 // ----------------------------------------------------------------------------- |
|
257 // CBSUpdater::InsertElementL() |
|
258 // ----------------------------------------------------------------------------- |
|
259 // |
|
260 void CBSUpdater::InsertElementL( MBSElement* aElement ) |
|
261 { |
|
262 if( !iActive ) |
|
263 { |
|
264 User::Leave( KErrNotReady ); |
|
265 } |
|
266 if( iTxType != EUpdateInstall ) |
|
267 { |
|
268 User::Leave( KErrArgument ); |
|
269 } |
|
270 iClient.InsertL( aElement ); |
|
271 } |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 //*** BRAND UPDATING - replacing ***// |
|
277 // ----------------------------------------------------------------------------- |
|
278 // CBSUpdater::ReplaceTextL() |
|
279 // ----------------------------------------------------------------------------- |
|
280 // |
|
281 void CBSUpdater::ReplaceTextL( const TDesC8& aId, |
|
282 const TDesC& aText ) |
|
283 { |
|
284 if( !iActive ) |
|
285 { |
|
286 User::Leave( KErrNotReady ); |
|
287 } |
|
288 if( iTxType != EUpdateReplace ) |
|
289 { |
|
290 User::Leave( KErrArgument ); |
|
291 } |
|
292 MBSElement* element = BSElementFactory::CreateBSElementL( aId, EBSText, aText ); |
|
293 CleanupClosePushL( *element ); |
|
294 ReplaceElementL( element ); |
|
295 CleanupStack::PopAndDestroy(); // element |
|
296 } |
|
297 |
|
298 |
|
299 // ----------------------------------------------------------------------------- |
|
300 // CBSUpdater::ReplaceBufferL() |
|
301 // ----------------------------------------------------------------------------- |
|
302 // |
|
303 void CBSUpdater::ReplaceBufferL( const TDesC8& aId, |
|
304 const TDesC8& aBuffer ) |
|
305 { |
|
306 if( !iActive ) |
|
307 { |
|
308 User::Leave( KErrNotReady ); |
|
309 } |
|
310 if( iTxType != EUpdateReplace ) |
|
311 { |
|
312 User::Leave( KErrArgument ); |
|
313 } |
|
314 MBSElement* element = BSElementFactory::CreateBSElementL( aId, EBSBuffer, aBuffer ); |
|
315 CleanupClosePushL( *element ); |
|
316 ReplaceElementL( element ); |
|
317 CleanupStack::PopAndDestroy(); // element |
|
318 } |
|
319 |
|
320 |
|
321 // ----------------------------------------------------------------------------- |
|
322 // CBSUpdater::ReplaceIntL() |
|
323 // ----------------------------------------------------------------------------- |
|
324 // |
|
325 void CBSUpdater::ReplaceIntL( const TDesC8& aId, |
|
326 TInt aInt ) |
|
327 { |
|
328 if( !iActive ) |
|
329 { |
|
330 User::Leave( KErrNotReady ); |
|
331 } |
|
332 if( iTxType != EUpdateReplace ) |
|
333 { |
|
334 User::Leave( KErrArgument ); |
|
335 } |
|
336 MBSElement* element = BSElementFactory::CreateBSElementL( aId, EBSInt, aInt ); |
|
337 CleanupClosePushL( *element ); |
|
338 ReplaceElementL( element ); |
|
339 CleanupStack::PopAndDestroy(); // element |
|
340 } |
|
341 |
|
342 |
|
343 // ----------------------------------------------------------------------------- |
|
344 // CBSUpdater::ReplaceFileL() |
|
345 // ----------------------------------------------------------------------------- |
|
346 // |
|
347 void CBSUpdater::ReplaceFileL( const TDesC8& aId, |
|
348 const TDesC& aFileName ) |
|
349 { |
|
350 if( !iActive ) |
|
351 { |
|
352 User::Leave( KErrNotReady ); |
|
353 } |
|
354 if( iTxType != EUpdateReplace ) |
|
355 { |
|
356 User::Leave( KErrArgument ); |
|
357 } |
|
358 MBSElement* element = BSElementFactory::CreateBSElementL( aId, EBSFile, aFileName ); |
|
359 CleanupClosePushL( *element ); |
|
360 ReplaceElementL( element ); |
|
361 CleanupStack::PopAndDestroy(); // element |
|
362 } |
|
363 |
|
364 |
|
365 // ----------------------------------------------------------------------------- |
|
366 // CBSUpdater::ReplaceElementL() |
|
367 // ----------------------------------------------------------------------------- |
|
368 // |
|
369 void CBSUpdater::ReplaceElementL( MBSElement* aElement ) |
|
370 { |
|
371 if( !iActive ) |
|
372 { |
|
373 User::Leave( KErrNotReady ); |
|
374 } |
|
375 if( iTxType != EUpdateReplace ) |
|
376 { |
|
377 User::Leave( KErrArgument ); |
|
378 } |
|
379 iClient.ReplaceL( aElement ); |
|
380 } |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 //*** BRAND UPDATING - appending ***// |
|
386 // ----------------------------------------------------------------------------- |
|
387 // CBSUpdater::AppendTextL() |
|
388 // ----------------------------------------------------------------------------- |
|
389 // |
|
390 void CBSUpdater::AppendTextL( const TDesC8& aId, |
|
391 const TDesC& aText ) |
|
392 { |
|
393 if( !iActive ) |
|
394 { |
|
395 User::Leave( KErrNotReady ); |
|
396 } |
|
397 if( iTxType != EUpdateAppend ) |
|
398 { |
|
399 User::Leave( KErrArgument ); |
|
400 } |
|
401 MBSElement* element = BSElementFactory::CreateBSElementL( aId, EBSText, aText ); |
|
402 CleanupClosePushL( *element ); |
|
403 AppendElementL( element ); |
|
404 CleanupStack::PopAndDestroy(); // element |
|
405 } |
|
406 |
|
407 |
|
408 // ----------------------------------------------------------------------------- |
|
409 // CBSUpdater::AppendBufferL() |
|
410 // ----------------------------------------------------------------------------- |
|
411 // |
|
412 void CBSUpdater::AppendBufferL( const TDesC8& aId, |
|
413 const TDesC8& aBuffer ) |
|
414 { |
|
415 if( !iActive ) |
|
416 { |
|
417 User::Leave( KErrNotReady ); |
|
418 } |
|
419 if( iTxType != EUpdateAppend ) |
|
420 { |
|
421 User::Leave( KErrArgument ); |
|
422 } |
|
423 MBSElement* element = BSElementFactory::CreateBSElementL( aId, EBSBuffer, aBuffer ); |
|
424 CleanupClosePushL( *element ); |
|
425 AppendElementL( element ); |
|
426 CleanupStack::PopAndDestroy(); // element |
|
427 } |
|
428 |
|
429 |
|
430 // ----------------------------------------------------------------------------- |
|
431 // CBSUpdater::AppendIntL() |
|
432 // ----------------------------------------------------------------------------- |
|
433 // |
|
434 void CBSUpdater::AppendIntL( const TDesC8& aId, |
|
435 TInt aInt ) |
|
436 { |
|
437 if( !iActive ) |
|
438 { |
|
439 User::Leave( KErrNotReady ); |
|
440 } |
|
441 if( iTxType != EUpdateAppend ) |
|
442 { |
|
443 User::Leave( KErrArgument ); |
|
444 } |
|
445 MBSElement* element = BSElementFactory::CreateBSElementL( aId, EBSInt, aInt ); |
|
446 CleanupClosePushL( *element ); |
|
447 AppendElementL( element ); |
|
448 CleanupStack::PopAndDestroy(); // element |
|
449 } |
|
450 |
|
451 |
|
452 // ----------------------------------------------------------------------------- |
|
453 // CBSUpdater::AppendFileL() |
|
454 // ----------------------------------------------------------------------------- |
|
455 // |
|
456 void CBSUpdater::AppendFileL( const TDesC8& aId, |
|
457 const TDesC& aFileName ) |
|
458 { |
|
459 if( !iActive ) |
|
460 { |
|
461 User::Leave( KErrNotReady ); |
|
462 } |
|
463 if( iTxType != EUpdateAppend ) |
|
464 { |
|
465 User::Leave( KErrArgument ); |
|
466 } |
|
467 MBSElement* element = BSElementFactory::CreateBSElementL( aId, EBSFile, aFileName ); |
|
468 CleanupClosePushL( *element ); |
|
469 AppendElementL( element ); |
|
470 CleanupStack::PopAndDestroy(); // element |
|
471 } |
|
472 |
|
473 |
|
474 // ----------------------------------------------------------------------------- |
|
475 // CBSUpdater::AppendElementL() |
|
476 // ----------------------------------------------------------------------------- |
|
477 // |
|
478 void CBSUpdater::AppendElementL( MBSElement* aElement ) |
|
479 { |
|
480 if( !iActive ) |
|
481 { |
|
482 User::Leave( KErrNotReady ); |
|
483 } |
|
484 if( iTxType != EUpdateAppend ) |
|
485 { |
|
486 User::Leave( KErrArgument ); |
|
487 } |
|
488 iClient.AppendL( aElement ); |
|
489 } |
|
490 |
|
491 |
|
492 // ----------------------------------------------------------------------------- |
|
493 // CBSUpdater::AppendElementL() |
|
494 // ----------------------------------------------------------------------------- |
|
495 // |
|
496 void CBSUpdater::RemoveBrandL( const TDesC8& aApplicationId, |
|
497 const TDesC8& aBrandId ) |
|
498 { |
|
499 if( !iActive ) |
|
500 { |
|
501 User::Leave( KErrNotReady ); |
|
502 } |
|
503 iClient.RemoveBrandL( aApplicationId, aBrandId ); |
|
504 } |
|
505 |
|
506 // ----------------------------------------------------------------------------- |
|
507 // CBSUpdater::AppendElementL() |
|
508 // ----------------------------------------------------------------------------- |
|
509 // |
|
510 void CBSUpdater:: RemoveBrandsL( const TDesC8& aApplicationId ) |
|
511 { |
|
512 if( !iActive ) |
|
513 { |
|
514 User::Leave( KErrNotReady ); |
|
515 } |
|
516 iClient.RemoveBrandsL( aApplicationId ); |
|
517 } |
|
518 |
|
519 // ----------------------------------------------------------------------------- |
|
520 // CBSUpdater::RegisterObserverL() |
|
521 // ----------------------------------------------------------------------------- |
|
522 // |
|
523 void CBSUpdater:: RegisterObserverL( MBSBackupRestoreStateObserver* aBackupObserver ) |
|
524 { |
|
525 iClient.RegisterObserverL(NULL, aBackupObserver) ; |
|
526 } |
|
527 |
|
528 // ----------------------------------------------------------------------------- |
|
529 // CBSUpdater::UnRegisterObserverL() |
|
530 // ----------------------------------------------------------------------------- |
|
531 // |
|
532 void CBSUpdater:: UnRegisterObserverL( MBSBackupRestoreStateObserver* aObserver ) |
|
533 { |
|
534 iClient.UnRegisterObserverL(NULL, aObserver) ; |
|
535 } |
|
536 |
|
537 // END OF FILE |
|
538 |
|