|
1 /* |
|
2 CpsKernelIf.h |
|
3 |
|
4 Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
5 All rights reserved. |
|
6 |
|
7 This program and the accompanying materials are made available |
|
8 under the terms of the Eclipse Public License v1.0 which accompanies |
|
9 this distribution, and is available at |
|
10 http://www.eclipse.org/legal/epl-v10.html |
|
11 |
|
12 Initial Contributors: |
|
13 Nokia Corporation - initial contribution. |
|
14 |
|
15 Contributors: |
|
16 */ |
|
17 |
|
18 #ifndef __CPSKERNELIF_H__ |
|
19 #define __CPSKERNELIF_H__ |
|
20 |
|
21 // - Includes ------------------------ |
|
22 |
|
23 // - Namespace ----------------------- |
|
24 |
|
25 // - Macros -------------------------- |
|
26 |
|
27 // - Constants ----------------------- |
|
28 |
|
29 // - External data ------------------- |
|
30 |
|
31 // - Forward declarations ------------ |
|
32 |
|
33 class DCpsLddFactory; |
|
34 class TCpsCallback; |
|
35 |
|
36 // - Data types ---------------------- |
|
37 |
|
38 // - Class declarations -------------- |
|
39 |
|
40 /** |
|
41 * CPS interface for kernel side clients |
|
42 */ |
|
43 class DCpsKernelIf : public DBase |
|
44 { |
|
45 public: |
|
46 /** |
|
47 * Returns data stored into record (synchronous). |
|
48 * |
|
49 * @param aGroup The group ID which is accessed. |
|
50 * @param aIndex The index ID which is accessed. |
|
51 * @param aLength The size of data to be read from the beginning of record. |
|
52 * @param aDataBuffer The pointer to data buffer that contains read data. |
|
53 * |
|
54 * @return KErrNone or standard error code |
|
55 */ |
|
56 IMPORT_C static TInt ReadRecord( TUint16 aGroup, TUint16 aIndex, TUint32 aLength, TDes8& aDataBuffer ); |
|
57 |
|
58 /** |
|
59 * Returns data stored into record (asynchronous). |
|
60 * |
|
61 * @param aCb The pointer to a CPS callback object. |
|
62 * @param aGroup The group ID which is accessed. |
|
63 * @param aIndex The index ID which is accessed. |
|
64 * @param aLength The size of data to be read from the beginning of record. |
|
65 * @param aDataBuffer The pointer to data buffer that contains read data. |
|
66 */ |
|
67 IMPORT_C static void ReadRecord( TCpsCallback* aCb, TUint16 aGroup, TUint16 aIndex, TUint32 aLength, TDes8& aDataBuffer ); |
|
68 |
|
69 /** |
|
70 * Used to store data into record (synchronous). |
|
71 * |
|
72 * @param aGroup The group ID which is accessed. |
|
73 * @param aIndex The index ID which is accessed. |
|
74 * @param aLength The size of data to be written into record. |
|
75 * @param aDataBuffer The pointer to data buffer that contains data. |
|
76 * |
|
77 * @return KErrNone or standard error code |
|
78 */ |
|
79 IMPORT_C static TInt WriteRecord( TUint16 aGroup, TUint16 aIndex, TUint32 aLength, const TDesC8& aDataBuffer ); |
|
80 |
|
81 /** |
|
82 * Used to store data into record (asynchronous). |
|
83 * |
|
84 * @param aCb The pointer to a CPS callback object. |
|
85 * @param aGroup The group ID which is accessed. |
|
86 * @param aIndex The index ID which is accessed. |
|
87 * @param aLength The size of data to be written into record. |
|
88 * @param aDataBuffer The pointer to data buffer that contains data. |
|
89 */ |
|
90 IMPORT_C static void WriteRecord( TCpsCallback* aCb, TUint16 aGroup, TUint16 aIndex, TUint32 aLength, const TDesC8& aDataBuffer ); |
|
91 |
|
92 /** |
|
93 * Used to remove existing record (synchronous). |
|
94 * |
|
95 * @param aGroup The group ID which is accessed. |
|
96 * @param aIndex The index ID which is accessed. |
|
97 * |
|
98 * @return KErrNone or standard error code |
|
99 */ |
|
100 IMPORT_C static TInt RemoveRecord( TUint16 aGroup, TUint16 aIndex ); |
|
101 |
|
102 /** |
|
103 * Used to remove existing record (asynchronous). |
|
104 * |
|
105 * @param aCb The pointer to a CPS callback object. |
|
106 * @param aGroup The group ID which is accessed. |
|
107 * @param aIndex The index ID which is accessed. |
|
108 */ |
|
109 IMPORT_C static void RemoveRecord( TCpsCallback* aCb, TUint16 aGroup, TUint16 aIndex ); |
|
110 |
|
111 /** |
|
112 * Used to remove all existing records from given group (synchronous). |
|
113 * |
|
114 * @param aGroup The group ID which is accessed. |
|
115 * |
|
116 * @return KErrNone or standard error code |
|
117 */ |
|
118 IMPORT_C static TInt RemoveAllRecords( TUint16 aGroup ); |
|
119 |
|
120 /** |
|
121 * Used to remove all existing records from given group (asynchronous). |
|
122 * |
|
123 * @param aCb The pointer to a CPS callback object. |
|
124 * @param aGroup The group ID which is accessed. |
|
125 */ |
|
126 IMPORT_C static void RemoveAllRecords( TCpsCallback* aCb, TUint16 aGroup ); |
|
127 |
|
128 /** |
|
129 * Used to query size of existing record (synchronous). |
|
130 * |
|
131 * @param aGroup The group ID which is accessed. |
|
132 * @param aIndex The index ID which is accessed. |
|
133 * @param aSize CPS stores record size to this parameter. |
|
134 * |
|
135 * @return KErrNone or standard error code |
|
136 */ |
|
137 IMPORT_C static TInt RecordSizeGet( TUint16 aGroup, TUint16 aIndex, TUint32& aSize ); |
|
138 |
|
139 /** |
|
140 * Used to query amount of memory used by given group (synchronous). |
|
141 * |
|
142 * @param aGroup The group ID which is accessed. |
|
143 * @param aSize CPS stores amount of used memory by aGroup to this parameter. |
|
144 * |
|
145 * @return KErrNone or standard error code |
|
146 */ |
|
147 IMPORT_C static TInt GroupSizeGet( TUint16 aGroup, TUint32& aSize ); |
|
148 |
|
149 /** |
|
150 * Used to amount of available memory for given group (synchronous). |
|
151 * |
|
152 * @param aGroup The group ID which is accessed. |
|
153 * @param aSize CPS stores amount of available memory to this parameter. |
|
154 * |
|
155 * @return KErrNone or standard error code |
|
156 */ |
|
157 IMPORT_C static TInt AvailableSizeGet( TUint16 aGroup, TUint32& aSize ); |
|
158 |
|
159 /** |
|
160 * Cancels ongoing client request. |
|
161 * |
|
162 * @note Client's callback is called with KErrCancel status if request is removed successfully from the operation queue |
|
163 * |
|
164 * @param aCb The pointer to a CPS callback object. |
|
165 */ |
|
166 IMPORT_C static void CancelRequest( TCpsCallback* aCb ); |
|
167 |
|
168 /** |
|
169 * CPS factory calls this to create kernel IF |
|
170 * |
|
171 * @note For CPS internal use only |
|
172 * |
|
173 * @param aFactoryObj Factory object |
|
174 */ |
|
175 static void CreateKernelInstance( DCpsLddFactory* aFactoryObj ); |
|
176 |
|
177 /** |
|
178 * CPS factory calls this to delete kernel IF |
|
179 * |
|
180 * @note For CPS internal use only |
|
181 */ |
|
182 static void DeleteKernelInstance(); |
|
183 |
|
184 private: |
|
185 |
|
186 /** |
|
187 * Used to query size of existing record (asynchronous). |
|
188 * |
|
189 * @param aCb The pointer to a CPS callback object. |
|
190 * @param aGroup The group ID which is accessed. |
|
191 * @param aIndex The index ID which is accessed. |
|
192 * @param aSize CPS stores record size to this parameter. |
|
193 */ |
|
194 static void RecordSizeGet( TCpsCallback* aCb, TUint16 aGroup, TUint16 aIndex, TUint32& aSize ); |
|
195 |
|
196 /** |
|
197 * Used to query amount of memory used by given group (asynchronous). |
|
198 * |
|
199 * @param aCb The pointer to a CPS callback object. |
|
200 * @param aGroup The group ID which is accessed. |
|
201 * @param aSize CPS stores amount of used memory by aGroup to this parameter. |
|
202 */ |
|
203 static void GroupSizeGet( TCpsCallback* aCb, TUint16 aGroup, TUint32& aSize ); |
|
204 |
|
205 /** |
|
206 * Used to amount of available memory for given group. |
|
207 * |
|
208 * @param aCb The pointer to a CPS callback object. |
|
209 * @param aGroup The group ID which is accessed. |
|
210 * @param aSize CPS stores amount of available memory to this parameter. |
|
211 */ |
|
212 static void AvailableSizeGet( TCpsCallback* aCb, TUint16 aGroup, TUint32& aSize ); |
|
213 |
|
214 /** |
|
215 * Callback function for synchronous CPS kernel operation. |
|
216 * |
|
217 * @ param aStatus KErrNone or standard error code |
|
218 * @ aArg Argument for callback |
|
219 */ |
|
220 static void SyncOperationReady( TInt aStatus, TAny* aArg ); |
|
221 |
|
222 private: |
|
223 /** |
|
224 * Constructor |
|
225 */ |
|
226 DCpsKernelIf(); |
|
227 |
|
228 /** |
|
229 * Destructor |
|
230 */ |
|
231 ~DCpsKernelIf(); |
|
232 |
|
233 private: |
|
234 /** Kernel IF object */ |
|
235 static DCpsKernelIf* iKernelIf; |
|
236 |
|
237 /** Factory object */ |
|
238 static DCpsLddFactory* iFactory; |
|
239 |
|
240 /** Callback for synchronous operations */ |
|
241 TCpsCallback* iSyncCb; |
|
242 |
|
243 /** Semaphore for locking the synchronous interface */ |
|
244 DSemaphore *iSyncLock; |
|
245 |
|
246 /** Synchronous operation result */ |
|
247 TInt iSyncOpResult; |
|
248 }; |
|
249 |
|
250 |
|
251 /** |
|
252 * CPS asynchronous callback function |
|
253 */ |
|
254 typedef void (*TCpsCbFn)( TInt aResult, TAny* aParam ); |
|
255 |
|
256 /** |
|
257 * CPS asynchronous callback DFC |
|
258 * The client must create one of these to be passed to each asynchronous call to kernel interface |
|
259 * The callback function is called in the context supplied by the client when creating an object of this kind (aQue) |
|
260 * The callback function takes as arguments the pin id and the state, so it can be common to all TGpioCallback |
|
261 */ |
|
262 class TCpsCallback : public TDfc |
|
263 { |
|
264 public: |
|
265 inline TCpsCallback( TCpsCbFn aFn, TAny* aPtr, TDfcQue* aQue, TInt aPriority ) |
|
266 : TDfc( DfcFunc, this, aQue, aPriority ), iParam( aPtr ), iCallback( aFn ) |
|
267 {} |
|
268 private: |
|
269 inline static void DfcFunc( TAny* aPtr ) |
|
270 { |
|
271 TCpsCallback* pCb = (TCpsCallback*)aPtr; |
|
272 //Warning -- Possible use of null pointer |
|
273 //lint -e613 |
|
274 pCb->iCallback( pCb->iResult, pCb->iParam ); |
|
275 } |
|
276 public: |
|
277 TInt iResult; |
|
278 TAny* iParam; |
|
279 TCpsCbFn iCallback; |
|
280 }; |
|
281 |
|
282 #endif /* __CPSKERNELIF_H__ */ |
|
283 |