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
00041 #include "centrepexample.h"
00042 #include <e32cons.h>
00043 #include "asyncwaiter.h"
00044
00045 _LIT(KTitle, "Central repository example");
00046 _LIT(KTextPressAKey, "\n\nPress any key to step through the example");
00047 _LIT(KExit,"\nPress any key to exit the application ");
00048 _LIT(KPressAKey,"\nPress any key to continue \n");
00049 _LIT(KErr,"\nThe repository file has not been set up. Please see the instructions in centrepexample.cpp for how to do this");
00050
00051 _LIT(KOpen,"\n\nOpening the repository and displaying some initial settings");
00052 _LIT(KChangeSet,"\nChanging some settings in the repository");
00053 _LIT(KReadSet,"\nReading the changed settings");
00054 _LIT(KTransact,"\n\nPerforming read and write transactions");
00055 _LIT(KDelete,"\n\nCreating integer and real number settings and deleting them");
00056 _LIT(KMove,"\n\nMoving the key to target position");
00057 _LIT(KReset,"\nResetting settings to default values, and getting notifications that the changes have occurred");
00058 _LIT(KFind,"\nFinding settings for simple and structured data");
00059 _LIT(KNonExisting,"\n\nValue of new setting is %d");
00060 _LIT(KInt,"\nValue of setting with key x01 is %d");
00061 _LIT(KReal,"\nValue of setting with key x02 is %f");
00062 _LIT(KInteg,"\nValue of setting with key x06 is %d \n");
00063 _LIT(KIntBefore,"\nValue of setting with key x01 before reset is %d");
00064 _LIT(KIntAfter,"\nValue of setting with key x01 after reset is %d");
00065 _LIT(KIdsFound,"\nFound %d settings");
00066 _LIT(KStringName,"Another string");
00067 _LIT(KString1_UpdatedValue, "Value of setting with key x05 is %s");
00068
00069 static const TUid KUidRepository = { 0xE80000AD };
00070 const TUint32 KNonExistentSetting = 0x10;
00071 const TUint32 KInt1 = 0x01;
00072 const TUint32 KInt3 = 0x06;
00073 const TUint32 KReal1 = 0x02;
00074 const TUint32 KString1 = 0x05;
00075 const TInt KInt1_InitialValue = 1;
00076 const TInt KInt1_UpdatedValue = 73;
00077 const TReal KReal1_InitialValue = 14.91;
00078 const TReal KReal1_UpdatedValue = 72.8;
00079 const TUint32 KMoveTarget = 0x30;
00080
00086 CCentRepExample* CCentRepExample::NewLC()
00087 {
00088 CCentRepExample* rep = new(ELeave) CCentRepExample();
00089 CleanupStack::PushL(rep);
00090 rep->ConstructL();
00091 return rep;
00092 }
00093
00097 CCentRepExample::CCentRepExample()
00098 {
00099 }
00100
00101 void CCentRepExample::ConstructL()
00102 {
00103
00104 iConsole = Console::NewL(KTitle,TSize(KConsFullScreen,KConsFullScreen));
00105 iConsole->Printf ( KTextPressAKey );
00106 iConsole->Getch ();
00107 }
00108
00112 CCentRepExample::~CCentRepExample()
00113 {
00114 iConsole->Printf(KExit);
00115 iConsole->Getch();
00116
00117 delete iConsole;
00118 delete iRepository;
00119 }
00120
00121
00128 void CCentRepExample::ResetL()
00129 {
00130 CRepository* repository = NULL;
00131 TRAPD(err, repository = CRepository::NewL(KUidRepository););
00132 CleanupStack::PushL(repository);
00133
00134
00135
00136 if (err == KErrNotFound)
00137 {
00138 iConsole->Printf(KErr);
00139 }
00140 User::LeaveIfError(err);
00141 User::LeaveIfError(err = repository->Reset());
00142 CleanupStack::PopAndDestroy(repository);
00143 }
00144
00151 void CCentRepExample::OpenRepositoryL()
00152 {
00153 TInt i, k;
00154 TReal j;
00155 TBuf<50> tooShort;
00156 iConsole->Printf(KOpen);
00157 iRepository = CRepository::NewL(KUidRepository);
00158
00159 User::LeaveIfError(iRepository->Get(KInt1, i));
00160 iConsole->Printf(KInt,i);
00161
00162 User::LeaveIfError(iRepository->Get(KReal1, j));
00163 iConsole->Printf(KReal,j);
00164
00165 User::LeaveIfError(iRepository->Get(KInt3, k));
00166 iConsole->Printf(KInteg,k);
00167
00168 User::LeaveIfError(iRepository->Get(KString1, tooShort));
00169 iConsole->Printf(KString1_UpdatedValue,tooShort.PtrZ());
00170
00171 iConsole->Printf(KPressAKey);
00172 iConsole->Getch();
00173
00174 }
00175
00181 void CCentRepExample::ChangeSettingsL()
00182 {
00183 iConsole->Printf(KChangeSet);
00184 User::LeaveIfError(iRepository->Set(KNonExistentSetting, 10));
00185
00186 User::LeaveIfError(iRepository->Set(KInt1, KInt1_UpdatedValue));
00187
00188 User::LeaveIfError(iRepository->Set(KReal1, KReal1_InitialValue));
00189
00190 User::LeaveIfError(iRepository->Set(KInt3, KInt1_InitialValue));
00191
00192 User::LeaveIfError(iRepository->Set(KString1, KStringName));
00193
00194 }
00195
00201 void CCentRepExample::ReadSettingsL()
00202 {
00203 TInt m, i, k;
00204 TReal j;
00205 TBuf<50> tooShort;
00206 iConsole->Printf(KReadSet);
00207
00208 User::LeaveIfError(iRepository->Get(KNonExistentSetting, m));
00209
00210 iConsole->Printf(KNonExisting,m);
00211
00212 User::LeaveIfError(iRepository->Get(KInt1, i));
00213
00214 iConsole->Printf(KInt,i);
00215
00216 User::LeaveIfError(iRepository->Get(KReal1, j));
00217
00218 iConsole->Printf(KReal,j);
00219
00220 User::LeaveIfError(iRepository->Get(KInt3, k));
00221
00222 iConsole->Printf(KInteg,k);
00223
00224 User::LeaveIfError(iRepository->Get(KString1, tooShort));
00225
00226 iConsole->Printf(KString1_UpdatedValue,tooShort.PtrZ());
00227
00228 iConsole->Printf(KPressAKey);
00229 iConsole->Getch();
00230
00231 }
00232
00240 void CCentRepExample::FindSettingsL()
00241 {
00242 RArray<TUint32> foundIds;
00243
00244
00245
00246 iConsole->Printf(KFind);
00247
00248
00249
00250
00251 User::LeaveIfError(iRepository->FindL(0x100 , 0xF00, foundIds));
00252
00253 iConsole->Printf(KIdsFound,foundIds.Count());
00254 foundIds.Reset();
00255
00256
00257
00258
00259 User::LeaveIfError(iRepository->FindEqL(0x00, 0x00,KInt1_InitialValue , foundIds));
00260
00261 iConsole->Printf(KIdsFound,foundIds.Count());
00262 foundIds.Reset();
00263
00264
00265
00266 User::LeaveIfError(iRepository->FindEqL(0x00, 0x00,KReal1_InitialValue, foundIds));
00267
00268 iConsole->Printf(KIdsFound,foundIds.Count());
00269 foundIds.Reset();
00270
00271
00272
00273
00274 User::LeaveIfError(iRepository->FindEqL(0x00, 0x00, KStringName, foundIds));
00275
00276 iConsole->Printf(KIdsFound,foundIds.Count());
00277 foundIds.Reset();
00278
00279
00280
00281
00282
00283 User::LeaveIfError(iRepository->FindNeqL(0x00, 0x00, KInt1_UpdatedValue, foundIds));
00284
00285 iConsole->Printf(KIdsFound,foundIds.Count());
00286 foundIds.Reset();
00287
00288
00289
00290
00291
00292 User::LeaveIfError(iRepository->FindNeqL(0x100, 0x0F0, KReal1_UpdatedValue, foundIds));
00293
00294 iConsole->Printf(KIdsFound,foundIds.Count());
00295 foundIds.Reset();
00296
00297 }
00303 void CCentRepExample::ResetAndNotifyL()
00304 {
00305 TInt x;
00306
00307
00308
00309 iConsole->Printf(KReset);
00310
00311 User::LeaveIfError(iRepository->Set(KInt1, KInt1_InitialValue+10));
00312
00313
00314 User::LeaveIfError(iRepository->Get(KInt1, x));
00315
00316 iConsole->Printf(KIntBefore, x);
00317
00318 CAsyncWaiter* waiter = CAsyncWaiter::NewL();
00319 CleanupStack::PushL(waiter);
00320
00321 User::LeaveIfError(iRepository->NotifyRequest(KInt1, waiter->iStatus));
00322
00323
00324
00325 User::LeaveIfError(iRepository->Reset(KInt1));
00326
00327
00328 waiter->StartAndWait();
00329 User::LeaveIfError(waiter->Result());
00330
00331
00332 User::LeaveIfError(iRepository->Get(KInt1, x));
00333 iConsole->Printf(KIntAfter, x);
00334
00335 CleanupStack::PopAndDestroy(waiter);
00336 }
00337
00342 void CCentRepExample::MoveSettingsL()
00343 {
00344 TUint32 keyInfo;
00345
00346 iConsole->Printf(KMove);
00347 iConsole->Printf(KPressAKey);
00348 iConsole->Getch();
00349
00350 User::LeaveIfError(iRepository->Move(KInt3, KMoveTarget, 0xFFFFFFFF,
00351 keyInfo));
00352 }
00353
00358 void CCentRepExample::TransactionFuncL()
00359 {
00360 TUint32 keyId;
00361 TInt intVal;
00362
00363 iConsole->Printf(KTransact);
00364
00365
00366 User::LeaveIfError(iRepository->StartTransaction(CRepository::EReadWriteTransaction));
00367
00368
00369 iRepository->CleanupCancelTransactionPushL();
00370
00371
00372 const TUint32 KNewInt = 0x16;
00373 const TInt KIntValue = 1201;
00374 intVal = KIntValue +33;
00375
00376
00377
00378 User::LeaveIfError(iRepository->Create(KNewInt, KIntValue));
00379
00380 User::LeaveIfError(iRepository->Set(KNewInt,intVal));
00381
00382
00383
00384 User::LeaveIfError(iRepository->CommitTransaction(keyId));
00385
00386
00387 User::LeaveIfError(iRepository->Get(KNewInt, intVal));
00388
00389
00390 User::LeaveIfError(iRepository->Delete(KNewInt));
00391 CleanupStack::Pop();
00392
00393 CRepository* repository1;
00394 User::LeaveIfNull(repository1 = CRepository::NewLC(KUidRepository));
00395
00396
00397 User::LeaveIfError(repository1->StartTransaction(CRepository::EReadTransaction));
00398
00399 CRepository* repository2;
00400 User::LeaveIfNull(repository2 = CRepository::NewLC(KUidRepository));
00401
00402
00403 User::LeaveIfError(repository2->StartTransaction(CRepository::EReadTransaction));
00404
00405
00406
00407 User::LeaveIfError(repository1->Get(KInt1, intVal));
00408
00409 repository1->CleanupCancelTransactionPushL();
00410
00411
00412 User::LeaveIfError(repository1->CommitTransaction(keyId));
00413 CleanupStack::Pop();
00414
00415
00416 repository2->CleanupCancelTransactionPushL();
00417 User::LeaveIfError(repository2->Get(KInt1, intVal));
00418 User::LeaveIfError(repository2->CommitTransaction(keyId));
00419
00420
00421 CleanupStack::Pop();
00422 CleanupStack::PopAndDestroy(2,repository1);
00423
00424
00425 }
00426
00431 void CCentRepExample::DeleteL()
00432 {
00433 TInt x;
00434 TReal y;
00435
00436 iConsole->Printf(KDelete);
00437
00438 User::LeaveIfError(iRepository->Get(KInt1_InitialValue, x));
00439 User::LeaveIfError(iRepository->Get(KReal1, y));
00440 User::LeaveIfError(iRepository->Delete(KInt1_InitialValue));
00441 User::LeaveIfError(iRepository->Delete(KMoveTarget));
00442 User::LeaveIfError(iRepository->Delete(KReal1));
00443 }
00444
00445 LOCAL_C void MainL()
00446 {
00447
00448 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
00449 CleanupStack::PushL(scheduler);
00450 CActiveScheduler::Install( scheduler );
00451 CCentRepExample * app = CCentRepExample ::NewLC();
00452
00453
00454 app->ResetL();
00455
00456
00457 app->OpenRepositoryL();
00458
00459
00460 app->ChangeSettingsL();
00461
00462
00463 app->ReadSettingsL();
00464
00465
00466 app->FindSettingsL();
00467
00468
00469 app->MoveSettingsL();
00470
00471
00472 app->ResetAndNotifyL();
00473
00474
00475 app->TransactionFuncL();
00476
00477
00478 app->DeleteL();
00479
00480 CleanupStack::PopAndDestroy(2);
00481
00482 }
00483
00484 GLDEF_C TInt E32Main()
00485 {
00486 __UHEAP_MARK;
00487 CTrapCleanup* cleanup = CTrapCleanup::New();
00488 if(cleanup == NULL)
00489 {
00490 return KErrNoMemory;
00491 }
00492 TRAPD(err, MainL());
00493 if(err != KErrNone)
00494 {
00495 User::Panic(_L("Failed to complete"),err);
00496 }
00497
00498 delete cleanup;
00499 __UHEAP_MARKEND;
00500 return KErrNone;
00501 }