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
00034 #include "Eikecho.h"
00035 #include <eikstart.h>
00036
00037
00038 CConsoleControl* CConsoleControl::NewL(CEchoEngine* aEchoEngine)
00039 {
00040 CConsoleControl* self=new (ELeave) CConsoleControl;
00041 CleanupStack::PushL(self);
00042 self->ConstructL(aEchoEngine);
00043 CleanupStack::Pop();
00044 return self;
00045 }
00046
00047 void CConsoleControl::ConstructL(CEchoEngine* aEchoEngine)
00048 {
00049 iEchoEngine=aEchoEngine;
00050 CreateWindowL();
00051 Window().SetShadowDisabled(ETrue);
00052 Window().SetBackgroundColor(KRgbGray);
00053 EnableDragEvents();
00054 SetExtentToWholeScreen();
00055 SetBlank();
00056 iConsole=new(ELeave) CEikConsoleScreen;
00057 _LIT(KEikEcho,"EikEcho");
00058 iConsole->ConstructL(KEikEcho,0);
00059 iConsole->SetHistorySizeL(10,10);
00060 }
00061
00062 CConsoleControl::~CConsoleControl()
00063 {
00064 delete iConsole;
00065 }
00069 void CConsoleControl::ActivateL()
00070 {
00071 CCoeControl::ActivateL();
00072 iConsole->SetKeepCursorInSight(TRUE);
00073 iConsole->DrawCursor();
00074 iConsole->ConsoleControl()->SetFocus(ETrue, EDrawNow);
00075 }
00076
00077 TKeyResponse CConsoleControl::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
00078
00079 {
00080 if (aType!=EEventKey)
00081 return(EKeyWasConsumed);
00082 TInt aChar=aKeyEvent.iCode;
00083
00084 if (aChar == '3')
00085
00086 {
00087 _LIT(KConnecting1,"Attempting connection to KInetAddr\n");
00088 iConsole->Printf(KConnecting1);
00089 iEchoEngine->ConnectTo(KInetAddr);
00090 }
00091 else if (aChar == '2')
00092 {
00093
00094 _LIT(KConnecting2,"Attempting connection to KInetHostName\n");
00095 iConsole->Printf(KConnecting2);
00096 iEchoEngine->ConnectL(KInetHostName);
00097 }
00098 else if (aChar == '1')
00099 {
00100
00101 _LIT(KConnecting3,"Testing GetHostByAddress and attempting connection\n");
00102 iConsole->Printf(KConnecting3);
00103 iEchoEngine->TestGetByAddrL(KInetAddr);
00104 }
00105 else iEchoEngine->Write(aChar);
00106
00107 return(EKeyWasConsumed);
00108 }
00109
00110
00111
00112
00113
00114
00115 void CConsoleControl::PrintNotify(const TDesC& aDes)
00116
00117 {
00118 iConsole->Printf(aDes);
00119 };
00120
00121 void CConsoleControl::PrintNotify(TInt aInt)
00122 {
00123 iConsole->Printf(KIntFormat,aInt);
00124 };
00125
00126 void CConsoleControl::ErrorNotifyL(const TDesC& aErrMessage, TInt aErrCode)
00127
00128 {
00129 _LIT(KErrorTitle,"Communications error ");
00130 TBuf<25> errorTitleCode(KErrorTitle);
00131 errorTitleCode.AppendNum(aErrCode);
00132 CEikonEnv::Static()->InfoWinL(errorTitleCode,aErrMessage);
00133 CBaActiveScheduler::Exit();
00134 }
00138 CEchoAppUi::CEchoAppUi(CEchoEngine* aEchoEngine)
00139 : iEchoEngine(aEchoEngine)
00140 {
00141 }
00142
00143 void CEchoAppUi::ConstructL()
00144
00145 {
00146 BaseConstructL();
00147 CreateConsoleL();
00148 iEchoEngine->ConstructL(iConsoleControl);
00149 _LIT(KCommands,"\nList of Commands:\n\
00150 3 - Test connecting with IP\n\
00151 2 - Test DNS lookup\n\
00152 1 - Test Get hostname from IP address\n\n");
00153
00154 iConsoleControl->PrintNotify(KCommands);
00155 }
00156
00157 void CEchoAppUi::CreateConsoleL()
00158 {
00159 iConsoleControl=CConsoleControl::NewL(iEchoEngine);
00160 AddToStackL(iConsoleControl);
00161 iConsoleControl->ActivateL();
00162 }
00163
00164 CEchoAppUi::~CEchoAppUi()
00165 {
00166 RemoveFromStack(iConsoleControl);
00167 delete iConsoleControl;
00168 }
00169
00170 void CEchoAppUi::HandleCommandL(TInt aCommand)
00171
00172 {
00173 switch (aCommand)
00174 {
00175
00176 case EEikCmdExit:
00177 iEchoEngine->Stop();
00178 Exit();
00179 default:;
00180 }
00181 }
00182
00183
00184
00185
00186
00187 CEchoDocument::CEchoDocument(CEikApplication& aApp)
00188 : CEikDocument(aApp) { }
00189
00190 CEchoDocument* CEchoDocument::NewL(CEikApplication& aApp)
00191 {
00192 CEchoDocument* self=new (ELeave) CEchoDocument(aApp);
00193 CleanupStack::PushL(self);
00194 self->ConstructL();
00195 CleanupStack::Pop();
00196 return self;
00197 }
00198
00199 void CEchoDocument::ConstructL()
00200 {
00201 iEchoEngine = new (ELeave) CEchoEngine;
00202 }
00203
00204 CEchoDocument::~CEchoDocument()
00205 {
00206 delete iEchoEngine;
00207 }
00208
00209 CEikAppUi* CEchoDocument::CreateAppUiL()
00210 {
00211 return(new(ELeave) CEchoAppUi(iEchoEngine));
00212 }
00213
00214
00215 TUid CEchoApplication::AppDllUid() const
00216 {
00217 return(KUidEikEchoApp);
00218 }
00219
00220 CApaDocument* CEchoApplication::CreateDocumentL()
00221 {
00222 return CEchoDocument::NewL(*this);
00223 }
00224
00228 EXPORT_C CApaApplication* NewApplication()
00229 {
00230 return(new CEchoApplication);
00231 }
00232
00233 GLDEF_C TInt E32Main()
00234 {
00235 return EikStart::RunApplication(NewApplication);
00236 }
00237