📄 _web_client_engine_8cpp-source.html
字号:
<a name="l00260"></a>00260 <span class="comment">// events via MHFRunL and MHFRunError.</span><a name="l00261"></a>00261 <a class="code" href="class_c_web_client_engine.html#7deee05e1ccb79197ceb34881cf60159">iTransaction</a>.SubmitL();<a name="l00262"></a>00262 <a name="l00263"></a>00263 <a class="code" href="class_c_web_client_engine.html#d19da1539625146ffaa8979ee6ced8c3">iRunning</a> = ETrue;<a name="l00264"></a>00264 <a name="l00265"></a>00265 <span class="comment">// Load a string from the resource file </span><a name="l00266"></a>00266 HBufC* textResource = StringLoader::LoadLC( R_WEBCLIENT_CONNECTING );<a name="l00267"></a>00267 <a class="code" href="class_c_web_client_engine.html#5598d19cc10719afd28055422087a200">iObserver</a>.<a class="code" href="class_m_web_client_observer.html#ba45586e3b6414e9a001aa362b83f6d3">ClientEvent</a>( *textResource );<a name="l00268"></a>00268 CleanupStack::PopAndDestroy( textResource );<a name="l00269"></a>00269 }<a name="l00270"></a>00270 <a name="l00271"></a>00271 <a name="l00272"></a>00272 <span class="comment">// ----------------------------------------------------------------------------</span><a name="l00273"></a>00273 <span class="comment">// CWebClientEngine::CancelTransactionL()</span><a name="l00274"></a>00274 <span class="comment">// Cancels currently running transaction and frees resources related to it.</span><a name="l00275"></a>00275 <span class="comment">// ----------------------------------------------------------------------------</span><a name="l00276"></a>00276 <span class="comment">//</span><a name="l00277"></a><a class="code" href="class_c_web_client_engine.html#5b3730609dcbc8696c0ff37e711e965d">00277</a> <span class="keywordtype">void</span> <a class="code" href="class_c_web_client_engine.html#5b3730609dcbc8696c0ff37e711e965d">CWebClientEngine::CancelTransactionL</a>()<a name="l00278"></a>00278 {<a name="l00279"></a>00279 <span class="keywordflow">if</span>( !<a class="code" href="class_c_web_client_engine.html#d19da1539625146ffaa8979ee6ced8c3">iRunning</a> ) <a name="l00280"></a>00280 <span class="keywordflow">return</span>;<a name="l00281"></a>00281 <a name="l00282"></a>00282 <span class="comment">// Close() also cancels transaction (Cancel() can also be used but </span><a name="l00283"></a>00283 <span class="comment">// resources allocated by transaction must be still freed with Close())</span><a name="l00284"></a>00284 <a class="code" href="class_c_web_client_engine.html#7deee05e1ccb79197ceb34881cf60159">iTransaction</a>.Close();<a name="l00285"></a>00285 <a name="l00286"></a>00286 <span class="comment">// Not running anymore</span><a name="l00287"></a>00287 <a class="code" href="class_c_web_client_engine.html#d19da1539625146ffaa8979ee6ced8c3">iRunning</a> = EFalse;<a name="l00288"></a>00288 <a name="l00289"></a>00289 <span class="comment">// Load a string from the resource file </span><a name="l00290"></a>00290 HBufC* textResource = StringLoader::LoadLC( R_WEBCLIENT_TRANSACTION_CANCEL );<a name="l00291"></a>00291 <a class="code" href="class_c_web_client_engine.html#5598d19cc10719afd28055422087a200">iObserver</a>.<a class="code" href="class_m_web_client_observer.html#ba45586e3b6414e9a001aa362b83f6d3">ClientEvent</a>( *textResource );<a name="l00292"></a>00292 CleanupStack::PopAndDestroy( textResource );<a name="l00293"></a>00293 }<a name="l00294"></a>00294 <a name="l00295"></a>00295 <span class="comment">// ----------------------------------------------------------------------------</span><a name="l00296"></a>00296 <span class="comment">// CWebClientEngine::SetCallBack()</span><a name="l00297"></a>00297 <span class="comment">// Set pointer to CApplicationUi instance</span><a name="l00298"></a>00298 <span class="comment">// ----------------------------------------------------------------------------</span><a name="l00299"></a>00299 <span class="comment">//</span><a name="l00300"></a><a class="code" href="class_c_web_client_engine.html#d7945af2beb1efffbb94f6007b666d46">00300</a> <span class="keywordtype">void</span> <a class="code" href="class_c_web_client_engine.html#d7945af2beb1efffbb94f6007b666d46">CWebClientEngine::SetCallBack</a>( <a class="code" href="class_c_web_client_app_ui.html">CWebClientAppUi</a>* aCallBack )<a name="l00301"></a>00301 {<a name="l00302"></a>00302 <a class="code" href="class_c_web_client_engine.html#6da7cfd219226594e04b0bf1b29cd50d">iApplicationUi</a> = aCallBack;<a name="l00303"></a>00303 }<a name="l00304"></a>00304 <a name="l00305"></a>00305 <span class="comment">// ----------------------------------------------------------------------------</span><a name="l00306"></a>00306 <span class="comment">// CWebClientEngine::MHFRunL()</span><a name="l00307"></a>00307 <span class="comment">// Inherited from MHTTPTransactionCallback</span><a name="l00308"></a>00308 <span class="comment">// Called by framework to pass transaction events.</span><a name="l00309"></a>00309 <span class="comment">// ----------------------------------------------------------------------------</span><a name="l00310"></a>00310 <span class="comment">//</span><a name="l00311"></a><a class="code" href="class_c_web_client_engine.html#5c546ad730e52f05cc98ad0dc9ed7461">00311</a> <span class="keywordtype">void</span> <a class="code" href="class_c_web_client_engine.html#5c546ad730e52f05cc98ad0dc9ed7461">CWebClientEngine::MHFRunL</a>( RHTTPTransaction aTransaction, <a name="l00312"></a>00312 <span class="keyword">const</span> THTTPEvent& aEvent )<a name="l00313"></a>00313 {<a name="l00314"></a>00314 <a name="l00315"></a>00315 <span class="keywordflow">switch</span> ( aEvent.iStatus ) <a name="l00316"></a>00316 {<a name="l00317"></a>00317 <span class="keywordflow">case</span> THTTPEvent::EGotResponseHeaders:<a name="l00318"></a>00318 {<a name="l00319"></a>00319 <span class="comment">// HTTP response headers have been received. Use</span><a name="l00320"></a>00320 <span class="comment">// aTransaction.Response() to get the response. However, it's not</span><a name="l00321"></a>00321 <span class="comment">// necessary to do anything with the response when this event occurs.</span><a name="l00322"></a>00322 <a name="l00323"></a>00323 <span class="comment">// Get HTTP status code from header (e.g. 200)</span><a name="l00324"></a>00324 RHTTPResponse resp = aTransaction.Response();<a name="l00325"></a>00325 TInt status = resp.StatusCode();<a name="l00326"></a>00326 <a name="l00327"></a>00327 <span class="comment">// Get status text (e.g. "OK")</span><a name="l00328"></a>00328 TBuf<KMaxStatusTextLength> statusText;<a name="l00329"></a>00329 statusText.Copy( resp.StatusText().DesC() );<a name="l00330"></a>00330 <a name="l00331"></a>00331 <span class="comment">// Load a string from the resource file and add status and status text</span><a name="l00332"></a>00332 HBufC* textResource = StringLoader::LoadLC( R_WEBCLIENT_HEADER_RECEIVED,<a name="l00333"></a>00333 statusText, status );<a name="l00334"></a>00334 <a class="code" href="class_c_web_client_engine.html#5598d19cc10719afd28055422087a200">iObserver</a>.<a class="code" href="class_m_web_client_observer.html#ba45586e3b6414e9a001aa362b83f6d3">ClientEvent</a>( *textResource );<a name="l00335"></a>00335 CleanupStack::PopAndDestroy( textResource );<a name="l00336"></a>00336 <a name="l00337"></a>00337 <span class="comment">// Display header field names and value</span><a name="l00338"></a>00338 <a class="code" href="class_c_web_client_engine.html#f0720cc791fe8b50eff81b4af13e9f89">DumpRespHeadersL</a>( aTransaction );<a name="l00339"></a>00339 <a name="l00340"></a>00340 }<a name="l00341"></a>00341 <span class="keywordflow">break</span>;<a name="l00342"></a>00342 <a name="l00343"></a>00343 <span class="keywordflow">case</span> THTTPEvent::EGotResponseBodyData:<a name="l00344"></a>00344 {<a name="l00345"></a>00345 <span class="comment">// Part (or all) of response's body data received. Use </span><a name="l00346"></a>00346 <span class="comment">// aTransaction.Response().Body()->GetNextDataPart() to get the actual</span><a name="l00347"></a>00347 <span class="comment">// body data.</span><a name="l00348"></a>00348 <a name="l00349"></a>00349 <span class="comment">// Get the body data supplier</span><a name="l00350"></a>00350 MHTTPDataSupplier* body = aTransaction.Response().Body();<a name="l00351"></a>00351 TPtrC8 dataChunk;<a name="l00352"></a>00352 <a name="l00353"></a>00353 <span class="comment">// GetNextDataPart() returns ETrue, if the received part is the last </span><a name="l00354"></a>00354 <span class="comment">// one.</span><a name="l00355"></a>00355 TBool isLast = body->GetNextDataPart( dataChunk );<a name="l00356"></a>00356 <a class="code" href="class_c_web_client_engine.html#5598d19cc10719afd28055422087a200">iObserver</a>.<a class="code" href="class_m_web_client_observer.html#50e49839449e3e1580d570d67eb956e8">ClientBodyReceived</a>( dataChunk );<a name="l00357"></a>00357 <a name="l00358"></a>00358 <span class="comment">// Load a string from the resource file and add data length to string</span><a name="l00359"></a>00359 HBufC* textResource = StringLoader::LoadLC( R_WEBCLIENT_BODY_PART_RECEIVED,<a name="l00360"></a>00360 dataChunk.Length() );<a name="l00361"></a>00361 <a class="code" href="class_c_web_client_engine.html#5598d19cc10719afd28055422087a200">iObserver</a>.<a class="code" href="class_m_web_client_observer.html#ba45586e3b6414e9a001aa362b83f6d3">ClientEvent</a>( *textResource );<a name="l00362"></a>00362 CleanupStack::PopAndDestroy( textResource );<a name="l00363"></a>00363 <a name="l00364"></a>00364 <span class="comment">// NOTE: isLast may not be ETrue even if last data part received.</span><a name="l00365"></a>00365 <span class="comment">// (e.g. multipart response without content length field)</span><a name="l00366"></a>00366 <span class="comment">// Use EResponseComplete to reliably determine when body is completely</span><a name="l00367"></a>00367 <span class="comment">// received.</span><a name="l00368"></a>00368 <span class="keywordflow">if</span> (isLast)<a name="l00369"></a>00369 {<a name="l00370"></a>00370 HBufC* textResource = StringLoader::LoadLC( R_WEBCLIENT_BODY_RECEIVED );<a name="l00371"></a>00371 <a class="code" href="class_c_web_client_engine.html#5598d19cc10719afd28055422087a200">iObserver</a>.<a class="code" href="class_m_web_client_observer.html#ba45586e3b6414e9a001aa362b83f6d3">ClientEvent</a>( *textResource );<a name="l00372"></a>00372 CleanupStack::PopAndDestroy( textResource );<a name="l00373"></a>00373 }<a name="l00374"></a>00374 <a name="l00375"></a>00375 <span class="comment">// Always remember to release the body data.</span><a name="l00376"></a>00376 body->ReleaseData();<a name="l00377"></a>00377 }<a name="l00378"></a>00378 <span class="keywordflow">break</span>;<a name="l00379"></a>00379 <a name="l00380"></a>00380 <span class="keywordflow">case</span> THTTPEvent::EResponseComplete:<a name="l00381"></a>00381 {<a name="l00382"></a>00382 <span class="comment">// Indicates that header & body of response is completely received.</span><a name="l00383"></a>00383 <span class="comment">// No further action here needed.</span><a name="l00384"></a>00384 HBufC* textResource = StringLoader::LoadLC( R_WEBCLIENT_TRANSACTION_COMPLETE );<a name="l00385"></a>00385 <a class="code" href="class_c_web_client_engine.html#5598d19cc10719afd28055422087a200">iObserver</a>.<a class="code" href="class_m_web_client_observer.html#ba45586e3b6414e9a001aa362b83f6d3">ClientEvent</a>( *textResource );<a name="l00386"></a>00386 CleanupStack::PopAndDestroy( textResource );<a name="l00387"></a>00387 }<a name="l00388"></a>00388 <span class="keywordflow">break</span>;<a name="l00389"></a>00389 <a name="l00390"></a>00390 <span class="keywordflow">case</span> THTTPEvent::ESucceeded:<a name="l00391"></a>00391 {<a name="l00392"></a>00392 <span class="comment">// Indicates that transaction succeeded. </span><a name="l00393"></a>00393 HBufC* textResource = StringLoader::LoadLC( R_WEBCLIENT_TRANSACTION_SUCCEED );<a name="l00394"></a>00394 <a class="code" href="class_c_web_client_engine.html#5598d19cc10719afd28055422087a200">iObserver</a>.<a class="code" href="class_m_web_client_observer.html#ba45586e3b6414e9a001aa362b83f6d3">ClientEvent</a>( *textResource );<a name="l00395"></a>00395 CleanupStack::PopAndDestroy( textResource );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -