Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/httpexampleutils_8cpp-source.html
week 10 bug fix submission: Bug 1892, Bug 1897, Bug 1319. Also 3 or 4 documents were found to contain code blocks with SFL, which has been fixed. Partial fix for broken links, links to Forum Nokia, and the 'Symbian platform' terminology issues.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>TB10.1 Example Applications: examples/AppProts/exampleclient/httpexampleutils.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.3 -->
<h1>examples/AppProts/exampleclient/httpexampleutils.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).</span>
<a name="l00002"></a>00002 <span class="comment">// All rights reserved.</span>
<a name="l00003"></a>00003 <span class="comment">// This component and the accompanying materials are made available</span>
<a name="l00004"></a>00004 <span class="comment">// under the terms of "Eclipse Public License v1.0"</span>
<a name="l00005"></a>00005 <span class="comment">// which accompanies this distribution, and is available</span>
<a name="l00006"></a>00006 <span class="comment">// at the URL "http://www.eclipse.org/legal/epl-v10.html".</span>
<a name="l00007"></a>00007 <span class="comment">//</span>
<a name="l00008"></a>00008 <span class="comment">// Initial Contributors:</span>
<a name="l00009"></a>00009 <span class="comment">// Nokia Corporation - initial contribution.</span>
<a name="l00010"></a>00010 <span class="comment">//</span>
<a name="l00011"></a>00011 <span class="comment">// Contributors:</span>
<a name="l00012"></a>00012 <span class="comment">//</span>
<a name="l00013"></a>00013 <span class="comment">// Description:</span>
<a name="l00014"></a>00014 <span class="comment">//</span>
<a name="l00015"></a>00015
<a name="l00016"></a>00016
<a name="l00017"></a>00017 <span class="comment">// for StartC32()</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include <c32comm.h></span>
<a name="l00019"></a>00019
<a name="l00020"></a>00020 <span class="preprocessor">#include "httpexampleutils.h"</span>
<a name="l00021"></a>00021
<a name="l00022"></a>00022
<a name="l00023"></a>00023 <span class="comment">// PDD names for the physical device drivers that are loaded in wins or arm</span>
<a name="l00024"></a>00024 <span class="preprocessor">#if defined (__WINS__)</span>
<a name="l00025"></a>00025 <span class="preprocessor"></span><span class="preprocessor">#define PDD_NAME _L("ECDRV")</span>
<a name="l00026"></a>00026 <span class="preprocessor"></span><span class="preprocessor">#else</span>
<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define PDD_NAME _L("EUART1")</span>
<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define PDD2_NAME _L("EUART2")</span>
<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define PDD3_NAME _L("EUART3")</span>
<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#define PDD4_NAME _L("EUART4")</span>
<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00032"></a>00032 <span class="preprocessor"></span>
<a name="l00033"></a>00033 <span class="preprocessor">#define LDD_NAME _L("ECOMM")</span>
<a name="l00034"></a>00034 <span class="preprocessor"></span>
<a name="l00035"></a>00035 <span class="keyword">const</span> TInt KMaxUserEntrySize = 128;
<a name="l00036"></a>00036
<a name="l00037"></a>00037
<a name="l00038"></a><a class="code" href="class_c_http_example_utils.html#61b3e32e1af201fbff951c0b7ef8cf53">00038</a> <span class="keywordtype">void</span> <a class="code" href="class_c_http_example_utils.html#61b3e32e1af201fbff951c0b7ef8cf53">CHttpExampleUtils::InitCommsL</a>()
<a name="l00039"></a>00039 {
<a name="l00040"></a>00040 TInt ret = User::LoadPhysicalDevice(PDD_NAME);
<a name="l00041"></a>00041 User::LeaveIfError(ret == KErrAlreadyExists?KErrNone:ret);
<a name="l00042"></a>00042
<a name="l00043"></a>00043 <span class="preprocessor">#ifndef __WINS__</span>
<a name="l00044"></a>00044 <span class="preprocessor"></span> ret = User::LoadPhysicalDevice(PDD2_NAME);
<a name="l00045"></a>00045 ret = User::LoadPhysicalDevice(PDD3_NAME);
<a name="l00046"></a>00046 ret = User::LoadPhysicalDevice(PDD4_NAME);
<a name="l00047"></a>00047 <span class="preprocessor">#endif</span>
<a name="l00048"></a>00048 <span class="preprocessor"></span>
<a name="l00049"></a>00049 ret = User::LoadLogicalDevice(LDD_NAME);
<a name="l00050"></a>00050 User::LeaveIfError(ret == KErrAlreadyExists?KErrNone:ret);
<a name="l00051"></a>00051 ret = StartC32();
<a name="l00052"></a>00052 User::LeaveIfError(ret == KErrAlreadyExists?KErrNone:ret);
<a name="l00053"></a>00053 }
<a name="l00054"></a>00054
<a name="l00055"></a>00055
<a name="l00056"></a><a class="code" href="class_c_http_example_utils.html#8d72f4ac8081a61aeb97934ca0143d05">00056</a> <a class="code" href="class_c_http_example_utils.html">CHttpExampleUtils</a>* <a class="code" href="class_c_http_example_utils.html#8d72f4ac8081a61aeb97934ca0143d05">CHttpExampleUtils::NewL</a>(<span class="keyword">const</span> TDesC& aTestName)
<a name="l00057"></a>00057 {
<a name="l00058"></a>00058 <a class="code" href="class_c_http_example_utils.html">CHttpExampleUtils</a>* me = <span class="keyword">new</span> (ELeave) <a class="code" href="class_c_http_example_utils.html">CHttpExampleUtils</a>(aTestName);
<a name="l00059"></a>00059 <span class="keywordflow">return</span> me;
<a name="l00060"></a>00060 }
<a name="l00061"></a>00061
<a name="l00062"></a>00062
<a name="l00063"></a>00063 CHttpExampleUtils::CHttpExampleUtils(<span class="keyword">const</span> TDesC& aTestName) : iTest(aTestName)
<a name="l00064"></a>00064 {
<a name="l00065"></a>00065 iTest.Start(KNullDesC);
<a name="l00066"></a>00066 }
<a name="l00067"></a>00067
<a name="l00068"></a><a class="code" href="class_c_http_example_utils.html#fee6503cc192bf64b47274d6aeb1ac9f">00068</a> <a class="code" href="class_c_http_example_utils.html#fee6503cc192bf64b47274d6aeb1ac9f">CHttpExampleUtils::~CHttpExampleUtils</a>()
<a name="l00069"></a>00069 {
<a name="l00070"></a>00070 iTest.End();
<a name="l00071"></a>00071 iTest.Close();
<a name="l00072"></a>00072 }
<a name="l00073"></a>00073
<a name="l00074"></a><a class="code" href="class_c_http_example_utils.html#297684dd9661c7a81e678853c8efc9fc">00074</a> RTest& <a class="code" href="class_c_http_example_utils.html#297684dd9661c7a81e678853c8efc9fc">CHttpExampleUtils::Test</a>()
<a name="l00075"></a>00075 {
<a name="l00076"></a>00076 <span class="keywordflow">return</span> iTest;
<a name="l00077"></a>00077 }
<a name="l00078"></a>00078
<a name="l00079"></a><a class="code" href="class_c_http_example_utils.html#b2040f19a2275a89b4d14a1128cc0fd9">00079</a> <span class="keywordtype">void</span> <a class="code" href="class_c_http_example_utils.html#b2040f19a2275a89b4d14a1128cc0fd9">CHttpExampleUtils::PressAnyKey</a>()
<a name="l00080"></a>00080 {
<a name="l00081"></a>00081 iTest.Printf(TRefByValue<const TDesC>_L(<span class="stringliteral">"\nPress a key"</span>));
<a name="l00082"></a>00082 iTest.Getch();
<a name="l00083"></a>00083 }
<a name="l00084"></a>00084
<a name="l00085"></a>00085
<a name="l00086"></a><a class="code" href="class_c_http_example_utils.html#0be9fcae764213dd9c5f8ce40eec5bee">00086</a> TInt <a class="code" href="class_c_http_example_utils.html#0be9fcae764213dd9c5f8ce40eec5bee">CHttpExampleUtils::GetSelection</a>(<span class="keyword">const</span> TDesC& aPrompt, <span class="keyword">const</span> TDesC& aValidChoices)
<a name="l00087"></a>00087 <span class="comment">//</span>
<a name="l00088"></a>00088 <span class="comment">// Present the user with a list of options, and get their selection</span>
<a name="l00089"></a>00089 {
<a name="l00090"></a>00090 TKeyCode key = EKeyNull;
<a name="l00091"></a>00091 iTest.Console()->SetPos (0, iTest.Console()->WhereY ());
<a name="l00092"></a>00092 iTest.Console()->Printf(_L(<span class="stringliteral">"%S "</span>), &aPrompt);
<a name="l00093"></a>00093 iTest.Console()->Printf(_L(<span class="stringliteral">"[%S] :"</span>), &aValidChoices);
<a name="l00094"></a>00094 TInt retVal = KErrNotFound;
<a name="l00095"></a>00095 <span class="keywordflow">while</span> (retVal == KErrNotFound)
<a name="l00096"></a>00096 {
<a name="l00097"></a>00097 key = iTest.Getch();
<a name="l00098"></a>00098 <span class="comment">// Check that key is in the list of valid choices</span>
<a name="l00099"></a>00099 retVal = aValidChoices.Locate((TChar)key);
<a name="l00100"></a>00100 }
<a name="l00101"></a>00101 iTest.Console()->Printf(_L(<span class="stringliteral">"%c\n\n"</span>), key);
<a name="l00102"></a>00102 <span class="keywordflow">return</span> retVal;
<a name="l00103"></a>00103 }
<a name="l00104"></a>00104
<a name="l00105"></a>00105
<a name="l00106"></a><a class="code" href="class_c_http_example_utils.html#4765445ad91210b4f429737146c62f79">00106</a> <span class="keywordtype">void</span> <a class="code" href="class_c_http_example_utils.html#4765445ad91210b4f429737146c62f79">CHttpExampleUtils::LogIt</a>(TRefByValue<const TDesC> aFmt, ...)
<a name="l00107"></a>00107 {
<a name="l00108"></a>00108 VA_LIST list;
<a name="l00109"></a>00109 VA_START(list,aFmt);
<a name="l00110"></a>00110 TBuf<KMaxFileName + 4> buf; <span class="comment">// 4 for the log prompt</span>
<a name="l00111"></a>00111 buf.Zero();
<a name="l00112"></a>00112 buf.Append(_L(<span class="stringliteral">"> "</span>));
<a name="l00113"></a>00113 buf.AppendFormatList(aFmt,list);
<a name="l00114"></a>00114 VA_END(list);
<a name="l00115"></a>00115 iTest.Printf(_L(<span class="stringliteral">"%S\n"</span>), &buf);
<a name="l00116"></a>00116 }
<a name="l00117"></a>00117
<a name="l00118"></a>00118
<a name="l00119"></a><a class="code" href="class_c_http_example_utils.html#fc580f413eb3bc8fc23163cb6bd69f63">00119</a> <span class="keywordtype">void</span> <a class="code" href="class_c_http_example_utils.html#fc580f413eb3bc8fc23163cb6bd69f63">CHttpExampleUtils::GetAnEntry</a>(<span class="keyword">const</span> TDesC& ourPrompt, TDes& currentstring)
<a name="l00120"></a>00120 {
<a name="l00121"></a>00121 TBuf16<KMaxUserEntrySize> ourLine;
<a name="l00122"></a>00122 TBuf<KMaxUserEntrySize> tempstring; <span class="comment">//tempstring is a unicode descriptor</span>
<a name="l00123"></a>00123 <span class="comment">//create a temporary buffer where the</span>
<a name="l00124"></a>00124 <span class="comment">//unicode strings are stored in order to </span>
<a name="l00125"></a>00125 <span class="comment">//be displayed</span>
<a name="l00126"></a>00126 ourLine.Zero ();
<a name="l00127"></a>00127 tempstring.Copy(currentstring); <span class="comment">//Copy current string to Unicode buffer</span>
<a name="l00128"></a>00128 TKeyCode key = EKeyNull; <span class="comment">//current string buffer is 8 bits wide.</span>
<a name="l00129"></a>00129 <span class="comment">//Unicode string bufffer (tempstring) is 16 bits wide.</span>
<a name="l00130"></a>00130 FOREVER
<a name="l00131"></a>00131 {
<a name="l00132"></a>00132 <span class="keywordflow">if</span> (ourLine.Length () == 0)
<a name="l00133"></a>00133 {
<a name="l00134"></a>00134 iTest.Console()->SetPos (0, iTest.Console()->WhereY ());
<a name="l00135"></a>00135 iTest.Console()->Printf (_L (<span class="stringliteral">"%S"</span>), &ourPrompt);
<a name="l00136"></a>00136 <span class="keywordflow">if</span> (tempstring.Length () != 0) <span class="comment">//get tempstring's number of items</span>
<a name="l00137"></a>00137 iTest.Console()->Printf (_L (<span class="stringliteral">" = %S"</span>), &tempstring); <span class="comment">//if not zero print them to iTest.Console()</span>
<a name="l00138"></a>00138 iTest.Console()->Printf (_L (<span class="stringliteral">" : "</span>));
<a name="l00139"></a>00139 iTest.Console()->ClearToEndOfLine ();
<a name="l00140"></a>00140 }
<a name="l00141"></a>00141 key = iTest.Getch();
<a name="l00142"></a>00142
<a name="l00143"></a>00143 <span class="keywordflow">if</span> (key == EKeyBackspace)
<a name="l00144"></a>00144 {
<a name="l00145"></a>00145 <span class="keywordflow">if</span> (ourLine.Length() !=0)
<a name="l00146"></a>00146 {
<a name="l00147"></a>00147 ourLine.SetLength(ourLine.Length()-1);
<a name="l00148"></a>00148 iTest.Console()->Printf (_L (<span class="stringliteral">"%c"</span>), key);
<a name="l00149"></a>00149 iTest.Console()->SetPos(iTest.Console()->WhereX(),iTest.Console()->WhereY());
<a name="l00150"></a>00150 iTest.Console()->ClearToEndOfLine();
<a name="l00151"></a>00151 } <span class="comment">// end if (ourLine.Length() !=0)</span>
<a name="l00152"></a>00152 } <span class="comment">// end if (key == KeyBackSpace)</span>
<a name="l00153"></a>00153
<a name="l00154"></a>00154
<a name="l00155"></a>00155 <span class="keywordflow">if</span> (key == EKeyDelete)
<a name="l00156"></a>00156 {
<a name="l00157"></a>00157 ourLine.Zero();
<a name="l00158"></a>00158 iTest.Console()->SetPos (0, iTest.Console()->WhereY ());
<a name="l00159"></a>00159 iTest.Console()->ClearToEndOfLine ();
<a name="l00160"></a>00160 tempstring.Copy(ourLine);
<a name="l00161"></a>00161 <span class="keywordflow">break</span>;
<a name="l00162"></a>00162 }
<a name="l00163"></a>00163
<a name="l00164"></a>00164 <span class="keywordflow">if</span> (key == EKeyEnter)
<a name="l00165"></a>00165 <span class="keywordflow">break</span>;
<a name="l00166"></a>00166
<a name="l00167"></a>00167 <span class="keywordflow">if</span> (key < <span class="charliteral">' '</span>) <span class="comment">// ascii code thats not a printable character</span>
<a name="l00168"></a>00168 {
<a name="l00169"></a>00169 <span class="keywordflow">continue</span>;
<a name="l00170"></a>00170 }
<a name="l00171"></a>00171
<a name="l00172"></a>00172 ourLine.Append (key);
<a name="l00173"></a>00173 iTest.Console()->Printf (_L (<span class="stringliteral">"%c"</span>), key);
<a name="l00174"></a>00174 iTest.Console()->SetPos(iTest.Console()->WhereX(),iTest.Console()->WhereY());
<a name="l00175"></a>00175 iTest.Console()->ClearToEndOfLine();
<a name="l00176"></a>00176 <span class="keywordflow">if</span> (ourLine.Length () == ourLine.MaxLength ())
<a name="l00177"></a>00177 <span class="keywordflow">break</span>;
<a name="l00178"></a>00178 } <span class="comment">// end of for statement</span>
<a name="l00179"></a>00179
<a name="l00180"></a>00180 <span class="keywordflow">if</span> ((key == EKeyEnter) && (ourLine.Length () == 0))
<a name="l00181"></a>00181 tempstring.Copy (currentstring); <span class="comment">//copy contents of 8 bit "ourLine" descriptor</span>
<a name="l00182"></a>00182
<a name="l00183"></a>00183 iTest.Console()->SetPos (0, iTest.Console()->WhereY ());
<a name="l00184"></a>00184 iTest.Console()->ClearToEndOfLine ();
<a name="l00185"></a>00185
<a name="l00186"></a>00186 <span class="keywordflow">if</span> ((key == EKeyEnter) && (ourLine.Length() !=0))
<a name="l00187"></a>00187 tempstring.Copy(ourLine);
<a name="l00188"></a>00188 <span class="keywordflow">if</span> (tempstring.Length () != 0) <span class="comment">//if temstring length is not zero</span>
<a name="l00189"></a>00189 {
<a name="l00190"></a>00190 iTest.Console()->Printf (_L (<span class="stringliteral">" Entered = %S\n"</span>), &tempstring); <span class="comment">//print the contents to iTest.Console()</span>
<a name="l00191"></a>00191 <a class="code" href="class_c_http_example_utils.html#4765445ad91210b4f429737146c62f79">LogIt</a>(_L (<span class="stringliteral">"%S = %S\n"</span>), &ourPrompt, &tempstring);
<a name="l00192"></a>00192 }
<a name="l00193"></a>00193
<a name="l00194"></a>00194 iTest.Console()->Printf (_L (<span class="stringliteral">"\n"</span>));
<a name="l00195"></a>00195 currentstring.Copy(tempstring); <span class="comment">//copy 16 bit tempstring descriptor back </span>
<a name="l00196"></a>00196 }
</pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Thu Jan 21 10:32:55 2010 for TB10.1 Example Applications by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
</body>
</html>