1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Wt examples: SimpleChatServer Class Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td style="padding-left: 0.5em;">
<div id="projectname">Wt examples
 <span id="projectnumber">3.2.1</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- Generated by Doxygen 1.7.5.1 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
<li class="current"><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div id="navrow2" class="tabs2">
<ul class="tablist">
<li><a href="annotated.html"><span>Class List</span></a></li>
<li><a href="inherits.html"><span>Class Hierarchy</span></a></li>
<li><a href="functions.html"><span>Class Members</span></a></li>
</ul>
</div>
</div>
<div class="header">
<div class="summary">
<a href="#nested-classes">Classes</a> |
<a href="#pub-types">Public Types</a> |
<a href="#pub-methods">Public Member Functions</a> |
<a href="#pri-types">Private Types</a> |
<a href="#pri-methods">Private Member Functions</a> |
<a href="#pri-attribs">Private Attributes</a> </div>
<div class="headertitle">
<div class="title">SimpleChatServer Class Reference<div class="ingroups"><a class="el" href="group__chatexample.html">Chat example</a></div></div> </div>
</div>
<div class="contents">
<!-- doxytag: class="SimpleChatServer" -->
<p>A simple chat server.
<a href="classSimpleChatServer.html#details">More...</a></p>
<p><code>#include <<a class="el" href="SimpleChatServer_8h_source.html">SimpleChatServer.h</a>></code></p>
<p><a href="classSimpleChatServer-members.html">List of all members.</a></p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="nested-classes"></a>
Classes</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">class  </td><td class="memItemRight" valign="bottom"><a class="el" href="classSimpleChatServer_1_1Client.html">Client</a></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">struct  </td><td class="memItemRight" valign="bottom"><a class="el" href="structSimpleChatServer_1_1ClientInfo.html">ClientInfo</a></td></tr>
<tr><td colspan="2"><h2><a name="pub-types"></a>
Public Types</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">typedef std::set< <a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a> > </td><td class="memItemRight" valign="bottom"><a class="el" href="classSimpleChatServer.html#a911329f24472ca7ed245ab18611488d4">UserSet</a></td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Typedef for a collection of user names. <a href="#a911329f24472ca7ed245ab18611488d4"></a><br/></td></tr>
<tr><td colspan="2"><h2><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classSimpleChatServer.html#a2cf35cb3b79c6a3d3815df92b25b713e">SimpleChatServer</a> (<a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WServer.html">Wt::WServer</a> &server)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Create a new chat server. <a href="#a2cf35cb3b79c6a3d3815df92b25b713e"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="classSimpleChatServer.html#a916cec08c2aeb2d2ccf413e9c9a45036">connect</a> (<a class="el" href="classSimpleChatServer_1_1Client.html">Client</a> *client, const <a class="el" href="group__chatexample.html#ga0b33bac2811bf39b0ea9412e91c3d4e7">ChatEventCallback</a> &handleEvent)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Connects to the chat server. <a href="#a916cec08c2aeb2d2ccf413e9c9a45036"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="classSimpleChatServer.html#a070e07e1a2a5ec5ecc4e944a761256c9">disconnect</a> (<a class="el" href="classSimpleChatServer_1_1Client.html">Client</a> *client)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Disconnect from the chat server. <a href="#a070e07e1a2a5ec5ecc4e944a761256c9"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="classSimpleChatServer.html#ada0ab17464e1711ca15f30b381ede57c">login</a> (const <a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a> &user)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Try to login with given user name. <a href="#ada0ab17464e1711ca15f30b381ede57c"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classSimpleChatServer.html#a5d376e3ff441f24843be648dd420e027">logout</a> (const <a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a> &user)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Logout from the server. <a href="#a5d376e3ff441f24843be648dd420e027"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="classSimpleChatServer.html#a0154462f2176611e8c44d93efe306283">changeName</a> (const <a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a> &user, const <a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a> &newUser)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Changes the name. <a href="#a0154462f2176611e8c44d93efe306283"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classSimpleChatServer.html#abf692567706118193111c2b2589c8d3f">suggestGuest</a> ()</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Get a suggestion for a guest user name. <a href="#abf692567706118193111c2b2589c8d3f"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classSimpleChatServer.html#aab42074f7904397b3547a6df89c16d9d">sendMessage</a> (const <a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a> &user, const <a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a> &message)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Send a message on behalve of a user. <a href="#aab42074f7904397b3547a6df89c16d9d"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="el" href="classSimpleChatServer.html#a911329f24472ca7ed245ab18611488d4">UserSet</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classSimpleChatServer.html#a40f5c6465b1edb44278be93c97a29a39">users</a> ()</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Get the users currently logged in. <a href="#a40f5c6465b1edb44278be93c97a29a39"></a><br/></td></tr>
<tr><td colspan="2"><h2><a name="pri-types"></a>
Private Types</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">typedef std::map< <a class="el" href="classSimpleChatServer_1_1Client.html">Client</a> <br class="typebreak"/>
*, <a class="el" href="structSimpleChatServer_1_1ClientInfo.html">ClientInfo</a> > </td><td class="memItemRight" valign="bottom"><a class="el" href="classSimpleChatServer.html#a2a3c1f56445447ee41294bd2b339a8ed">ClientMap</a></td></tr>
<tr><td colspan="2"><h2><a name="pri-methods"></a>
Private Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classSimpleChatServer.html#a5038714fb4463072bd795fea419e6f09">postChatEvent</a> (const <a class="el" href="classChatEvent.html">ChatEvent</a> &event)</td></tr>
<tr><td colspan="2"><h2><a name="pri-attribs"></a>
Private Attributes</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WServer.html">Wt::WServer</a> & </td><td class="memItemRight" valign="bottom"><a class="el" href="classSimpleChatServer.html#ab63a496e6fdfebbb2ca3ab9dfaace70b">server_</a></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">boost::recursive_mutex </td><td class="memItemRight" valign="bottom"><a class="el" href="classSimpleChatServer.html#a91a994a5f6fb9879646dfd29f0b47556">mutex_</a></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="el" href="classSimpleChatServer.html#a2a3c1f56445447ee41294bd2b339a8ed">ClientMap</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classSimpleChatServer.html#ae04169217cc74765f5d08fff55e8ee26">clients_</a></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="el" href="classSimpleChatServer.html#a911329f24472ca7ed245ab18611488d4">UserSet</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classSimpleChatServer.html#ae6712308cbb1f6b1ff4024630ea1d20c">users_</a></td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><p>A simple chat server. </p>
<p>Definition at line <a class="el" href="SimpleChatServer_8h_source.html#l00085">85</a> of file <a class="el" href="SimpleChatServer_8h_source.html">SimpleChatServer.h</a>.</p>
</div><hr/><h2>Member Typedef Documentation</h2>
<a class="anchor" id="a2a3c1f56445447ee41294bd2b339a8ed"></a><!-- doxytag: member="SimpleChatServer::ClientMap" ref="a2a3c1f56445447ee41294bd2b339a8ed" args="" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">typedef std::map<<a class="el" href="classSimpleChatServer_1_1Client.html">Client</a> *, <a class="el" href="structSimpleChatServer_1_1ClientInfo.html">ClientInfo</a>> <a class="el" href="classSimpleChatServer.html#a2a3c1f56445447ee41294bd2b339a8ed">SimpleChatServer::ClientMap</a><code> [private]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Definition at line <a class="el" href="SimpleChatServer_8h_source.html#l00152">152</a> of file <a class="el" href="SimpleChatServer_8h_source.html">SimpleChatServer.h</a>.</p>
</div>
</div>
<a class="anchor" id="a911329f24472ca7ed245ab18611488d4"></a><!-- doxytag: member="SimpleChatServer::UserSet" ref="a911329f24472ca7ed245ab18611488d4" args="" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">typedef std::set<<a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a>> <a class="el" href="classSimpleChatServer.html#a911329f24472ca7ed245ab18611488d4">SimpleChatServer::UserSet</a></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Typedef for a collection of user names. </p>
<p>Definition at line <a class="el" href="SimpleChatServer_8h_source.html#l00140">140</a> of file <a class="el" href="SimpleChatServer_8h_source.html">SimpleChatServer.h</a>.</p>
</div>
</div>
<hr/><h2>Constructor & Destructor Documentation</h2>
<a class="anchor" id="a2cf35cb3b79c6a3d3815df92b25b713e"></a><!-- doxytag: member="SimpleChatServer::SimpleChatServer" ref="a2cf35cb3b79c6a3d3815df92b25b713e" args="(Wt::WServer &server)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">SimpleChatServer::SimpleChatServer </td>
<td>(</td>
<td class="paramtype"><a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WServer.html">Wt::WServer</a> & </td>
<td class="paramname"><em>server</em></td><td>)</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Create a new chat server. </p>
<p>Definition at line <a class="el" href="SimpleChatServer_8C_source.html#l00057">57</a> of file <a class="el" href="SimpleChatServer_8C_source.html">SimpleChatServer.C</a>.</p>
<div class="fragment"><pre class="fragment"> : <a class="code" href="classSimpleChatServer.html#ab63a496e6fdfebbb2ca3ab9dfaace70b">server_</a>(server)
{ }
</pre></div>
</div>
</div>
<hr/><h2>Member Function Documentation</h2>
<a class="anchor" id="a0154462f2176611e8c44d93efe306283"></a><!-- doxytag: member="SimpleChatServer::changeName" ref="a0154462f2176611e8c44d93efe306283" args="(const Wt::WString &user, const Wt::WString &newUser)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">bool SimpleChatServer::changeName </td>
<td>(</td>
<td class="paramtype">const <a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a> & </td>
<td class="paramname"><em>user</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const <a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a> & </td>
<td class="paramname"><em>newUser</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Changes the name. </p>
<p>Definition at line <a class="el" href="SimpleChatServer_8C_source.html#l00113">113</a> of file <a class="el" href="SimpleChatServer_8C_source.html">SimpleChatServer.C</a>.</p>
<div class="fragment"><pre class="fragment">{
<span class="keywordflow">if</span> (user == newUser)
<span class="keywordflow">return</span> <span class="keyword">true</span>;
boost::recursive_mutex::scoped_lock lock(<a class="code" href="classSimpleChatServer.html#a91a994a5f6fb9879646dfd29f0b47556">mutex_</a>);
UserSet::iterator i = <a class="code" href="classSimpleChatServer.html#ae6712308cbb1f6b1ff4024630ea1d20c">users_</a>.find(user);
<span class="keywordflow">if</span> (i != <a class="code" href="classSimpleChatServer.html#ae6712308cbb1f6b1ff4024630ea1d20c">users_</a>.end()) {
<span class="keywordflow">if</span> (<a class="code" href="classSimpleChatServer.html#ae6712308cbb1f6b1ff4024630ea1d20c">users_</a>.count(newUser) == 0) {
<a class="code" href="classSimpleChatServer.html#ae6712308cbb1f6b1ff4024630ea1d20c">users_</a>.erase(i);
<a class="code" href="classSimpleChatServer.html#ae6712308cbb1f6b1ff4024630ea1d20c">users_</a>.insert(newUser);
<a class="code" href="classSimpleChatServer.html#a5038714fb4463072bd795fea419e6f09">postChatEvent</a>(<a class="code" href="classChatEvent.html" title="Encapsulate a chat event.">ChatEvent</a>(<a class="code" href="classChatEvent.html#afa84446dae17c08fe15cf932fc0b7d61ab168d89affa0c72ba9a37d2881479ed8">ChatEvent::Rename</a>, user, newUser));
<span class="keywordflow">return</span> <span class="keyword">true</span>;
} <span class="keywordflow">else</span>
<span class="keywordflow">return</span> <span class="keyword">false</span>;
} <span class="keywordflow">else</span>
<span class="keywordflow">return</span> <span class="keyword">false</span>;
}
</pre></div>
</div>
</div>
<a class="anchor" id="a916cec08c2aeb2d2ccf413e9c9a45036"></a><!-- doxytag: member="SimpleChatServer::connect" ref="a916cec08c2aeb2d2ccf413e9c9a45036" args="(Client *client, const ChatEventCallback &handleEvent)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">bool SimpleChatServer::connect </td>
<td>(</td>
<td class="paramtype"><a class="el" href="classSimpleChatServer_1_1Client.html">Client</a> * </td>
<td class="paramname"><em>client</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const <a class="el" href="group__chatexample.html#ga0b33bac2811bf39b0ea9412e91c3d4e7">ChatEventCallback</a> & </td>
<td class="paramname"><em>handleEvent</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Connects to the chat server. </p>
<p>The passed callback method is posted to when a new chat event is received.</p>
<p>Returns whether the client has been connected (or false if the client was already connected). </p>
<p>Definition at line <a class="el" href="SimpleChatServer_8C_source.html#l00061">61</a> of file <a class="el" href="SimpleChatServer_8C_source.html">SimpleChatServer.C</a>.</p>
<div class="fragment"><pre class="fragment">{
boost::recursive_mutex::scoped_lock lock(<a class="code" href="classSimpleChatServer.html#a91a994a5f6fb9879646dfd29f0b47556">mutex_</a>);
<span class="keywordflow">if</span> (<a class="code" href="classSimpleChatServer.html#ae04169217cc74765f5d08fff55e8ee26">clients_</a>.count(client) == 0) {
ClientInfo clientInfo;
clientInfo.sessionId = WApplication::instance()->sessionId();
clientInfo.eventCallback = handleEvent;
<a class="code" href="classSimpleChatServer.html#ae04169217cc74765f5d08fff55e8ee26">clients_</a>[client] = clientInfo;
<span class="keywordflow">return</span> <span class="keyword">true</span>;
} <span class="keywordflow">else</span>
<span class="keywordflow">return</span> <span class="keyword">false</span>;
}
</pre></div>
</div>
</div>
<a class="anchor" id="a070e07e1a2a5ec5ecc4e944a761256c9"></a><!-- doxytag: member="SimpleChatServer::disconnect" ref="a070e07e1a2a5ec5ecc4e944a761256c9" args="(Client *client)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">bool SimpleChatServer::disconnect </td>
<td>(</td>
<td class="paramtype"><a class="el" href="classSimpleChatServer_1_1Client.html">Client</a> * </td>
<td class="paramname"><em>client</em></td><td>)</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Disconnect from the chat server. </p>
<p>Returns whether the client has been disconnected (or false if the client was not connected). </p>
<p>Definition at line <a class="el" href="SimpleChatServer_8C_source.html#l00079">79</a> of file <a class="el" href="SimpleChatServer_8C_source.html">SimpleChatServer.C</a>.</p>
<div class="fragment"><pre class="fragment">{
boost::recursive_mutex::scoped_lock lock(<a class="code" href="classSimpleChatServer.html#a91a994a5f6fb9879646dfd29f0b47556">mutex_</a>);
<span class="keywordflow">return</span> <a class="code" href="classSimpleChatServer.html#ae04169217cc74765f5d08fff55e8ee26">clients_</a>.erase(client) == 1;
}
</pre></div>
</div>
</div>
<a class="anchor" id="ada0ab17464e1711ca15f30b381ede57c"></a><!-- doxytag: member="SimpleChatServer::login" ref="ada0ab17464e1711ca15f30b381ede57c" args="(const Wt::WString &user)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">bool SimpleChatServer::login </td>
<td>(</td>
<td class="paramtype">const <a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a> & </td>
<td class="paramname"><em>user</em></td><td>)</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Try to login with given user name. </p>
<p>Returns false if the login was not successful. </p>
<p>Definition at line <a class="el" href="SimpleChatServer_8C_source.html#l00086">86</a> of file <a class="el" href="SimpleChatServer_8C_source.html">SimpleChatServer.C</a>.</p>
<div class="fragment"><pre class="fragment">{
boost::recursive_mutex::scoped_lock lock(<a class="code" href="classSimpleChatServer.html#a91a994a5f6fb9879646dfd29f0b47556">mutex_</a>);
<span class="keywordflow">if</span> (<a class="code" href="classSimpleChatServer.html#ae6712308cbb1f6b1ff4024630ea1d20c">users_</a>.find(user) == <a class="code" href="classSimpleChatServer.html#ae6712308cbb1f6b1ff4024630ea1d20c">users_</a>.end()) {
<a class="code" href="classSimpleChatServer.html#ae6712308cbb1f6b1ff4024630ea1d20c">users_</a>.insert(user);
<a class="code" href="classSimpleChatServer.html#a5038714fb4463072bd795fea419e6f09">postChatEvent</a>(<a class="code" href="classChatEvent.html" title="Encapsulate a chat event.">ChatEvent</a>(<a class="code" href="classChatEvent.html#afa84446dae17c08fe15cf932fc0b7d61a5173cb4baa818f95af4604d7a01e3ae6">ChatEvent::Login</a>, user));
<span class="keywordflow">return</span> <span class="keyword">true</span>;
} <span class="keywordflow">else</span>
<span class="keywordflow">return</span> <span class="keyword">false</span>;
}
</pre></div>
</div>
</div>
<a class="anchor" id="a5d376e3ff441f24843be648dd420e027"></a><!-- doxytag: member="SimpleChatServer::logout" ref="a5d376e3ff441f24843be648dd420e027" args="(const Wt::WString &user)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void SimpleChatServer::logout </td>
<td>(</td>
<td class="paramtype">const <a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a> & </td>
<td class="paramname"><em>user</em></td><td>)</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Logout from the server. </p>
<p>Definition at line <a class="el" href="SimpleChatServer_8C_source.html#l00100">100</a> of file <a class="el" href="SimpleChatServer_8C_source.html">SimpleChatServer.C</a>.</p>
<div class="fragment"><pre class="fragment">{
boost::recursive_mutex::scoped_lock lock(<a class="code" href="classSimpleChatServer.html#a91a994a5f6fb9879646dfd29f0b47556">mutex_</a>);
UserSet::iterator i = <a class="code" href="classSimpleChatServer.html#ae6712308cbb1f6b1ff4024630ea1d20c">users_</a>.find(user);
<span class="keywordflow">if</span> (i != <a class="code" href="classSimpleChatServer.html#ae6712308cbb1f6b1ff4024630ea1d20c">users_</a>.end()) {
<a class="code" href="classSimpleChatServer.html#ae6712308cbb1f6b1ff4024630ea1d20c">users_</a>.erase(i);
<a class="code" href="classSimpleChatServer.html#a5038714fb4463072bd795fea419e6f09">postChatEvent</a>(<a class="code" href="classChatEvent.html" title="Encapsulate a chat event.">ChatEvent</a>(<a class="code" href="classChatEvent.html#afa84446dae17c08fe15cf932fc0b7d61aa8b11c1512738c200b2cfe1facd1c171">ChatEvent::Logout</a>, user));
}
}
</pre></div>
</div>
</div>
<a class="anchor" id="a5038714fb4463072bd795fea419e6f09"></a><!-- doxytag: member="SimpleChatServer::postChatEvent" ref="a5038714fb4463072bd795fea419e6f09" args="(const ChatEvent &event)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void SimpleChatServer::postChatEvent </td>
<td>(</td>
<td class="paramtype">const <a class="el" href="classChatEvent.html">ChatEvent</a> & </td>
<td class="paramname"><em>event</em></td><td>)</td>
<td><code> [private]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Definition at line <a class="el" href="SimpleChatServer_8C_source.html#l00154">154</a> of file <a class="el" href="SimpleChatServer_8C_source.html">SimpleChatServer.C</a>.</p>
<div class="fragment"><pre class="fragment">{
boost::recursive_mutex::scoped_lock lock(<a class="code" href="classSimpleChatServer.html#a91a994a5f6fb9879646dfd29f0b47556">mutex_</a>);
<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html">WApplication</a> *app = WApplication::instance();
<span class="keywordflow">for</span> (ClientMap::const_iterator i = <a class="code" href="classSimpleChatServer.html#ae04169217cc74765f5d08fff55e8ee26">clients_</a>.begin(); i != <a class="code" href="classSimpleChatServer.html#ae04169217cc74765f5d08fff55e8ee26">clients_</a>.end();
++i) {
<span class="comment">/*</span>
<span class="comment"> * If the user corresponds to the current application, we directly</span>
<span class="comment"> * call the call back method. This avoids an unnecessary delay for</span>
<span class="comment"> * the update to the user causing the event.</span>
<span class="comment"> *</span>
<span class="comment"> * For other uses, we post it to their session. By posting the</span>
<span class="comment"> * event, we avoid dead-lock scenarios, race conditions, and</span>
<span class="comment"> * delivering the event to a session that is just about to be</span>
<span class="comment"> * terminated.</span>
<span class="comment"> */</span>
<span class="keywordflow">if</span> (app && app-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html#ab55c625a3197fec416544be8ad1529af">sessionId</a>() == i->second.sessionId)
i->second.eventCallback(event);
<span class="keywordflow">else</span>
<a class="code" href="classSimpleChatServer.html#ab63a496e6fdfebbb2ca3ab9dfaace70b">server_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WServer.html#a6115cc9ad6ec28e55fb85e32a045df88">post</a>(i->second.sessionId,
boost::bind(i->second.eventCallback, event));
}
}
</pre></div>
</div>
</div>
<a class="anchor" id="aab42074f7904397b3547a6df89c16d9d"></a><!-- doxytag: member="SimpleChatServer::sendMessage" ref="aab42074f7904397b3547a6df89c16d9d" args="(const Wt::WString &user, const Wt::WString &message)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void SimpleChatServer::sendMessage </td>
<td>(</td>
<td class="paramtype">const <a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a> & </td>
<td class="paramname"><em>user</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const <a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a> & </td>
<td class="paramname"><em>message</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Send a message on behalve of a user. </p>
<p>Definition at line <a class="el" href="SimpleChatServer_8C_source.html#l00149">149</a> of file <a class="el" href="SimpleChatServer_8C_source.html">SimpleChatServer.C</a>.</p>
<div class="fragment"><pre class="fragment">{
<a class="code" href="classSimpleChatServer.html#a5038714fb4463072bd795fea419e6f09">postChatEvent</a>(<a class="code" href="classChatEvent.html" title="Encapsulate a chat event.">ChatEvent</a>(user, message));
}
</pre></div>
</div>
</div>
<a class="anchor" id="abf692567706118193111c2b2589c8d3f"></a><!-- doxytag: member="SimpleChatServer::suggestGuest" ref="abf692567706118193111c2b2589c8d3f" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">WString</a> SimpleChatServer::suggestGuest </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Get a suggestion for a guest user name. </p>
<p>Definition at line <a class="el" href="SimpleChatServer_8C_source.html#l00136">136</a> of file <a class="el" href="SimpleChatServer_8C_source.html">SimpleChatServer.C</a>.</p>
<div class="fragment"><pre class="fragment">{
boost::recursive_mutex::scoped_lock lock(<a class="code" href="classSimpleChatServer.html#a91a994a5f6fb9879646dfd29f0b47556">mutex_</a>);
<span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 1;; ++i) {
std::string s = <span class="stringliteral">"guest "</span> + boost::lexical_cast<std::string>(i);
<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">WString</a> ss = s;
<span class="keywordflow">if</span> (<a class="code" href="classSimpleChatServer.html#ae6712308cbb1f6b1ff4024630ea1d20c">users_</a>.find(ss) == <a class="code" href="classSimpleChatServer.html#ae6712308cbb1f6b1ff4024630ea1d20c">users_</a>.end())
<span class="keywordflow">return</span> ss;
}
}
</pre></div>
</div>
</div>
<a class="anchor" id="a40f5c6465b1edb44278be93c97a29a39"></a><!-- doxytag: member="SimpleChatServer::users" ref="a40f5c6465b1edb44278be93c97a29a39" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="classSimpleChatServer.html#a911329f24472ca7ed245ab18611488d4">SimpleChatServer::UserSet</a> SimpleChatServer::users </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Get the users currently logged in. </p>
<p>Definition at line <a class="el" href="SimpleChatServer_8C_source.html#l00180">180</a> of file <a class="el" href="SimpleChatServer_8C_source.html">SimpleChatServer.C</a>.</p>
<div class="fragment"><pre class="fragment">{
boost::recursive_mutex::scoped_lock lock(<a class="code" href="classSimpleChatServer.html#a91a994a5f6fb9879646dfd29f0b47556">mutex_</a>);
<a class="code" href="classSimpleChatServer.html#a911329f24472ca7ed245ab18611488d4" title="Typedef for a collection of user names.">UserSet</a> result = <a class="code" href="classSimpleChatServer.html#ae6712308cbb1f6b1ff4024630ea1d20c">users_</a>;
<span class="keywordflow">return</span> result;
}
</pre></div>
</div>
</div>
<hr/><h2>Member Data Documentation</h2>
<a class="anchor" id="ae04169217cc74765f5d08fff55e8ee26"></a><!-- doxytag: member="SimpleChatServer::clients_" ref="ae04169217cc74765f5d08fff55e8ee26" args="" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="classSimpleChatServer.html#a2a3c1f56445447ee41294bd2b339a8ed">ClientMap</a> <a class="el" href="classSimpleChatServer.html#ae04169217cc74765f5d08fff55e8ee26">SimpleChatServer::clients_</a><code> [private]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Definition at line <a class="el" href="SimpleChatServer_8h_source.html#l00156">156</a> of file <a class="el" href="SimpleChatServer_8h_source.html">SimpleChatServer.h</a>.</p>
</div>
</div>
<a class="anchor" id="a91a994a5f6fb9879646dfd29f0b47556"></a><!-- doxytag: member="SimpleChatServer::mutex_" ref="a91a994a5f6fb9879646dfd29f0b47556" args="" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">boost::recursive_mutex <a class="el" href="classSimpleChatServer.html#a91a994a5f6fb9879646dfd29f0b47556">SimpleChatServer::mutex_</a><code> [private]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Definition at line <a class="el" href="SimpleChatServer_8h_source.html#l00155">155</a> of file <a class="el" href="SimpleChatServer_8h_source.html">SimpleChatServer.h</a>.</p>
</div>
</div>
<a class="anchor" id="ab63a496e6fdfebbb2ca3ab9dfaace70b"></a><!-- doxytag: member="SimpleChatServer::server_" ref="ab63a496e6fdfebbb2ca3ab9dfaace70b" args="" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WServer.html">Wt::WServer</a>& <a class="el" href="classSimpleChatServer.html#ab63a496e6fdfebbb2ca3ab9dfaace70b">SimpleChatServer::server_</a><code> [private]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Definition at line <a class="el" href="SimpleChatServer_8h_source.html#l00154">154</a> of file <a class="el" href="SimpleChatServer_8h_source.html">SimpleChatServer.h</a>.</p>
</div>
</div>
<a class="anchor" id="ae6712308cbb1f6b1ff4024630ea1d20c"></a><!-- doxytag: member="SimpleChatServer::users_" ref="ae6712308cbb1f6b1ff4024630ea1d20c" args="" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="classSimpleChatServer.html#a911329f24472ca7ed245ab18611488d4">UserSet</a> <a class="el" href="classSimpleChatServer.html#ae6712308cbb1f6b1ff4024630ea1d20c">SimpleChatServer::users_</a><code> [private]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Definition at line <a class="el" href="SimpleChatServer_8h_source.html#l00157">157</a> of file <a class="el" href="SimpleChatServer_8h_source.html">SimpleChatServer.h</a>.</p>
</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li>/home/koen/project/wt/public-git/wt/examples/simplechat/<a class="el" href="SimpleChatServer_8h_source.html">SimpleChatServer.h</a></li>
<li>/home/koen/project/wt/public-git/wt/examples/simplechat/<a class="el" href="SimpleChatServer_8C_source.html">SimpleChatServer.C</a></li>
</ul>
</div>
<hr size="1"><address style="text-align: right; margin: 3px"><small>
Generated on Fri Mar 30 2012 for <a href="http://www.webtoolkit.eu/wt">the
C++ Web Toolkit (Wt)</a> by <a
href="http://www.doxygen.org/index.html"><img src="doxygen.png"
alt="doxygen" border="0" style="vertical-align: middle; display:
inline-block; height: 2em"></a> 1.7.5.1</small></address>
</body>
</html>
|