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
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 #include "WritePermFS1.h"
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 _LIT(KFullNameOfFileStore,"\\epoc32ex\\data\\WritePermFS.dat");
00091
00092
00093 LOCAL_C void doExampleL()
00094 {
00095
00096 fsSession.MkDirAll(KFullNameOfFileStore);
00097 doMakeL(KFullNameOfFileStore);
00098 doUseL(KFullNameOfFileStore);
00099 }
00100
00101
00102 LOCAL_C void doMakeL(const TDesC& aName)
00103 {
00104
00105 TParse filestorename;
00106 fsSession.Parse(aName,filestorename);
00107 CFileStore* store = CPermanentFileStore::ReplaceLC(fsSession,filestorename.FullName(),EFileWrite);
00108
00109
00110 store->SetTypeL(KPermanentFileStoreLayoutUid);
00111
00112
00113
00114 TExampleIndex theIndex;
00115
00116
00117
00118
00119
00120 _LIT(KTxtDataForClassP,"Data for CClassP - PPPPP");
00121 CClassP* theP = CClassP::NewLC(KTxtDataForClassP,*store);
00122 theIndex.iPid = theP->StoreL();
00123 CleanupStack::PopAndDestroy();
00124
00125
00126
00127
00128
00129 _LIT(KTxtDataForClassR,"Data for the CClassR - RRRRR");
00130 CClassR* theR = CClassR::NewLC(KTxtDataForClassR,*store);
00131 theIndex.iRid = theR->StoreL();
00132 CleanupStack::PopAndDestroy();
00133
00134
00135
00136
00137
00138
00139
00140
00141 _LIT(KTxtDataForClassA,"Data for the CClassA - AAAAA");
00142 _LIT(KTxtDataForClassB,"Data for the CClassB - BBBBB");
00143 _LIT(KTxtDataForClassC,"Data for the CClassC - CCCCC");
00144
00145 CClassABC* theABC = CClassABC::NewLC(*store);
00146 theABC->ConstructAL(KTxtDataForClassA,-1,2);
00147 theABC->ConstructB(KTxtDataForClassB,-3,4,5.6);
00148 theABC->ConstructC(KTxtDataForClassC);
00149 theIndex.iABCid = theABC->StoreL();
00150 CleanupStack::PopAndDestroy();
00151
00152
00153 TStreamId id = theIndex.StoreL(*store);
00154
00155
00156 store->SetRootL(id);
00157
00158
00159 store->CommitL();
00160
00161
00162 CleanupStack::PopAndDestroy();
00163 }
00164
00165
00166 LOCAL_C void doUseL(const TDesC& aName)
00167 {
00168
00169 TParse filestorename;
00170 fsSession.Parse(aName,filestorename);
00171 CFileStore* store = CPermanentFileStore::OpenLC(fsSession,filestorename.FullName(),EFileRead|EFileWrite);
00172
00173
00174
00175 TExampleIndex theIndex;
00176 theIndex.RestoreL(*store,store->Root());
00177
00178
00179
00180
00181
00182
00183
00184 CClassR* theR;
00185
00186 _LIT(KTxtClassRContent,"CClassR content ...");
00187 _LIT(KTxtNewForClassR,"New data for the CClassR +++++++");
00188
00189 theR = CClassR::NewLC(*store,theIndex.iRid);
00190 doShow(KTxtClassRContent,*theR);
00191 theR->ChangeDataL(KTxtNewForClassR);
00192 CleanupStack::PopAndDestroy();
00193
00194
00195
00196 _LIT(KTxtUpadtedClassR,"Updated CClassR content ...");
00197
00198 theR = CClassR::NewLC(*store,theIndex.iRid);
00199 doShow(KTxtUpadtedClassR,*theR);
00200 CleanupStack::PopAndDestroy();
00201
00202
00203
00204
00205
00206 _LIT(KTxtShowClassA,"CClassA content ...");
00207 _LIT(KTxtShowClassB,"CClassB content ...");
00208 _LIT(KTxtShowClassC,"CClassC content ...");
00209
00210 CClassABC* theABC = CClassABC::NewLC(*store,theIndex.iABCid);
00211 doShow(KTxtShowClassA,*theABC->PtrA());
00212 doShow(KTxtShowClassB,*theABC->PtrBL());
00213 doShow(KTxtShowClassC,*theABC->PtrC());
00214 CleanupStack::PopAndDestroy();
00215
00216
00217
00218 _LIT(KTxtShowClassP,"CClassP content ...");
00219
00220 CClassP* theP = CClassP::NewLC(*store,theIndex.iPid);
00221 doShow(KTxtShowClassP,*theP);
00222 CleanupStack::PopAndDestroy();
00223
00224
00225 CleanupStack::PopAndDestroy();
00226 }
00227
00228 _LIT(KTxtNewLine,"\n");
00229 _LIT(KFormatType1,"\n%S, ");
00230 _LIT(KFormatType2,"%d, ");
00231 _LIT(KFormatType3,"%u ");
00232 _LIT(KFormatType4,"%u, ");
00233 _LIT(KFormatType5,"%f ");
00234
00235 LOCAL_C void doShow(const TDesC& aHeading,const CClassA& anA)
00236 {
00237 console->Printf(KTxtNewLine);
00238 console->Printf(aHeading);
00239 console->Printf(KFormatType1,anA.iVarBuf);
00240 console->Printf(KFormatType2,anA.iIntValue);
00241 console->Printf(KFormatType3,anA.iUintValue);
00242 console->Printf(KTxtNewLine);
00243 }
00244
00245
00246 LOCAL_C void doShow(const TDesC& aHeading,const CClassB& aB)
00247 {
00248 console->Printf(KTxtNewLine);
00249 console->Printf(aHeading);
00250 console->Printf(KFormatType1,&aB.iFixBuf);
00251 console->Printf(KFormatType2,aB.iIntValue);
00252 console->Printf(KFormatType4,aB.iUintValue);
00253 console->Printf(KFormatType5,aB.iRealValue);
00254 console->Printf(KTxtNewLine);
00255 }
00256
00257
00258 LOCAL_C void doShow(const TDesC& aHeading,const CClassC& aC)
00259 {
00260 console->Printf(KTxtNewLine);
00261 console->Printf(aHeading);
00262 console->Printf(KFormatType1,&aC.iFixBuf);
00263 console->Printf(KTxtNewLine);
00264 }
00265
00266 LOCAL_C void doShow(const TDesC& aHeading,const CClassP& aP)
00267 {
00268 console->Printf(KTxtNewLine);
00269 console->Printf(aHeading);
00270 console->Printf(KFormatType1,&aP.iFixBuf);
00271 console->Printf(KTxtNewLine);
00272 }
00273
00274 LOCAL_C void doShow(const TDesC& aHeading,const CClassR& aR)
00275 {
00276 console->Printf(KTxtNewLine);
00277 console->Printf(aHeading);
00278 console->Printf(KFormatType1,&aR.iFixBuf);
00279 console->Printf(KTxtNewLine);
00280 }
00281
00282
00283
00284
00285
00286
00287 CClassABC::CClassABC(CStreamStore& aStore)
00288 : iStore(aStore)
00289 {}
00290
00291 CClassABC::CClassABC(CStreamStore& aStore,TStreamId anId)
00292 : iStore(aStore), iId(anId)
00293 {}
00294
00295 CClassABC* CClassABC::NewLC(CStreamStore& aStore)
00296 {
00297 CClassABC* self = new (ELeave) CClassABC(aStore);
00298 CleanupStack::PushL(self);
00299 self->ConstructL();
00300 return self;
00301 }
00302
00303 CClassABC* CClassABC::NewLC(CStreamStore& aStore, TStreamId anId)
00304 {
00305 CClassABC* self = new (ELeave) CClassABC(aStore,anId);
00306 CleanupStack::PushL(self);
00307 self->RestoreL();
00308 return self;
00309 }
00310
00311 void CClassABC::ConstructL()
00312 {
00313 iA = CClassA::NewL();
00314 iB = CClassB::NewL();
00315 iC = CClassC::NewL();
00316 }
00317
00318 void CClassABC::ConstructAL(const TDesC& aData,TInt anInt,TUint aUint)
00319 {
00320 iA->iVarBuf = aData.AllocL();
00321 iA->iIntValue = anInt;
00322 iA->iUintValue = aUint;
00323 }
00324
00325 void CClassABC::ConstructB(const TDesC& aData,TInt anInt,TUint aUint,TReal aReal)
00326 {
00327 iB->iFixBuf = aData;
00328 iB->iIntValue = anInt;
00329 iB->iUintValue = aUint;
00330 iB->iRealValue = aReal;
00331 }
00332
00333 void CClassABC::ConstructC(const TDesC& aData)
00334 {
00335 iC->iFixBuf = aData;
00336 }
00337
00338
00339
00340
00341
00342
00343 CClassABC::~CClassABC()
00344 {
00345 delete iA;
00346 delete iC;
00347 if (iB.IsPtr())
00348 delete iB.AsPtr();
00349 }
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361 TStreamId CClassABC::StoreL()
00362 {
00363
00364
00365 RStoreWriteStream outstream;
00366 TStreamId idForB = outstream.CreateLC(iStore);
00367
00368
00369
00370 outstream << *iB;
00371
00372 outstream.CommitL();
00373
00374 CleanupStack::PopAndDestroy();
00375
00376
00377
00378
00379
00380 TStreamId id = outstream.CreateLC(iStore);
00381
00382 outstream << *iA;
00383
00384 outstream << idForB;
00385
00386 outstream << *iC;
00387
00388 outstream.CommitL();
00389
00390 CleanupStack::PopAndDestroy();
00391
00392 return id;
00393 }
00394
00395
00396 const CClassA* CClassABC::PtrA()
00397 {
00398 return iA;
00399 }
00400
00401
00402 const CClassB* CClassABC::PtrBL()
00403 {
00404 if (iB.IsId())
00405 RestoreBL();
00406 return iB.AsPtr();
00407 }
00408
00409
00410 const CClassC* CClassABC::PtrC()
00411 {
00412 return iC;
00413 }
00414
00415
00416
00417
00418
00419
00420
00421
00422 void CClassABC::RestoreL()
00423 {
00424
00425 RStoreReadStream instream;
00426 instream.OpenLC(iStore,iId);
00427
00428 iA = CClassA::NewL();
00429 instream >> *iA;
00430
00431
00432
00433
00434
00435
00436 instream >> iB;
00437
00438 iC = CClassC::NewL();
00439 instream >> *iC;
00440
00441 CleanupStack::PopAndDestroy();
00442 }
00443
00444
00445
00446
00447
00448
00449 void CClassABC::RestoreBL()
00450 {
00451
00452
00453 RStoreReadStream instream;
00454 instream.OpenLC(iStore,iB.AsId());
00455
00456
00457
00458
00459 CClassB* ptrB = CClassB::NewLC();
00460 instream >> *ptrB;
00461 CleanupStack::Pop();
00462 iB = ptrB;
00463
00464 CleanupStack::PopAndDestroy();
00465 }
00466
00467
00468
00469
00470
00471
00472
00473 CClassA* CClassA::NewL()
00474 {
00475 CClassA* self = CClassA::NewLC();
00476 CleanupStack::Pop();
00477 return self;
00478 }
00479
00480 CClassA* CClassA::NewLC()
00481 {
00482 CClassA* self = new (ELeave) CClassA;
00483 CleanupStack::PushL(self);
00484 return self;
00485 }
00486
00487 CClassA::~CClassA()
00488 {
00489 delete iVarBuf;
00490 }
00491
00492 void CClassA::ExternalizeL(RWriteStream& aStream) const
00493 {
00494 aStream.WriteInt32L(iVarBuf->Des().MaxLength());
00495 aStream << *iVarBuf;
00496 aStream.WriteInt32L(iIntValue);
00497 aStream.WriteUint32L(iUintValue);
00498 }
00499
00500 void CClassA::InternalizeL(RReadStream& aStream)
00501 {
00502 TInt maxlen;
00503 maxlen = aStream.ReadInt32L();
00504 iVarBuf = HBufC::NewL(aStream,maxlen);
00505 iIntValue = aStream.ReadInt32L();
00506 iUintValue = aStream.ReadUint32L();
00507 }
00508
00509
00510
00511
00512
00513
00514
00515 CClassB* CClassB::NewLC()
00516 {
00517 CClassB* self = new (ELeave) CClassB;
00518 CleanupStack::PushL(self);
00519 return self;
00520 }
00521
00522 CClassB* CClassB::NewL()
00523 {
00524 CClassB* self = CClassB::NewLC();
00525 CleanupStack::Pop();
00526 return self;
00527 }
00528
00529 void CClassB::ExternalizeL(RWriteStream& aStream) const
00530 {
00531 aStream << iFixBuf;
00532 aStream.WriteInt32L(iIntValue);
00533 aStream.WriteUint32L(iUintValue);
00534 aStream.WriteReal64L(iRealValue);
00535 }
00536
00537 void CClassB::InternalizeL(RReadStream& aStream)
00538 {
00539 aStream >> iFixBuf;
00540 iIntValue = aStream.ReadInt32L();
00541 iUintValue = aStream.ReadUint32L();
00542 iRealValue = aStream.ReadReal64L();
00543 }
00544
00545
00546
00547
00548
00549
00550 CClassC* CClassC::NewL()
00551 {
00552 CClassC* self = CClassC::NewLC();
00553 CleanupStack::Pop();
00554 return self;
00555 }
00556
00557 CClassC* CClassC::NewLC()
00558 {
00559 CClassC* self = new (ELeave) CClassC;
00560 CleanupStack::PushL(self);
00561 return self;
00562 }
00563
00564 void CClassC::ExternalizeL(RWriteStream& aStream) const
00565 {
00566 aStream << iFixBuf;
00567 }
00568
00569 void CClassC::InternalizeL(RReadStream& aStream)
00570 {
00571 aStream >> iFixBuf;
00572 }
00573
00574
00575
00576
00577
00578
00579 CClassP::CClassP(CStreamStore& aStore)
00580 : iStore(aStore)
00581 {}
00582
00583 CClassP::CClassP(CStreamStore& aStore,TStreamId anId)
00584 : iStore(aStore), iId(anId)
00585 {}
00586
00587 CClassP* CClassP::NewLC(const TDesC& aData,CStreamStore& aStore)
00588 {
00589 CClassP* self = new (ELeave) CClassP(aStore);
00590 CleanupStack::PushL(self);
00591 self->Construct(aData);
00592 return self;
00593 }
00594
00595 CClassP* CClassP::NewLC(CStreamStore& aStore, TStreamId anId)
00596 {
00597 CClassP* self = new (ELeave) CClassP(aStore,anId);
00598 CleanupStack::PushL(self);
00599 self->RestoreL();
00600 return self;
00601 }
00602
00603 void CClassP::Construct(const TDesC& aData)
00604 {
00605 iFixBuf = aData;
00606 }
00607
00608 void CClassP::RestoreL()
00609 {
00610 RStoreReadStream instream;
00611 instream.OpenLC(iStore,iId);
00612 InternalizeL(instream);
00613 CleanupStack::PopAndDestroy();
00614 }
00615
00616 TStreamId CClassP::StoreL()
00617 {
00618 RStoreWriteStream outstream;
00619 TStreamId id = outstream.CreateLC(iStore);
00620 ExternalizeL(outstream);
00621 outstream.CommitL();
00622 CleanupStack::PopAndDestroy();
00623 return id;
00624 }
00625
00626 void CClassP::ExternalizeL(RWriteStream& aStream) const
00627 {
00628 aStream << iFixBuf;
00629 }
00630
00631 void CClassP::InternalizeL(RReadStream& aStream)
00632 {
00633 aStream >> iFixBuf;
00634 }
00635
00636
00637
00638
00639
00640
00641
00642 CClassR::CClassR(CStreamStore& aStore)
00643 : iStore(aStore)
00644 {}
00645
00646 CClassR::CClassR(CStreamStore& aStore,TStreamId anId)
00647 : iStore(aStore), iId(anId)
00648 {}
00649
00650 CClassR* CClassR::NewLC(const TDesC& aData,CStreamStore& aStore)
00651 {
00652 CClassR* self = new (ELeave) CClassR(aStore);
00653 CleanupStack::PushL(self);
00654 self->Construct(aData);
00655 return self;
00656 }
00657
00658 CClassR* CClassR::NewLC(CStreamStore& aStore, TStreamId anId)
00659 {
00660 CClassR* self = new (ELeave) CClassR(aStore,anId);
00661 CleanupStack::PushL(self);
00662 self->RestoreL();
00663 return self;
00664 }
00665
00666 void CClassR::Construct(const TDesC& aData)
00667 {
00668 iFixBuf = aData;
00669 }
00670
00671 _LIT(KTxtFailedMsg,"Failed to update CClassR stream\n");
00672
00673 void CClassR::ChangeDataL(const TDesC& aData)
00674 {
00675 iFixBuf = aData;
00676 TRAPD(error,UpdateStoreL());
00677 if (error!=KErrNone)
00678 {
00679 iStore.Revert();
00680 console->Printf(KTxtFailedMsg);
00681 User::Leave(error);
00682 }
00683 }
00684
00685 void CClassR::RestoreL()
00686 {
00687 RStoreReadStream instream;
00688 instream.OpenLC(iStore,iId);
00689 InternalizeL(instream);
00690 CleanupStack::PopAndDestroy();
00691 }
00692
00693 TStreamId CClassR::StoreL()
00694 {
00695 RStoreWriteStream outstream;
00696 TStreamId id = outstream.CreateLC(iStore);
00697 ExternalizeL(outstream);
00698 outstream.CommitL();
00699 CleanupStack::PopAndDestroy();
00700 return id;
00701 }
00702
00703 void CClassR::UpdateStoreL()
00704 {
00705 RStoreWriteStream outstream;
00706 outstream.ReplaceLC(iStore,iId);
00707 ExternalizeL(outstream);
00708 outstream.CommitL();
00709 CleanupStack::PopAndDestroy();
00710 iStore.CommitL();
00711 }
00712
00713 void CClassR::ExternalizeL(RWriteStream& aStream) const
00714 {
00715 aStream << iFixBuf;
00716 }
00717
00718 void CClassR::InternalizeL(RReadStream& aStream)
00719 {
00720 aStream >> iFixBuf;
00721 }
00722
00723
00724
00725
00726
00727
00728
00729 TStreamId TExampleIndex::StoreL(CStreamStore& aStore)
00730 {
00731 RStoreWriteStream outstream;
00732 TStreamId id = outstream.CreateLC(aStore);
00733 ExternalizeL(outstream);
00734 outstream.CommitL();
00735 CleanupStack::PopAndDestroy();
00736 return id;
00737 }
00738
00739 void TExampleIndex::RestoreL(CStreamStore& aStore, TStreamId anId)
00740 {
00741 RStoreReadStream instream;
00742 instream.OpenLC(aStore,anId);
00743 InternalizeL(instream);
00744 CleanupStack::PopAndDestroy();
00745 }
00746
00747 void TExampleIndex::ExternalizeL(RWriteStream& aStream) const
00748 {
00749 aStream << iPid;
00750 aStream << iRid;
00751 aStream << iABCid;
00752 }
00753
00754 void TExampleIndex::InternalizeL(RReadStream& aStream)
00755 {
00756 aStream >> iPid;
00757 aStream >> iRid;
00758 aStream >> iABCid;
00759 }