00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef _ECHOENG_H_
00034 #define _ECHOENG_H_
00035
00036 #include <e32cons.h>
00037 #include <in_sock.h>
00038 #include <nifman.h>
00039
00040
00041 class MTimeOutNotify
00042 {
00043 public:
00044 virtual void TimerExpired() = 0;
00045 };
00046
00047
00048 class MUINotify
00049 {
00050 public:
00051 virtual void PrintNotify(const TDesC& aMessage) = 0;
00052 virtual void PrintNotify(TInt aMessage) = 0;
00053 virtual void ErrorNotifyL(const TDesC& aErrMessage, TInt aErrCode) = 0;
00054 };
00055
00056
00057 class CTimeOutTimer: public CTimer
00058 {
00059 public:
00060 static CTimeOutTimer* NewL(const TInt aPriority, MTimeOutNotify& aTimeOutNotify);
00061 ~CTimeOutTimer();
00062
00063 protected:
00064 CTimeOutTimer(const TInt aPriority);
00065 void ConstructL(MTimeOutNotify& aTimeOutNotify);
00066 virtual void RunL();
00067
00068 private:
00069 MTimeOutNotify* iNotify;
00070 };
00071
00072
00073 class CEchoRead : public CActive
00074 {
00075 public:
00076
00077 void IssueRead();
00078 void IssueRecvFrom(TInetAddr &aAddr);
00079
00080
00081 void DoCancel();
00082 void RunL();
00083 CEchoRead(RSocket* aSocket, MUINotify* aConsole);
00084
00085
00086 private:
00087 RSocket* iEchoSocket;
00088 MUINotify* iConsole;
00089 TBuf8<1> iBuffer;
00090 };
00091
00092
00093 class CEchoWrite : public CActive, public MTimeOutNotify
00094 {
00095 public:
00096 enum TWriteState
00097 {
00098 ESending, EWaiting ,ETimedOut
00099 };
00100
00101 public:
00102 static CEchoWrite* NewL(RSocket* aSocket, MUINotify* aConsole);
00103 static CEchoWrite* NewLC(RSocket* aSocket, MUINotify* aConsole);
00104 ~CEchoWrite();
00105 void ConstructL(RSocket* aSocket, MUINotify* aConsole);
00106 void IssueWrite(const TChar &aChar);
00107 void IssueSendTo(TInetAddr &aAddr, const TChar &aChar);
00108
00109
00110 void DoCancel();
00111 void RunL();
00112
00113
00114 void TimerExpired();
00115
00116 protected:
00117 CEchoWrite();
00118
00119 private:
00120 MUINotify* iConsole;
00121 RSocket* iEchoSocket;
00122 TBuf8<1> iBuffer;
00123 CTimeOutTimer* iTimer;
00124 TInt iTimeOut;
00125 TWriteState iWriteStatus;
00126 };
00127
00128
00129 class CEchoEngine : public CActive, public MTimeOutNotify
00130 {
00131 public:
00132 enum TEchoEngineState
00133 {
00134 EComplete, EConnecting, EConnected, ETimedOut,
00135 ELookingUp, ELookUpFailed, EConnectFailed,
00136
00137 };
00138 public:
00139 IMPORT_C CEchoEngine();
00140 IMPORT_C static CEchoEngine* NewL(MUINotify* aConsole);
00141 IMPORT_C static CEchoEngine* NewLC(MUINotify* aConsole);
00142 IMPORT_C void ConstructL(MUINotify* aConsole);
00143 IMPORT_C void Stop();
00144 IMPORT_C void ConnectTo(TUint32 aAddr);
00145 IMPORT_C void ConnectL(const TDesC& aServerName);
00146 IMPORT_C void Write(TChar aChar);
00147 IMPORT_C void Read();
00148 IMPORT_C void TestGetByAddrL(TUint32 aAddr);
00149
00150
00151 void TimerExpired();
00152
00153
00154 void DoCancel();
00155 void RunL();
00156
00157 ~CEchoEngine();
00158
00159 private:
00160 TEchoEngineState iEngineStatus;
00161 MUINotify* iConsole;
00162 CEchoRead* iEchoRead;
00163 CEchoWrite* iEchoWrite;
00164 RSocket iEchoSocket;
00165 RSocketServ iSocketServ;
00166 RHostResolver iResolver;
00167 TNameEntry iNameEntry;
00168 TNameRecord iNameRecord;
00169 CTimeOutTimer* iTimer;
00170 TInt iTimeOut;
00171 TInetAddr iAddress;
00172 };
00173
00174 #endif
00175