sl@0: /* sl@0: * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: #if (!defined __ACTIVEIO_H__) sl@0: #define __ACTIVEIO_H__ sl@0: sl@0: #include sl@0: sl@0: class CIOBuffer : public CBase sl@0: { sl@0: public: sl@0: ~CIOBuffer(); sl@0: HBufC8* Data() const; sl@0: void FreeData(); sl@0: TPtr8& Ptr(); sl@0: void Assign(HBufC8* aBuffer = NULL); sl@0: static CIOBuffer* NewL(HBufC8* aBuf = NULL); sl@0: static CIOBuffer* NewL(const TInt aSize); sl@0: static TInt LinkOffset(); sl@0: sl@0: private: sl@0: CIOBuffer(); sl@0: void ConstructL(const TInt aSize); sl@0: void ConstructL(HBufC8* aBuffer); sl@0: sl@0: TSglQueLink iLink; sl@0: HBufC8* iBuf; sl@0: TPtr8 iBufPtr; sl@0: }; sl@0: sl@0: /////// sl@0: // Pure Abstract 'M' interface classes that CDemoControl derives from sl@0: class MWriterNotify sl@0: { sl@0: public: sl@0: virtual void WriteCompleteL(const TInt aStatus) = 0; sl@0: }; sl@0: sl@0: class MReaderNotify sl@0: { sl@0: public: sl@0: virtual void ReadCompleteL(const TInt aStatus) = 0; sl@0: }; sl@0: /////// sl@0: sl@0: class CDemoWriter : public CActive sl@0: // Active object class for writing to the server sl@0: { sl@0: public: sl@0: ~CDemoWriter(); sl@0: sl@0: static CDemoWriter* NewL(MWriterNotify& aNotify,RBusDevEthernet& aCard); sl@0: sl@0: void WriteL(const TDesC8& aBuffer); sl@0: void RunL(); sl@0: void DoCancel(); sl@0: private: sl@0: // Construct with pointer to the notifier and reference to the server session sl@0: sl@0: sl@0: void ConstructL(MWriterNotify& aNotify,RBusDevEthernet& aCard); sl@0: sl@0: sl@0: CDemoWriter(TInt aPriority) : CActive(aPriority){}; sl@0: private: sl@0: sl@0: sl@0: RBusDevEthernet *iCard; sl@0: sl@0: MWriterNotify* iNotify; sl@0: }; sl@0: sl@0: class CDemoReader : public CActive sl@0: { sl@0: public: sl@0: ~CDemoReader(); sl@0: sl@0: sl@0: static CDemoReader* NewL(MReaderNotify& aNotify,RBusDevEthernet& aCard); sl@0: sl@0: void RunL(); sl@0: void DoCancel(); sl@0: void ReadL(TDes8& aBuffer); sl@0: private: sl@0: sl@0: sl@0: void ConstructL(MReaderNotify& aNotify,RBusDevEthernet& aCard); sl@0: sl@0: sl@0: CDemoReader(TInt aPriority) : CActive(aPriority){}; sl@0: private: sl@0: MReaderNotify* iNotify; sl@0: sl@0: sl@0: RBusDevEthernet *iCard; sl@0: sl@0: }; sl@0: sl@0: sl@0: // C Class derived fron CActive sl@0: // CActive derived from CBase sl@0: // See PSP Chapter 18 Active Objects sl@0: class CDemoControl : public CActive , public MReaderNotify , public MWriterNotify sl@0: { sl@0: public: sl@0: ~CDemoControl(); sl@0: static CDemoControl* NewLC(); sl@0: // Mandatory Overrides of CActive pure virtuals sl@0: void RunL(); sl@0: void DoCancel(); sl@0: sl@0: static TInt Callback(TAny* aCtrl); sl@0: void RequestCharacter(); sl@0: virtual void WriteCompleteL(const TInt aStatus); sl@0: virtual void ReadCompleteL(const TInt aStatus); sl@0: sl@0: void ReadAndSetDestMacL(); sl@0: void ReadAndDisplaySettings(); sl@0: CIOBuffer* CreateRandomPacketL(TInt aOffset); sl@0: void SendAndCompareEchoL(); sl@0: void CompareEcho(); sl@0: void HandleWriteCompleteSndCmpEchoModeL(); sl@0: void HandleReadCompleteSndCmpEchoModeL(); sl@0: sl@0: private: sl@0: void ConstructL(); sl@0: CDemoControl(TInt aPriority) : CActive(aPriority){}; sl@0: void ProcessKeyPress(TChar aChar); sl@0: void HelpText() const; sl@0: void StartCardL(); sl@0: void StopCard(); sl@0: void EchoL(); sl@0: void PumpL(); sl@0: void ReadL(); sl@0: void StopL(); sl@0: void PrintError(TChar aChar); sl@0: void EmptyWriteQueue(); sl@0: void HandleWriteCompleteEchoModeL(); sl@0: void HandleReadCompleteEchoModeL(); sl@0: void HandleWriteCompletePumpModeL(); sl@0: void HandleReadCompletePumpModeL(); sl@0: void HandleReadCompleteReadModeL(); sl@0: void FlipMacAddresses(TDes8& aBuf); sl@0: CIOBuffer* CreateSendPacketL(); sl@0: sl@0: private: sl@0: enum TIfState {EIdle,EEcho,ERead,EPump,ESendAndCmpEcho}; sl@0: TIfState iIfState; sl@0: sl@0: CDemoWriter* iWriter; sl@0: CDemoReader* iReader; sl@0: TInt iPacketsWritten; sl@0: TInt iPacketsRead; sl@0: CPeriodic* iTimer; sl@0: sl@0: TBuf8<1600> iReadBuffer; sl@0: sl@0: sl@0: RBusDevEthernet iCard; sl@0: TBuf8<32> iConfig; sl@0: sl@0: TSglQue iWriteQueue; sl@0: sl@0: TBool iSendAndEchoSame; sl@0: TInt iIntRandomOffset; sl@0: TInt64 iIntSeed; sl@0: static TInt iSendAndEchoCmpCounter; sl@0: }; sl@0: sl@0: #endif