Sophie

Sophie

distrib > Fedora > 18 > x86_64 > by-pkgid > b3a1f4d91c26f535919e39e25606614a > files > 181

wt-doc-3.2.3-1.fc18.noarch.rpm

<!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: /home/koen/project/wt/public-git/wt/examples/simplechat/SimpleChatServer.h Source File</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
   &#160;<span id="projectnumber">3.2.3</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&#160;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><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">/home/koen/project/wt/public-git/wt/examples/simplechat/SimpleChatServer.h</div>  </div>
</div>
<div class="contents">
<a href="SimpleChatServer_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// This may look like C code, but it&#39;s really -*- C++ -*-</span>
<a name="l00002"></a>00002 <span class="comment">/*</span>
<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2008 Emweb bvba, Heverlee, Belgium.</span>
<a name="l00004"></a>00004 <span class="comment"> *</span>
<a name="l00005"></a>00005 <span class="comment"> * See the LICENSE file for terms of use.</span>
<a name="l00006"></a>00006 <span class="comment"> */</span>
<a name="l00007"></a>00007 <span class="preprocessor">#ifndef SIMPLECHATSERVER_H_</span>
<a name="l00008"></a>00008 <span class="preprocessor"></span><span class="preprocessor">#define SIMPLECHATSERVER_H_</span>
<a name="l00009"></a>00009 <span class="preprocessor"></span>
<a name="l00010"></a>00010 <span class="preprocessor">#include &lt;boost/noncopyable.hpp&gt;</span>
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 <span class="preprocessor">#include &lt;Wt/WSignal&gt;</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;Wt/WString&gt;</span>
<a name="l00014"></a>00014 
<a name="l00015"></a>00015 <span class="keyword">namespace </span>Wt {
<a name="l00016"></a>00016   <span class="keyword">class </span>WServer;
<a name="l00017"></a>00017 }
<a name="l00018"></a>00018 
<a name="l00019"></a>00019 <span class="preprocessor">#include &lt;set&gt;</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include &lt;map&gt;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;boost/thread.hpp&gt;</span>
<a name="l00022"></a>00022 
<a name="l00027"></a>00027 
<a name="l00030"></a><a class="code" href="classChatEvent.html">00030</a> <span class="keyword">class </span><a class="code" href="classChatEvent.html" title="Encapsulate a chat event.">ChatEvent</a>
<a name="l00031"></a>00031 {
<a name="l00032"></a>00032 <span class="keyword">public</span>:
<a name="l00035"></a><a class="code" href="classChatEvent.html#afa84446dae17c08fe15cf932fc0b7d61">00035</a>   <span class="keyword">enum</span> <a class="code" href="classChatEvent.html#afa84446dae17c08fe15cf932fc0b7d61" title="Enumeration for the event type.">Type</a> { <a class="code" href="classChatEvent.html#afa84446dae17c08fe15cf932fc0b7d61a5173cb4baa818f95af4604d7a01e3ae6">Login</a>, <a class="code" href="classChatEvent.html#afa84446dae17c08fe15cf932fc0b7d61aa8b11c1512738c200b2cfe1facd1c171">Logout</a>, <a class="code" href="classChatEvent.html#afa84446dae17c08fe15cf932fc0b7d61ab168d89affa0c72ba9a37d2881479ed8">Rename</a>, <a class="code" href="classChatEvent.html#afa84446dae17c08fe15cf932fc0b7d61ab8894351cd11a316e25495f677eb9ae1">Message</a> };
<a name="l00036"></a>00036 
<a name="l00039"></a><a class="code" href="classChatEvent.html#ac932234e63d23080f4f91f7ae1167418">00039</a>   <a class="code" href="classChatEvent.html#afa84446dae17c08fe15cf932fc0b7d61" title="Enumeration for the event type.">Type</a> <a class="code" href="classChatEvent.html#ac932234e63d23080f4f91f7ae1167418" title="Get the event type.">type</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classChatEvent.html#a8a55c20da17f812694469924b04bfd4c">type_</a>; }
<a name="l00040"></a>00040 
<a name="l00043"></a><a class="code" href="classChatEvent.html#adbeff19aece69e75ab0b69f2adecc5b6">00043</a>   <span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a>&amp; <a class="code" href="classChatEvent.html#adbeff19aece69e75ab0b69f2adecc5b6" title="Get the user who caused the event.">user</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classChatEvent.html#a3e2d08dca6b95343ad494e796a320eec">user_</a>; }
<a name="l00044"></a>00044 
<a name="l00047"></a><a class="code" href="classChatEvent.html#a1e73c4e7d9a59d790d4ba3a5bb36902d">00047</a>   <span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a>&amp; <a class="code" href="classChatEvent.html#a1e73c4e7d9a59d790d4ba3a5bb36902d" title="Get the message of the event.">message</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classChatEvent.html#ad51677c773550286593db4793dae62eb">message_</a>; }
<a name="l00048"></a>00048 
<a name="l00051"></a><a class="code" href="classChatEvent.html#a7a16dc199e1da813b8fc6bc155dc04e2">00051</a>   <span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a>&amp; <a class="code" href="classChatEvent.html#a7a16dc199e1da813b8fc6bc155dc04e2" title="Get the extra data for this event.">data</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classChatEvent.html#af24b35a3833777adff7e149383225e41">data_</a>; }
<a name="l00052"></a>00052 
<a name="l00057"></a>00057   <span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a> <a class="code" href="classChatEvent.html#a459911a1ba1c3e793c6c797e534691b7" title="Get the message formatted as HTML, rendered for the given user.">formattedHTML</a>(<span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a>&amp; <a class="code" href="classChatEvent.html#adbeff19aece69e75ab0b69f2adecc5b6" title="Get the user who caused the event.">user</a>,
<a name="l00058"></a>00058                                   <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#a140dea437d52d3d7c438ea3bd16a1480">Wt::TextFormat</a> format) <span class="keyword">const</span>;
<a name="l00059"></a>00059 
<a name="l00060"></a>00060 <span class="keyword">private</span>:
<a name="l00061"></a><a class="code" href="classChatEvent.html#a8a55c20da17f812694469924b04bfd4c">00061</a>   <a class="code" href="classChatEvent.html#afa84446dae17c08fe15cf932fc0b7d61" title="Enumeration for the event type.">Type</a> <a class="code" href="classChatEvent.html#a8a55c20da17f812694469924b04bfd4c">type_</a>;
<a name="l00062"></a><a class="code" href="classChatEvent.html#a3e2d08dca6b95343ad494e796a320eec">00062</a>   <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a> <a class="code" href="classChatEvent.html#a3e2d08dca6b95343ad494e796a320eec">user_</a>;
<a name="l00063"></a><a class="code" href="classChatEvent.html#af24b35a3833777adff7e149383225e41">00063</a>   <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a> <a class="code" href="classChatEvent.html#af24b35a3833777adff7e149383225e41">data_</a>;
<a name="l00064"></a><a class="code" href="classChatEvent.html#ad51677c773550286593db4793dae62eb">00064</a>   <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a> <a class="code" href="classChatEvent.html#ad51677c773550286593db4793dae62eb">message_</a>;
<a name="l00065"></a>00065 
<a name="l00066"></a>00066   <span class="comment">/*</span>
<a name="l00067"></a>00067 <span class="comment">   * Both user and html will be formatted as html</span>
<a name="l00068"></a>00068 <span class="comment">   */</span>
<a name="l00069"></a><a class="code" href="classChatEvent.html#a87e8c95da862b11466c9de1c9039cf6b">00069</a>   <a class="code" href="classChatEvent.html#a87e8c95da862b11466c9de1c9039cf6b">ChatEvent</a>(<span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a>&amp; <a class="code" href="classChatEvent.html#adbeff19aece69e75ab0b69f2adecc5b6" title="Get the user who caused the event.">user</a>, <span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a>&amp; <a class="code" href="classChatEvent.html#a1e73c4e7d9a59d790d4ba3a5bb36902d" title="Get the message of the event.">message</a>)
<a name="l00070"></a>00070     : <a class="code" href="classChatEvent.html#a8a55c20da17f812694469924b04bfd4c">type_</a>(<a class="code" href="classChatEvent.html#afa84446dae17c08fe15cf932fc0b7d61ab8894351cd11a316e25495f677eb9ae1">Message</a>), <a class="code" href="classChatEvent.html#a3e2d08dca6b95343ad494e796a320eec">user_</a>(user), <a class="code" href="classChatEvent.html#ad51677c773550286593db4793dae62eb">message_</a>(message)
<a name="l00071"></a>00071   { }
<a name="l00072"></a>00072 
<a name="l00073"></a><a class="code" href="classChatEvent.html#a78a7f54e8a39eb3448197461bcc7b125">00073</a>   <a class="code" href="classChatEvent.html#a87e8c95da862b11466c9de1c9039cf6b">ChatEvent</a>(<a class="code" href="classChatEvent.html#afa84446dae17c08fe15cf932fc0b7d61" title="Enumeration for the event type.">Type</a> <a class="code" href="classChatEvent.html#ac932234e63d23080f4f91f7ae1167418" title="Get the event type.">type</a>, <span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a>&amp; <a class="code" href="classChatEvent.html#adbeff19aece69e75ab0b69f2adecc5b6" title="Get the user who caused the event.">user</a>,
<a name="l00074"></a>00074             <span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a>&amp; <a class="code" href="classChatEvent.html#a7a16dc199e1da813b8fc6bc155dc04e2" title="Get the extra data for this event.">data</a> = <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html#a511a12bce677dc733bd7b6b9415bff73">Wt::WString::Empty</a>)
<a name="l00075"></a>00075     : <a class="code" href="classChatEvent.html#a8a55c20da17f812694469924b04bfd4c">type_</a>(type), <a class="code" href="classChatEvent.html#a3e2d08dca6b95343ad494e796a320eec">user_</a>(user), <a class="code" href="classChatEvent.html#af24b35a3833777adff7e149383225e41">data_</a>(<a class="code" href="classChatEvent.html#a7a16dc199e1da813b8fc6bc155dc04e2" title="Get the extra data for this event.">data</a>)
<a name="l00076"></a>00076   { }
<a name="l00077"></a>00077 
<a name="l00078"></a><a class="code" href="classChatEvent.html#ac99c17370c25b3c92dbb0578e4298ade">00078</a>   <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classSimpleChatServer.html" title="A simple chat server.">SimpleChatServer</a>;
<a name="l00079"></a>00079 };
<a name="l00080"></a>00080 
<a name="l00081"></a><a class="code" href="group__chatexample.html#ga0b33bac2811bf39b0ea9412e91c3d4e7">00081</a> <span class="keyword">typedef</span> boost::function&lt;void (const ChatEvent&amp;)&gt; <a class="code" href="group__chatexample.html#ga0b33bac2811bf39b0ea9412e91c3d4e7">ChatEventCallback</a>;
<a name="l00082"></a>00082 
<a name="l00085"></a><a class="code" href="classSimpleChatServer.html">00085</a> <span class="keyword">class </span><a class="code" href="classSimpleChatServer.html" title="A simple chat server.">SimpleChatServer</a> : boost::noncopyable
<a name="l00086"></a>00086 {
<a name="l00087"></a>00087 <span class="keyword">public</span>:
<a name="l00088"></a>00088   <span class="comment">/*</span>
<a name="l00089"></a>00089 <span class="comment">   * A reference to a client.</span>
<a name="l00090"></a>00090 <span class="comment">   */</span>
<a name="l00091"></a><a class="code" href="classSimpleChatServer_1_1Client.html">00091</a>   <span class="keyword">class </span><a class="code" href="classSimpleChatServer_1_1Client.html">Client</a>
<a name="l00092"></a>00092   {
<a name="l00093"></a>00093   };
<a name="l00094"></a>00094 
<a name="l00097"></a>00097   <a class="code" href="classSimpleChatServer.html#a2cf35cb3b79c6a3d3815df92b25b713e" title="Create a new chat server.">SimpleChatServer</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WServer.html">Wt::WServer</a>&amp; server);
<a name="l00098"></a>00098 
<a name="l00107"></a>00107   <span class="keywordtype">bool</span> <a class="code" href="classSimpleChatServer.html#a916cec08c2aeb2d2ccf413e9c9a45036" title="Connects to the chat server.">connect</a>(<a class="code" href="classSimpleChatServer_1_1Client.html">Client</a> *client, <span class="keyword">const</span> <a class="code" href="group__chatexample.html#ga0b33bac2811bf39b0ea9412e91c3d4e7">ChatEventCallback</a>&amp; handleEvent);
<a name="l00108"></a>00108 
<a name="l00114"></a>00114   <span class="keywordtype">bool</span> <a class="code" href="classSimpleChatServer.html#a070e07e1a2a5ec5ecc4e944a761256c9" title="Disconnect from the chat server.">disconnect</a>(<a class="code" href="classSimpleChatServer_1_1Client.html">Client</a> *client);
<a name="l00115"></a>00115 
<a name="l00120"></a>00120   <span class="keywordtype">bool</span> <a class="code" href="classSimpleChatServer.html#ada0ab17464e1711ca15f30b381ede57c" title="Try to login with given user name.">login</a>(<span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a>&amp; user);
<a name="l00121"></a>00121 
<a name="l00124"></a>00124   <span class="keywordtype">void</span> <a class="code" href="classSimpleChatServer.html#a5d376e3ff441f24843be648dd420e027" title="Logout from the server.">logout</a>(<span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a>&amp; user);
<a name="l00125"></a>00125 
<a name="l00128"></a>00128   <span class="keywordtype">bool</span> <a class="code" href="classSimpleChatServer.html#a0154462f2176611e8c44d93efe306283" title="Changes the name.">changeName</a>(<span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a>&amp; user, <span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a>&amp; newUser);
<a name="l00129"></a>00129 
<a name="l00132"></a>00132   <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a> <a class="code" href="classSimpleChatServer.html#abf692567706118193111c2b2589c8d3f" title="Get a suggestion for a guest user name.">suggestGuest</a>();
<a name="l00133"></a>00133 
<a name="l00136"></a>00136   <span class="keywordtype">void</span> <a class="code" href="classSimpleChatServer.html#aab42074f7904397b3547a6df89c16d9d" title="Send a message on behalve of a user.">sendMessage</a>(<span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a>&amp; user, <span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">Wt::WString</a>&amp; message);
<a name="l00137"></a>00137 
<a name="l00140"></a><a class="code" href="classSimpleChatServer.html#a911329f24472ca7ed245ab18611488d4">00140</a>   <span class="keyword">typedef</span> std::set&lt;Wt::WString&gt; <a class="code" href="classSimpleChatServer.html#a911329f24472ca7ed245ab18611488d4" title="Typedef for a collection of user names.">UserSet</a>;
<a name="l00141"></a>00141 
<a name="l00144"></a>00144   <a class="code" href="classSimpleChatServer.html#a911329f24472ca7ed245ab18611488d4" title="Typedef for a collection of user names.">UserSet</a> <a class="code" href="classSimpleChatServer.html#a40f5c6465b1edb44278be93c97a29a39" title="Get the users currently logged in.">users</a>();
<a name="l00145"></a>00145 
<a name="l00146"></a>00146 <span class="keyword">private</span>:
<a name="l00147"></a><a class="code" href="structSimpleChatServer_1_1ClientInfo.html">00147</a>   <span class="keyword">struct </span><a class="code" href="structSimpleChatServer_1_1ClientInfo.html">ClientInfo</a> {
<a name="l00148"></a><a class="code" href="structSimpleChatServer_1_1ClientInfo.html#a0bf0cce3b1da1a9de0a5073b3002f167">00148</a>     std::string <a class="code" href="structSimpleChatServer_1_1ClientInfo.html#a0bf0cce3b1da1a9de0a5073b3002f167">sessionId</a>;
<a name="l00149"></a><a class="code" href="structSimpleChatServer_1_1ClientInfo.html#ae410d9888b231e77ad48361e2da519b6">00149</a>     <a class="code" href="group__chatexample.html#ga0b33bac2811bf39b0ea9412e91c3d4e7">ChatEventCallback</a> <a class="code" href="structSimpleChatServer_1_1ClientInfo.html#ae410d9888b231e77ad48361e2da519b6">eventCallback</a>;
<a name="l00150"></a>00150   };
<a name="l00151"></a>00151 
<a name="l00152"></a><a class="code" href="classSimpleChatServer.html#a2a3c1f56445447ee41294bd2b339a8ed">00152</a>   <span class="keyword">typedef</span> std::map&lt;Client *, ClientInfo&gt; <a class="code" href="classSimpleChatServer.html#a2a3c1f56445447ee41294bd2b339a8ed">ClientMap</a>;
<a name="l00153"></a>00153 
<a name="l00154"></a><a class="code" href="classSimpleChatServer.html#ab63a496e6fdfebbb2ca3ab9dfaace70b">00154</a>   <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WServer.html">Wt::WServer</a>&amp; <a class="code" href="classSimpleChatServer.html#ab63a496e6fdfebbb2ca3ab9dfaace70b">server_</a>;
<a name="l00155"></a><a class="code" href="classSimpleChatServer.html#a91a994a5f6fb9879646dfd29f0b47556">00155</a>   boost::recursive_mutex <a class="code" href="classSimpleChatServer.html#a91a994a5f6fb9879646dfd29f0b47556">mutex_</a>;
<a name="l00156"></a><a class="code" href="classSimpleChatServer.html#ae04169217cc74765f5d08fff55e8ee26">00156</a>   <a class="code" href="classSimpleChatServer.html#a2a3c1f56445447ee41294bd2b339a8ed">ClientMap</a> <a class="code" href="classSimpleChatServer.html#ae04169217cc74765f5d08fff55e8ee26">clients_</a>;
<a name="l00157"></a><a class="code" href="classSimpleChatServer.html#ae6712308cbb1f6b1ff4024630ea1d20c">00157</a>   <a class="code" href="classSimpleChatServer.html#a911329f24472ca7ed245ab18611488d4" title="Typedef for a collection of user names.">UserSet</a> <a class="code" href="classSimpleChatServer.html#ae6712308cbb1f6b1ff4024630ea1d20c">users_</a>;
<a name="l00158"></a>00158 
<a name="l00159"></a>00159   <span class="keywordtype">void</span> <a class="code" href="classSimpleChatServer.html#a5038714fb4463072bd795fea419e6f09">postChatEvent</a>(<span class="keyword">const</span> <a class="code" href="classChatEvent.html" title="Encapsulate a chat event.">ChatEvent</a>&amp; event);
<a name="l00160"></a>00160 };
<a name="l00161"></a>00161 
<a name="l00164"></a>00164 <span class="preprocessor">#endif // SIMPLECHATSERVER_H_</span>
</pre></div></div>
</div>
<hr size="1"><address style="text-align: right; margin: 3px"><small>
Generated on Thu Nov 1 2012 for <a href="http://www.webtoolkit.eu/wt">the
C++ Web Toolkit (Wt)</a> by&nbsp;<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>