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