First public contribution.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
17 #if (!defined __ACTIVEIO_H__)
18 #define __ACTIVEIO_H__
22 class CIOBuffer : public CBase
29 void Assign(HBufC8* aBuffer = NULL);
30 static CIOBuffer* NewL(HBufC8* aBuf = NULL);
31 static CIOBuffer* NewL(const TInt aSize);
32 static TInt LinkOffset();
36 void ConstructL(const TInt aSize);
37 void ConstructL(HBufC8* aBuffer);
45 // Pure Abstract 'M' interface classes that CDemoControl derives from
49 virtual void WriteCompleteL(const TInt aStatus) = 0;
55 virtual void ReadCompleteL(const TInt aStatus) = 0;
59 class CDemoWriter : public CActive
60 // Active object class for writing to the server
65 static CDemoWriter* NewL(MWriterNotify& aNotify,RBusDevEthernet& aCard);
67 void WriteL(const TDesC8& aBuffer);
71 // Construct with pointer to the notifier and reference to the server session
74 void ConstructL(MWriterNotify& aNotify,RBusDevEthernet& aCard);
77 CDemoWriter(TInt aPriority) : CActive(aPriority){};
81 RBusDevEthernet *iCard;
83 MWriterNotify* iNotify;
86 class CDemoReader : public CActive
92 static CDemoReader* NewL(MReaderNotify& aNotify,RBusDevEthernet& aCard);
96 void ReadL(TDes8& aBuffer);
100 void ConstructL(MReaderNotify& aNotify,RBusDevEthernet& aCard);
103 CDemoReader(TInt aPriority) : CActive(aPriority){};
105 MReaderNotify* iNotify;
108 RBusDevEthernet *iCard;
113 // C Class derived fron CActive
114 // CActive derived from CBase
115 // See PSP Chapter 18 Active Objects
116 class CDemoControl : public CActive , public MReaderNotify , public MWriterNotify
120 static CDemoControl* NewLC();
121 // Mandatory Overrides of CActive pure virtuals
125 static TInt Callback(TAny* aCtrl);
126 void RequestCharacter();
127 virtual void WriteCompleteL(const TInt aStatus);
128 virtual void ReadCompleteL(const TInt aStatus);
130 void ReadAndSetDestMacL();
131 void ReadAndDisplaySettings();
132 CIOBuffer* CreateRandomPacketL(TInt aOffset);
133 void SendAndCompareEchoL();
135 void HandleWriteCompleteSndCmpEchoModeL();
136 void HandleReadCompleteSndCmpEchoModeL();
140 CDemoControl(TInt aPriority) : CActive(aPriority){};
141 void ProcessKeyPress(TChar aChar);
142 void HelpText() const;
149 void PrintError(TChar aChar);
150 void EmptyWriteQueue();
151 void HandleWriteCompleteEchoModeL();
152 void HandleReadCompleteEchoModeL();
153 void HandleWriteCompletePumpModeL();
154 void HandleReadCompletePumpModeL();
155 void HandleReadCompleteReadModeL();
156 void FlipMacAddresses(TDes8& aBuf);
157 CIOBuffer* CreateSendPacketL();
160 enum TIfState {EIdle,EEcho,ERead,EPump,ESendAndCmpEcho};
163 CDemoWriter* iWriter;
164 CDemoReader* iReader;
165 TInt iPacketsWritten;
169 TBuf8<1600> iReadBuffer;
172 RBusDevEthernet iCard;
175 TSglQue<CIOBuffer> iWriteQueue;
177 TBool iSendAndEchoSame;
178 TInt iIntRandomOffset;
180 static TInt iSendAndEchoCmpCounter;