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