os/kernelhwsrv/kerneltest/e32test/ethernet/pump/activeio.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
/*
sl@0
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description:
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
#if (!defined __ACTIVEIO_H__)
sl@0
    18
#define __ACTIVEIO_H__
sl@0
    19
sl@0
    20
#include <e32base.h>
sl@0
    21
sl@0
    22
class CIOBuffer : public CBase
sl@0
    23
	{
sl@0
    24
public:
sl@0
    25
	~CIOBuffer();
sl@0
    26
	HBufC8*	Data() const;
sl@0
    27
	void FreeData();
sl@0
    28
	TPtr8& Ptr();
sl@0
    29
	void Assign(HBufC8* aBuffer = NULL);
sl@0
    30
    static CIOBuffer* NewL(HBufC8* aBuf = NULL);
sl@0
    31
    static CIOBuffer* NewL(const TInt aSize);
sl@0
    32
	static TInt LinkOffset();
sl@0
    33
sl@0
    34
private:
sl@0
    35
	CIOBuffer();
sl@0
    36
	void ConstructL(const TInt aSize);
sl@0
    37
	void ConstructL(HBufC8* aBuffer);
sl@0
    38
	
sl@0
    39
	TSglQueLink iLink;
sl@0
    40
	HBufC8* iBuf;
sl@0
    41
	TPtr8 iBufPtr;
sl@0
    42
	};
sl@0
    43
sl@0
    44
///////
sl@0
    45
// Pure Abstract 'M' interface classes that CDemoControl derives from
sl@0
    46
class MWriterNotify
sl@0
    47
	{
sl@0
    48
public:
sl@0
    49
	virtual void WriteCompleteL(const TInt aStatus) = 0;
sl@0
    50
	};
sl@0
    51
sl@0
    52
class MReaderNotify
sl@0
    53
	{
sl@0
    54
public:
sl@0
    55
	virtual void ReadCompleteL(const TInt aStatus) = 0;
sl@0
    56
	};
sl@0
    57
///////
sl@0
    58
sl@0
    59
class CDemoWriter : public CActive
sl@0
    60
// Active object class for writing to the server
sl@0
    61
	{
sl@0
    62
public:
sl@0
    63
	~CDemoWriter();
sl@0
    64
sl@0
    65
	static CDemoWriter* NewL(MWriterNotify& aNotify,RBusDevEthernet& aCard);
sl@0
    66
sl@0
    67
	void WriteL(const TDesC8& aBuffer);
sl@0
    68
	void RunL();
sl@0
    69
	void DoCancel();
sl@0
    70
private:
sl@0
    71
	// Construct with pointer to the notifier and reference to the server session
sl@0
    72
sl@0
    73
sl@0
    74
	void ConstructL(MWriterNotify& aNotify,RBusDevEthernet& aCard);
sl@0
    75
sl@0
    76
sl@0
    77
	CDemoWriter(TInt aPriority) : CActive(aPriority){};
sl@0
    78
private:
sl@0
    79
sl@0
    80
sl@0
    81
	RBusDevEthernet *iCard;
sl@0
    82
sl@0
    83
	MWriterNotify* iNotify;
sl@0
    84
	};
sl@0
    85
sl@0
    86
class CDemoReader : public CActive
sl@0
    87
	{
sl@0
    88
public:
sl@0
    89
	~CDemoReader();
sl@0
    90
sl@0
    91
sl@0
    92
	static CDemoReader* NewL(MReaderNotify& aNotify,RBusDevEthernet& aCard);
sl@0
    93
sl@0
    94
	void RunL();
sl@0
    95
	void DoCancel();
sl@0
    96
	void ReadL(TDes8& aBuffer);
sl@0
    97
private:
sl@0
    98
sl@0
    99
sl@0
   100
	void ConstructL(MReaderNotify& aNotify,RBusDevEthernet& aCard);
sl@0
   101
sl@0
   102
sl@0
   103
	CDemoReader(TInt aPriority) : CActive(aPriority){};
sl@0
   104
private:
sl@0
   105
	MReaderNotify* iNotify;
sl@0
   106
sl@0
   107
sl@0
   108
	RBusDevEthernet *iCard;
sl@0
   109
sl@0
   110
	};
sl@0
   111
sl@0
   112
sl@0
   113
// C Class derived fron CActive
sl@0
   114
// CActive derived from CBase
sl@0
   115
// See PSP Chapter 18 Active Objects
sl@0
   116
class CDemoControl : public CActive , public MReaderNotify , public MWriterNotify
sl@0
   117
	{
sl@0
   118
public:
sl@0
   119
	~CDemoControl();
sl@0
   120
	static CDemoControl* NewLC();
sl@0
   121
	// Mandatory Overrides of CActive pure virtuals
sl@0
   122
	void RunL();
sl@0
   123
	void DoCancel();
sl@0
   124
sl@0
   125
	static TInt Callback(TAny* aCtrl);
sl@0
   126
	void RequestCharacter();
sl@0
   127
	virtual void WriteCompleteL(const TInt aStatus);
sl@0
   128
	virtual void ReadCompleteL(const TInt aStatus);
sl@0
   129
sl@0
   130
	void ReadAndSetDestMacL();
sl@0
   131
	void ReadAndDisplaySettings();
sl@0
   132
	CIOBuffer* CreateRandomPacketL(TInt aOffset);
sl@0
   133
	void SendAndCompareEchoL();
sl@0
   134
	void CompareEcho();
sl@0
   135
	void HandleWriteCompleteSndCmpEchoModeL();
sl@0
   136
	void HandleReadCompleteSndCmpEchoModeL();
sl@0
   137
	
sl@0
   138
private:
sl@0
   139
	void ConstructL();
sl@0
   140
	CDemoControl(TInt aPriority) : CActive(aPriority){};
sl@0
   141
	void ProcessKeyPress(TChar aChar);
sl@0
   142
	void HelpText() const;
sl@0
   143
	void StartCardL();
sl@0
   144
	void StopCard();
sl@0
   145
	void EchoL();
sl@0
   146
	void PumpL();
sl@0
   147
	void ReadL();
sl@0
   148
	void StopL();
sl@0
   149
	void PrintError(TChar aChar);
sl@0
   150
	void EmptyWriteQueue();
sl@0
   151
	void HandleWriteCompleteEchoModeL();
sl@0
   152
	void HandleReadCompleteEchoModeL();
sl@0
   153
	void HandleWriteCompletePumpModeL();
sl@0
   154
	void HandleReadCompletePumpModeL();
sl@0
   155
	void HandleReadCompleteReadModeL();
sl@0
   156
	void FlipMacAddresses(TDes8& aBuf);
sl@0
   157
	CIOBuffer*  CreateSendPacketL();
sl@0
   158
sl@0
   159
private:
sl@0
   160
	enum TIfState {EIdle,EEcho,ERead,EPump,ESendAndCmpEcho};
sl@0
   161
	TIfState iIfState;
sl@0
   162
sl@0
   163
	CDemoWriter* iWriter;
sl@0
   164
	CDemoReader* iReader;
sl@0
   165
	TInt		iPacketsWritten;
sl@0
   166
	TInt		iPacketsRead;
sl@0
   167
	CPeriodic*	iTimer;
sl@0
   168
sl@0
   169
	TBuf8<1600> iReadBuffer;
sl@0
   170
sl@0
   171
sl@0
   172
	RBusDevEthernet iCard;
sl@0
   173
	TBuf8<32>	iConfig;
sl@0
   174
sl@0
   175
	TSglQue<CIOBuffer> iWriteQueue;
sl@0
   176
sl@0
   177
	TBool iSendAndEchoSame;
sl@0
   178
	TInt iIntRandomOffset;
sl@0
   179
	TInt64 iIntSeed;
sl@0
   180
	static TInt iSendAndEchoCmpCounter;
sl@0
   181
	};
sl@0
   182
sl@0
   183
#endif