⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 _chat_bt_8cpp-source.html

📁 一个聊天的软件
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<a name="l00465"></a>00465         User::Leave( result ); <a name="l00466"></a>00466         }<a name="l00467"></a>00467 <a name="l00468"></a>00468    <a name="l00469"></a>00469     <span class="comment">// </span><a name="l00470"></a>00470     <span class="comment">// Set the Socket's security with parameters, </span><a name="l00471"></a>00471     <span class="comment">// Authentication, Encryption, Authorisation and Denied</span><a name="l00472"></a>00472     <span class="comment">// Method also return the channel available to listen to. </span><a name="l00473"></a>00473     TInt channel;<a name="l00474"></a>00474     <a class="code" href="class_c_chat_bt.html#0820a88dbf60867ff8bd16608ca82127">SetSecurityWithChannelL</a>( EFalse, EFalse, ETrue, EFalse, channel );<a name="l00475"></a>00475 <a name="l00476"></a>00476     <a class="code" href="class_c_chat_bt.html#c6e4669be42b0ffcebccf64b06d29163">iAdvertiser</a>-&gt;<a class="code" href="class_c_chat_bt_service_advertiser.html#9093b04fd818259d860c2018923de28d">StartAdvertisingL</a>( channel );<a name="l00477"></a>00477     <a class="code" href="class_c_chat_bt.html#c6e4669be42b0ffcebccf64b06d29163">iAdvertiser</a>-&gt;<a class="code" href="class_c_chat_bt_service_advertiser.html#29ff2152d04f8af97601d4a42d6ec6c0">UpdateAvailabilityL</a>( ETrue );<a name="l00478"></a>00478     <a name="l00479"></a>00479     <a class="code" href="class_c_chat_base.html#3632b5e9a01d31118bbf932b3cd23f34">SetServer</a>( ETrue );<a name="l00480"></a>00480 <a name="l00481"></a>00481     }<a name="l00482"></a>00482 <a name="l00483"></a>00483 <span class="comment">// ----------------------------------------------------------------------------</span><a name="l00484"></a>00484 <span class="comment">// CChatBt::SetSecurityWithChannelL( )</span><a name="l00485"></a>00485 <span class="comment">// Sets the security on the channel port and returns the available port.</span><a name="l00486"></a>00486 <span class="comment">// ----------------------------------------------------------------------------</span><a name="l00487"></a>00487 <span class="comment">//</span><a name="l00488"></a><a class="code" href="class_c_chat_bt.html#0820a88dbf60867ff8bd16608ca82127">00488</a> <span class="keywordtype">void</span> <a class="code" href="class_c_chat_bt.html#0820a88dbf60867ff8bd16608ca82127">CChatBt::SetSecurityWithChannelL</a>( <a name="l00489"></a>00489     TBool aAuthentication,<a name="l00490"></a>00490     TBool aEncryption,<a name="l00491"></a>00491     TBool aAuthorisation,<a name="l00492"></a>00492     TBool aDenied,<a name="l00493"></a>00493     TInt&amp; aChannel )<a name="l00494"></a>00494 <a name="l00495"></a>00495     {<a name="l00496"></a>00496 <a name="l00497"></a>00497     <span class="comment">// Local variable to channel to listen to.</span><a name="l00498"></a>00498     TInt channel;<a name="l00499"></a>00499 <a name="l00500"></a>00500 <a name="l00501"></a>00501     User::LeaveIfError( <a class="code" href="class_c_chat_bt.html#4791a9b2a2447d2068a89acb05c8c25b">iSocket</a>.GetOpt( <a name="l00502"></a>00502         KRFCOMMGetAvailableServerChannel, <a name="l00503"></a>00503         KSolBtRFCOMM, <a name="l00504"></a>00504         channel ) );<a name="l00505"></a>00505 <a name="l00506"></a>00506     TBTSockAddr listeningAddress;<a name="l00507"></a>00507     <span class="comment">// Set the Port to listen to.</span><a name="l00508"></a>00508     listeningAddress.SetPort( channel );<a name="l00509"></a>00509 <a name="l00510"></a>00510     <span class="comment">// Write Log events</span><a name="l00511"></a>00511     HBufC* strGetPort = StringLoader::LoadLC ( R_CHAT_STR_GET_PORT );<a name="l00512"></a>00512 <a name="l00513"></a>00513     <a class="code" href="class_c_chat_bt.html#9d387bbae93f2ae894f3e1c32e6bf1c6">iLog</a>.<a class="code" href="class_m_log.html#70fb5098d98a8b349c056b46102d5de9">LogL</a>( *strGetPort, channel );<a name="l00514"></a>00514     CleanupStack::PopAndDestroy( strGetPort );<a name="l00515"></a>00515 <a name="l00516"></a>00516 <a name="l00517"></a>00517     User::LeaveIfError( <a class="code" href="class_c_chat_bt.html#4791a9b2a2447d2068a89acb05c8c25b">iSocket</a>.Bind( listeningAddress ) );<a name="l00518"></a>00518     User::LeaveIfError( <a class="code" href="class_c_chat_bt.html#4791a9b2a2447d2068a89acb05c8c25b">iSocket</a>.Listen( KListeningQueSize ) );<a name="l00519"></a>00519 <a name="l00520"></a>00520      <span class="comment">// close old connection - if any</span><a name="l00521"></a>00521     <a class="code" href="class_c_chat_bt.html#43d47cb0a780f4af02110487231ac627">iAcceptedSocket</a>.Close();<a name="l00522"></a>00522 <a name="l00523"></a>00523     <span class="comment">// Open abstract socket</span><a name="l00524"></a>00524     User::LeaveIfError( <a class="code" href="class_c_chat_bt.html#43d47cb0a780f4af02110487231ac627">iAcceptedSocket</a>.Open( <a class="code" href="class_c_chat_bt.html#56bd53f21c6818eaa0d4a1ad2c7c5a84">iSocketServer</a> ) );  <a name="l00525"></a>00525 <a name="l00526"></a>00526     <span class="comment">// Set the Active Object's State to Connecting indicated.</span><a name="l00527"></a>00527     <a class="code" href="class_c_chat_base.html#deacd9f98d0548748cf116698aea2be0">SetState</a>( EConnecting );<a name="l00528"></a>00528 <a name="l00529"></a>00529     <a class="code" href="class_c_chat_bt.html#4791a9b2a2447d2068a89acb05c8c25b">iSocket</a>.Accept( <a class="code" href="class_c_chat_bt.html#43d47cb0a780f4af02110487231ac627">iAcceptedSocket</a>, iStatus );<a name="l00530"></a>00530   <a name="l00531"></a>00531     <a class="code" href="class_c_chat_bt.html#42435def2f80909f7700ad684c625f0f">iActiveSocket</a> = &amp;<a class="code" href="class_c_chat_bt.html#43d47cb0a780f4af02110487231ac627">iAcceptedSocket</a>;<a name="l00532"></a>00532   <a name="l00533"></a>00533     <span class="comment">// Set the Active Object Active again,</span><a name="l00534"></a>00534     SetActive();<a name="l00535"></a>00535 <a name="l00536"></a>00536     <span class="comment">// Write Log events</span><a name="l00537"></a>00537     HBufC* acceptNextConn = StringLoader::LoadLC ( <a name="l00538"></a>00538         R_CHAT_ACCEPT_NEXT_CONN );<a name="l00539"></a>00539     <a class="code" href="class_c_chat_bt.html#9d387bbae93f2ae894f3e1c32e6bf1c6">iLog</a>.<a class="code" href="class_m_log.html#70fb5098d98a8b349c056b46102d5de9">LogL</a>( *acceptNextConn );<a name="l00540"></a>00540     CleanupStack::PopAndDestroy( acceptNextConn );<a name="l00541"></a>00541 <a name="l00542"></a>00542  <a name="l00543"></a>00543     <span class="comment">// Set the security according to.</span><a name="l00544"></a>00544     TBTServiceSecurity serviceSecurity;<a name="l00545"></a>00545     serviceSecurity.SetUid ( KUidChatApp );<a name="l00546"></a>00546     serviceSecurity.SetAuthentication ( aAuthentication );<a name="l00547"></a>00547     serviceSecurity.SetEncryption ( aEncryption );<a name="l00548"></a>00548     serviceSecurity.SetAuthorisation ( aAuthorisation );<a name="l00549"></a>00549     serviceSecurity.SetDenied( aDenied );<a name="l00550"></a>00550 <a name="l00551"></a>00551     <span class="comment">// Attach the security settings.</span><a name="l00552"></a>00552     listeningAddress.SetSecurity(serviceSecurity);<a name="l00553"></a>00553 <a name="l00554"></a>00554     <span class="comment">// Return the port to listen to.</span><a name="l00555"></a>00555     aChannel = channel;<a name="l00556"></a>00556   <a name="l00557"></a>00557     }<a name="l00558"></a>00558                       <a name="l00559"></a>00559 <a name="l00560"></a>00560 <span class="comment">// ----------------------------------------------------------------------------</span><a name="l00561"></a>00561 <span class="comment">// CChatBt::StopL()</span><a name="l00562"></a>00562 <span class="comment">// Stops the server.</span><a name="l00563"></a>00563 <span class="comment">// ----------------------------------------------------------------------------</span><a name="l00564"></a>00564 <span class="comment">//</span><a name="l00565"></a><a class="code" href="class_c_chat_bt.html#b1104e8857d8028d35407cd7fa38c8df">00565</a> <span class="keywordtype">void</span> <a class="code" href="class_c_chat_bt.html#b1104e8857d8028d35407cd7fa38c8df">CChatBt::StopL</a>()<a name="l00566"></a>00566     {<a name="l00567"></a>00567     <span class="keywordflow">if</span> ( <a class="code" href="class_c_chat_base.html#af77e92297a4bac4704e440284577ebe">State</a>() != EDisconnected )<a name="l00568"></a>00568         {<a name="l00569"></a>00569         <span class="keywordflow">if</span> ( <a class="code" href="class_c_chat_bt.html#c6e4669be42b0ffcebccf64b06d29163">iAdvertiser</a>-&gt;<a class="code" href="class_c_chat_bt_service_advertiser.html#8b6ebb2e28d11dbf0c365fe8d479df10">IsAdvertising</a>() )<a name="l00570"></a>00570             {<a name="l00571"></a>00571             <a class="code" href="class_c_chat_bt.html#c6e4669be42b0ffcebccf64b06d29163">iAdvertiser</a>-&gt;<a class="code" href="class_c_chat_bt_service_advertiser.html#e66d57ea0fe5dcabfa4673a7b6adc47b">StopAdvertisingL</a>();<a name="l00572"></a>00572             }<a name="l00573"></a>00573         <span class="comment">// Close() will wait forever for Read to complete</span><a name="l00574"></a>00574         <span class="keywordflow">if</span> ( <a class="code" href="class_c_chat_base.html#af77e92297a4bac4704e440284577ebe">State</a>() == EConnected )<a name="l00575"></a>00575             {<a name="l00576"></a>00576             <span class="keywordflow">if</span> ( <a class="code" href="class_c_chat_bt.html#42435def2f80909f7700ad684c625f0f">iActiveSocket</a> )<a name="l00577"></a>00577                 {<a name="l00578"></a>00578                 iActiveSocket-&gt;CancelRead();<a name="l00579"></a>00579                 }<a name="l00580"></a>00580             }    <a name="l00581"></a>00581         <a class="code" href="class_c_chat_bt.html#43d47cb0a780f4af02110487231ac627">iAcceptedSocket</a>.Close();<a name="l00582"></a>00582         <a class="code" href="class_c_chat_bt.html#4791a9b2a2447d2068a89acb05c8c25b">iSocket</a>.Close();<a name="l00583"></a>00583         }<a name="l00584"></a>00584         SetState( EWaitingToGetDevice );<a name="l00585"></a>00585     }<a name="l00586"></a>00586 <a name="l00587"></a>00587 <span class="comment">// ----------------------------------------------------------------------------</span><a name="l00588"></a>00588 <span class="comment">// CChatBt::RequestData()</span><a name="l00589"></a>00589 <span class="comment">// Request data from the client.</span><a name="l00590"></a>00590 <span class="comment">// ----------------------------------------------------------------------------</span><a name="l00591"></a>00591 <span class="comment">//</span><a name="l00592"></a><a class="code" href="class_c_chat_bt.html#06e3ea78e9321c78ffb364082161da6c">00592</a> <span class="keywordtype">void</span> <a class="code" href="class_c_chat_bt.html#06e3ea78e9321c78ffb364082161da6c">CChatBt::RequestData</a>()<a name="l00593"></a>00593     {<a name="l00594"></a>00594     <span class="keywordflow">if</span> ( <a class="code" href="class_c_chat_bt.html#42435def2f80909f7700ad684c625f0f">iActiveSocket</a> )<a name="l00595"></a>00595         {<a name="l00596"></a>00596         <a class="code" href="class_c_chat_bt.html#42435def2f80909f7700ad684c625f0f">iActiveSocket</a>-&gt;RecvOneOrMore( <a class="code" href="class_c_chat_bt.html#04fb56a9c5c1c56ed0335a50a6065a82">iBuffer</a>, 0, iStatus, <a class="code" href="class_c_chat_bt.html#cb196e8158421aa29d9c132a8522e9b4">iLen</a> );<a name="l00597"></a>00597         }<a name="l00598"></a>00598     SetActive();<a name="l00599"></a>00599     }<a name="l00600"></a>00600 <a name="l00601"></a>00601 <span class="comment">// End of File</span></pre></div><hr><table x-use-null-cells		style="x-cell-content-align: top;				width: 100%;				border-spacing: 0px;				border-spacing: 0px;"		cellspacing=0		width=100%>  <col style="width: 50%;">  <col style="width: 50%;">  <tr style="x-cell-content-align: top;"	valign=top>  <td style="width: 50%;			padding-right: 10px;			padding-left: 10px;			border-right-style: None;			border-left-style: None;			border-top-style: None;			border-bottom-style: None;"	width=50%>  <p style="font-family: Arial;"><small style="font-size: smaller;">

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -