Update contrib.
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // CPolicyDomainLoader class
19 #include "D32Strings.h"
20 #include "SC_StrmIn.h"
21 #include "SC_DomainLoader.h"
23 //This function returns ETrue if the drives in aPath1 and aPath2 are equal.
24 TBool CheckDrivesL(const TDesC& aPath1, const TDesC& aPath2)
26 __ASSERT(aPath1.Length() > 0);
27 __ASSERT(aPath2.Length() > 0);
29 TChar drvc1 = aPath1[0];
31 __LEAVE_IF_ERROR(RFs::CharToDrive(drvc1, drv1));
33 TChar drvc2 = aPath2[0];
35 __LEAVE_IF_ERROR(RFs::CharToDrive(drvc2, drv2));
44 @param aFs A reference to a file server session object
45 @param aPolicyDir A reference to policy file sdirectory
46 @param aPDCollection The created policy domain objects will be stored in this output parameter.
48 inline CPolicyDomainLoader::CPolicyDomainLoader(RFs& aFs, const TDesC& aPolicyDir,
49 RMap<TInt, CPolicyDomain*>& aPDCollection) :
51 iPolicyDir(aPolicyDir),
52 iPDCollection(aPDCollection)
54 __ASSERT(iPolicyDir.Length() > 0);
55 __ASSERT(iPDCollection.Count() == 0);
59 Standard phase-one CPolicyDomainLoader factory method
60 @param aFs A reference to a file server session object
61 @param aPolicyDir A reference to policy file sdirectory
62 @param aPDCollection The created policy domain objects will be stored in this output parameter.
63 @return A pointer to just created CPolicyDomainLoader instance.
64 @leave System-wide error codes, including KErrNoMemory
66 CPolicyDomainLoader* CPolicyDomainLoader::NewLC(RFs& aFs, const TDesC& aPolicyDir,
67 RMap<TInt,CPolicyDomain*>& aPDCollection)
69 CPolicyDomainLoader* self = new (ELeave) CPolicyDomainLoader(aFs, aPolicyDir, aPDCollection);
70 CleanupStack::PushL(self);
77 CPolicyDomainLoader::~CPolicyDomainLoader()
79 delete iFoundPolicyFiles;
83 Standard phase-two CPolicyDomainLoader construction method.
84 It does a search for binary policy files in the system and creates and stores
85 a list of found ones in iFoundPolicyFiles data member.
86 @leave System-wide error codes, including KErrNoMemory
88 void CPolicyDomainLoader::ConstructL()
90 TFindFile findFile(iFs);
91 TInt err = findFile.FindWildByDir(KPolicyFileExtMask, iPolicyDir, iFoundPolicyFiles);
93 {//Check if the found drive is the same as the drive in iPolicyDir.
94 if(!::CheckDrivesL(findFile.File(), iPolicyDir))
99 __LEAVE_IF_ERROR(err);
103 The method creates the policy file path related to aPolicyFileIndex entry in
104 iFoundPolicyFiles list of binary policy file names. The path will be stored
105 in iPolicyFilePath data member.
106 @param aPolicyFileIndex Index of binary policy file name in iFoundPolicyFiles list.
107 @return The UID, extracted from binary policy file name.
108 @leave System-wide error codes, including KErrNoMemory
110 TUid CPolicyDomainLoader::CreatePolicyFilePathL(TInt aPolicyFileIndex)
112 __ASSERT(aPolicyFileIndex < iFoundPolicyFiles->Count());
113 const ::TEntry& entry = (*iFoundPolicyFiles)[aPolicyFileIndex];
114 __LEAVE_IF_ERROR(iParser.Set(entry.iName, NULL, NULL));
115 TPtrC fileName = iParser.Name();
116 TUid domainUid = KNullUid;
118 __LEAVE_IF_ERROR(lex.Val(*(TUint32*)&domainUid, EHex));
119 if(domainUid == KNullUid)
121 __LEAVE(KErrCorrupt);
123 iPolicyFilePath.Copy(iPolicyDir);
124 iPolicyFilePath.Append(entry.iName);
129 The method creates the policy domain object related to aPolicyFileIndex entry in
130 iFoundPolicyFiles list of binary policy file names. The created policy domain object
131 will be added to iPDCollection collection of policy domain objects.
132 @param aPolicyFileIndex Index of binary policy file name in iFoundPolicyFiles list.
133 @leave System-wide error codes, including KErrNoMemory
135 void CPolicyDomainLoader::DoCreatePolicyDomainL(TInt aPolicyFileIndex)
137 TUid domainUid = CreatePolicyFilePathL(aPolicyFileIndex);
138 RFileReadStream strm;
139 CleanupClosePushL(strm);
140 __LEAVE_IF_ERROR(strm.Open(iFs, iPolicyFilePath, EFileRead));
141 TPDStreamLoader in(strm);
142 CPolicyDomain* policyDomain = CPolicyDomain::NewLC(domainUid, in);
143 __ASSERT(policyDomain);
144 __LEAVE_IF_ERROR(iPDCollection.Insert(domainUid.iUid, policyDomain));
145 CleanupStack::Pop(policyDomain);
146 CleanupStack::PopAndDestroy(&strm);
150 The method creates the policy domain object related to aPolicyFileIndex entry in
151 iFoundPolicyFiles list of binary policy file names. The created policy domain object
152 will be added to iPDCollection collection of policy domain objects.
153 @param aPolicyFileIndex Index of binary policy file name in iFoundPolicyFiles list.
154 @leave KErrNoMemory is the only possible leaving error code. The rest of errors
157 void CPolicyDomainLoader::CreatePolicyDomainL(TInt aPolicyFileIndex)
159 TRAPD(err, DoCreatePolicyDomainL(aPolicyFileIndex));
163 _LIT(KText, "Failed to load policy file \"%S\"!\n");
165 buf.Format(KText, &iPolicyFilePath);
169 if(err == KErrNoMemory)
176 The method creates a policy domain object for each binary policy file found in the system.
177 The created objects will be added to iPDCollection collection of policy domain objects.
178 @leave KErrNoMemory is the only possible leaving error code. The rest of errors
181 void CPolicyDomainLoader::RunL()
183 __ASSERT(iFoundPolicyFiles);
184 for(TInt i=(iFoundPolicyFiles->Count()-1);i>-1;--i)
186 CreatePolicyDomainL(i);
190 } //end of - namespace DBSC