os/kernelhwsrv/kerneltest/e32test/examples/driver1/driver1_dev.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2003-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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 /**
    17  @file Kernel side interfaces to example Logical and Physical Device Drivers
    18  @publishedPartner
    19  @released
    20 */
    21 
    22 #ifndef __DRIVER1_DEV_H__
    23 #define __DRIVER1_DEV_H__
    24 
    25 /**
    26   Physical Device (factory class) for 'Driver1'
    27 */
    28 class DDevice1PddFactory : public DPhysicalDevice
    29 	{
    30 public:
    31 	DDevice1PddFactory();
    32 	~DDevice1PddFactory();
    33 	// Inherited from DPhysicalDevice
    34 	virtual TInt Install();
    35 	virtual void GetCaps(TDes8& aDes) const;
    36 	virtual TInt Create(DBase*& aChannel, TInt aUnit, const TDesC8* aInfo, const TVersion& aVer);
    37 	virtual TInt Validate(TInt aUnit, const TDesC8* aInfo, const TVersion& aVer);
    38 public:
    39 	TInt iHardwareInUse;
    40 private:
    41 	enum TMinimumLDDVersion
    42 		{
    43 		EMinimumLddMajorVersion=1,
    44 		EMinimumLddMinorVersion=0,
    45 		EMinimumLddBuild=0 //Not used
    46 		};
    47 public:
    48 	TDynamicDfcQue* iDfcQ;
    49 	};
    50 
    51 /**
    52   Logical Device (factory class) for 'Driver1'
    53 */
    54 class DDriver1Factory : public DLogicalDevice
    55 	{
    56 public:
    57 	DDriver1Factory();
    58 	~DDriver1Factory();
    59 	//	Inherited from DLogicalDevice
    60 	virtual TInt Install();
    61 	virtual void GetCaps(TDes8& aDes) const;
    62 	virtual TInt Create(DLogicalChannelBase*& aChannel);
    63 	};
    64 
    65 class DDriver1;
    66 
    67 
    68 /**
    69   Logical Channel class for 'Driver1'
    70 */
    71 class DDriver1Channel : public DLogicalChannel
    72 	{
    73 public:
    74 	DDriver1Channel();
    75 	virtual ~DDriver1Channel();
    76 	//	Inherited from DObject
    77 	virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
    78 	// Inherited from DLogicalChannelBase
    79 	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
    80 	// Inherited from DLogicalChannel
    81 	virtual void HandleMsg(TMessageBase* aMsg);
    82 private:
    83 	// Panic reasons
    84 	enum TPanic
    85 		{
    86 		ERequestAlreadyPending = 1
    87 		};
    88 	// Implementation for the differnt kinds of messages sent through RBusLogicalChannel
    89 	TInt DoControl(TInt aFunction, TAny* a1, TAny* a2);
    90 	TInt DoRequest(TInt aReqNo, TRequestStatus* aStatus, TAny* a1, TAny* a2);
    91 	void DoCancel(TUint aMask);
    92 	// Accessor for the PDD
    93 	inline DDriver1* Pdd();
    94 	// Methods for configuration
    95 	TInt GetConfig(TDes8* aConfigBuf);
    96 	TInt SetConfig(const TDesC8* aConfigBuf);
    97 	void CurrentConfig(RDriver1::TConfig& aConfig);
    98 	// Methods for processing a SendData request
    99 	TInt SendData(TRequestStatus* aStatus,const TDesC8* aData);
   100 	void SendDataCancel();
   101 	void DoSendDataComplete();
   102 	static void SendDataDfc(TAny* aPtr);
   103 	// Methods for processing a ReceiveData request
   104 	TInt ReceiveData(TRequestStatus* aStatus,TDes8* aBuffer);
   105 	void ReceiveDataCancel();
   106 	void DoReceiveDataComplete();
   107 	static void ReceiveDataDfc(TAny* aPtr);
   108 public:
   109 	// Interface methods for use by PDD
   110 	virtual void SendDataComplete(TInt aResult);
   111 	virtual void ReceiveDataComplete(TInt aResult);
   112 private:
   113 	DThread* iClient;
   114 	// Members used for processing a SendData request
   115 	TRequestStatus* iSendDataStatus;
   116 	TDfc iSendDataDfc;
   117 	TInt iSendDataResult;
   118 	TBuf8<256> iSendDataBuffer;
   119 	// Members used for processing a ReceiveData request
   120 	TDes8* iReceiveDataDescriptor;
   121 	TRequestStatus* iReceiveDataStatus;
   122 	TDfc iReceiveDataDfc;
   123 	TInt iReceiveDataResult;
   124 	TBuf8<256> iReceiveDataBuffer;
   125 	};
   126 
   127 inline DDriver1* DDriver1Channel::Pdd()
   128 	{ return (DDriver1*)iPdd; }
   129 
   130 /**
   131   Interface to 'Driver1' physical device
   132 */
   133 class DDriver1 : public DBase
   134 	{
   135 public:
   136 	/**
   137 	Structure for holding PDD capabilities information
   138 	*/
   139 	class TCaps
   140 		{
   141 	public:
   142 		TVersion iVersion;
   143 		};
   144 public:
   145 	virtual TInt BufferSize() const =0;
   146 	virtual TInt Speed() const =0;
   147 	virtual TInt SetSpeed(TInt aSpeed) =0;
   148 	virtual TInt SendData(const TDesC8& aData) =0;
   149 	virtual void SendDataCancel() =0;
   150 	virtual TInt ReceiveData(TDes8& aBuffer) =0;
   151 	virtual void ReceiveDataCancel() =0;
   152 public:
   153 	DDriver1Channel* iLdd;
   154 	};
   155 
   156 #endif
   157