00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00057 #include "centrepexample.h"
00058 #include <e32cons.h>
00059 #include "asyncwaiter.h"
00060
00061 _LIT(KTitle, "Central repository example");
00062 _LIT(KTextPressAKey, "\n\nPress any key to step through the example");
00063 _LIT(KExit,"\nPress any key to exit the application ");
00064 _LIT(KPressAKey,"\nPress any key to continue \n");
00065 _LIT(KErr,"\nThe repository file has not been set up. Please see the instructions in centrepexample.cpp for how to do this");
00066
00067 _LIT(KOpen,"\n\nOpening the repository and displaying some initial settings");
00068 _LIT(KChangeSet,"\nChanging some settings in the repository");
00069 _LIT(KReadSet,"\nReading the changed settings");
00070 _LIT(KTransact,"\n\nPerforming read and write transactions");
00071 _LIT(KDelete,"\n\nCreating integer and real number settings and deleting them");
00072 _LIT(KMove,"\n\nMoving the key to target position");
00073 _LIT(KReset,"\nResetting settings to default values, and getting notifications that the changes have occurred");
00074 _LIT(KFind,"\nFinding settings for simple and structured data");
00075 _LIT(KNonExisting,"\n\nValue of new setting is %d");
00076 _LIT(KInt,"\nValue of setting with key x01 is %d");
00077 _LIT(KReal,"\nValue of setting with key x02 is %f");
00078 _LIT(KInteg,"\nValue of setting with key x06 is %d \n");
00079 _LIT(KIntBefore,"\nValue of setting with key x01 before reset is %d");
00080 _LIT(KIntAfter,"\nValue of setting with key x01 after reset is %d");
00081 _LIT(KIdsFound,"\nFound %d settings");
00082 _LIT(KStringName,"Another string");
00083 _LIT(KString1_UpdatedValue, "Value of setting with key x05 is %s");
00084
00085 static const TUid KUidRepository = { 0xE80000AD };
00086 const TUint32 KNonExistentSetting = 0x10;
00087 const TUint32 KInt1 = 0x01;
00088 const TUint32 KInt3 = 0x06;
00089 const TUint32 KReal1 = 0x02;
00090 const TUint32 KString1 = 0x05;
00091 const TInt KInt1_InitialValue = 1;
00092 const TInt KInt1_UpdatedValue = 73;
00093 const TReal KReal1_InitialValue = 14.91;
00094 const TReal KReal1_UpdatedValue = 72.8;
00095 const TUint32 KMoveTarget = 0x30;
00096
00102 CCentRepExample* CCentRepExample::NewLC()
00103 {
00104 CCentRepExample* rep = new(ELeave) CCentRepExample();
00105 CleanupStack::PushL(rep);
00106 rep->ConstructL();
00107 return rep;
00108 }
00109
00113 CCentRepExample::CCentRepExample()
00114 {
00115 }
00116
00117 void CCentRepExample::ConstructL()
00118 {
00119
00120 iConsole = Console::NewL(KTitle,TSize(KConsFullScreen,KConsFullScreen));
00121 iConsole->Printf ( KTextPressAKey );
00122 iConsole->Getch ();
00123 }
00124
00128 CCentRepExample::~CCentRepExample()
00129 {
00130 iConsole->Printf(KExit);
00131 iConsole->Getch();
00132
00133 delete iConsole;
00134 delete iRepository;
00135 }
00136
00137
00144 void CCentRepExample::ResetL()
00145 {
00146 CRepository* repository = NULL;
00147 TRAPD(err, repository = CRepository::NewL(KUidRepository););
00148 CleanupStack::PushL(repository);
00149
00150
00151
00152 if (err == KErrNotFound)
00153 {
00154 iConsole->Printf(KErr);
00155 }
00156 User::LeaveIfError(err);
00157 User::LeaveIfError(err = repository->Reset());
00158 CleanupStack::PopAndDestroy(repository);
00159 }
00160
00167 void CCentRepExample::OpenRepositoryL()
00168 {
00169 TInt i, k;
00170 TReal j;
00171 TBuf<50> tooShort;
00172 iConsole->Printf(KOpen);
00173 iRepository = CRepository::NewL(KUidRepository);
00174
00175 User::LeaveIfError(iRepository->Get(KInt1, i));
00176 iConsole->Printf(KInt,i);
00177
00178 User::LeaveIfError(iRepository->Get(KReal1, j));
00179 iConsole->Printf(KReal,j);
00180
00181 User::LeaveIfError(iRepository->Get(KInt3, k));
00182 iConsole->Printf(KInteg,k);
00183
00184 User::LeaveIfError(iRepository->Get(KString1, tooShort));
00185 iConsole->Printf(KString1_UpdatedValue,tooShort.PtrZ());
00186
00187 iConsole->Printf(KPressAKey);
00188 iConsole->Getch();
00189
00190 }
00191
00197 void CCentRepExample::ChangeSettingsL()
00198 {
00199 iConsole->Printf(KChangeSet);
00200 User::LeaveIfError(iRepository->Set(KNonExistentSetting, 10));
00201
00202 User::LeaveIfError(iRepository->Set(KInt1, KInt1_UpdatedValue));
00203
00204 User::LeaveIfError(iRepository->Set(KReal1, KReal1_InitialValue));
00205
00206 User::LeaveIfError(iRepository->Set(KInt3, KInt1_InitialValue));
00207
00208 User::LeaveIfError(iRepository->Set(KString1, KStringName));
00209
00210 }
00211
00217 void CCentRepExample::ReadSettingsL()
00218 {
00219 TInt m, i, k;
00220 TReal j;
00221 TBuf<50> tooShort;
00222 iConsole->Printf(KReadSet);
00223
00224 User::LeaveIfError(iRepository->Get(KNonExistentSetting, m));
00225
00226 iConsole->Printf(KNonExisting,m);
00227
00228 User::LeaveIfError(iRepository->Get(KInt1, i));
00229
00230 iConsole->Printf(KInt,i);
00231
00232 User::LeaveIfError(iRepository->Get(KReal1, j));
00233
00234 iConsole->Printf(KReal,j);
00235
00236 User::LeaveIfError(iRepository->Get(KInt3, k));
00237
00238 iConsole->Printf(KInteg,k);
00239
00240 User::LeaveIfError(iRepository->Get(KString1, tooShort));
00241
00242 iConsole->Printf(KString1_UpdatedValue,tooShort.PtrZ());
00243
00244 iConsole->Printf(KPressAKey);
00245 iConsole->Getch();
00246
00247 }
00248
00256 void CCentRepExample::FindSettingsL()
00257 {
00258 RArray<TUint32> foundIds;
00259
00260
00261
00262 iConsole->Printf(KFind);
00263
00264
00265
00266
00267 User::LeaveIfError(iRepository->FindL(0x100 , 0xF00, foundIds));
00268
00269 iConsole->Printf(KIdsFound,foundIds.Count());
00270 foundIds.Reset();
00271
00272
00273
00274
00275 User::LeaveIfError(iRepository->FindEqL(0x00, 0x00,KInt1_InitialValue , foundIds));
00276
00277 iConsole->Printf(KIdsFound,foundIds.Count());
00278 foundIds.Reset();
00279
00280
00281
00282 User::LeaveIfError(iRepository->FindEqL(0x00, 0x00,KReal1_InitialValue, foundIds));
00283
00284 iConsole->Printf(KIdsFound,foundIds.Count());
00285 foundIds.Reset();
00286
00287
00288
00289
00290 User::LeaveIfError(iRepository->FindEqL(0x00, 0x00, KStringName, foundIds));
00291
00292 iConsole->Printf(KIdsFound,foundIds.Count());
00293 foundIds.Reset();
00294
00295
00296
00297
00298
00299 User::LeaveIfError(iRepository->FindNeqL(0x00, 0x00, KInt1_UpdatedValue, foundIds));
00300
00301 iConsole->Printf(KIdsFound,foundIds.Count());
00302 foundIds.Reset();
00303
00304
00305
00306
00307
00308 User::LeaveIfError(iRepository->FindNeqL(0x100, 0x0F0, KReal1_UpdatedValue, foundIds));
00309
00310 iConsole->Printf(KIdsFound,foundIds.Count());
00311 foundIds.Reset();
00312
00313 }
00319 void CCentRepExample::ResetAndNotifyL()
00320 {
00321 TInt x;
00322
00323
00324
00325 iConsole->Printf(KReset);
00326
00327 User::LeaveIfError(iRepository->Set(KInt1, KInt1_InitialValue+10));
00328
00329
00330 User::LeaveIfError(iRepository->Get(KInt1, x));
00331
00332 iConsole->Printf(KIntBefore, x);
00333
00334 CAsyncWaiter* waiter = CAsyncWaiter::NewL();
00335 CleanupStack::PushL(waiter);
00336
00337 User::LeaveIfError(iRepository->NotifyRequest(KInt1, waiter->iStatus));
00338
00339
00340
00341 User::LeaveIfError(iRepository->Reset(KInt1));
00342
00343
00344 waiter->StartAndWait();
00345 User::LeaveIfError(waiter->Result());
00346
00347
00348 User::LeaveIfError(iRepository->Get(KInt1, x));
00349 iConsole->Printf(KIntAfter, x);
00350
00351 CleanupStack::PopAndDestroy(waiter);
00352 }
00353
00358 void CCentRepExample::MoveSettingsL()
00359 {
00360 TUint32 keyInfo;
00361
00362 iConsole->Printf(KMove);
00363 iConsole->Printf(KPressAKey);
00364 iConsole->Getch();
00365
00366 User::LeaveIfError(iRepository->Move(KInt3, KMoveTarget, 0xFFFFFFFF,
00367 keyInfo));
00368 }
00369
00374 void CCentRepExample::TransactionFuncL()
00375 {
00376 TUint32 keyId;
00377 TInt intVal;
00378
00379 iConsole->Printf(KTransact);
00380
00381
00382 User::LeaveIfError(iRepository->StartTransaction(CRepository::EReadWriteTransaction));
00383
00384
00385 iRepository->CleanupCancelTransactionPushL();
00386
00387
00388 const TUint32 KNewInt = 0x16;
00389 const TInt KIntValue = 1201;
00390 intVal = KIntValue +33;
00391
00392
00393
00394 User::LeaveIfError(iRepository->Create(KNewInt, KIntValue));
00395
00396 User::LeaveIfError(iRepository->Set(KNewInt,intVal));
00397
00398
00399
00400 User::LeaveIfError(iRepository->CommitTransaction(keyId));
00401
00402
00403 User::LeaveIfError(iRepository->Get(KNewInt, intVal));
00404
00405
00406 User::LeaveIfError(iRepository->Delete(KNewInt));
00407 CleanupStack::Pop();
00408
00409 CRepository* repository1;
00410 User::LeaveIfNull(repository1 = CRepository::NewLC(KUidRepository));
00411
00412
00413 User::LeaveIfError(repository1->StartTransaction(CRepository::EReadTransaction));
00414
00415 CRepository* repository2;
00416 User::LeaveIfNull(repository2 = CRepository::NewLC(KUidRepository));
00417
00418
00419 User::LeaveIfError(repository2->StartTransaction(CRepository::EReadTransaction));
00420
00421
00422
00423 User::LeaveIfError(repository1->Get(KInt1, intVal));
00424
00425 repository1->CleanupCancelTransactionPushL();
00426
00427
00428 User::LeaveIfError(repository1->CommitTransaction(keyId));
00429 CleanupStack::Pop();
00430
00431
00432 repository2->CleanupCancelTransactionPushL();
00433 User::LeaveIfError(repository2->Get(KInt1, intVal));
00434 User::LeaveIfError(repository2->CommitTransaction(keyId));
00435
00436
00437 CleanupStack::Pop();
00438 CleanupStack::PopAndDestroy(2,repository1);
00439
00440
00441 }
00442
00447 void CCentRepExample::DeleteL()
00448 {
00449 TInt x;
00450 TReal y;
00451
00452 iConsole->Printf(KDelete);
00453
00454 User::LeaveIfError(iRepository->Get(KInt1_InitialValue, x));
00455 User::LeaveIfError(iRepository->Get(KReal1, y));
00456 User::LeaveIfError(iRepository->Delete(KInt1_InitialValue));
00457 User::LeaveIfError(iRepository->Delete(KMoveTarget));
00458 User::LeaveIfError(iRepository->Delete(KReal1));
00459 }
00460
00461 LOCAL_C void MainL()
00462 {
00463
00464 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
00465 CleanupStack::PushL(scheduler);
00466 CActiveScheduler::Install( scheduler );
00467 CCentRepExample * app = CCentRepExample ::NewLC();
00468
00469
00470 app->ResetL();
00471
00472
00473 app->OpenRepositoryL();
00474
00475
00476 app->ChangeSettingsL();
00477
00478
00479 app->ReadSettingsL();
00480
00481
00482 app->FindSettingsL();
00483
00484
00485 app->MoveSettingsL();
00486
00487
00488 app->ResetAndNotifyL();
00489
00490
00491 app->TransactionFuncL();
00492
00493
00494 app->DeleteL();
00495
00496 CleanupStack::PopAndDestroy(2);
00497
00498 }
00499
00500 GLDEF_C TInt E32Main()
00501 {
00502 __UHEAP_MARK;
00503 CTrapCleanup* cleanup = CTrapCleanup::New();
00504 if(cleanup == NULL)
00505 {
00506 return KErrNoMemory;
00507 }
00508 TRAPD(err, MainL());
00509 if(err != KErrNone)
00510 {
00511 User::Panic(_L("Failed to complete"),err);
00512 }
00513
00514 delete cleanup;
00515 __UHEAP_MARKEND;
00516 return KErrNone;
00517 }