examples/Networking/TcpIp/EchoClientEngine/ECHOENG.H

00001 /*
00002 Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description: 
00028 Declares MTimeOutNotify, MUINotify, CEchoEngine
00029 CEchoRead, CEchoWrite, CTimeOutTimer 
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 // MTimeOutNotify: used in conjunction with CTimeOutTimer class
00041 class MTimeOutNotify
00042         {
00043 public:
00044         virtual void TimerExpired() = 0;
00045         };
00046 
00047 // MUINotify: implemented by user interfaces; engine up calls
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 // CTimeOutTimer: timer for comms time-outs
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 // CEchoRead: active object wrapping comms read requests
00073 class CEchoRead : public CActive
00074         {
00075 public:
00076         
00077         void IssueRead();
00078         void IssueRecvFrom(TInetAddr &aAddr);
00079 
00080         //Implemented functions from CActive
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 // CEchoWrite: active object wrapping comms write requests
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         //Implemented functions from CActive
00110         void DoCancel();  
00111         void RunL(); 
00112 
00113         //Implemented functions from MNTimeOutNotify
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 // CEchoEngine: main engine class for connection and shutdown
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         //Implemented functions from MTimeOutNotify
00151         void TimerExpired(); 
00152 
00153         //Implemented functions from CActive
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 

Generated by  doxygen 1.6.2