sl@0
|
1 |
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// in its implementation.
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
/**
|
sl@0
|
19 |
@file The interface to an example data converter device driver which uses Shared Chunks
|
sl@0
|
20 |
@publishedPartner
|
sl@0
|
21 |
@prototype 9.1
|
sl@0
|
22 |
*/
|
sl@0
|
23 |
|
sl@0
|
24 |
#ifndef __CONVERT1_H__
|
sl@0
|
25 |
#define __CONVERT1_H__
|
sl@0
|
26 |
|
sl@0
|
27 |
#include <e32cmn.h>
|
sl@0
|
28 |
#include <e32ver.h>
|
sl@0
|
29 |
#ifndef __KERNEL_MODE__
|
sl@0
|
30 |
#include <e32std.h>
|
sl@0
|
31 |
#endif
|
sl@0
|
32 |
|
sl@0
|
33 |
/**
|
sl@0
|
34 |
User interface for 'Convert1'
|
sl@0
|
35 |
*/
|
sl@0
|
36 |
class RConvert1 : public RBusLogicalChannel
|
sl@0
|
37 |
{
|
sl@0
|
38 |
public:
|
sl@0
|
39 |
/**
|
sl@0
|
40 |
Structure for holding driver capabilities information
|
sl@0
|
41 |
*/
|
sl@0
|
42 |
class TCaps
|
sl@0
|
43 |
{
|
sl@0
|
44 |
public:
|
sl@0
|
45 |
TVersion iVersion;
|
sl@0
|
46 |
TInt iMaxChannels; /**< Maximum number of simultaneous channels supported by driver */
|
sl@0
|
47 |
};
|
sl@0
|
48 |
|
sl@0
|
49 |
/**
|
sl@0
|
50 |
Structure for holding driver configuration data
|
sl@0
|
51 |
*/
|
sl@0
|
52 |
class TConfig
|
sl@0
|
53 |
{
|
sl@0
|
54 |
public:
|
sl@0
|
55 |
TInt iBufferSize; /**< Size of convert buffer */
|
sl@0
|
56 |
TBool iCreateInputChunk; /**< True if driver is to create an input chunk */
|
sl@0
|
57 |
TInt iSpeed; /**< Speed of converter in bytes/second (for this example test) */
|
sl@0
|
58 |
};
|
sl@0
|
59 |
typedef TPckgBuf<TConfig> TConfigBuf;
|
sl@0
|
60 |
|
sl@0
|
61 |
#ifndef __KERNEL_MODE__
|
sl@0
|
62 |
public:
|
sl@0
|
63 |
RConvert1();
|
sl@0
|
64 |
TInt Open();
|
sl@0
|
65 |
void Close();
|
sl@0
|
66 |
TInt GetConfig(TConfigBuf& aConfig);
|
sl@0
|
67 |
TInt SetConfig(const TConfigBuf& aConfig);
|
sl@0
|
68 |
void Convert(const TDesC8& aInput,TRequestStatus& aStatus);
|
sl@0
|
69 |
void Convert(RChunk aInputChunk,TInt aInputOffset,TInt aInputSize,TRequestStatus& aStatus);
|
sl@0
|
70 |
void Convert(TInt aSize,TRequestStatus& aStatus);
|
sl@0
|
71 |
inline RChunk OutChunk() const;
|
sl@0
|
72 |
inline RChunk InChunk();
|
sl@0
|
73 |
inline TPtr8 InBuffer();
|
sl@0
|
74 |
private:
|
sl@0
|
75 |
/**
|
sl@0
|
76 |
Hide the Duplicate() method by making it private.
|
sl@0
|
77 |
The purpose of hiding the method is to prevent it's use because this object also contains
|
sl@0
|
78 |
chunk handles which would need special consideration.
|
sl@0
|
79 |
We don't want to bother supporting Duplicate() for this particular driver because
|
sl@0
|
80 |
it only supports a single client thread so normal use wouldn't require Duplicate().
|
sl@0
|
81 |
*/
|
sl@0
|
82 |
TInt Duplicate(const RThread& aSrc,TOwnerType aType=EOwnerProcess);
|
sl@0
|
83 |
#endif
|
sl@0
|
84 |
|
sl@0
|
85 |
public:
|
sl@0
|
86 |
inline static const TDesC& Name();
|
sl@0
|
87 |
inline static TVersion VersionRequired();
|
sl@0
|
88 |
private:
|
sl@0
|
89 |
/**
|
sl@0
|
90 |
Enumeration of Control messages.
|
sl@0
|
91 |
*/
|
sl@0
|
92 |
enum TControl
|
sl@0
|
93 |
{
|
sl@0
|
94 |
EGetConfig,
|
sl@0
|
95 |
ESetConfig,
|
sl@0
|
96 |
EConvertDes,
|
sl@0
|
97 |
EConvertChunk,
|
sl@0
|
98 |
EConvertInChunk,
|
sl@0
|
99 |
};
|
sl@0
|
100 |
|
sl@0
|
101 |
/**
|
sl@0
|
102 |
Enumeration of Request messages.
|
sl@0
|
103 |
(None used in this example)
|
sl@0
|
104 |
*/
|
sl@0
|
105 |
enum TRequest
|
sl@0
|
106 |
{
|
sl@0
|
107 |
ENumRequests,
|
sl@0
|
108 |
EAllRequests = (1<<ENumRequests)-1
|
sl@0
|
109 |
};
|
sl@0
|
110 |
|
sl@0
|
111 |
/**
|
sl@0
|
112 |
Structure used to package arguments for a EConvertChunk control message
|
sl@0
|
113 |
*/
|
sl@0
|
114 |
struct TConvertArgs
|
sl@0
|
115 |
{
|
sl@0
|
116 |
TInt iChunkHandle;
|
sl@0
|
117 |
TInt iOffset;
|
sl@0
|
118 |
TInt iSize;
|
sl@0
|
119 |
};
|
sl@0
|
120 |
|
sl@0
|
121 |
/**
|
sl@0
|
122 |
Structure representing input and output buffers
|
sl@0
|
123 |
*/
|
sl@0
|
124 |
struct TBufferInfo
|
sl@0
|
125 |
{
|
sl@0
|
126 |
TInt iOutChunkHandle; /**< Handle to Shared Chunk used to hold output data */
|
sl@0
|
127 |
TInt iInChunkHandle; /**< Handle to Shared Chunk used to hold input data */
|
sl@0
|
128 |
TInt iInBufferOffset; /**< Offset within input chunk where the input buffer actually starts */
|
sl@0
|
129 |
TUint8* iInBufferPtr; /**< Calculated address for start of input buffer within client process */
|
sl@0
|
130 |
TInt iInBufferSize; /**< Size of input buffer in bytes */
|
sl@0
|
131 |
};
|
sl@0
|
132 |
|
sl@0
|
133 |
TBufferInfo iBufferInfo;
|
sl@0
|
134 |
|
sl@0
|
135 |
// Kernel side LDD channel is a friend
|
sl@0
|
136 |
friend class DConvert1Channel;
|
sl@0
|
137 |
};
|
sl@0
|
138 |
|
sl@0
|
139 |
/**
|
sl@0
|
140 |
The driver's name
|
sl@0
|
141 |
|
sl@0
|
142 |
@return The name of the driver
|
sl@0
|
143 |
|
sl@0
|
144 |
@internalComponent
|
sl@0
|
145 |
*/
|
sl@0
|
146 |
inline const TDesC& RConvert1::Name()
|
sl@0
|
147 |
{
|
sl@0
|
148 |
_LIT(KConvert1Name,"CONVERT1");
|
sl@0
|
149 |
return KConvert1Name;
|
sl@0
|
150 |
}
|
sl@0
|
151 |
|
sl@0
|
152 |
/**
|
sl@0
|
153 |
The driver's version
|
sl@0
|
154 |
|
sl@0
|
155 |
@return The version number of the driver
|
sl@0
|
156 |
|
sl@0
|
157 |
@internalComponent
|
sl@0
|
158 |
*/
|
sl@0
|
159 |
inline TVersion RConvert1::VersionRequired()
|
sl@0
|
160 |
{
|
sl@0
|
161 |
const TInt KMajorVersionNumber=1;
|
sl@0
|
162 |
const TInt KMinorVersionNumber=0;
|
sl@0
|
163 |
const TInt KBuildVersionNumber=KE32BuildVersionNumber;
|
sl@0
|
164 |
return TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
|
sl@0
|
165 |
}
|
sl@0
|
166 |
|
sl@0
|
167 |
/*
|
sl@0
|
168 |
NOTE: The following methods would normally be exported from a seperate client DLL
|
sl@0
|
169 |
but are included inline in this header file for convenience.
|
sl@0
|
170 |
*/
|
sl@0
|
171 |
|
sl@0
|
172 |
#ifndef __KERNEL_MODE__
|
sl@0
|
173 |
|
sl@0
|
174 |
/**
|
sl@0
|
175 |
Constructor to clear member data
|
sl@0
|
176 |
*/
|
sl@0
|
177 |
RConvert1::RConvert1()
|
sl@0
|
178 |
{
|
sl@0
|
179 |
memclr(&iBufferInfo,sizeof(iBufferInfo));
|
sl@0
|
180 |
}
|
sl@0
|
181 |
|
sl@0
|
182 |
/**
|
sl@0
|
183 |
Open a logical channel to the driver.
|
sl@0
|
184 |
The opened channel may only be used by the calling trhead.
|
sl@0
|
185 |
|
sl@0
|
186 |
@return One of the system wide error codes.
|
sl@0
|
187 |
*/
|
sl@0
|
188 |
TInt RConvert1::Open()
|
sl@0
|
189 |
{
|
sl@0
|
190 |
return DoCreate(Name(),VersionRequired(),KNullUnit,NULL,NULL,EOwnerThread);
|
sl@0
|
191 |
}
|
sl@0
|
192 |
|
sl@0
|
193 |
/**
|
sl@0
|
194 |
Close a logical channel to the driver
|
sl@0
|
195 |
*/
|
sl@0
|
196 |
void RConvert1::Close()
|
sl@0
|
197 |
{
|
sl@0
|
198 |
OutChunk().Close();
|
sl@0
|
199 |
InChunk().Close();
|
sl@0
|
200 |
RBusLogicalChannel::Close();
|
sl@0
|
201 |
}
|
sl@0
|
202 |
|
sl@0
|
203 |
/**
|
sl@0
|
204 |
Get the current configuration settings.
|
sl@0
|
205 |
|
sl@0
|
206 |
@param aConfig A structure which will be filled with the configuration settings.
|
sl@0
|
207 |
|
sl@0
|
208 |
@return KErrNone
|
sl@0
|
209 |
*/
|
sl@0
|
210 |
TInt RConvert1::GetConfig(TConfigBuf& aConfig)
|
sl@0
|
211 |
{
|
sl@0
|
212 |
return DoControl(EGetConfig,(TAny*)&aConfig);
|
sl@0
|
213 |
}
|
sl@0
|
214 |
|
sl@0
|
215 |
/**
|
sl@0
|
216 |
Set the current configuration settings.
|
sl@0
|
217 |
|
sl@0
|
218 |
@param aConfig The new configuration settings to be used.
|
sl@0
|
219 |
|
sl@0
|
220 |
@return KErrInUse if data convertion is already in progress
|
sl@0
|
221 |
KErrArgument if any configuration values are invalid.
|
sl@0
|
222 |
KErrNone otherwise
|
sl@0
|
223 |
|
sl@0
|
224 |
@post On success, new memory buffers will have been created and mapped into client process.
|
sl@0
|
225 |
*/
|
sl@0
|
226 |
TInt RConvert1::SetConfig(const TConfigBuf& aConfig)
|
sl@0
|
227 |
{
|
sl@0
|
228 |
OutChunk().Close();
|
sl@0
|
229 |
InChunk().Close();
|
sl@0
|
230 |
TInt r = DoControl(ESetConfig,(TAny*)&aConfig,&iBufferInfo);
|
sl@0
|
231 |
if(r!=KErrNone)
|
sl@0
|
232 |
return r;
|
sl@0
|
233 |
// Sett address of input
|
sl@0
|
234 |
if(InChunk().Handle())
|
sl@0
|
235 |
iBufferInfo.iInBufferPtr = InChunk().Base()+iBufferInfo.iInBufferOffset;
|
sl@0
|
236 |
return r;
|
sl@0
|
237 |
}
|
sl@0
|
238 |
|
sl@0
|
239 |
/**
|
sl@0
|
240 |
Convert data in the specified descriptor.
|
sl@0
|
241 |
|
sl@0
|
242 |
@param aInput A descriptor containing the data to be converted
|
sl@0
|
243 |
@param aStatus The request status signaled when convertion is complete (or on error).
|
sl@0
|
244 |
The result value is the offset within OutChunk() where the coverted output
|
sl@0
|
245 |
data resides; or set to one of the system wide error codes when an error
|
sl@0
|
246 |
occurs:
|
sl@0
|
247 |
|
sl@0
|
248 |
@pre The driver must have been previousely initialised by a call to SetConfig()
|
sl@0
|
249 |
*/
|
sl@0
|
250 |
void RConvert1::Convert(const TDesC8& aInput,TRequestStatus& aStatus)
|
sl@0
|
251 |
{
|
sl@0
|
252 |
DoControl(EConvertDes,(TAny*)&aInput,&aStatus);
|
sl@0
|
253 |
}
|
sl@0
|
254 |
|
sl@0
|
255 |
/**
|
sl@0
|
256 |
Convert data in the specified chunk.
|
sl@0
|
257 |
|
sl@0
|
258 |
@param aInputChunk The chunk containing the data to be converted
|
sl@0
|
259 |
@param aInputOffset Offset from start of chunk for the start of data to be converted.
|
sl@0
|
260 |
@param aInputSize Number of bytes of data to be converted.
|
sl@0
|
261 |
@param aStatus The request status signaled when convertion is complete (or on error).
|
sl@0
|
262 |
The result value is the offset within OutChunk() where the coverted output
|
sl@0
|
263 |
data resides; or set to one of the system wide error codes when an error
|
sl@0
|
264 |
occurs:
|
sl@0
|
265 |
|
sl@0
|
266 |
@pre The driver must have been previousely initialised by a call to SetConfig()
|
sl@0
|
267 |
*/
|
sl@0
|
268 |
void RConvert1::Convert(RChunk aInputChunk,TInt aInputOffset,TInt aInputSize,TRequestStatus& aStatus)
|
sl@0
|
269 |
{
|
sl@0
|
270 |
TConvertArgs args;
|
sl@0
|
271 |
args.iChunkHandle = aInputChunk.Handle();
|
sl@0
|
272 |
args.iOffset = aInputOffset;
|
sl@0
|
273 |
args.iSize = aInputSize;
|
sl@0
|
274 |
DoControl(EConvertChunk,(TAny*)&args,(TAny*)&aStatus);
|
sl@0
|
275 |
}
|
sl@0
|
276 |
|
sl@0
|
277 |
/**
|
sl@0
|
278 |
Convert data in the input chunk. I.e. placed in InBuffer().
|
sl@0
|
279 |
|
sl@0
|
280 |
@param aSize Number of bytes of data to be converted.
|
sl@0
|
281 |
@param aStatus The request status signaled when convertion is complete (or on error).
|
sl@0
|
282 |
The result value is the offset within OutChunk() where the coverted output
|
sl@0
|
283 |
data resides; or set to one of the system wide error codes when an error
|
sl@0
|
284 |
occurs:
|
sl@0
|
285 |
|
sl@0
|
286 |
@pre The driver must have been previousely initialised by a call to SetConfig()
|
sl@0
|
287 |
*/
|
sl@0
|
288 |
void RConvert1::Convert(TInt aSize,TRequestStatus& aStatus)
|
sl@0
|
289 |
{
|
sl@0
|
290 |
DoControl(EConvertInChunk,(TAny*)aSize,(TAny*)&aStatus);
|
sl@0
|
291 |
}
|
sl@0
|
292 |
|
sl@0
|
293 |
/**
|
sl@0
|
294 |
Obtain the chunk into which converted data will be placed.
|
sl@0
|
295 |
This chunk may change after calls to SetConfig().
|
sl@0
|
296 |
|
sl@0
|
297 |
@return The chunk
|
sl@0
|
298 |
|
sl@0
|
299 |
@pre The driver must have been configured using SetConfig()
|
sl@0
|
300 |
with TConfig::iCreateInputChunk set true.
|
sl@0
|
301 |
*/
|
sl@0
|
302 |
inline RChunk RConvert1::InChunk()
|
sl@0
|
303 |
{
|
sl@0
|
304 |
return RChunk((RChunk&)iBufferInfo.iInChunkHandle);
|
sl@0
|
305 |
}
|
sl@0
|
306 |
|
sl@0
|
307 |
/**
|
sl@0
|
308 |
Obtain the chunk into which converted data will be placed.
|
sl@0
|
309 |
This chunk may change after calls to SetConfig().
|
sl@0
|
310 |
|
sl@0
|
311 |
@return The chunk
|
sl@0
|
312 |
|
sl@0
|
313 |
@pre The driver must have been configured using SetConfig()
|
sl@0
|
314 |
*/
|
sl@0
|
315 |
inline RChunk RConvert1::OutChunk() const
|
sl@0
|
316 |
{
|
sl@0
|
317 |
return RChunk((RChunk&)iBufferInfo.iOutChunkHandle);
|
sl@0
|
318 |
}
|
sl@0
|
319 |
|
sl@0
|
320 |
/**
|
sl@0
|
321 |
Get a pointer descriptor for the input buffer.
|
sl@0
|
322 |
|
sl@0
|
323 |
@return A pointer descriptor to the input buffer memory.
|
sl@0
|
324 |
|
sl@0
|
325 |
@pre The driver must have been configured using SetConfig()
|
sl@0
|
326 |
with TConfig::iCreateInputChunk set true.
|
sl@0
|
327 |
*/
|
sl@0
|
328 |
inline TPtr8 RConvert1::InBuffer()
|
sl@0
|
329 |
{
|
sl@0
|
330 |
return TPtr8(iBufferInfo.iInBufferPtr,iBufferInfo.iInBufferSize);
|
sl@0
|
331 |
}
|
sl@0
|
332 |
|
sl@0
|
333 |
#endif // !__KERNEL_MODE__
|
sl@0
|
334 |
|
sl@0
|
335 |
#endif
|
sl@0
|
336 |
|