Click here to Skip to main content
15,881,709 members
Articles / Web Development / HTML

A C++ Embedded Web Server

Rate me:
Please Sign up or sign in to vote.
4.76/5 (47 votes)
23 Jun 2014BSD7 min read 448.6K   8.5K   209  
Give a C++ application its own web page
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>C:/Documents and Settings/james/My Documents/code/webem/world/cWebem.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.6-NO -->
<div class="tabs">
  <ul>
    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="annotated.html"><span>Classes</span></a></li>
    <li id="current"><a href="files.html"><span>Files</span></a></li>
  </ul></div>
<h1>C:/Documents and Settings/james/My Documents/code/webem/world/cWebem.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#pragma once</span>
<a name="l00002"></a>00002 <span class="preprocessor"></span>
<a name="l00003"></a>00003 <span class="preprocessor">#include &lt;map&gt;</span>
<a name="l00004"></a>00004 <span class="preprocessor">#include &lt;boost/function.hpp&gt;</span>
<a name="l00005"></a>00005 <span class="preprocessor">#include "server/server.hpp"</span>
<a name="l00006"></a>00006 
<a name="l00007"></a>00007 <span class="keyword">namespace </span>http {
<a name="l00008"></a>00008         <span class="keyword">namespace </span>server {
<a name="l00009"></a>00009 
<a name="l00036"></a>00036                 <span class="keyword">class </span>cWebem;
<a name="l00037"></a>00037                 <span class="keyword">typedef</span> boost::function&lt; char*() &gt; webem_include_function;
<a name="l00038"></a>00038                 <span class="keyword">typedef</span> boost::function&lt; wchar_t*() &gt; webem_include_function_w;
<a name="l00039"></a>00039                 <span class="keyword">typedef</span> boost::function&lt; char*( cWebem* ) &gt; webem_action_function;
<a name="l00040"></a>00040 
<a name="l00041"></a>00041 
<a name="l00051"></a><a class="code" href="classhttp_1_1server_1_1c_webem_request_handler.html">00051</a>                 <span class="keyword">class </span><a class="code" href="classhttp_1_1server_1_1c_webem_request_handler.html">cWebemRequestHandler</a> : <span class="keyword">public</span> request_handler
<a name="l00052"></a>00052                 {
<a name="l00053"></a>00053                 <span class="keyword">public</span>:
<a name="l00055"></a><a class="code" href="classhttp_1_1server_1_1c_webem_request_handler.html#4864092e57779786f13f0c5ca93029ee">00055</a>                         <a class="code" href="classhttp_1_1server_1_1c_webem_request_handler.html#4864092e57779786f13f0c5ca93029ee">cWebemRequestHandler</a>( <span class="keyword">const</span> std::string&amp; doc_root ) :
<a name="l00056"></a>00056                           request_handler( doc_root )
<a name="l00057"></a>00057                           {}
<a name="l00058"></a>00058 
<a name="l00059"></a>00059                           <span class="keywordtype">void</span> setWebem( <a class="code" href="classhttp_1_1server_1_1c_webem.html">cWebem</a>* webem ) { myWebem = webem; }
<a name="l00060"></a>00060 
<a name="l00062"></a>00062                           <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classhttp_1_1server_1_1c_webem_request_handler.html#62a055936f1100e457d97bbcb5570bed">handle_request</a>( <span class="keyword">const</span> request&amp; req, reply&amp; rep);
<a name="l00063"></a>00063 
<a name="l00064"></a>00064                 <span class="keyword">private</span>:
<a name="l00065"></a>00065                         <span class="comment">// Webem link to application code</span>
<a name="l00066"></a>00066                         cWebem* myWebem;
<a name="l00067"></a>00067 
<a name="l00068"></a>00068                 };
<a name="l00069"></a>00069 
<a name="l00075"></a><a class="code" href="classhttp_1_1server_1_1c_webem.html">00075</a>                 <span class="keyword">class </span><a class="code" href="classhttp_1_1server_1_1c_webem.html">cWebem</a>
<a name="l00076"></a>00076                 {
<a name="l00077"></a>00077                 <span class="keyword">public</span>:
<a name="l00078"></a>00078                         <a class="code" href="classhttp_1_1server_1_1c_webem.html#407df237556d03f0ce61da96f4c27784">cWebem</a>(
<a name="l00079"></a>00079                                 <span class="keyword">const</span> std::string&amp; address,
<a name="l00080"></a>00080                                 <span class="keyword">const</span> std::string&amp; port,
<a name="l00081"></a>00081                                 <span class="keyword">const</span> std::string&amp; doc_root );
<a name="l00082"></a>00082 
<a name="l00083"></a>00083                         <span class="keywordtype">void</span> <a class="code" href="classhttp_1_1server_1_1c_webem.html#74f874a1701e9db90def357499d2514f">Run</a>();
<a name="l00084"></a>00084 
<a name="l00085"></a>00085                         <span class="keywordtype">void</span> <a class="code" href="classhttp_1_1server_1_1c_webem.html#82a44b3106c18b39a52224183ef99ed6">RegisterIncludeCode</a>(
<a name="l00086"></a>00086                                 <span class="keyword">const</span> <span class="keywordtype">char</span>* idname,
<a name="l00087"></a>00087                                 webem_include_function fun );
<a name="l00088"></a>00088                         <span class="keywordtype">void</span> <a class="code" href="classhttp_1_1server_1_1c_webem.html#4f5e8e5743442db530f544e950db9f9f">RegisterIncludeCodeW</a>(
<a name="l00089"></a>00089                                 <span class="keyword">const</span> <span class="keywordtype">char</span>* idname,
<a name="l00090"></a>00090                                 webem_include_function_w fun );
<a name="l00091"></a>00091                         <span class="keywordtype">void</span> <a class="code" href="classhttp_1_1server_1_1c_webem.html#3774cf129d5d4f9551468855fc196365">Include</a>( std::string&amp; reply );
<a name="l00092"></a>00092 
<a name="l00093"></a>00093                         <span class="keywordtype">void</span> <a class="code" href="classhttp_1_1server_1_1c_webem.html#48288d924dfd8b9f4e2cff6250ad6143">RegisterActionCode</a>(
<a name="l00094"></a>00094                                 <span class="keyword">const</span> <span class="keywordtype">char</span>* idname,
<a name="l00095"></a>00095                                 webem_action_function fun );
<a name="l00096"></a>00096                         <span class="keywordtype">void</span> <a class="code" href="classhttp_1_1server_1_1c_webem.html#9be6d7aa9061680131d067abc1f3c7e5">CheckForAction</a>( request&amp; req );
<a name="l00097"></a>00097                         std::string&amp; <a class="code" href="classhttp_1_1server_1_1c_webem.html#d681d25d2edda5406ed04ab6687734e4">FindValue</a>( <span class="keyword">const</span> <span class="keywordtype">char</span>* name );
<a name="l00098"></a>00098                         std::string&amp; <a class="code" href="classhttp_1_1server_1_1c_webem.html#a74ce105cd74aadb895397ec3f0a83a2">Splash</a>();
<a name="l00099"></a>00099 
<a name="l00100"></a>00100                 <span class="keyword">private</span>:
<a name="l00102"></a>00102                         std::map &lt; std::string, webem_include_function &gt; myIncludes;
<a name="l00104"></a>00104                         std::map &lt; std::string, webem_include_function_w &gt; myIncludes_w;
<a name="l00106"></a>00106                         std::map &lt; std::string, webem_action_function &gt; myActions;
<a name="l00108"></a>00108                         std::multimap  &lt; std::string, std::string&gt; myNameValues;
<a name="l00110"></a>00110                         <a class="code" href="classhttp_1_1server_1_1c_webem_request_handler.html">cWebemRequestHandler</a> myRequestHandler;
<a name="l00112"></a>00112                         server myServer;
<a name="l00114"></a>00114                         std::string myPort;
<a name="l00115"></a>00115 
<a name="l00116"></a>00116 
<a name="l00117"></a>00117                 };
<a name="l00118"></a>00118 
<a name="l00119"></a>00119         }
<a name="l00120"></a>00120 }
<a name="l00121"></a>00121 
<a name="l00122"></a>00122 
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon May 31 11:27:51 2010 by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.6-NO </small></address>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License


Written By
Founder Raven's Point Consulting
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions