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