00001 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). 00002 // All rights reserved. 00003 // This component and the accompanying materials are made available 00004 // under the terms of "Eclipse Public License v1.0" 00005 // which accompanies this distribution, and is available 00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html". 00007 // 00008 // Initial Contributors: 00009 // Nokia Corporation - initial contribution. 00010 // 00011 // Contributors: 00012 // 00013 // Description: 00014 // Declares MTimeOutNotify, MUINotify, CEchoEngine 00015 // CEchoRead, CEchoWrite, CTimeOutTimer 00016 // 00017 00018 #ifndef _ECHOENG_H_ 00019 #define _ECHOENG_H_ 00020 00021 #include <e32cons.h> 00022 #include <in_sock.h> 00023 #include <nifman.h> 00024 00025 // MTimeOutNotify: used in conjunction with CTimeOutTimer class 00026 class MTimeOutNotify 00027 { 00028 public: 00029 virtual void TimerExpired() = 0; 00030 }; 00031 00032 // MUINotify: implemented by user interfaces; engine up calls 00033 class MUINotify 00034 { 00035 public: 00036 virtual void PrintNotify(const TDesC& aMessage) = 0; 00037 virtual void PrintNotify(TInt aMessage) = 0; 00038 virtual void ErrorNotifyL(const TDesC& aErrMessage, TInt aErrCode) = 0; 00039 }; 00040 00041 // CTimeOutTimer: timer for comms time-outs 00042 class CTimeOutTimer: public CTimer 00043 { 00044 public: 00045 static CTimeOutTimer* NewL(const TInt aPriority, MTimeOutNotify& aTimeOutNotify); 00046 ~CTimeOutTimer(); 00047 00048 protected: 00049 CTimeOutTimer(const TInt aPriority); 00050 void ConstructL(MTimeOutNotify& aTimeOutNotify); 00051 virtual void RunL(); 00052 00053 private: 00054 MTimeOutNotify* iNotify; 00055 }; 00056 00057 // CEchoRead: active object wrapping comms read requests 00058 class CEchoRead : public CActive 00059 { 00060 public: 00061 00062 void IssueRead(); 00063 void IssueRecvFrom(TInetAddr &aAddr); 00064 00065 //Implemented functions from CActive 00066 void DoCancel(); 00067 void RunL(); 00068 CEchoRead(RSocket* aSocket, MUINotify* aConsole); 00069 00070 00071 private: 00072 RSocket* iEchoSocket; 00073 MUINotify* iConsole; 00074 TBuf8<1> iBuffer; 00075 }; 00076 00077 // CEchoWrite: active object wrapping comms write requests 00078 class CEchoWrite : public CActive, public MTimeOutNotify 00079 { 00080 public: 00081 enum TWriteState 00082 { 00083 ESending, EWaiting ,ETimedOut 00084 }; 00085 00086 public: 00087 static CEchoWrite* NewL(RSocket* aSocket, MUINotify* aConsole); 00088 static CEchoWrite* NewLC(RSocket* aSocket, MUINotify* aConsole); 00089 ~CEchoWrite(); 00090 void ConstructL(RSocket* aSocket, MUINotify* aConsole); 00091 void IssueWrite(const TChar &aChar); 00092 void IssueSendTo(TInetAddr &aAddr, const TChar &aChar); 00093 00094 //Implemented functions from CActive 00095 void DoCancel(); 00096 void RunL(); 00097 00098 //Implemented functions from MNTimeOutNotify 00099 void TimerExpired(); 00100 00101 protected: 00102 CEchoWrite(); 00103 00104 private: 00105 MUINotify* iConsole; 00106 RSocket* iEchoSocket; 00107 TBuf8<1> iBuffer; 00108 CTimeOutTimer* iTimer; 00109 TInt iTimeOut; 00110 TWriteState iWriteStatus; 00111 }; 00112 00113 // CEchoEngine: main engine class for connection and shutdown 00114 class CEchoEngine : public CActive, public MTimeOutNotify 00115 { 00116 public: 00117 enum TEchoEngineState 00118 { 00119 EComplete, EConnecting, EConnected, ETimedOut, 00120 ELookingUp, ELookUpFailed, EConnectFailed, 00121 00122 }; 00123 public: 00124 IMPORT_C CEchoEngine(); 00125 IMPORT_C static CEchoEngine* NewL(MUINotify* aConsole); 00126 IMPORT_C static CEchoEngine* NewLC(MUINotify* aConsole); 00127 IMPORT_C void ConstructL(MUINotify* aConsole); 00128 IMPORT_C void Stop(); 00129 IMPORT_C void ConnectTo(TUint32 aAddr); 00130 IMPORT_C void ConnectL(const TDesC& aServerName); 00131 IMPORT_C void Write(TChar aChar); 00132 IMPORT_C void Read(); 00133 IMPORT_C void TestGetByAddrL(TUint32 aAddr); 00134 00135 //Implemented functions from MTimeOutNotify 00136 void TimerExpired(); 00137 00138 //Implemented functions from CActive 00139 void DoCancel(); 00140 void RunL(); 00141 00142 ~CEchoEngine(); 00143 00144 private: 00145 TEchoEngineState iEngineStatus; 00146 MUINotify* iConsole; 00147 CEchoRead* iEchoRead; 00148 CEchoWrite* iEchoWrite; 00149 RSocket iEchoSocket; 00150 RSocketServ iSocketServ; 00151 RHostResolver iResolver; 00152 TNameEntry iNameEntry; 00153 TNameRecord iNameRecord; 00154 CTimeOutTimer* iTimer; 00155 TInt iTimeOut; 00156 TInetAddr iAddress; 00157 }; 00158 00159 #endif 00160
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.