diff -r 89d6a7a84779 -r 25a17d01db0c Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/httpexampleutils_8cpp-source.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/httpexampleutils_8cpp-source.html Fri Jan 22 18:26:19 2010 +0000 @@ -0,0 +1,208 @@ + + +TB10.1 Example Applications: examples/AppProts/exampleclient/httpexampleutils.cpp Source File + + + + +

examples/AppProts/exampleclient/httpexampleutils.cpp

00001 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
+00002 // All rights reserved.
+00003 // This component and the accompanying materials are made available
+00004 // under the terms of "Eclipse Public License v1.0"
+00005 // which accompanies this distribution, and is available
+00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
+00007 //
+00008 // Initial Contributors:
+00009 // Nokia Corporation - initial contribution.
+00010 //
+00011 // Contributors:
+00012 //
+00013 // Description:
+00014 //
+00015 
+00016 
+00017 // for StartC32()
+00018 #include <c32comm.h>
+00019 
+00020 #include "httpexampleutils.h"
+00021 
+00022 
+00023 // PDD names for the physical device drivers that are loaded in wins or arm
+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         //      Present the user with a list of options, and get their selection
+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                 // Check that key is in the list of valid choices
+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; // 4 for the log prompt
+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;     //tempstring is a unicode descriptor
+00123                                                                                 //create a temporary buffer where the
+00124                                                                                 //unicode strings are stored in order to 
+00125                                                                                 //be displayed
+00126         ourLine.Zero ();
+00127         tempstring.Copy(currentstring);         //Copy current string to Unicode buffer
+00128         TKeyCode key = EKeyNull;                                                //current string buffer is 8 bits wide.
+00129                                                                                 //Unicode string bufffer (tempstring) is 16 bits wide.
+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)                                          //get tempstring's number of items
+00137                                 iTest.Console()->Printf (_L (" = %S"), &tempstring);    //if not zero print them to iTest.Console()
+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                                         }       // end if (ourLine.Length() !=0)
+00152                                 }       // end if (key == KeyBackSpace)
+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 < ' ') // ascii code thats not a printable character
+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                 }       // end of for statement
+00179 
+00180         if ((key == EKeyEnter) && (ourLine.Length () == 0))
+00181                 tempstring.Copy (currentstring);                                //copy contents of 8 bit "ourLine" descriptor
+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)                                          //if temstring length is not zero
+00189                 {
+00190                 iTest.Console()->Printf (_L (" Entered = %S\n"), &tempstring);  //print the contents to iTest.Console()
+00191                 LogIt(_L ("%S = %S\n"), &ourPrompt, &tempstring);
+00192                 }
+00193 
+00194         iTest.Console()->Printf (_L ("\n"));
+00195         currentstring.Copy(tempstring);                                         //copy 16 bit tempstring descriptor back 
+00196         } 
+

Generated on Thu Jan 21 10:32:55 2010 for TB10.1 Example Applications by  + +doxygen 1.5.3
+ +