|
1 /* |
|
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 /** |
|
22 @file |
|
23 @internalTechnology |
|
24 */ |
|
25 |
|
26 #ifndef HWRMPOLICY_H |
|
27 #define HWRMPOLICY_H |
|
28 |
|
29 // INCLUDES |
|
30 #include <e32base.h> |
|
31 #include <f32file.h> // For RFs |
|
32 |
|
33 // CONSTANTS |
|
34 const TInt KHighestPriority( 1 ); |
|
35 const TInt KLowestPriority( 1000 ); |
|
36 // If no 'ALL' client exists in file this is the default priority |
|
37 const TInt KDefaultNormalPriority( 500 ); |
|
38 // HWRM Lights policy |
|
39 _LIT( KLightsPolicyFilename, "HWRMLightsPolicy.ini" ); |
|
40 // HWRM Vibra policy |
|
41 _LIT( KVibraPolicyFilename, "HWRMVibraPolicy.ini" ); |
|
42 // HWRM FM Tx policy |
|
43 _LIT( KFmTxPolicyFilename, "HWRMFmTxPolicy.ini" ); |
|
44 // Customer policy filename prefix |
|
45 _LIT( KCustomerPolicyPrefix, "Customer" ); |
|
46 // Product policy filename prefix |
|
47 _LIT( KProductPolicyPrefix, "Product" ); |
|
48 |
|
49 // Drive used to store policy files |
|
50 _LIT( KDrivename, "Z:" ); |
|
51 |
|
52 |
|
53 // CLASS DECLARATION |
|
54 |
|
55 /** |
|
56 * This class is intended to parse the associated priority text file and |
|
57 * provide an API to return the clients priority. |
|
58 * |
|
59 */ |
|
60 class CHWRMPolicy : public CBase |
|
61 { |
|
62 public: // Constructors and destructor |
|
63 |
|
64 /** |
|
65 * Two-phased constructor. |
|
66 * @param aFilename Filename of policy file, filename should not |
|
67 * include the path as the file is stored in |
|
68 * the private directory. |
|
69 */ |
|
70 static CHWRMPolicy* NewL( const TDesC& aFilename ); |
|
71 |
|
72 /** |
|
73 * Two-phased constructor. |
|
74 * Leaves instance on the cleanup stack. |
|
75 * @param aFilename Filename of policy file, filename should not |
|
76 * include the path as the file is stored in |
|
77 * the private directory. |
|
78 */ |
|
79 static CHWRMPolicy* NewLC( const TDesC& aFilename ); |
|
80 |
|
81 /** |
|
82 * Destructor. |
|
83 */ |
|
84 virtual ~CHWRMPolicy(); |
|
85 |
|
86 public: // New functions |
|
87 |
|
88 /** |
|
89 * Method to retrieve the priority of a client with the given ID. |
|
90 * This ID can be the UID or SID defined in the policy file. |
|
91 * @param aMsg Message from client, used to obtain SID |
|
92 * @param aTrusted Returns ETrue if client is trusted, i.e. |
|
93 * explicitly specified in policy file. |
|
94 * @return Priority of client. |
|
95 * If client does not exist default priority defined |
|
96 * by client ALL. |
|
97 * Method to return indication of feedback client |
|
98 * @param aSid Clients SID |
|
99 * @return ETrue if feedback client, otherwise EFalse |
|
100 */ |
|
101 TInt GetPriority( const TSecureId aSid, TBool& aTrusted ) const; |
|
102 |
|
103 /** |
|
104 * Method to return indication of feedback client |
|
105 * @param aSid Clients SID |
|
106 * @return ETrue if feedback client, otherwise EFalse |
|
107 */ |
|
108 TBool FeedbackClient(TSecureId aSid) const; |
|
109 |
|
110 private: // New functions |
|
111 |
|
112 /** |
|
113 * C++ constructor. |
|
114 */ |
|
115 CHWRMPolicy(); |
|
116 |
|
117 /** |
|
118 * By default Symbian 2nd phase constructor is private. |
|
119 * @param aFilename Filename of policy file, filename should not |
|
120 * include the path as the file is stored in |
|
121 * the private directory. |
|
122 */ |
|
123 void ConstructL( const TDesC& aFilename ); |
|
124 |
|
125 /** |
|
126 * Method constructs the array of policy clients from the |
|
127 * given stream (usually an RFileReadStream) |
|
128 * @param aFs File server session |
|
129 * @param aFilename Filename to read |
|
130 */ |
|
131 void ParsePriorityFileL( RFs& aFs, const TDesC& aFilename ); |
|
132 |
|
133 /** |
|
134 * Helper method to convert and validate SID from a descriptor. |
|
135 * @param aSidDes The Sid to be converted |
|
136 * @param aSid Reference that will contain the SID |
|
137 * @return KErrNone if successful, KErrCorrupt if invalid |
|
138 */ |
|
139 TInt ConvertId( const TDesC8& aSidDes, TSecureId& aSid ) const; |
|
140 |
|
141 /** |
|
142 * Adds a policy client to the array, first checks that no other |
|
143 * client has been registered with the identical id. If one already |
|
144 * exists KErrAlreadyExists is returned. |
|
145 * @param aPriority Clients priorty |
|
146 * @param aSid Clients SID or KAllPolicySid |
|
147 * @param aFeedbackClient Indication whether feedback client |
|
148 * @param aAppName Clients application name |
|
149 * @return KErrNone if successful |
|
150 * KErrAlreadyExists if client id already exists |
|
151 */ |
|
152 TInt AddPolicyClientL( const TInt aPriority, const TSecureId& aSid, |
|
153 const TBool aFeedbackClient, const TDesC8& aAppName ); |
|
154 |
|
155 /** |
|
156 * Searches for client with the given id |
|
157 * @param aId Clients SID or KAllPolicySid |
|
158 * @return Client position in iClientArray |
|
159 * KErrNotFound if client does not exist |
|
160 */ |
|
161 TInt FindClient( const TSecureId& aSid ) const; |
|
162 |
|
163 private: // Data |
|
164 |
|
165 /** |
|
166 * Embedded class to contain policy client data intended |
|
167 * to be read from the policy file. |
|
168 * |
|
169 */ |
|
170 class CPolicyClient : public CBase |
|
171 { |
|
172 public: // Constructors and destructor |
|
173 |
|
174 /** |
|
175 * Two-phased constructor. |
|
176 * @param aPriority Clients priorty |
|
177 * @param aSid Clients SID or KAllPolicySid |
|
178 * @param aFeedbackClient Indication whether feedback client |
|
179 * @param aAppName Clients application name |
|
180 */ |
|
181 static CPolicyClient* NewL( const TInt aPriority, |
|
182 const TSecureId& aSid, |
|
183 const TBool aFeedbackClient, |
|
184 const TDesC8& aAppName ); |
|
185 |
|
186 /** |
|
187 * Two-phased constructor. |
|
188 * Leaves instance on the cleanup stack. |
|
189 * @param aPriority Clients priorty |
|
190 * @param aFeedbackClient Indication whether feedback client |
|
191 * @param aAppName Clients application name |
|
192 */ |
|
193 static CPolicyClient* NewLC( const TInt aPriority, |
|
194 const TSecureId& aSid, |
|
195 const TBool aFeedbackClient, |
|
196 const TDesC8& aAppName ); |
|
197 |
|
198 /** |
|
199 * Destructor. |
|
200 */ |
|
201 virtual ~CPolicyClient(); |
|
202 |
|
203 public: // New functions |
|
204 |
|
205 /** |
|
206 * Method to return the clients priority |
|
207 * @return Priority of client |
|
208 */ |
|
209 TInt Priority() const; |
|
210 |
|
211 /** |
|
212 * Method to returns the clients SID |
|
213 * @return SID of client |
|
214 */ |
|
215 TSecureId Sid() const; |
|
216 |
|
217 /** |
|
218 * Method to return indication whether feedback client |
|
219 * @return ETrue if feedback client, otherwise EFalse |
|
220 */ |
|
221 TBool FeedbackClient() const; |
|
222 |
|
223 /** |
|
224 * Method to returns the client application name |
|
225 * @return Application name of the client |
|
226 */ |
|
227 const TDesC& AppName() const; |
|
228 |
|
229 |
|
230 |
|
231 private: // New functions |
|
232 |
|
233 /** |
|
234 * C++ constructor. |
|
235 * @param aPriority Clients priorty |
|
236 * @param aFeedbackClient Indication whether feedback client |
|
237 */ |
|
238 CPolicyClient( const TInt aPriority, const TSecureId& aSid, |
|
239 const TBool aFeedbackClient ); |
|
240 |
|
241 |
|
242 /** |
|
243 * By default Symbian 2nd phase constructor is private. |
|
244 * @param aAppName Clients application name |
|
245 */ |
|
246 void ConstructL( const TDesC8& aAppName ); |
|
247 |
|
248 private: // Data |
|
249 |
|
250 // priority of client |
|
251 TInt iPriority; |
|
252 // the sid of client |
|
253 TSecureId iSid; |
|
254 // boolean indicating whether tactile feedback client |
|
255 TBool iFeedbackClient; |
|
256 // clients app name |
|
257 HBufC* iAppName; |
|
258 |
|
259 }; |
|
260 |
|
261 // Array of objects representing each client from the policy file. |
|
262 RPointerArray<CPolicyClient> iClientArray; |
|
263 |
|
264 // Default policy for 'ALL' client, not stored in array for efficiency |
|
265 CPolicyClient* iAllPolicyClient; |
|
266 }; |
|
267 |
|
268 |
|
269 #endif // HWRMPOLICY_H |
|
270 |
|
271 // End of File |