|
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
2 <html xmlns="http://www.w3.org/1999/xhtml"> |
|
3 <head> |
|
4 <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> |
|
5 <title>TB9.2 Example Applications: examples/Base/BufsAndStrings/rbufexample/rbufexample.cpp Source File</title> |
|
6 <link href="tabs.css" rel="stylesheet" type="text/css"/> |
|
7 <link href="doxygen.css" rel="stylesheet" type="text/css"/> |
|
8 </head> |
|
9 <body> |
|
10 <!-- Generated by Doxygen 1.6.2 --> |
|
11 <h1>examples/Base/BufsAndStrings/rbufexample/rbufexample.cpp</h1><a href="rbufexample_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).</span> |
|
12 <a name="l00002"></a>00002 <span class="comment">// All rights reserved.</span> |
|
13 <a name="l00003"></a>00003 <span class="comment">// This component and the accompanying materials are made available</span> |
|
14 <a name="l00004"></a>00004 <span class="comment">// under the terms of "Eclipse Public License v1.0"</span> |
|
15 <a name="l00005"></a>00005 <span class="comment">// which accompanies this distribution, and is available</span> |
|
16 <a name="l00006"></a>00006 <span class="comment">// at the URL "http://www.eclipse.org/legal/epl-v10.html".</span> |
|
17 <a name="l00007"></a>00007 <span class="comment">//</span> |
|
18 <a name="l00008"></a>00008 <span class="comment">// Initial Contributors:</span> |
|
19 <a name="l00009"></a>00009 <span class="comment">// Nokia Corporation - initial contribution.</span> |
|
20 <a name="l00010"></a>00010 <span class="comment">//</span> |
|
21 <a name="l00011"></a>00011 <span class="comment">// Contributors:</span> |
|
22 <a name="l00012"></a>00012 <span class="comment">//</span> |
|
23 <a name="l00013"></a>00013 <span class="comment">// Description:</span> |
|
24 <a name="l00014"></a>00014 <span class="comment">// This example program demonstrates how to use the resizable buffer descriptor class RBuf.</span> |
|
25 <a name="l00015"></a>00015 <span class="comment">//</span> |
|
26 <a name="l00016"></a>00016 |
|
27 <a name="l00017"></a>00017 |
|
28 <a name="l00018"></a>00018 |
|
29 <a name="l00022"></a>00022 <span class="preprocessor">#include "rbufexample.h"</span> |
|
30 <a name="l00023"></a>00023 |
|
31 <a name="l00024"></a>00024 <span class="keyword">const</span> TInt KLargeBufSize = 15; |
|
32 <a name="l00025"></a>00025 <span class="keyword">const</span> TInt KSmallBufSize = 3; |
|
33 <a name="l00026"></a>00026 <span class="keyword">const</span> TInt KMedBufSize = 7; |
|
34 <a name="l00027"></a>00027 |
|
35 <a name="l00028"></a>00028 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KFailed, <span class="stringliteral">"\n Error occurred"</span>); |
|
36 <a name="l00029"></a>00029 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KPressAKey, <span class="stringliteral">"\n\n Press any key to continue the example\n"</span>); |
|
37 <a name="l00030"></a>00030 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KLength,<span class="stringliteral">"\n Length= %d"</span>); |
|
38 <a name="l00031"></a>00031 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KMaxLength,<span class="stringliteral">"\n MaxLength= %d"</span>); |
|
39 <a name="l00032"></a>00032 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KBuffer1,<span class="stringliteral">"11111"</span>); |
|
40 <a name="l00033"></a>00033 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KBuffer2,<span class="stringliteral">"22222"</span>); |
|
41 <a name="l00034"></a>00034 |
|
42 <a name="l00038"></a>00038 CRBufExample::CRBufExample() |
|
43 <a name="l00039"></a>00039 { |
|
44 <a name="l00040"></a>00040 } |
|
45 <a name="l00041"></a>00041 |
|
46 <a name="l00042"></a>00042 <span class="keywordtype">void</span> CRBufExample::ConstructL() |
|
47 <a name="l00043"></a>00043 { |
|
48 <a name="l00044"></a>00044 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTitle,<span class="stringliteral">" RBuf Example"</span>); |
|
49 <a name="l00045"></a>00045 iConsole = <a class="code" href="class_c_r_buf_example.html#a8bd254efe876ae2b5138f79a101272d6">Console::NewL</a>(KTitle, TSize(KConsFullScreen, KConsFullScreen)); |
|
50 <a name="l00046"></a>00046 |
|
51 <a name="l00047"></a>00047 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KWelcome,<span class="stringliteral">" Welcome to the RBuf example application"</span>); |
|
52 <a name="l00048"></a>00048 iConsole->Printf(KWelcome); |
|
53 <a name="l00049"></a>00049 |
|
54 <a name="l00050"></a>00050 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KPressAKeyMsg, <span class="stringliteral">"\n\n Press any key to step through the example\n"</span>); |
|
55 <a name="l00051"></a>00051 iConsole->Printf(KPressAKeyMsg ); |
|
56 <a name="l00052"></a>00052 iConsole->Getch(); |
|
57 <a name="l00053"></a>00053 } |
|
58 <a name="l00054"></a>00054 |
|
59 <a name="l00058"></a><a class="code" href="class_c_r_buf_example.html#a70b4f8db8bcc7c567f48594d2f7371c5">00058</a> <a class="code" href="class_c_r_buf_example.html#a70b4f8db8bcc7c567f48594d2f7371c5">CRBufExample::~CRBufExample</a>() |
|
60 <a name="l00059"></a>00059 { |
|
61 <a name="l00060"></a>00060 <span class="keyword">delete</span> iConsole; |
|
62 <a name="l00061"></a>00061 } |
|
63 <a name="l00062"></a>00062 |
|
64 <a name="l00067"></a><a class="code" href="class_c_r_buf_example.html#a8bd254efe876ae2b5138f79a101272d6">00067</a> <a class="code" href="class_c_r_buf_example.html">CRBufExample</a>* <a class="code" href="class_c_r_buf_example.html#a8bd254efe876ae2b5138f79a101272d6">CRBufExample::NewL</a>() |
|
65 <a name="l00068"></a>00068 { |
|
66 <a name="l00069"></a>00069 <a class="code" href="class_c_r_buf_example.html">CRBufExample</a>* <span class="keyword">self</span>=<span class="keyword">new</span>(ELeave)<a class="code" href="class_c_r_buf_example.html">CRBufExample</a>(); |
|
67 <a name="l00070"></a>00070 CleanupStack::PushL(<span class="keyword">self</span>); |
|
68 <a name="l00071"></a>00071 <span class="keyword">self</span>->ConstructL(); |
|
69 <a name="l00072"></a>00072 CleanupStack::Pop(<span class="keyword">self</span>); |
|
70 <a name="l00073"></a>00073 <span class="keywordflow">return</span> <span class="keyword">self</span>; |
|
71 <a name="l00074"></a>00074 } |
|
72 <a name="l00075"></a>00075 |
|
73 <a name="l00079"></a><a class="code" href="class_c_r_buf_example.html#a57856a0e131215ccef45af713f5aad5f">00079</a> <span class="keywordtype">void</span> <a class="code" href="class_c_r_buf_example.html#a57856a0e131215ccef45af713f5aad5f">CRBufExample::CreateRBufL</a>() |
|
74 <a name="l00080"></a>00080 { |
|
75 <a name="l00081"></a>00081 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KCreate,<span class="stringliteral">"\n Creating an RBuf: \n"</span>); |
|
76 <a name="l00082"></a>00082 |
|
77 <a name="l00083"></a>00083 iConsole->Printf(KCreate); |
|
78 <a name="l00084"></a>00084 |
|
79 <a name="l00085"></a>00085 RBuf buf; |
|
80 <a name="l00086"></a>00086 |
|
81 <a name="l00087"></a>00087 <span class="comment">// Create an empty buffer descriptor</span> |
|
82 <a name="l00088"></a>00088 <span class="comment">// The length is zero, the maxlength is 3</span> |
|
83 <a name="l00089"></a>00089 User::LeaveIfError(buf.Create(KSmallBufSize)); |
|
84 <a name="l00090"></a>00090 CleanupClosePushL(buf); |
|
85 <a name="l00091"></a>00091 |
|
86 <a name="l00092"></a>00092 <span class="comment">// Get the length of the buffer</span> |
|
87 <a name="l00093"></a>00093 TInt length= buf.Length(); |
|
88 <a name="l00094"></a>00094 |
|
89 <a name="l00095"></a>00095 <span class="comment">// Get the maximum length of the buffer</span> |
|
90 <a name="l00096"></a>00096 TInt maxLength= buf.MaxLength(); |
|
91 <a name="l00097"></a>00097 |
|
92 <a name="l00098"></a>00098 <span class="comment">// Check that length and maximum length are not equal because it was created using Create()</span> |
|
93 <a name="l00099"></a>00099 <span class="keywordflow">if</span>(length != maxLength) |
|
94 <a name="l00100"></a>00100 { |
|
95 <a name="l00101"></a>00101 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KUsingCreate, <span class="stringliteral">"\n Using Create() API: "</span>); |
|
96 <a name="l00102"></a>00102 iConsole->Printf(KUsingCreate); |
|
97 <a name="l00103"></a>00103 iConsole->Printf(KLength, length); |
|
98 <a name="l00104"></a>00104 iConsole->Printf(KMaxLength, maxLength); |
|
99 <a name="l00105"></a>00105 } |
|
100 <a name="l00106"></a>00106 <span class="keywordflow">else</span> |
|
101 <a name="l00107"></a>00107 { |
|
102 <a name="l00108"></a>00108 iConsole->Printf(KFailed); |
|
103 <a name="l00109"></a>00109 } |
|
104 <a name="l00110"></a>00110 |
|
105 <a name="l00111"></a>00111 <span class="comment">// Deallocate the memory assigned to the buffer</span> |
|
106 <a name="l00112"></a>00112 CleanupStack::PopAndDestroy(&buf); |
|
107 <a name="l00113"></a>00113 |
|
108 <a name="l00114"></a>00114 <span class="comment">// Create buffer descriptor</span> |
|
109 <a name="l00115"></a>00115 <span class="comment">// The length is 3, the maxlength is 3</span> |
|
110 <a name="l00116"></a>00116 User::LeaveIfError(buf.CreateMax(KSmallBufSize)); |
|
111 <a name="l00117"></a>00117 CleanupClosePushL(buf); |
|
112 <a name="l00118"></a>00118 |
|
113 <a name="l00119"></a>00119 <span class="comment">// Get the length of the buffer.</span> |
|
114 <a name="l00120"></a>00120 length= buf.Length(); |
|
115 <a name="l00121"></a>00121 |
|
116 <a name="l00122"></a>00122 <span class="comment">// Get the maximum length of the buffer.</span> |
|
117 <a name="l00123"></a>00123 maxLength=buf.MaxLength(); |
|
118 <a name="l00124"></a>00124 |
|
119 <a name="l00125"></a>00125 <span class="comment">// Check that length and maximum length are equal because it was created using CreateMax().</span> |
|
120 <a name="l00126"></a>00126 <span class="keywordflow">if</span>(length == maxLength) |
|
121 <a name="l00127"></a>00127 { |
|
122 <a name="l00128"></a>00128 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KCreateInAdvance, <span class="stringliteral">"\n Using CreateMax() API: "</span>); |
|
123 <a name="l00129"></a>00129 iConsole->Printf(KCreateInAdvance); |
|
124 <a name="l00130"></a>00130 iConsole->Printf(KLength, length); |
|
125 <a name="l00131"></a>00131 iConsole->Printf(KMaxLength, maxLength); |
|
126 <a name="l00132"></a>00132 } |
|
127 <a name="l00133"></a>00133 <span class="keywordflow">else</span> |
|
128 <a name="l00134"></a>00134 { |
|
129 <a name="l00135"></a>00135 iConsole->Printf(KFailed); |
|
130 <a name="l00136"></a>00136 } |
|
131 <a name="l00137"></a>00137 |
|
132 <a name="l00138"></a>00138 <span class="comment">// Deallocate the memory assigned to the buffer.</span> |
|
133 <a name="l00139"></a>00139 CleanupStack::PopAndDestroy(&buf); |
|
134 <a name="l00140"></a>00140 } |
|
135 <a name="l00141"></a>00141 |
|
136 <a name="l00145"></a><a class="code" href="class_c_r_buf_example.html#ac33844cce7df0b1c2a57f6edc3ac0906">00145</a> <span class="keywordtype">void</span> <a class="code" href="class_c_r_buf_example.html#ac33844cce7df0b1c2a57f6edc3ac0906">CRBufExample::CreateRBufFromExistingDesL</a>() |
|
137 <a name="l00146"></a>00146 { |
|
138 <a name="l00147"></a>00147 RBuf buf; |
|
139 <a name="l00148"></a>00148 |
|
140 <a name="l00149"></a>00149 <span class="comment">// Create a buffer descriptor, initialised with some text</span> |
|
141 <a name="l00150"></a>00150 buf.CreateL(KBuffer1); |
|
142 <a name="l00151"></a>00151 |
|
143 <a name="l00152"></a>00152 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KCreateFromExistingDes, <span class="stringliteral">"\n From an existing descriptor "</span>); |
|
144 <a name="l00153"></a>00153 iConsole->Printf(KCreateFromExistingDes); |
|
145 <a name="l00154"></a>00154 |
|
146 <a name="l00155"></a>00155 <span class="comment">// Deallocates the memory assigned to the buffer</span> |
|
147 <a name="l00156"></a>00156 buf.Close(); |
|
148 <a name="l00157"></a>00157 } |
|
149 <a name="l00158"></a>00158 |
|
150 <a name="l00162"></a><a class="code" href="class_c_r_buf_example.html#a398c08c23d056f1705f82ea5117c07e8">00162</a> <span class="keywordtype">void</span> <a class="code" href="class_c_r_buf_example.html#a398c08c23d056f1705f82ea5117c07e8">CRBufExample::CreateRBufFromHBufCL</a>() |
|
151 <a name="l00163"></a>00163 { |
|
152 <a name="l00164"></a>00164 <span class="comment">// Create a pointer to a heap descriptor</span> |
|
153 <a name="l00165"></a>00165 HBufC* hptr = <a class="code" href="class_c_r_buf_example.html#a8bd254efe876ae2b5138f79a101272d6">HBufC::NewL</a>(KBuffer1().Length()); |
|
154 <a name="l00166"></a>00166 |
|
155 <a name="l00167"></a>00167 <span class="comment">// Assign some data to the heap descriptor.</span> |
|
156 <a name="l00168"></a>00168 *hptr = KBuffer1; |
|
157 <a name="l00169"></a>00169 |
|
158 <a name="l00170"></a>00170 RBuf buf; |
|
159 <a name="l00171"></a>00171 |
|
160 <a name="l00172"></a>00172 <span class="comment">// Assign the HBufC to the buffer. This transfers ownership of the heap descriptor.</span> |
|
161 <a name="l00173"></a>00173 buf.Assign(hptr); |
|
162 <a name="l00174"></a>00174 |
|
163 <a name="l00175"></a>00175 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KCreateFromHBufC, <span class="stringliteral">"\n From HBufC "</span>); |
|
164 <a name="l00176"></a>00176 iConsole->Printf(KCreateFromHBufC); |
|
165 <a name="l00177"></a>00177 |
|
166 <a name="l00178"></a>00178 <span class="comment">// Deallocate the memory assigned to the buffer. </span> |
|
167 <a name="l00179"></a>00179 <span class="comment">// There is no need to free the HBufC because Assign() transferred ownership.</span> |
|
168 <a name="l00180"></a>00180 buf.Close(); |
|
169 <a name="l00181"></a>00181 } |
|
170 <a name="l00182"></a>00182 |
|
171 <a name="l00186"></a><a class="code" href="class_c_r_buf_example.html#a0a4263b7828a5214748786dae31e66b7">00186</a> <span class="keywordtype">void</span> <a class="code" href="class_c_r_buf_example.html#a0a4263b7828a5214748786dae31e66b7">CRBufExample::CreateRBufFromAnotherRBufL</a>() |
|
172 <a name="l00187"></a>00187 { |
|
173 <a name="l00188"></a>00188 RBuf buf; |
|
174 <a name="l00189"></a>00189 |
|
175 <a name="l00190"></a>00190 <span class="comment">// Create a buffer descriptor, initialised with some text</span> |
|
176 <a name="l00191"></a>00191 User::LeaveIfError(buf.Create(KBuffer1)); |
|
177 <a name="l00192"></a>00192 |
|
178 <a name="l00193"></a>00193 RBuf targetBuf; |
|
179 <a name="l00194"></a>00194 |
|
180 <a name="l00195"></a>00195 <span class="comment">// Assign one buffer to the other. </span> |
|
181 <a name="l00196"></a>00196 <span class="comment">// Transfers ownership of the source buffer's memory to the target buffer.</span> |
|
182 <a name="l00197"></a>00197 <span class="comment">// Note that targetBuf should have no memory allocated to it beforehand</span> |
|
183 <a name="l00198"></a>00198 <span class="comment">// otherwise a memory leak will occur.</span> |
|
184 <a name="l00199"></a>00199 targetBuf.Assign(buf); |
|
185 <a name="l00200"></a>00200 |
|
186 <a name="l00201"></a>00201 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KCreateFromAnotherRBuf, <span class="stringliteral">"\n From another RBuf"</span>); |
|
187 <a name="l00202"></a>00202 iConsole->Printf(KCreateFromAnotherRBuf); |
|
188 <a name="l00203"></a>00203 |
|
189 <a name="l00204"></a>00204 <span class="comment">// Deallocate the memory assigned to the buffer.</span> |
|
190 <a name="l00205"></a>00205 targetBuf.Close(); |
|
191 <a name="l00206"></a>00206 } |
|
192 <a name="l00207"></a>00207 |
|
193 <a name="l00211"></a><a class="code" href="class_c_r_buf_example.html#a15c0b84f3b6704d60b1e4f3ff50f590b">00211</a> <span class="keywordtype">void</span> <a class="code" href="class_c_r_buf_example.html#a15c0b84f3b6704d60b1e4f3ff50f590b">CRBufExample::CreateRBufUsingRReadStreamL</a>() |
|
194 <a name="l00212"></a>00212 { |
|
195 <a name="l00213"></a>00213 <span class="comment">// A handle to a file server session. </span> |
|
196 <a name="l00214"></a>00214 <span class="comment">// This is used to create and write to/read from a file.</span> |
|
197 <a name="l00215"></a>00215 RFs fs; |
|
198 <a name="l00216"></a>00216 |
|
199 <a name="l00217"></a>00217 <span class="comment">// Connect to the file server.</span> |
|
200 <a name="l00218"></a>00218 User::LeaveIfError(fs.Connect()); |
|
201 <a name="l00219"></a>00219 CleanupClosePushL(fs); |
|
202 <a name="l00220"></a>00220 <span class="comment">// Create the session path at the process's private path on the system drive.</span> |
|
203 <a name="l00221"></a>00221 User::LeaveIfError(fs.CreatePrivatePath(RFs::GetSystemDrive())); |
|
204 <a name="l00222"></a>00222 |
|
205 <a name="l00223"></a>00223 <span class="comment">// Set the session path to point to the process's private path on the system drive.</span> |
|
206 <a name="l00224"></a>00224 User::LeaveIfError(fs.SetSessionToPrivate(RFs::GetSystemDrive())); |
|
207 <a name="l00225"></a>00225 |
|
208 <a name="l00226"></a>00226 <span class="comment">// Declare a file stream to write to.</span> |
|
209 <a name="l00227"></a>00227 RFileWriteStream wStream; |
|
210 <a name="l00228"></a>00228 |
|
211 <a name="l00229"></a>00229 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KFileName,<span class="stringliteral">"stream.dat"</span>); |
|
212 <a name="l00230"></a>00230 |
|
213 <a name="l00231"></a>00231 <span class="comment">// Create a file, associates it with the stream, and prepares the stream for writing.</span> |
|
214 <a name="l00232"></a>00232 User::LeaveIfError(wStream.Replace(fs, KFileName, EFileWrite)); |
|
215 <a name="l00233"></a>00233 CleanupClosePushL(wStream); |
|
216 <a name="l00234"></a>00234 |
|
217 <a name="l00235"></a>00235 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KText, <span class="stringliteral">"RBuf Example"</span>); |
|
218 <a name="l00236"></a>00236 |
|
219 <a name="l00237"></a>00237 <span class="comment">// Write some text to the stream.</span> |
|
220 <a name="l00238"></a>00238 wStream << KText(); |
|
221 <a name="l00239"></a>00239 wStream.CommitL(); |
|
222 <a name="l00240"></a>00240 CleanupStack::PopAndDestroy(&wStream); |
|
223 <a name="l00241"></a>00241 |
|
224 <a name="l00242"></a>00242 <span class="comment">// Declare a file stream to read from.</span> |
|
225 <a name="l00243"></a>00243 RFileReadStream rStream; |
|
226 <a name="l00244"></a>00244 |
|
227 <a name="l00245"></a>00245 <span class="comment">// Open the file</span> |
|
228 <a name="l00246"></a>00246 User::LeaveIfError(rStream.Open(fs, KFileName, EFileRead)); |
|
229 <a name="l00247"></a>00247 CleanupClosePushL(rStream); |
|
230 <a name="l00248"></a>00248 |
|
231 <a name="l00249"></a>00249 RBuf buf; |
|
232 <a name="l00250"></a>00250 CleanupClosePushL(buf); |
|
233 <a name="l00251"></a>00251 |
|
234 <a name="l00252"></a>00252 <span class="comment">// Create the buffer by passing the open stream object to CreateL().</span> |
|
235 <a name="l00253"></a>00253 buf.CreateL(rStream, KLargeBufSize); |
|
236 <a name="l00254"></a>00254 |
|
237 <a name="l00255"></a>00255 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KCreateUsingRReadStream, <span class="stringliteral">"\n Using RReadStream "</span>); |
|
238 <a name="l00256"></a>00256 iConsole->Printf(KCreateUsingRReadStream); |
|
239 <a name="l00257"></a>00257 |
|
240 <a name="l00258"></a>00258 <span class="comment">// Deallocate the memory assigned to the buffer, close the stream and close the file server connection</span> |
|
241 <a name="l00259"></a>00259 CleanupStack::PopAndDestroy(&buf); |
|
242 <a name="l00260"></a>00260 CleanupStack::PopAndDestroy(&rStream); |
|
243 <a name="l00261"></a>00261 CleanupStack::PopAndDestroy(&fs); |
|
244 <a name="l00262"></a>00262 } |
|
245 <a name="l00263"></a>00263 |
|
246 <a name="l00267"></a><a class="code" href="class_c_r_buf_example.html#a7815a44916e13bd2a567a6a25a1ffc6d">00267</a> <span class="keywordtype">void</span> <a class="code" href="class_c_r_buf_example.html#a7815a44916e13bd2a567a6a25a1ffc6d">CRBufExample::CreateRBufFromAllocatedMemoryL</a>() |
|
247 <a name="l00268"></a>00268 { |
|
248 <a name="l00269"></a>00269 RBuf buf; |
|
249 <a name="l00270"></a>00270 |
|
250 <a name="l00271"></a>00271 <span class="comment">// Allocate some memory.</span> |
|
251 <a name="l00272"></a>00272 TUint16* allocatedMemory = <span class="keyword">static_cast<</span>TUint16*<span class="keyword">></span>( User::Alloc( KLargeBufSize * <span class="keyword">sizeof</span>( TUint16) ) ) ; |
|
252 <a name="l00273"></a>00273 |
|
253 <a name="l00274"></a>00274 <span class="comment">// Transfer ownership of the memory to the descriptor.</span> |
|
254 <a name="l00275"></a>00275 buf.Assign(allocatedMemory, KLargeBufSize); |
|
255 <a name="l00276"></a>00276 |
|
256 <a name="l00277"></a>00277 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KCreateFromAllocatedMemory, <span class="stringliteral">"\n By transferring ownership of allocated memory"</span>); |
|
257 <a name="l00278"></a>00278 iConsole->Printf(KCreateFromAllocatedMemory); |
|
258 <a name="l00279"></a>00279 |
|
259 <a name="l00280"></a>00280 iConsole->Printf(KPressAKey); |
|
260 <a name="l00281"></a>00281 iConsole->Getch(); |
|
261 <a name="l00282"></a>00282 |
|
262 <a name="l00283"></a>00283 <span class="comment">// Deallocate the memory assigned to the buffer.</span> |
|
263 <a name="l00284"></a>00284 <span class="comment">// There is no need to free memory here because Assign() transferred ownership.</span> |
|
264 <a name="l00285"></a>00285 buf.Close(); |
|
265 <a name="l00286"></a>00286 } |
|
266 <a name="l00287"></a>00287 |
|
267 <a name="l00291"></a><a class="code" href="class_c_r_buf_example.html#a6de7e813c107211fc904905e39582ee0">00291</a> <span class="keywordtype">void</span> <a class="code" href="class_c_r_buf_example.html#a6de7e813c107211fc904905e39582ee0">CRBufExample::SwapTwoRBufsL</a>() |
|
268 <a name="l00292"></a>00292 { |
|
269 <a name="l00293"></a>00293 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KSwapAndCopy,<span class="stringliteral">"\n Swapping and copying data: "</span>); |
|
270 <a name="l00294"></a>00294 iConsole->Printf(KSwapAndCopy); |
|
271 <a name="l00295"></a>00295 |
|
272 <a name="l00296"></a>00296 RBuf buf1; |
|
273 <a name="l00297"></a>00297 |
|
274 <a name="l00298"></a>00298 <span class="comment">// Create a buffer descriptor, initialised with some text</span> |
|
275 <a name="l00299"></a>00299 User::LeaveIfError(buf1.Create(KBuffer1)); |
|
276 <a name="l00300"></a>00300 CleanupClosePushL(buf1); |
|
277 <a name="l00301"></a>00301 |
|
278 <a name="l00302"></a>00302 RBuf buf2; |
|
279 <a name="l00303"></a>00303 |
|
280 <a name="l00304"></a>00304 <span class="comment">// Create a second buffer descriptor, initialised with some text</span> |
|
281 <a name="l00305"></a>00305 User::LeaveIfError(buf2.Create(KBuffer2)); |
|
282 <a name="l00306"></a>00306 CleanupClosePushL(buf2); |
|
283 <a name="l00307"></a>00307 |
|
284 <a name="l00308"></a>00308 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KBeforeSwapping, <span class="stringliteral">"\n Before swapping: "</span>); |
|
285 <a name="l00309"></a>00309 iConsole->Printf(KBeforeSwapping); |
|
286 <a name="l00310"></a>00310 |
|
287 <a name="l00311"></a>00311 <span class="comment">// Print out the contents of the 2 descriptors</span> |
|
288 <a name="l00312"></a>00312 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KPrintFirstdata,<span class="stringliteral">"\n Data present in first descriptor is: "</span>); |
|
289 <a name="l00313"></a>00313 iConsole->Printf(KPrintFirstdata); |
|
290 <a name="l00314"></a>00314 iConsole->Printf(buf1); |
|
291 <a name="l00315"></a>00315 |
|
292 <a name="l00316"></a>00316 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KPrintSecondData,<span class="stringliteral">"\n Data present in second descriptor is: "</span>); |
|
293 <a name="l00317"></a>00317 iConsole->Printf(KPrintSecondData); |
|
294 <a name="l00318"></a>00318 iConsole->Printf(buf2); |
|
295 <a name="l00319"></a>00319 |
|
296 <a name="l00320"></a>00320 <span class="comment">// Swap them and print out the new contents</span> |
|
297 <a name="l00321"></a>00321 buf1.Swap(buf2); |
|
298 <a name="l00322"></a>00322 |
|
299 <a name="l00323"></a>00323 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KAfterSwapping, <span class="stringliteral">"\n After swapping: "</span>); |
|
300 <a name="l00324"></a>00324 iConsole->Printf(KAfterSwapping); |
|
301 <a name="l00325"></a>00325 |
|
302 <a name="l00326"></a>00326 iConsole->Printf(KPrintFirstdata); |
|
303 <a name="l00327"></a>00327 iConsole->Printf(buf1); |
|
304 <a name="l00328"></a>00328 |
|
305 <a name="l00329"></a>00329 iConsole->Printf(KPrintSecondData); |
|
306 <a name="l00330"></a>00330 iConsole->Printf(buf2); |
|
307 <a name="l00331"></a>00331 |
|
308 <a name="l00332"></a>00332 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KSwap, <span class="stringliteral">"\n Swapping between two RBufs is successful"</span>); |
|
309 <a name="l00333"></a>00333 iConsole->Printf(KSwap); |
|
310 <a name="l00334"></a>00334 |
|
311 <a name="l00335"></a>00335 <span class="comment">// Deallocate memory assigned to the 2 buffer descriptors.</span> |
|
312 <a name="l00336"></a>00336 CleanupStack::PopAndDestroy(2); <span class="comment">// buf1, buf2</span> |
|
313 <a name="l00337"></a>00337 } |
|
314 <a name="l00338"></a>00338 |
|
315 <a name="l00342"></a><a class="code" href="class_c_r_buf_example.html#afd4b2bcfb6b0a1fbef134f021ee7bcac">00342</a> <span class="keywordtype">void</span> <a class="code" href="class_c_r_buf_example.html#afd4b2bcfb6b0a1fbef134f021ee7bcac">CRBufExample::CopyDataUsingAssignmentOperatorL</a>() |
|
316 <a name="l00343"></a>00343 { |
|
317 <a name="l00344"></a>00344 RBuf buf1; |
|
318 <a name="l00345"></a>00345 |
|
319 <a name="l00346"></a>00346 <span class="comment">// Create a buffer descriptor, initialised with some text</span> |
|
320 <a name="l00347"></a>00347 buf1.Create(KBuffer1); |
|
321 <a name="l00348"></a>00348 CleanupClosePushL(buf1); |
|
322 <a name="l00349"></a>00349 |
|
323 <a name="l00350"></a>00350 RBuf buf2; |
|
324 <a name="l00351"></a>00351 |
|
325 <a name="l00352"></a>00352 <span class="comment">// Create a second buffer descriptor, initialised with some text</span> |
|
326 <a name="l00353"></a>00353 User::LeaveIfError(buf2.Create(KBuffer2)); |
|
327 <a name="l00354"></a>00354 CleanupClosePushL(buf2); |
|
328 <a name="l00355"></a>00355 |
|
329 <a name="l00356"></a>00356 <span class="comment">// Copy data using assignment operator from one to the other. </span> |
|
330 <a name="l00357"></a>00357 <span class="comment">// Target buffer must be long enough, otherwise a panic occurs.</span> |
|
331 <a name="l00358"></a>00358 buf2= buf1; |
|
332 <a name="l00359"></a>00359 |
|
333 <a name="l00360"></a>00360 <span class="comment">// Check the value of the buffers .</span> |
|
334 <a name="l00361"></a>00361 <span class="keywordflow">if</span> (buf1==buf2) |
|
335 <a name="l00362"></a>00362 { |
|
336 <a name="l00363"></a>00363 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KCopyDataUsingAssignmentOperator,<span class="stringliteral">"\n Copying data using assignment operator from descriptor, and RBuf is successful"</span>); |
|
337 <a name="l00364"></a>00364 iConsole->Printf(KCopyDataUsingAssignmentOperator); |
|
338 <a name="l00365"></a>00365 } |
|
339 <a name="l00366"></a>00366 <span class="keywordflow">else</span> |
|
340 <a name="l00367"></a>00367 { |
|
341 <a name="l00368"></a>00368 iConsole->Printf(KFailed); |
|
342 <a name="l00369"></a>00369 } |
|
343 <a name="l00370"></a>00370 |
|
344 <a name="l00371"></a>00371 iConsole->Printf(KPressAKey); |
|
345 <a name="l00372"></a>00372 iConsole->Getch(); |
|
346 <a name="l00373"></a>00373 |
|
347 <a name="l00374"></a>00374 <span class="comment">// Deallocate memory assigned to the 2 buffer descriptors.</span> |
|
348 <a name="l00375"></a>00375 CleanupStack::PopAndDestroy(2); <span class="comment">// buf1, buf2</span> |
|
349 <a name="l00376"></a>00376 } |
|
350 <a name="l00377"></a>00377 |
|
351 <a name="l00381"></a><a class="code" href="class_c_r_buf_example.html#ada558a684cebf4b9034706007ad7bda0">00381</a> <span class="keywordtype">void</span> <a class="code" href="class_c_r_buf_example.html#ada558a684cebf4b9034706007ad7bda0">CRBufExample::ReallocateAndFreeTheMemoryBufferL</a>() |
|
352 <a name="l00382"></a>00382 { |
|
353 <a name="l00383"></a>00383 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KReAllocAndFree,<span class="stringliteral">"\n Realloc and free:"</span>); |
|
354 <a name="l00384"></a>00384 iConsole->Printf(KReAllocAndFree); |
|
355 <a name="l00385"></a>00385 |
|
356 <a name="l00386"></a>00386 RBuf buf; |
|
357 <a name="l00387"></a>00387 |
|
358 <a name="l00388"></a>00388 <span class="comment">// Create empty buffer descriptor with max length of KSmallBufSize.</span> |
|
359 <a name="l00389"></a>00389 User::LeaveIfError(buf.Create(KSmallBufSize)); |
|
360 <a name="l00390"></a>00390 |
|
361 <a name="l00391"></a>00391 <span class="comment">// Get the length of the buffer.</span> |
|
362 <a name="l00392"></a>00392 TInt length= buf.Length(); |
|
363 <a name="l00393"></a>00393 |
|
364 <a name="l00394"></a>00394 <span class="comment">// Get the maximum length of the buffer.</span> |
|
365 <a name="l00395"></a>00395 TInt maxLength= buf.MaxLength(); |
|
366 <a name="l00396"></a>00396 |
|
367 <a name="l00397"></a>00397 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KBeforeReAlloc,<span class="stringliteral">"\n Before ReAlloc: "</span>); |
|
368 <a name="l00398"></a>00398 iConsole->Printf(KBeforeReAlloc); |
|
369 <a name="l00399"></a>00399 |
|
370 <a name="l00400"></a>00400 <span class="comment">// Print out the length and max length</span> |
|
371 <a name="l00401"></a>00401 iConsole->Printf(KLength, length); |
|
372 <a name="l00402"></a>00402 iConsole->Printf(KMaxLength, maxLength); |
|
373 <a name="l00403"></a>00403 |
|
374 <a name="l00404"></a>00404 <span class="comment">// Re-allocate the buffer descriptor. Length doesnt change but maxlength does.</span> |
|
375 <a name="l00405"></a>00405 User::LeaveIfError(buf.ReAlloc(KMedBufSize)); |
|
376 <a name="l00406"></a>00406 |
|
377 <a name="l00407"></a>00407 <span class="comment">// Get the length of the buffer.</span> |
|
378 <a name="l00408"></a>00408 length= buf.Length(); |
|
379 <a name="l00409"></a>00409 |
|
380 <a name="l00410"></a>00410 <span class="comment">// Get the maximum length of the reallocated buffer.</span> |
|
381 <a name="l00411"></a>00411 maxLength= buf.MaxLength(); |
|
382 <a name="l00412"></a>00412 |
|
383 <a name="l00413"></a>00413 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KAfterReAlloc,<span class="stringliteral">"\n After ReAlloc: "</span>); |
|
384 <a name="l00414"></a>00414 iConsole->Printf(KAfterReAlloc); |
|
385 <a name="l00415"></a>00415 |
|
386 <a name="l00416"></a>00416 <span class="comment">// Print out the length and new max length</span> |
|
387 <a name="l00417"></a>00417 iConsole->Printf(KLength, length); |
|
388 <a name="l00418"></a>00418 iConsole->Printf(KMaxLength, maxLength); |
|
389 <a name="l00419"></a>00419 |
|
390 <a name="l00420"></a>00420 <span class="comment">// Free the memory buffer. It sets the length and maxlength to zero.</span> |
|
391 <a name="l00421"></a>00421 User::LeaveIfError(buf.ReAlloc(0)); |
|
392 <a name="l00422"></a>00422 |
|
393 <a name="l00423"></a>00423 <span class="comment">// Get the length of the buffer.</span> |
|
394 <a name="l00424"></a>00424 length= buf.Length(); |
|
395 <a name="l00425"></a>00425 |
|
396 <a name="l00426"></a>00426 <span class="comment">// Get the maximum length of the buffer.</span> |
|
397 <a name="l00427"></a>00427 maxLength= buf.MaxLength(); |
|
398 <a name="l00428"></a>00428 |
|
399 <a name="l00429"></a>00429 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KFreeBuffer,<span class="stringliteral">"\n After free: "</span>); |
|
400 <a name="l00430"></a>00430 iConsole->Printf(KFreeBuffer); |
|
401 <a name="l00431"></a>00431 |
|
402 <a name="l00432"></a>00432 iConsole->Printf(KLength, length); |
|
403 <a name="l00433"></a>00433 iConsole->Printf(KMaxLength, maxLength); |
|
404 <a name="l00434"></a>00434 } |
|
405 <a name="l00435"></a>00435 |
|
406 <a name="l00439"></a><a class="code" href="class_c_r_buf_example.html#a9ee071c3749b927f6af99dcb04c6bd4d">00439</a> <span class="keywordtype">void</span> <a class="code" href="class_c_r_buf_example.html#a9ee071c3749b927f6af99dcb04c6bd4d">CRBufExample::ReplaceAndModifyTheDataL</a>() |
|
407 <a name="l00440"></a>00440 { |
|
408 <a name="l00441"></a>00441 RBuf buf; |
|
409 <a name="l00442"></a>00442 |
|
410 <a name="l00443"></a>00443 <span class="comment">// Create a buffer descriptor, initialised with some text</span> |
|
411 <a name="l00444"></a>00444 User::LeaveIfError(buf.Create(KBuffer1)); |
|
412 <a name="l00445"></a>00445 CleanupClosePushL(buf); |
|
413 <a name="l00446"></a>00446 |
|
414 <a name="l00447"></a>00447 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KReplaceAndModify,<span class="stringliteral">"\n Replace and modify: "</span>); |
|
415 <a name="l00448"></a>00448 iConsole->Printf(KReplaceAndModify); |
|
416 <a name="l00449"></a>00449 |
|
417 <a name="l00450"></a>00450 <span class="comment">// Print the original data present in the buffer.</span> |
|
418 <a name="l00451"></a>00451 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KOriginalData,<span class="stringliteral">"\n Data present in RBuf is: "</span>); |
|
419 <a name="l00452"></a>00452 iConsole->Printf(KOriginalData); |
|
420 <a name="l00453"></a>00453 iConsole->Printf(buf); |
|
421 <a name="l00454"></a>00454 |
|
422 <a name="l00455"></a>00455 TInt pos= 1; |
|
423 <a name="l00456"></a>00456 |
|
424 <a name="l00457"></a>00457 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KReplacedMessage,<span class="stringliteral">"22"</span>); |
|
425 <a name="l00458"></a>00458 |
|
426 <a name="l00459"></a>00459 TInt length= KReplacedMessage().Length(); |
|
427 <a name="l00460"></a>00460 |
|
428 <a name="l00461"></a>00461 <span class="comment">// Replace a portion of the data in the buffer descriptor.</span> |
|
429 <a name="l00462"></a>00462 buf.Replace(pos,length, KReplacedMessage); |
|
430 <a name="l00463"></a>00463 |
|
431 <a name="l00464"></a>00464 <span class="comment">// Print the buffer's new contents.</span> |
|
432 <a name="l00465"></a>00465 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KReplacedData,<span class="stringliteral">"\n After replacement, data held in RBuf is: "</span>); |
|
433 <a name="l00466"></a>00466 iConsole->Printf(KReplacedData); |
|
434 <a name="l00467"></a>00467 iConsole->Printf(buf); |
|
435 <a name="l00468"></a>00468 |
|
436 <a name="l00469"></a>00469 pos=3; |
|
437 <a name="l00470"></a>00470 length=1; |
|
438 <a name="l00471"></a>00471 |
|
439 <a name="l00472"></a>00472 <span class="comment">// Delete the replacement text.</span> |
|
440 <a name="l00473"></a>00473 buf.Delete(pos,length); |
|
441 <a name="l00474"></a>00474 |
|
442 <a name="l00475"></a>00475 <span class="comment">// Print the buffer's contents again.</span> |
|
443 <a name="l00476"></a>00476 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KModifiedData,<span class="stringliteral">"\n After modification, data held in RBuf is: "</span>); |
|
444 <a name="l00477"></a>00477 iConsole->Printf(KModifiedData); |
|
445 <a name="l00478"></a>00478 iConsole->Printf(buf); |
|
446 <a name="l00479"></a>00479 |
|
447 <a name="l00480"></a>00480 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KReplaceAndModifyData,<span class="stringliteral">"\n Replacing and modifying the data held in RBuf is successful"</span>); |
|
448 <a name="l00481"></a>00481 iConsole->Printf(KReplaceAndModifyData); |
|
449 <a name="l00482"></a>00482 |
|
450 <a name="l00483"></a>00483 <span class="comment">// Deallocate the memory assigned to the buffer. </span> |
|
451 <a name="l00484"></a>00484 CleanupStack::PopAndDestroy(&buf); |
|
452 <a name="l00485"></a>00485 } |
|
453 <a name="l00486"></a>00486 |
|
454 <a name="l00490"></a><a class="code" href="class_c_r_buf_example.html#a1d99cb2bef146c76bd1f99908435ecfb">00490</a> <span class="keywordtype">void</span> <a class="code" href="class_c_r_buf_example.html#a1d99cb2bef146c76bd1f99908435ecfb">CRBufExample::CleanUpRulesL</a>() |
|
455 <a name="l00491"></a>00491 { |
|
456 <a name="l00492"></a>00492 RBuf buf; |
|
457 <a name="l00493"></a>00493 |
|
458 <a name="l00494"></a>00494 <span class="comment">// Create a buffer descriptor, initialised with some text</span> |
|
459 <a name="l00495"></a>00495 User::LeaveIfError(buf.Create(KBuffer1)); |
|
460 <a name="l00496"></a>00496 |
|
461 <a name="l00497"></a>00497 <span class="comment">// To avoid memory leaks use RBuf::CleanupClosePushL() to push a cleanup item for the RBuf onto the cleanup stack.</span> |
|
462 <a name="l00498"></a>00498 <span class="comment">// The effect is to cause Close() to be called on the buffer descriptor if a leave occurs, </span> |
|
463 <a name="l00499"></a>00499 <span class="comment">// or when CleanupStack::PopAndDestroy() is called.</span> |
|
464 <a name="l00500"></a>00500 buf.CleanupClosePushL(); |
|
465 <a name="l00501"></a>00501 |
|
466 <a name="l00502"></a>00502 <span class="comment">// Causes Close() to be called to deallocate the memory assigned to the buffer.</span> |
|
467 <a name="l00503"></a>00503 CleanupStack::PopAndDestroy(&buf); |
|
468 <a name="l00504"></a>00504 |
|
469 <a name="l00505"></a>00505 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KCleanUp,<span class="stringliteral">"\n RBuf cleanup is successful"</span>); |
|
470 <a name="l00506"></a>00506 iConsole->Printf(KCleanUp); |
|
471 <a name="l00507"></a>00507 |
|
472 <a name="l00508"></a>00508 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KExitMsg, <span class="stringliteral">"\n\n Press any key to exit the example"</span>); |
|
473 <a name="l00509"></a>00509 iConsole->Printf(KExitMsg); |
|
474 <a name="l00510"></a>00510 iConsole->Getch(); |
|
475 <a name="l00511"></a>00511 } |
|
476 <a name="l00512"></a>00512 |
|
477 <a name="l00513"></a>00513 <span class="keywordtype">void</span> MainL() |
|
478 <a name="l00514"></a>00514 { |
|
479 <a name="l00515"></a>00515 <a class="code" href="class_c_r_buf_example.html">CRBufExample</a>* app= <a class="code" href="class_c_r_buf_example.html#a8bd254efe876ae2b5138f79a101272d6">CRBufExample::NewL</a>(); |
|
480 <a name="l00516"></a>00516 CleanupStack::PushL(app); |
|
481 <a name="l00517"></a>00517 |
|
482 <a name="l00518"></a>00518 <span class="comment">// Creates empty RBuf.</span> |
|
483 <a name="l00519"></a>00519 app-><a class="code" href="class_c_r_buf_example.html#a57856a0e131215ccef45af713f5aad5f">CreateRBufL</a>(); |
|
484 <a name="l00520"></a>00520 |
|
485 <a name="l00521"></a>00521 <span class="comment">// Creates RBuf from an existing descriptor.</span> |
|
486 <a name="l00522"></a>00522 app-><a class="code" href="class_c_r_buf_example.html#ac33844cce7df0b1c2a57f6edc3ac0906">CreateRBufFromExistingDesL</a>(); |
|
487 <a name="l00523"></a>00523 |
|
488 <a name="l00524"></a>00524 <span class="comment">// Creates RBuf from an HBufC.</span> |
|
489 <a name="l00525"></a>00525 app-><a class="code" href="class_c_r_buf_example.html#a398c08c23d056f1705f82ea5117c07e8">CreateRBufFromHBufCL</a>(); |
|
490 <a name="l00526"></a>00526 |
|
491 <a name="l00527"></a>00527 <span class="comment">// Creates RBuf from another RBuf.</span> |
|
492 <a name="l00528"></a>00528 app-><a class="code" href="class_c_r_buf_example.html#a0a4263b7828a5214748786dae31e66b7">CreateRBufFromAnotherRBufL</a>(); |
|
493 <a name="l00529"></a>00529 |
|
494 <a name="l00530"></a>00530 <span class="comment">// Create RBuf using RReadStream</span> |
|
495 <a name="l00531"></a>00531 app-><a class="code" href="class_c_r_buf_example.html#a15c0b84f3b6704d60b1e4f3ff50f590b">CreateRBufUsingRReadStreamL</a>(); |
|
496 <a name="l00532"></a>00532 |
|
497 <a name="l00533"></a>00533 <span class="comment">// Creates RBuf from allocated memory.</span> |
|
498 <a name="l00534"></a>00534 app-><a class="code" href="class_c_r_buf_example.html#a7815a44916e13bd2a567a6a25a1ffc6d">CreateRBufFromAllocatedMemoryL</a>(); |
|
499 <a name="l00535"></a>00535 |
|
500 <a name="l00536"></a>00536 <span class="comment">// Swaps two RBufs.</span> |
|
501 <a name="l00537"></a>00537 app-><a class="code" href="class_c_r_buf_example.html#a6de7e813c107211fc904905e39582ee0">SwapTwoRBufsL</a>(); |
|
502 <a name="l00538"></a>00538 |
|
503 <a name="l00539"></a>00539 <span class="comment">// Copies data using assignment operator.</span> |
|
504 <a name="l00540"></a>00540 app-><a class="code" href="class_c_r_buf_example.html#afd4b2bcfb6b0a1fbef134f021ee7bcac">CopyDataUsingAssignmentOperatorL</a>(); |
|
505 <a name="l00541"></a>00541 |
|
506 <a name="l00542"></a>00542 <span class="comment">// Reallocates and frees the memory buffer.</span> |
|
507 <a name="l00543"></a>00543 app-><a class="code" href="class_c_r_buf_example.html#ada558a684cebf4b9034706007ad7bda0">ReallocateAndFreeTheMemoryBufferL</a>(); |
|
508 <a name="l00544"></a>00544 |
|
509 <a name="l00545"></a>00545 <span class="comment">// Replaces and modifies the data in the descriptor.</span> |
|
510 <a name="l00546"></a>00546 app-><a class="code" href="class_c_r_buf_example.html#a9ee071c3749b927f6af99dcb04c6bd4d">ReplaceAndModifyTheDataL</a>(); |
|
511 <a name="l00547"></a>00547 |
|
512 <a name="l00548"></a>00548 <span class="comment">// Demonstrates cleanup.</span> |
|
513 <a name="l00549"></a>00549 app-><a class="code" href="class_c_r_buf_example.html#a1d99cb2bef146c76bd1f99908435ecfb">CleanUpRulesL</a>(); |
|
514 <a name="l00550"></a>00550 |
|
515 <a name="l00551"></a>00551 CleanupStack::PopAndDestroy(app); |
|
516 <a name="l00552"></a>00552 } |
|
517 <a name="l00553"></a>00553 |
|
518 <a name="l00554"></a>00554 GLDEF_C TInt E32Main() |
|
519 <a name="l00555"></a>00555 { |
|
520 <a name="l00556"></a>00556 __UHEAP_MARK; |
|
521 <a name="l00557"></a>00557 |
|
522 <a name="l00558"></a>00558 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
523 <a name="l00559"></a>00559 <span class="keywordflow">if</span>(cleanup == NULL) |
|
524 <a name="l00560"></a>00560 { |
|
525 <a name="l00561"></a>00561 <span class="keywordflow">return</span> KErrNoMemory; |
|
526 <a name="l00562"></a>00562 } |
|
527 <a name="l00563"></a>00563 TRAPD(err, MainL()); |
|
528 <a name="l00564"></a>00564 <span class="keyword">delete</span> cleanup; |
|
529 <a name="l00565"></a>00565 |
|
530 <a name="l00566"></a>00566 <span class="keywordflow">if</span>(err !=KErrNone) |
|
531 <a name="l00567"></a>00567 { |
|
532 <a name="l00568"></a>00568 User::Panic(KFailed, err); |
|
533 <a name="l00569"></a>00569 } |
|
534 <a name="l00570"></a>00570 |
|
535 <a name="l00571"></a>00571 __UHEAP_MARKEND; |
|
536 <a name="l00572"></a>00572 <span class="keywordflow">return</span> KErrNone; |
|
537 <a name="l00573"></a>00573 } |
|
538 <a name="l00574"></a>00574 |
|
539 <a name="l00575"></a>00575 |
|
540 <a name="l00576"></a>00576 |
|
541 <a name="l00577"></a>00577 |
|
542 <a name="l00578"></a>00578 |
|
543 <a name="l00579"></a>00579 |
|
544 <a name="l00580"></a>00580 |
|
545 </pre></div></div> |
|
546 <hr size="1"/><address style="text-align: right;"><small>Generated by |
|
547 <a href="http://www.doxygen.org/index.html"> |
|
548 <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2 </small></address> |
|
549 </body> |
|
550 </html> |