os/kernelhwsrv/kerneltest/e32test/ethernet/pump/activeio.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/ethernet/pump/activeio.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,183 @@
     1.4 +/*
     1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +*
    1.19 +*/
    1.20 +#if (!defined __ACTIVEIO_H__)
    1.21 +#define __ACTIVEIO_H__
    1.22 +
    1.23 +#include <e32base.h>
    1.24 +
    1.25 +class CIOBuffer : public CBase
    1.26 +	{
    1.27 +public:
    1.28 +	~CIOBuffer();
    1.29 +	HBufC8*	Data() const;
    1.30 +	void FreeData();
    1.31 +	TPtr8& Ptr();
    1.32 +	void Assign(HBufC8* aBuffer = NULL);
    1.33 +    static CIOBuffer* NewL(HBufC8* aBuf = NULL);
    1.34 +    static CIOBuffer* NewL(const TInt aSize);
    1.35 +	static TInt LinkOffset();
    1.36 +
    1.37 +private:
    1.38 +	CIOBuffer();
    1.39 +	void ConstructL(const TInt aSize);
    1.40 +	void ConstructL(HBufC8* aBuffer);
    1.41 +	
    1.42 +	TSglQueLink iLink;
    1.43 +	HBufC8* iBuf;
    1.44 +	TPtr8 iBufPtr;
    1.45 +	};
    1.46 +
    1.47 +///////
    1.48 +// Pure Abstract 'M' interface classes that CDemoControl derives from
    1.49 +class MWriterNotify
    1.50 +	{
    1.51 +public:
    1.52 +	virtual void WriteCompleteL(const TInt aStatus) = 0;
    1.53 +	};
    1.54 +
    1.55 +class MReaderNotify
    1.56 +	{
    1.57 +public:
    1.58 +	virtual void ReadCompleteL(const TInt aStatus) = 0;
    1.59 +	};
    1.60 +///////
    1.61 +
    1.62 +class CDemoWriter : public CActive
    1.63 +// Active object class for writing to the server
    1.64 +	{
    1.65 +public:
    1.66 +	~CDemoWriter();
    1.67 +
    1.68 +	static CDemoWriter* NewL(MWriterNotify& aNotify,RBusDevEthernet& aCard);
    1.69 +
    1.70 +	void WriteL(const TDesC8& aBuffer);
    1.71 +	void RunL();
    1.72 +	void DoCancel();
    1.73 +private:
    1.74 +	// Construct with pointer to the notifier and reference to the server session
    1.75 +
    1.76 +
    1.77 +	void ConstructL(MWriterNotify& aNotify,RBusDevEthernet& aCard);
    1.78 +
    1.79 +
    1.80 +	CDemoWriter(TInt aPriority) : CActive(aPriority){};
    1.81 +private:
    1.82 +
    1.83 +
    1.84 +	RBusDevEthernet *iCard;
    1.85 +
    1.86 +	MWriterNotify* iNotify;
    1.87 +	};
    1.88 +
    1.89 +class CDemoReader : public CActive
    1.90 +	{
    1.91 +public:
    1.92 +	~CDemoReader();
    1.93 +
    1.94 +
    1.95 +	static CDemoReader* NewL(MReaderNotify& aNotify,RBusDevEthernet& aCard);
    1.96 +
    1.97 +	void RunL();
    1.98 +	void DoCancel();
    1.99 +	void ReadL(TDes8& aBuffer);
   1.100 +private:
   1.101 +
   1.102 +
   1.103 +	void ConstructL(MReaderNotify& aNotify,RBusDevEthernet& aCard);
   1.104 +
   1.105 +
   1.106 +	CDemoReader(TInt aPriority) : CActive(aPriority){};
   1.107 +private:
   1.108 +	MReaderNotify* iNotify;
   1.109 +
   1.110 +
   1.111 +	RBusDevEthernet *iCard;
   1.112 +
   1.113 +	};
   1.114 +
   1.115 +
   1.116 +// C Class derived fron CActive
   1.117 +// CActive derived from CBase
   1.118 +// See PSP Chapter 18 Active Objects
   1.119 +class CDemoControl : public CActive , public MReaderNotify , public MWriterNotify
   1.120 +	{
   1.121 +public:
   1.122 +	~CDemoControl();
   1.123 +	static CDemoControl* NewLC();
   1.124 +	// Mandatory Overrides of CActive pure virtuals
   1.125 +	void RunL();
   1.126 +	void DoCancel();
   1.127 +
   1.128 +	static TInt Callback(TAny* aCtrl);
   1.129 +	void RequestCharacter();
   1.130 +	virtual void WriteCompleteL(const TInt aStatus);
   1.131 +	virtual void ReadCompleteL(const TInt aStatus);
   1.132 +
   1.133 +	void ReadAndSetDestMacL();
   1.134 +	void ReadAndDisplaySettings();
   1.135 +	CIOBuffer* CreateRandomPacketL(TInt aOffset);
   1.136 +	void SendAndCompareEchoL();
   1.137 +	void CompareEcho();
   1.138 +	void HandleWriteCompleteSndCmpEchoModeL();
   1.139 +	void HandleReadCompleteSndCmpEchoModeL();
   1.140 +	
   1.141 +private:
   1.142 +	void ConstructL();
   1.143 +	CDemoControl(TInt aPriority) : CActive(aPriority){};
   1.144 +	void ProcessKeyPress(TChar aChar);
   1.145 +	void HelpText() const;
   1.146 +	void StartCardL();
   1.147 +	void StopCard();
   1.148 +	void EchoL();
   1.149 +	void PumpL();
   1.150 +	void ReadL();
   1.151 +	void StopL();
   1.152 +	void PrintError(TChar aChar);
   1.153 +	void EmptyWriteQueue();
   1.154 +	void HandleWriteCompleteEchoModeL();
   1.155 +	void HandleReadCompleteEchoModeL();
   1.156 +	void HandleWriteCompletePumpModeL();
   1.157 +	void HandleReadCompletePumpModeL();
   1.158 +	void HandleReadCompleteReadModeL();
   1.159 +	void FlipMacAddresses(TDes8& aBuf);
   1.160 +	CIOBuffer*  CreateSendPacketL();
   1.161 +
   1.162 +private:
   1.163 +	enum TIfState {EIdle,EEcho,ERead,EPump,ESendAndCmpEcho};
   1.164 +	TIfState iIfState;
   1.165 +
   1.166 +	CDemoWriter* iWriter;
   1.167 +	CDemoReader* iReader;
   1.168 +	TInt		iPacketsWritten;
   1.169 +	TInt		iPacketsRead;
   1.170 +	CPeriodic*	iTimer;
   1.171 +
   1.172 +	TBuf8<1600> iReadBuffer;
   1.173 +
   1.174 +
   1.175 +	RBusDevEthernet iCard;
   1.176 +	TBuf8<32>	iConfig;
   1.177 +
   1.178 +	TSglQue<CIOBuffer> iWriteQueue;
   1.179 +
   1.180 +	TBool iSendAndEchoSame;
   1.181 +	TInt iIntRandomOffset;
   1.182 +	TInt64 iIntSeed;
   1.183 +	static TInt iSendAndEchoCmpCounter;
   1.184 +	};
   1.185 +
   1.186 +#endif