EchoClientUI
: TCP/IP echo client UI
Found in: examples\Networking\TcpIp\EchoClientUI
These are the main files contained in the examples. Some extra files may be needed to run the examples, and these will be found in the appropriate examples directory.
Note: This example is designed to work with TechView and there is no guarantee that it will work with other interfaces.
// Copyright (c) 2000-2005 Symbian Software Ltd. All rights reserved.
//
//
// EIKECHO.CPP
//
// EIKON interface to ECHOENG
// Definitions of CConsoleControl, CEchoAppUi,
// CEchoDocument, CEchoApplication
#include "Eikecho.h"
#include <eikstart.h>
CConsoleControl* CConsoleControl::NewL(CEchoEngine* aEchoEngine)
{
CConsoleControl* self=new (ELeave) CConsoleControl;
CleanupStack::PushL(self);
self->ConstructL(aEchoEngine);
CleanupStack::Pop();
return self;
}
void CConsoleControl::ConstructL(CEchoEngine* aEchoEngine)
{
iEchoEngine=aEchoEngine;
CreateWindowL();
Window().SetShadowDisabled(ETrue);
Window().SetBackgroundColor(KRgbGray);
EnableDragEvents();
SetExtentToWholeScreen();
SetBlank();
iConsole=new(ELeave) CEikConsoleScreen;
_LIT(KEikEcho,"EikEcho");
iConsole->ConstructL(KEikEcho,0);
iConsole->SetHistorySizeL(10,10);
}
CConsoleControl::~CConsoleControl()
{
delete iConsole;
}
/**
Mark control ready to draw
*/
void CConsoleControl::ActivateL()
{
CCoeControl::ActivateL();
iConsole->SetKeepCursorInSight(TRUE);
iConsole->DrawCursor();
iConsole->ConsoleControl()->SetFocus(ETrue, EDrawNow);
}
TKeyResponse CConsoleControl::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
// The key event handler
{
if (aType!=EEventKey)
return(EKeyWasConsumed);
TInt aChar=aKeyEvent.iCode;
if (aChar == '3')
// Connect using an IP address
{
_LIT(KConnecting1,"Attempting connection to KInetAddr\n");
iConsole->Printf(KConnecting1);
iEchoEngine->ConnectL(KInetAddr);
}
else if (aChar == '2')
{
// Connect using a hostname, calling DNS first to resolve this to an IP address
_LIT(KConnecting2,"Attempting connection to KInetHostName\n");
iConsole->Printf(KConnecting2);
iEchoEngine->ConnectL(KInetHostName);
}
else if (aChar == '1')
{
// Connect using an IP address, obtaining the symbolic name for this IP address first.
_LIT(KConnecting3,"Testing GetHostByAddress and attempting connection\n");
iConsole->Printf(KConnecting3);
iEchoEngine->TestGetByAddr(KInetAddr);
}
else iEchoEngine->Write(aChar); // Send input character to echo server
return(EKeyWasConsumed);
}
// The following functions are to implement MUINotify
void CConsoleControl::PrintNotify(const TDesC& aDes)
// Print up calls: write information to screen
{
iConsole->Printf(aDes);
};
void CConsoleControl::PrintNotify(TInt aInt)
{
iConsole->Printf(KIntFormat,aInt);
};
void CConsoleControl::ErrorNotify(const TDesC& aErrMessage, TInt aErrCode)
// Error up call: inform user and quit
{
_LIT(KErrorTitle,"Communications error ");
TBuf<25> errorTitleCode(KErrorTitle);
errorTitleCode.AppendNum(aErrCode);
CEikonEnv::Static()->InfoWinL(errorTitleCode,aErrMessage);
CBaActiveScheduler::Exit();
}
/**
CEchoAppUi: user interface command handling
*/
CEchoAppUi::CEchoAppUi(CEchoEngine* aEchoEngine)
: iEchoEngine(aEchoEngine)
{
}
void CEchoAppUi::ConstructL()
// Set up control and engine
{
BaseConstructL();
CreateConsoleL();
iEchoEngine->ConstructL(iConsoleControl);
_LIT(KCommands,"\nList of Commands:\n\
3 - Test connecting with IP\n\
2 - Test DNS lookup\n\
1 - Test Get hostname from IP address\n\n");
iConsoleControl->PrintNotify(KCommands);
}
void CEchoAppUi::CreateConsoleL()
{
iConsoleControl=CConsoleControl::NewL(iEchoEngine);
AddToStackL(iConsoleControl);
iConsoleControl->ActivateL();
}
CEchoAppUi::~CEchoAppUi()
{
RemoveFromStack(iConsoleControl);
delete iConsoleControl;
}
void CEchoAppUi::HandleCommandL(TInt aCommand)
// Command handling
{
switch (aCommand)
{
// When Exit chosen, stop engine and quit
case EEikCmdExit:
iEchoEngine->Stop();
Exit();
default:;
}
}
/*
Two-phase construction
CEchoDocument: document class, which owns the engine
*/
CEchoDocument::CEchoDocument(CEikApplication& aApp)
: CEikDocument(aApp) { }
CEchoDocument* CEchoDocument::NewL(CEikApplication& aApp)
{
CEchoDocument* self=new (ELeave) CEchoDocument(aApp);
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop();
return self;
}
void CEchoDocument::ConstructL()
{
iEchoEngine = new (ELeave) CEchoEngine;
}
CEchoDocument::~CEchoDocument()
{
delete iEchoEngine;
}
CEikAppUi* CEchoDocument::CreateAppUiL()
{
return(new(ELeave) CEchoAppUi(iEchoEngine));
}
TUid CEchoApplication::AppDllUid() const
{
return(KUidEikEchoApp);
}
CApaDocument* CEchoApplication::CreateDocumentL()
{
return CEchoDocument::NewL(*this);
}
/**
EXPORTed functions
*/
EXPORT_C CApaApplication* NewApplication()
{
return(new CEchoApplication);
}
GLDEF_C TInt E32Main()
{
return EikStart::RunApplication(NewApplication);
}
// EIKECHO.H
//
// Copyright (c) 1997-1999 Symbian Ltd. All rights reserved.
//
// Header file for EIKON interface to ECHOENG
#include <basched.h>
#include <eikenv.h>
#include <coecntrl.h>
#include <eikappui.h>
#include <e32keys.h>
#include <eikconso.h>
#include <eikapp.h>
#include <eikdoc.h>
#include <eikon.rsg>
#include <eikinfo.h>
//#include <eikcmds.hrh>
#include <eikon.hrh>//newly added
#include <eikecho.rsg>
#include "echoeng.h"
#ifndef _EIKECHO_H_
#define _EIKECHO_H_
const TUid KUidEikEchoApp = {0x10004851};
// Connection values: substitute alternative values for KInetAddr
// and KInetHostName if you want to use different servers
const TUint32 KInetAddr = INET_ADDR(10,159,34,198);//(193,63,255,1); //
_LIT(KInetHostName,"phoenix.doc.ic.ac.uk");
// Integer formatting descriptor
_LIT(KIntFormat,"%d");
//
// CConsoleControl: console-type control
//
class CConsoleControl : public CCoeControl, public MUINotify
{
public:
static CConsoleControl* NewL(CEchoEngine* aEchoEngine);
~CConsoleControl();
void ConstructL(CEchoEngine* aEchoEngine);
// Override CCoeControl
TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
void ActivateL();
//Implement MUINotify up calls
void PrintNotify(const TDesC& aDes);
void PrintNotify(TInt aInt);
void ErrorNotify(const TDesC& aErrMessage, TInt aErrCode);
protected:
CConsoleControl() {}
private:
CEikConsoleScreen* iConsole; // Standard EIKON console control
CEchoEngine* iEchoEngine; // The echo engine
};
//
// CEchoAppUi: user interface command handling
//
class CEchoAppUi : public CEikAppUi
{
public:
CEchoAppUi(CEchoEngine* aEchoEngine);
void ConstructL();
void CreateConsoleL();
~CEchoAppUi();
private:
// Override CEikAppUi
void HandleCommandL(TInt aCommand);
private:
CConsoleControl* iConsoleControl;
CEchoEngine* iEchoEngine;
};
//
// CEchoDocument: document class, which owns the engine
//
class CEchoDocument : public CEikDocument
{
public:
CEchoDocument(CEikApplication& aApp);
static CEchoDocument* NewL(CEikApplication& aApp);
~CEchoDocument();
void ConstructL();
private:
// Override CApaDocument
CEikAppUi* CreateAppUiL();
private:
CEchoEngine* iEchoEngine; // Document owns the echo engine
};
//
// CEchoApplication
//
class CEchoApplication : public CEikApplication
{
private: // from CApaApplication
CApaDocument* CreateDocumentL();
TUid AppDllUid() const;
};
#endif
// Eikecho.mmp
//
// Copyright (c) 2000-2005 Symbian Software Ltd. All rights reserved.
TARGET Eikecho.exe
TARGETTYPE exe
UID 0x10004851
VENDORID 0x70000001
CAPABILITY All -TCB
SOURCEPATH .
SOURCE Eikecho.cpp
START RESOURCE Eikecho.rss
TARGET Eikecho.rsc
TARGETPATH \Resource\Apps
HEADER
LANG 01 // Build English language versions
END
start resource Eikecho_reg.rss
targetpath \private\10003a3f\apps
end
start resource Eikecho_loc.rss
lang 01
end
USERINCLUDE .
USERINCLUDE ..\EchoClientEngine
SYSTEMINCLUDE \Epoc32\include
SYSTEMINCLUDE \epoc32\include\techview
LIBRARY euser.lib apparc.lib cone.lib WS32.lib bafl.lib
LIBRARY eikcore.lib eikcoctl.lib echoeng.lib
/ EIKECHO.RSS
//
// Copyright (c) 1997-1999 Symbian Ltd. All rights reserved.
//
NAME ECHO
#include <eikon.rh>
RESOURCE RSS_SIGNATURE { }
RESOURCE TBUF16 { buf=""; }
RESOURCE EIK_APP_INFO { hotkeys=r_cons_hotkeys; menubar=r_cons_menubar; }
RESOURCE HOTKEYS r_cons_hotkeys
{
control=
{
HOTKEY { command=EEikCmdExit; key='e'; }
};
}
RESOURCE MENU_BAR r_cons_menubar
{
titles=
{
MENU_TITLE { menu_pane=r_cons_file_menu; txt="File"; }
};
}
RESOURCE MENU_PANE r_cons_file_menu
{
items=
{
MENU_ITEM
{
command=EEikCmdExit;
txt="Exit";
}
};
}
Eikecho_loc.rss
#include <appinfo.rh>
RESOURCE LOCALISABLE_APP_INFO
{
short_caption = "Eikecho";
caption_and_icon =
{
CAPTION_AND_ICON_INFO
{
caption = "Eikecho";
number_of_icons = 0; // each icon must be a bitmap/mask pair
}
};
}
// Eikecho_reg.RSS
//
// Copyright (c) 2005 Symbian Software Ltd. All rights reserved.
//
#include <appinfo.rh>
UID2 KUidAppRegistrationResourceFile
UID3 0x10004851
RESOURCE APP_REGISTRATION_INFO
{
app_file = Eikecho;
localisable_resource_file="\\resource\\apps\\Eikecho_loc.rss";
hidden=KAppNotHidden;
embeddability=KAppNotEmbeddable;
newfile=KAppDoesNotSupportNewFile;
launch=KAppLaunchInForeground;
}
This project provides the user interface for the TCP echo client engine example EchoClientEngine.
CConsoleControl
: console control.
standard Uikon application framework classes