00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <c32comm.h>
00019
00020 #include "httpexampleutils.h"
00021
00022
00023
00024 #if defined (__WINS__)
00025 #define PDD_NAME _L("ECDRV")
00026 #else
00027 #define PDD_NAME _L("EUART1")
00028 #define PDD2_NAME _L("EUART2")
00029 #define PDD3_NAME _L("EUART3")
00030 #define PDD4_NAME _L("EUART4")
00031 #endif
00032
00033 #define LDD_NAME _L("ECOMM")
00034
00035 const TInt KMaxUserEntrySize = 128;
00036
00037
00038 void CHttpExampleUtils::InitCommsL()
00039 {
00040 TInt ret = User::LoadPhysicalDevice(PDD_NAME);
00041 User::LeaveIfError(ret == KErrAlreadyExists?KErrNone:ret);
00042
00043 #ifndef __WINS__
00044 ret = User::LoadPhysicalDevice(PDD2_NAME);
00045 ret = User::LoadPhysicalDevice(PDD3_NAME);
00046 ret = User::LoadPhysicalDevice(PDD4_NAME);
00047 #endif
00048
00049 ret = User::LoadLogicalDevice(LDD_NAME);
00050 User::LeaveIfError(ret == KErrAlreadyExists?KErrNone:ret);
00051 ret = StartC32();
00052 User::LeaveIfError(ret == KErrAlreadyExists?KErrNone:ret);
00053 }
00054
00055
00056 CHttpExampleUtils* CHttpExampleUtils::NewL(const TDesC& aTestName)
00057 {
00058 CHttpExampleUtils* me = new (ELeave) CHttpExampleUtils(aTestName);
00059 return me;
00060 }
00061
00062
00063 CHttpExampleUtils::CHttpExampleUtils(const TDesC& aTestName) : iTest(aTestName)
00064 {
00065 iTest.Start(KNullDesC);
00066 }
00067
00068 CHttpExampleUtils::~CHttpExampleUtils()
00069 {
00070 iTest.End();
00071 iTest.Close();
00072 }
00073
00074 RTest& CHttpExampleUtils::Test()
00075 {
00076 return iTest;
00077 }
00078
00079 void CHttpExampleUtils::PressAnyKey()
00080 {
00081 iTest.Printf(TRefByValue<const TDesC>_L("\nPress a key"));
00082 iTest.Getch();
00083 }
00084
00085
00086 TInt CHttpExampleUtils::GetSelection(const TDesC& aPrompt, const TDesC& aValidChoices)
00087
00088
00089 {
00090 TKeyCode key = EKeyNull;
00091 iTest.Console()->SetPos (0, iTest.Console()->WhereY ());
00092 iTest.Console()->Printf(_L("%S "), &aPrompt);
00093 iTest.Console()->Printf(_L("[%S] :"), &aValidChoices);
00094 TInt retVal = KErrNotFound;
00095 while (retVal == KErrNotFound)
00096 {
00097 key = iTest.Getch();
00098
00099 retVal = aValidChoices.Locate((TChar)key);
00100 }
00101 iTest.Console()->Printf(_L("%c\n\n"), key);
00102 return retVal;
00103 }
00104
00105
00106 void CHttpExampleUtils::LogIt(TRefByValue<const TDesC> aFmt, ...)
00107 {
00108 VA_LIST list;
00109 VA_START(list,aFmt);
00110 TBuf<KMaxFileName + 4> buf;
00111 buf.Zero();
00112 buf.Append(_L("> "));
00113 buf.AppendFormatList(aFmt,list);
00114 VA_END(list);
00115 iTest.Printf(_L("%S\n"), &buf);
00116 }
00117
00118
00119 void CHttpExampleUtils::GetAnEntry(const TDesC& ourPrompt, TDes& currentstring)
00120 {
00121 TBuf16<KMaxUserEntrySize> ourLine;
00122 TBuf<KMaxUserEntrySize> tempstring;
00123
00124
00125
00126 ourLine.Zero ();
00127 tempstring.Copy(currentstring);
00128 TKeyCode key = EKeyNull;
00129
00130 FOREVER
00131 {
00132 if (ourLine.Length () == 0)
00133 {
00134 iTest.Console()->SetPos (0, iTest.Console()->WhereY ());
00135 iTest.Console()->Printf (_L ("%S"), &ourPrompt);
00136 if (tempstring.Length () != 0)
00137 iTest.Console()->Printf (_L (" = %S"), &tempstring);
00138 iTest.Console()->Printf (_L (" : "));
00139 iTest.Console()->ClearToEndOfLine ();
00140 }
00141 key = iTest.Getch();
00142
00143 if (key == EKeyBackspace)
00144 {
00145 if (ourLine.Length() !=0)
00146 {
00147 ourLine.SetLength(ourLine.Length()-1);
00148 iTest.Console()->Printf (_L ("%c"), key);
00149 iTest.Console()->SetPos(iTest.Console()->WhereX(),iTest.Console()->WhereY());
00150 iTest.Console()->ClearToEndOfLine();
00151 }
00152 }
00153
00154
00155 if (key == EKeyDelete)
00156 {
00157 ourLine.Zero();
00158 iTest.Console()->SetPos (0, iTest.Console()->WhereY ());
00159 iTest.Console()->ClearToEndOfLine ();
00160 tempstring.Copy(ourLine);
00161 break;
00162 }
00163
00164 if (key == EKeyEnter)
00165 break;
00166
00167 if (key < ' ')
00168 {
00169 continue;
00170 }
00171
00172 ourLine.Append (key);
00173 iTest.Console()->Printf (_L ("%c"), key);
00174 iTest.Console()->SetPos(iTest.Console()->WhereX(),iTest.Console()->WhereY());
00175 iTest.Console()->ClearToEndOfLine();
00176 if (ourLine.Length () == ourLine.MaxLength ())
00177 break;
00178 }
00179
00180 if ((key == EKeyEnter) && (ourLine.Length () == 0))
00181 tempstring.Copy (currentstring);
00182
00183 iTest.Console()->SetPos (0, iTest.Console()->WhereY ());
00184 iTest.Console()->ClearToEndOfLine ();
00185
00186 if ((key == EKeyEnter) && (ourLine.Length() !=0))
00187 tempstring.Copy(ourLine);
00188 if (tempstring.Length () != 0)
00189 {
00190 iTest.Console()->Printf (_L (" Entered = %S\n"), &tempstring);
00191 LogIt(_L ("%S = %S\n"), &ourPrompt, &tempstring);
00192 }
00193
00194 iTest.Console()->Printf (_L ("\n"));
00195 currentstring.Copy(tempstring);
00196 }