examples/SysLibs/ResourceFiles/MultiRead1/MultiRead.h

00001 /*
00002 Copyright (c) 2000-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:
00028 Define the multiple resource file reader class
00029 for use in MultiRead1 and MultiRead2 examples  
00030 */
00031 
00032 
00033 
00034 #ifndef __MultiRead_H
00035 #define __MultiRead_H
00036 
00037 class CMultipleResourceFileReader : public CBase
00038         {
00039 public:
00040         // construct/destruct
00041         ~CMultipleResourceFileReader();
00042         static CMultipleResourceFileReader* NewLC();
00043         // add resource file
00044         void AddResourceFileL(const TDesC& aName, TInt aVersion);
00045         HBufC8* AllocReadLC(TInt aResourceId);
00046 private:
00047         // construct/destruct
00048         void ConstructL();
00049 private:
00050         CArrayFixFlat<RResourceFile>* iResourceFiles;
00051         };
00052 
00053 // construct/destruct
00054 
00055 CMultipleResourceFileReader* CMultipleResourceFileReader::NewLC()
00056         {
00057         CMultipleResourceFileReader* self=new (ELeave) CMultipleResourceFileReader;
00058         CleanupStack::PushL(self);
00059         self->ConstructL();
00060         return self;
00061         }
00062 
00063 void CMultipleResourceFileReader::ConstructL()
00064         {
00065         iResourceFiles=new (ELeave) CArrayFixFlat<RResourceFile> (2);
00066                 // new array of resource files
00067                 // typically two in an application, so use granularity 2
00068         }
00069 
00070 CMultipleResourceFileReader::~CMultipleResourceFileReader()
00071         {
00072         if (iResourceFiles)
00073                 {
00074                 for (TInt i=0; i < iResourceFiles->Count(); i++)
00075                         (*iResourceFiles)[i].Close(); // close each resource file
00076                 delete iResourceFiles; // and destroy container
00077                 }
00078         }
00079 
00080 // manipulate resource files and resources
00081 
00082 void CMultipleResourceFileReader::AddResourceFileL(const TDesC& aName, TInt aVersion)
00083         {
00084         _LIT(KAddingResourceFile,"Adding resource file %S, version %d: will be file %d\n");
00085         console->Printf(KAddingResourceFile,
00086                         &aName, aVersion, iResourceFiles->Count()
00087                         );
00088         RResourceFile file;
00089         file.OpenL(fsSession,aName); // open resource file
00090         TRAPD(error,file.ConfirmSignatureL(aVersion)); // confirm its signature
00091         if (error!=KErrNone)
00092                 {
00093                 file.Close();
00094                 User::Leave(error);
00095                 }
00096         TRAP(error,iResourceFiles->AppendL(file))
00097         if (error!=KErrNone)
00098                 {
00099                 file.Close();
00100                 User::Leave(error);
00101                 }
00102         return;
00103         }
00104 
00105 HBufC8* CMultipleResourceFileReader::AllocReadLC(TInt aResourceId)
00106         {
00107         _LIT(KReadingResource,"Reading resource %08X\n");
00108         _LIT(KOwnedByFile,"   Owned by file %d\n");
00109 
00110         console->Printf(KReadingResource,aResourceId);
00111         for (TInt i=0; i < iResourceFiles->Count(); i++)
00112                 { // scan all resource files to find owner
00113                 RResourceFile& file=(*iResourceFiles)[i]; // get resource file
00114                 if (!file.OwnsResourceId(aResourceId))
00115                         continue; // continue if not owner
00116                 console->Printf(KOwnedByFile,i);
00117                 return file.AllocReadLC(aResourceId);
00118                                 // return resource from owning file (if present)
00119                 }
00120         User::Leave(KErrNotFound);
00121         return 0; // can never be executed, but keeps compiler happy
00122         }
00123 
00124 #endif

Generated by  doxygen 1.6.2