os/kernelhwsrv/kerneltest/e32test/examples/driver1/driver1.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/examples/driver1/driver1.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,213 @@
     1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +/**
    1.20 + @file Interface to example Logical Device Driver
    1.21 + @publishedPartner
    1.22 + @released
    1.23 +*/
    1.24 +
    1.25 +#ifndef __DRIVER1_H__
    1.26 +#define __DRIVER1_H__
    1.27 +
    1.28 +#include <e32cmn.h>
    1.29 +#include <e32ver.h>
    1.30 +#ifndef __KERNEL_MODE__
    1.31 +#include <e32std.h>
    1.32 +#endif
    1.33 +
    1.34 +/**
    1.35 +User interface for 'Driver1'
    1.36 +*/
    1.37 +class RDriver1 : public RBusLogicalChannel
    1.38 +	{
    1.39 +public:
    1.40 +	/**
    1.41 +	Structure for holding driver capabilities information
    1.42 +	(Just a version number in this example.)
    1.43 +	*/
    1.44 +	class TCaps
    1.45 +		{
    1.46 +	public:
    1.47 +		TVersion iVersion;
    1.48 +		};
    1.49 +
    1.50 +	/**
    1.51 +	Structure for holding driver configuration data
    1.52 +	*/
    1.53 +	class TConfig
    1.54 +		{
    1.55 +	public:
    1.56 +		TInt iSpeed;				/**< Data transfer speed in microseconds/byte */
    1.57 +		TInt iPddBufferSize;		/**< Size of the PDD's data buffer (not modifiable) */
    1.58 +		TInt iMaxSendDataSize;		/**< Maximum size of data which can be sent in one go (not modifiable) */
    1.59 +		TInt iMaxReceiveDataSize;	/**< Maximum size of data which can be received in one go (not modifiable) */
    1.60 +		};
    1.61 +	typedef TPckgBuf<TConfig> TConfigBuf;
    1.62 +
    1.63 +public:
    1.64 +	TInt Open();
    1.65 +	TInt GetConfig(TConfigBuf& aConfig);
    1.66 +	TInt SetConfig(const TConfigBuf& aConfig);
    1.67 +	void SendData(TRequestStatus &aStatus,const TDesC8& aData);
    1.68 +	void SendDataCancel();
    1.69 +	void ReceiveData(TRequestStatus &aStatus,TDes8& aBuffer);
    1.70 +	void ReceiveDataCancel();
    1.71 +	inline static const TDesC& Name();
    1.72 +	inline static TVersion VersionRequired();
    1.73 +private:
    1.74 +	/**
    1.75 +	Enumeration of Control messages.
    1.76 +	*/
    1.77 +	enum TControl
    1.78 +		{
    1.79 +		EGetConfig,
    1.80 +		ESetConfig
    1.81 +		};
    1.82 +
    1.83 +	/**
    1.84 +	Enumeration of Request messages.
    1.85 +	*/
    1.86 +	enum TRequest
    1.87 +		{
    1.88 +		ESendData,
    1.89 +		EReceiveData,
    1.90 +		ENumRequests,
    1.91 +		EAllRequests = (1<<ENumRequests)-1
    1.92 +		};
    1.93 +
    1.94 +	// Kernel side LDD channel is a friend
    1.95 +	friend class DDriver1Channel;
    1.96 +	};
    1.97 +
    1.98 +/**
    1.99 +  The driver's name
   1.100 +
   1.101 +  @return The name of the driver
   1.102 +
   1.103 +  @internalComponent
   1.104 +*/
   1.105 +inline const TDesC& RDriver1::Name()
   1.106 +	{
   1.107 +	_LIT(KDriver1Name,"DRIVER1");
   1.108 +	return KDriver1Name;
   1.109 +	}
   1.110 +
   1.111 +/**
   1.112 +  The driver's version
   1.113 +
   1.114 +  @return The version number of the driver
   1.115 +
   1.116 +  @internalComponent
   1.117 +*/
   1.118 +inline TVersion RDriver1::VersionRequired()
   1.119 +	{
   1.120 +	const TInt KMajorVersionNumber=1;
   1.121 +	const TInt KMinorVersionNumber=0;
   1.122 +	const TInt KBuildVersionNumber=KE32BuildVersionNumber;
   1.123 +	return TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
   1.124 +	}
   1.125 +
   1.126 +/*
   1.127 +  NOTE: The following methods would normally be exported from a seperate client DLL
   1.128 +  but are included inline in this header file for convenience.
   1.129 +*/
   1.130 +
   1.131 +#ifndef __KERNEL_MODE__
   1.132 +
   1.133 +/**
   1.134 +  Open a logical channel to the driver
   1.135 +
   1.136 +  @return One of the system wide error codes.
   1.137 +*/
   1.138 +TInt RDriver1::Open()
   1.139 +	{
   1.140 +	return DoCreate(Name(),VersionRequired(),KNullUnit,NULL,NULL,EOwnerThread);
   1.141 +	}
   1.142 +
   1.143 +/**
   1.144 +  Get the current configuration settings.
   1.145 +
   1.146 +  @param aConfig A structure which will be filled with the configuration settings.
   1.147 +
   1.148 +  @return KErrNone
   1.149 +*/
   1.150 +TInt RDriver1::GetConfig(TConfigBuf& aConfig)
   1.151 +	{
   1.152 +	return DoControl(EGetConfig,(TAny*)&aConfig);
   1.153 +	}
   1.154 +
   1.155 +/**
   1.156 +  Set the current configuration settings.
   1.157 +
   1.158 +  @param aConfig The new configuration settings to be used.
   1.159 +
   1.160 +  @return KErrInUse if there are outstanding data transfer requests.
   1.161 +          KErrArgument if any configuration values are invalid.
   1.162 +		  KErrNone otherwise
   1.163 +*/
   1.164 +TInt RDriver1::SetConfig(const TConfigBuf& aConfig)
   1.165 +	{
   1.166 +	return DoControl(ESetConfig,(TAny*)&aConfig);
   1.167 +	}
   1.168 +
   1.169 +/**
   1.170 +  Send data to the device.
   1.171 +  Only one send request may be pending at any time.
   1.172 +
   1.173 +  @param aStatus The request to be signaled when the data has been sent.
   1.174 +		         The result value will be set to KErrNone on success;
   1.175 +		         or set to one of the system wide error codes when an error occurs.
   1.176 +  @param aData   A descriptor containing the data to send.
   1.177 +*/
   1.178 +void RDriver1::SendData(TRequestStatus &aStatus,const TDesC8& aData)
   1.179 +	{
   1.180 +	DoRequest(ESendData,aStatus,(TAny*)&aData);
   1.181 +	}
   1.182 +
   1.183 +/**
   1.184 +  Cancel a previous SendData request.
   1.185 +*/
   1.186 +void RDriver1::SendDataCancel()
   1.187 +	{
   1.188 +	DoCancel(1<<ESendData);
   1.189 +	}
   1.190 +
   1.191 +/**
   1.192 +  Receive data from the device.
   1.193 +  Only one receive request may be pending at any time.
   1.194 +
   1.195 +  @param aStatus The request to be signaled when the data has been received.
   1.196 +		         The result value will be set to KErrNone on success;
   1.197 +		         or set to one of the system wide error codes when an error occurs.
   1.198 +  @param aData	A descriptor to which the received data will be written.
   1.199 +*/
   1.200 +void RDriver1::ReceiveData(TRequestStatus &aStatus,TDes8& aBuffer)
   1.201 +	{
   1.202 +	DoRequest(EReceiveData,aStatus,(TAny*)&aBuffer);
   1.203 +	}
   1.204 +
   1.205 +/**
   1.206 +  Cancel a previous ReceiveData request.
   1.207 +*/
   1.208 +void RDriver1::ReceiveDataCancel()
   1.209 +	{
   1.210 +	DoCancel(1<<EReceiveData);
   1.211 +	}
   1.212 +
   1.213 +#endif  // !__KERNEL_MODE__
   1.214 +
   1.215 +#endif
   1.216 +