os/kernelhwsrv/kerneltest/e32test/examples/driver1/driver1.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2003-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
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file Interface to example Logical Device Driver
sl@0
    18
 @publishedPartner
sl@0
    19
 @released
sl@0
    20
*/
sl@0
    21
sl@0
    22
#ifndef __DRIVER1_H__
sl@0
    23
#define __DRIVER1_H__
sl@0
    24
sl@0
    25
#include <e32cmn.h>
sl@0
    26
#include <e32ver.h>
sl@0
    27
#ifndef __KERNEL_MODE__
sl@0
    28
#include <e32std.h>
sl@0
    29
#endif
sl@0
    30
sl@0
    31
/**
sl@0
    32
User interface for 'Driver1'
sl@0
    33
*/
sl@0
    34
class RDriver1 : public RBusLogicalChannel
sl@0
    35
	{
sl@0
    36
public:
sl@0
    37
	/**
sl@0
    38
	Structure for holding driver capabilities information
sl@0
    39
	(Just a version number in this example.)
sl@0
    40
	*/
sl@0
    41
	class TCaps
sl@0
    42
		{
sl@0
    43
	public:
sl@0
    44
		TVersion iVersion;
sl@0
    45
		};
sl@0
    46
sl@0
    47
	/**
sl@0
    48
	Structure for holding driver configuration data
sl@0
    49
	*/
sl@0
    50
	class TConfig
sl@0
    51
		{
sl@0
    52
	public:
sl@0
    53
		TInt iSpeed;				/**< Data transfer speed in microseconds/byte */
sl@0
    54
		TInt iPddBufferSize;		/**< Size of the PDD's data buffer (not modifiable) */
sl@0
    55
		TInt iMaxSendDataSize;		/**< Maximum size of data which can be sent in one go (not modifiable) */
sl@0
    56
		TInt iMaxReceiveDataSize;	/**< Maximum size of data which can be received in one go (not modifiable) */
sl@0
    57
		};
sl@0
    58
	typedef TPckgBuf<TConfig> TConfigBuf;
sl@0
    59
sl@0
    60
public:
sl@0
    61
	TInt Open();
sl@0
    62
	TInt GetConfig(TConfigBuf& aConfig);
sl@0
    63
	TInt SetConfig(const TConfigBuf& aConfig);
sl@0
    64
	void SendData(TRequestStatus &aStatus,const TDesC8& aData);
sl@0
    65
	void SendDataCancel();
sl@0
    66
	void ReceiveData(TRequestStatus &aStatus,TDes8& aBuffer);
sl@0
    67
	void ReceiveDataCancel();
sl@0
    68
	inline static const TDesC& Name();
sl@0
    69
	inline static TVersion VersionRequired();
sl@0
    70
private:
sl@0
    71
	/**
sl@0
    72
	Enumeration of Control messages.
sl@0
    73
	*/
sl@0
    74
	enum TControl
sl@0
    75
		{
sl@0
    76
		EGetConfig,
sl@0
    77
		ESetConfig
sl@0
    78
		};
sl@0
    79
sl@0
    80
	/**
sl@0
    81
	Enumeration of Request messages.
sl@0
    82
	*/
sl@0
    83
	enum TRequest
sl@0
    84
		{
sl@0
    85
		ESendData,
sl@0
    86
		EReceiveData,
sl@0
    87
		ENumRequests,
sl@0
    88
		EAllRequests = (1<<ENumRequests)-1
sl@0
    89
		};
sl@0
    90
sl@0
    91
	// Kernel side LDD channel is a friend
sl@0
    92
	friend class DDriver1Channel;
sl@0
    93
	};
sl@0
    94
sl@0
    95
/**
sl@0
    96
  The driver's name
sl@0
    97
sl@0
    98
  @return The name of the driver
sl@0
    99
sl@0
   100
  @internalComponent
sl@0
   101
*/
sl@0
   102
inline const TDesC& RDriver1::Name()
sl@0
   103
	{
sl@0
   104
	_LIT(KDriver1Name,"DRIVER1");
sl@0
   105
	return KDriver1Name;
sl@0
   106
	}
sl@0
   107
sl@0
   108
/**
sl@0
   109
  The driver's version
sl@0
   110
sl@0
   111
  @return The version number of the driver
sl@0
   112
sl@0
   113
  @internalComponent
sl@0
   114
*/
sl@0
   115
