Update contrib.
1 // Copyright (c) 2005-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 the License "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 // in its implementation.
19 @file The interface to an example data converter device driver which uses Shared Chunks
24 #ifndef __CONVERT1_H__
25 #define __CONVERT1_H__
29 #ifndef __KERNEL_MODE__
34 User interface for 'Convert1'
36 class RConvert1 : public RBusLogicalChannel
40 Structure for holding driver capabilities information
46 TInt iMaxChannels; /**< Maximum number of simultaneous channels supported by driver */
50 Structure for holding driver configuration data
55 TInt iBufferSize; /**< Size of convert buffer */
56 TBool iCreateInputChunk; /**< True if driver is to create an input chunk */
57 TInt iSpeed; /**< Speed of converter in bytes/second (for this example test) */
59 typedef TPckgBuf<TConfig> TConfigBuf;
61 #ifndef __KERNEL_MODE__
66 TInt GetConfig(TConfigBuf& aConfig);
67 TInt SetConfig(const TConfigBuf& aConfig);
68 void Convert(const TDesC8& aInput,TRequestStatus& aStatus);
69 void Convert(RChunk aInputChunk,TInt aInputOffset,TInt aInputSize,TRequestStatus& aStatus);
70 void Convert(TInt aSize,TRequestStatus& aStatus);
71 inline RChunk OutChunk() const;
72 inline RChunk InChunk();
73 inline TPtr8 InBuffer();
76 Hide the Duplicate() method by making it private.
77 The purpose of hiding the method is to prevent it's use because this object also contains
78 chunk handles which would need special consideration.
79 We don't want to bother supporting Duplicate() for this particular driver because
80 it only supports a single client thread so normal use wouldn't require Duplicate().
82 TInt Duplicate(const RThread& aSrc,TOwnerType aType=EOwnerProcess);
86 inline static const TDesC& Name();
87 inline static TVersion VersionRequired();
90 Enumeration of Control messages.
102 Enumeration of Request messages.
103 (None used in this example)
108 EAllRequests = (1<<ENumRequests)-1
112 Structure used to package arguments for a EConvertChunk control message
122 Structure representing input and output buffers
126 TInt iOutChunkHandle; /**< Handle to Shared Chunk used to hold output data */
127 TInt iInChunkHandle; /**< Handle to Shared Chunk used to hold input data */
128 TInt iInBufferOffset; /**< Offset within input chunk where the input buffer actually starts */
129 TUint8* iInBufferPtr; /**< Calculated address for start of input buffer within client process */
130 TInt iInBufferSize; /**< Size of input buffer in bytes */
133 TBufferInfo iBufferInfo;
135 // Kernel side LDD channel is a friend
136 friend class DConvert1Channel;
142 @return The name of the driver
146 inline const TDesC& RConvert1::Name()
148 _LIT(KConvert1Name,"CONVERT1");
149 return KConvert1Name;
155 @return The version number of the driver
159 inline TVersion RConvert1::VersionRequired()
161 const TInt KMajorVersionNumber=1;
162 const TInt KMinorVersionNumber=0;
163 const TInt KBuildVersionNumber=KE32BuildVersionNumber;
164 return TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
168 NOTE: The following methods would normally be exported from a seperate client DLL
169 but are included inline in this header file for convenience.
172 #ifndef __KERNEL_MODE__
175 Constructor to clear member data
177 RConvert1::RConvert1()
179 memclr(&iBufferInfo,sizeof(iBufferInfo));
183 Open a logical channel to the driver.
184 The opened channel may only be used by the calling trhead.
186 @return One of the system wide error codes.
188 TInt RConvert1::Open()
190 return DoCreate(Name(),VersionRequired(),KNullUnit,NULL,NULL,EOwnerThread);
194 Close a logical channel to the driver
196 void RConvert1::Close()
200 RBusLogicalChannel::Close();
204 Get the current configuration settings.
206 @param aConfig A structure which will be filled with the configuration settings.
210 TInt RConvert1::GetConfig(TConfigBuf& aConfig)
212 return DoControl(EGetConfig,(TAny*)&aConfig);
216 Set the current configuration settings.
218 @param aConfig The new configuration settings to be used.
220 @return KErrInUse if data convertion is already in progress
221 KErrArgument if any configuration values are invalid.
224 @post On success, new memory buffers will have been created and mapped into client process.
226 TInt RConvert1::SetConfig(const TConfigBuf& aConfig)
230 TInt r = DoControl(ESetConfig,(TAny*)&aConfig,&iBufferInfo);
233 // Sett address of input
234 if(InChunk().Handle())
235 iBufferInfo.iInBufferPtr = InChunk().Base()+iBufferInfo.iInBufferOffset;
240 Convert data in the specified descriptor.
242 @param aInput A descriptor containing the data to be converted
243 @param aStatus The request status signaled when convertion is complete (or on error).
244 The result value is the offset within OutChunk() where the coverted output
245 data resides; or set to one of the system wide error codes when an error
248 @pre The driver must have been previousely initialised by a call to SetConfig()
250 void RConvert1::Convert(const TDesC8& aInput,TRequestStatus& aStatus)
252 DoControl(EConvertDes,(TAny*)&aInput,&aStatus);
256 Convert data in the specified chunk.
258 @param aInputChunk The chunk containing the data to be converted
259 @param aInputOffset Offset from start of chunk for the start of data to be converted.
260 @param aInputSize Number of bytes of data to be converted.
261 @param aStatus The request status signaled when convertion is complete (or on error).
262 The result value is the offset within OutChunk() where the coverted output
263 data resides; or set to one of the system wide error codes when an error
266 @pre The driver must have been previousely initialised by a call to SetConfig()
268 void RConvert1::Convert(RChunk aInputChunk,TInt aInputOffset,TInt aInputSize,TRequestStatus& aStatus)
271 args.iChunkHandle = aInputChunk.Handle();
272 args.iOffset = aInputOffset;
273 args.iSize = aInputSize;
274 DoControl(EConvertChunk,(TAny*)&args,(TAny*)&aStatus);
278 Convert data in the input chunk. I.e. placed in InBuffer().
280 @param aSize Number of bytes of data to be converted.
281 @param aStatus The request status signaled when convertion is complete (or on error).
282 The result value is the offset within OutChunk() where the coverted output
283 data resides; or set to one of the system wide error codes when an error
286 @pre The driver must have been previousely initialised by a call to SetConfig()
288 void RConvert1::Convert(TInt aSize,TRequestStatus& aStatus)
290 DoControl(EConvertInChunk,(TAny*)aSize,(TAny*)&aStatus);
294 Obtain the chunk into which converted data will be placed.
295 This chunk may change after calls to SetConfig().
299 @pre The driver must have been configured using SetConfig()
300 with TConfig::iCreateInputChunk set true.
302 inline RChunk RConvert1::InChunk()
304 return RChunk((RChunk&)iBufferInfo.iInChunkHandle);
308 Obtain the chunk into which converted data will be placed.
309 This chunk may change after calls to SetConfig().
313 @pre The driver must have been configured using SetConfig()
315 inline RChunk RConvert1::OutChunk() const
317 return RChunk((RChunk&)iBufferInfo.iOutChunkHandle);
321 Get a pointer descriptor for the input buffer.
323 @return A pointer descriptor to the input buffer memory.
325 @pre The driver must have been configured using SetConfig()
326 with TConfig::iCreateInputChunk set true.
328 inline TPtr8 RConvert1::InBuffer()
330 return TPtr8(iBufferInfo.iInBufferPtr,iBufferInfo.iInBufferSize);
333 #endif // !__KERNEL_MODE__