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