inline TVersion RDriver1::VersionRequired()
sl@0
   116
	{
sl@0
   117
	const TInt KMajorVersionNumber=1;
sl@0
   118
	const TInt KMinorVersionNumber=0;
sl@0
   119
	const TInt KBuildVersionNumber=KE32BuildVersionNumber;
sl@0
   120
	return TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
sl@0
   121
	}
sl@0
   122
sl@0
   123
/*
sl@0
   124
  NOTE: The following methods would normally be exported from a seperate client DLL
sl@0
   125
  but are included inline in this header file for convenience.
sl@0
   126
*/
sl@0
   127
sl@0
   128
#ifndef __KERNEL_MODE__
sl@0
   129
sl@0
   130
/**
sl@0
   131
  Open a logical channel to the driver
sl@0
   132
sl@0
   133
  @return One of the system wide error codes.
sl@0
   134
*/
sl@0
   135
TInt RDriver1::Open()
sl@0
   136
	{
sl@0
   137
	return DoCreate(Name(),VersionRequired(),KNullUnit,NULL,NULL,EOwnerThread);
sl@0
   138
	}
sl@0
   139
sl@0
   140
/**
sl@0
   141
  Get the current configuration settings.
sl@0
   142
sl@0
   143
  @param aConfig A structure which will be filled with the configuration settings.
sl@0
   144
sl@0
   145
  @return KErrNone
sl@0
   146
*/
sl@0
   147
TInt RDriver1::GetConfig(TConfigBuf& aConfig)
sl@0
   148
	{
sl@0
   149
	return DoControl(EGetConfig,(TAny*)&aConfig);
sl@0
   150
	}
sl@0
   151
sl@0
   152
/**
sl@0
   153
  Set the current configuration settings.
sl@0
   154
sl@0
   155
  @param aConfig The new configuration settings to be used.
sl@0
   156
sl@0
   157
  @return KErrInUse if there are outstanding data transfer requests.
sl@0
   158
          KErrArgument if any configuration values are invalid.
sl@0
   159
		  KErrNone otherwise
sl@0
   160
*/
sl@0
   161
TInt RDriver1::SetConfig(const TConfigBuf& aConfig)
sl@0
   162
	{
sl@0
   163
	return DoControl(ESetConfig,(TAny*)&aConfig);
sl@0
   164
	}
sl@0
   165
sl@0
   166
/**
sl@0
   167
  Send data to the device.
sl@0
   168
  Only one send request may be pending at any time.
sl@0
   169
sl@0
   170
  @param aStatus The request to be signaled when the data has been sent.
sl@0
   171
		         The result value will be set to KErrNone on success;
sl@0
   172
		         or set to one of the system wide error codes when an error occurs.
sl@0
   173
  @param aData   A descriptor containing the data to send.
sl@0
   174
*/
sl@0
   175
void RDriver1::SendData(TRequestStatus &aStatus,const TDesC8& aData)
sl@0
   176
	{
sl@0
   177
	DoRequest(ESendData,aStatus,(TAny*)&aData);
sl@0
   178
	}
sl@0
   179
sl@0
   180
/**
sl@0
   181
  Cancel a previous SendData request.
sl@0
   182
*/
sl@0
   183
void RDriver1::SendDataCancel()
sl@0
   184
	{
sl@0
   185
	DoCancel(1<<ESendData);
sl@0
   186
	}
sl@0
   187
sl@0
   188
/**
sl@0
   189
  Receive data from the device.
sl@0
   190
  Only one receive request may be pending at any time.
sl@0
   191
sl@0
   192
  @param aStatus The request to be signaled when the data has been received.
sl@0
   193
		         The result value will be set to KErrNone on success;
sl@0
   194
		         or set to one of the system wide error codes when an error occurs.
sl@0
   195
  @param aData	A descriptor to which the received data will be written.
sl@0
   196
*/
sl@0
   197
void RDriver1::ReceiveData(TRequestStatus &aStatus,TDes8& aBuffer)
sl@0
   198
	{
sl@0
   199
	DoRequest(EReceiveData,aStatus,(TAny*)&aBuffer);
sl@0
   200
	}
sl@0
   201
sl@0
   202
/**
sl@0
   203
  Cancel a previous ReceiveData request.
sl@0
   204
*/
sl@0
   205
void RDriver1::ReceiveDataCancel()
sl@0
   206
	{
sl@0
   207
	DoCancel(1<<EReceiveData);
sl@0
   208
	}
sl@0
   209
sl@0
   210
#endif  // !__KERNEL_MODE__
sl@0
   211
sl@0
   212
#endif
sl@0
   213