Click here to Skip to main content
15,892,480 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 451.2K   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>http::server::cWebem Class Reference</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 id="current"><a href="annotated.html"><span>Classes</span></a></li>
    <li><a href="files.html"><span>Files</span></a></li>
  </ul></div>
<div class="tabs">
  <ul>
    <li><a href="annotated.html"><span>Class&nbsp;List</span></a></li>
    <li><a href="hierarchy.html"><span>Class&nbsp;Hierarchy</span></a></li>
    <li><a href="functions.html"><span>Class&nbsp;Members</span></a></li>
  </ul></div>
<div class="nav">
<b>http</b>::<b>server</b>::<a class="el" href="classhttp_1_1server_1_1c_webem.html">cWebem</a></div>
<h1>http::server::cWebem Class Reference</h1><!-- doxytag: class="http::server::cWebem" -->The webem embedded web server.  
<a href="#_details">More...</a>
<p>
<code>#include &lt;<a class="el" href="c_webem_8h-source.html">cWebem.h</a>&gt;</code>
<p>
<a href="classhttp_1_1server_1_1c_webem-members.html">List of all members.</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classhttp_1_1server_1_1c_webem.html#407df237556d03f0ce61da96f4c27784">cWebem</a> (const std::string &amp;address, const std::string &amp;port, const std::string &amp;doc_root)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Webem constructor.  <a href="#407df237556d03f0ce61da96f4c27784"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classhttp_1_1server_1_1c_webem.html#74f874a1701e9db90def357499d2514f">Run</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Start the server.  <a href="#74f874a1701e9db90def357499d2514f"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classhttp_1_1server_1_1c_webem.html#82a44b3106c18b39a52224183ef99ed6">RegisterIncludeCode</a> (const char *idname, webem_include_function fun)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Create a link between a string ID and a function to calculate the dynamic content of the string.  <a href="#82a44b3106c18b39a52224183ef99ed6"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classhttp_1_1server_1_1c_webem.html#4f5e8e5743442db530f544e950db9f9f">RegisterIncludeCodeW</a> (const char *idname, webem_include_function_w fun)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Create a link between a string ID and a function to calculate the dynamic content of the string.  <a href="#4f5e8e5743442db530f544e950db9f9f"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classhttp_1_1server_1_1c_webem.html#3774cf129d5d4f9551468855fc196365">Include</a> (std::string &amp;reply)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Do not call from application code, used by server to include generated text.  <a href="#3774cf129d5d4f9551468855fc196365"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classhttp_1_1server_1_1c_webem.html#48288d924dfd8b9f4e2cff6250ad6143">RegisterActionCode</a> (const char *idname, webem_action_function fun)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Specify link between form and application function to run when form submitted.  <a href="#48288d924dfd8b9f4e2cff6250ad6143"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="9be6d7aa9061680131d067abc1f3c7e5"></a><!-- doxytag: member="http::server::cWebem::CheckForAction" ref="9be6d7aa9061680131d067abc1f3c7e5" args="(request &amp;req)" -->
void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classhttp_1_1server_1_1c_webem.html#9be6d7aa9061680131d067abc1f3c7e5">CheckForAction</a> (request &amp;req)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Do not call from application code, used by server to handle form submissions. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="d681d25d2edda5406ed04ab6687734e4"></a><!-- doxytag: member="http::server::cWebem::FindValue" ref="d681d25d2edda5406ed04ab6687734e4" args="(const char *name)" -->
std::string &amp;&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classhttp_1_1server_1_1c_webem.html#d681d25d2edda5406ed04ab6687734e4">FindValue</a> (const char *name)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Find the value of a name set by a form submit action. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="a74ce105cd74aadb895397ec3f0a83a2"></a><!-- doxytag: member="http::server::cWebem::Splash" ref="a74ce105cd74aadb895397ec3f0a83a2" args="()" -->
std::string &amp;&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classhttp_1_1server_1_1c_webem.html#a74ce105cd74aadb895397ec3f0a83a2">Splash</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Tell user where to find the <a class="el" href="classhttp_1_1server_1_1c_webem.html">cWebem</a> GUI. <br></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
The webem embedded web server. 
<p>
<hr><h2>Constructor &amp; Destructor Documentation</h2>
<a class="anchor" name="407df237556d03f0ce61da96f4c27784"></a><!-- doxytag: member="http::server::cWebem::cWebem" ref="407df237556d03f0ce61da96f4c27784" args="(const std::string &amp;address, const std::string &amp;port, const std::string &amp;doc_root)" --><p>
<table class="mdTable" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top">http::server::cWebem::cWebem           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="md" nowrap valign="top">const std::string &amp;&nbsp;</td>
          <td class="mdname" nowrap> <em>address</em>, </td>
        </tr>
        <tr>
          <td class="md" nowrap align="right"></td>
          <td class="md"></td>
          <td class="md" nowrap>const std::string &amp;&nbsp;</td>
          <td class="mdname" nowrap> <em>port</em>, </td>
        </tr>
        <tr>
          <td class="md" nowrap align="right"></td>
          <td class="md"></td>
          <td class="md" nowrap>const std::string &amp;&nbsp;</td>
          <td class="mdname" nowrap> <em>doc_root</em></td>
        </tr>
        <tr>
          <td class="md"></td>
          <td class="md">)&nbsp;</td>
          <td class="md" colspan="2"></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
Webem constructor. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>address</em>&nbsp;</td><td>IP address. In general, use "0.0.0.0" </td></tr>
    <tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>port</em>&nbsp;</td><td>port to listen on for browser requests e.g. "8080" </td></tr>
    <tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>doc_root</em>&nbsp;</td><td>path to folder containing html e.g. "./" </td></tr>
  </table>
</dl>
    </td>
  </tr>
</table>
<hr><h2>Member Function Documentation</h2>
<a class="anchor" name="3774cf129d5d4f9551468855fc196365"></a><!-- doxytag: member="http::server::cWebem::Include" ref="3774cf129d5d4f9551468855fc196365" args="(std::string &amp;reply)" --><p>
<table class="mdTable" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top">void http::server::cWebem::Include           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="md" nowrap valign="top">std::string &amp;&nbsp;</td>
          <td class="mdname1" valign="top" nowrap> <em>reply</em>          </td>
          <td class="md" valign="top">&nbsp;)&nbsp;</td>
          <td class="md" nowrap></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
Do not call from application code, used by server to include generated text. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>in/out]</em>&nbsp;</td><td>reply text to include generated</td></tr>
  </table>
</dl>
The text is searched for "&lt;!--#cWebemX--&gt;". The X can be any string not containing "--&gt;"<p>
If X has been registered with <a class="el" href="classhttp_1_1server_1_1c_webem.html">cWebem</a> then the associated function is called to generate text to be inserted.     </td>
  </tr>
</table>
<a class="anchor" name="48288d924dfd8b9f4e2cff6250ad6143"></a><!-- doxytag: member="http::server::cWebem::RegisterActionCode" ref="48288d924dfd8b9f4e2cff6250ad6143" args="(const char *idname, webem_action_function fun)" --><p>
<table class="mdTable" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top">void http::server::cWebem::RegisterActionCode           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="md" nowrap valign="top">const char *&nbsp;</td>
          <td class="mdname" nowrap> <em>idname</em>, </td>
        </tr>
        <tr>
          <td class="md" nowrap align="right"></td>
          <td class="md"></td>
          <td class="md" nowrap>webem_action_function&nbsp;</td>
          <td class="mdname" nowrap> <em>fun</em></td>
        </tr>
        <tr>
          <td class="md"></td>
          <td class="md">)&nbsp;</td>
          <td class="md" colspan="2"></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
Specify link between form and application function to run when form submitted. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>idname</em>&nbsp;</td><td>string identifier </td></tr>
    <tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>fun</em>&nbsp;</td><td>fpointer to function </td></tr>
  </table>
</dl>
    </td>
  </tr>
</table>
<a class="anchor" name="82a44b3106c18b39a52224183ef99ed6"></a><!-- doxytag: member="http::server::cWebem::RegisterIncludeCode" ref="82a44b3106c18b39a52224183ef99ed6" args="(const char *idname, webem_include_function fun)" --><p>
<table class="mdTable" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top">void http::server::cWebem::RegisterIncludeCode           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="md" nowrap valign="top">const char *&nbsp;</td>
          <td class="mdname" nowrap> <em>idname</em>, </td>
        </tr>
        <tr>
          <td class="md" nowrap align="right"></td>
          <td class="md"></td>
          <td class="md" nowrap>webem_include_function&nbsp;</td>
          <td class="mdname" nowrap> <em>fun</em></td>
        </tr>
        <tr>
          <td class="md"></td>
          <td class="md">)&nbsp;</td>
          <td class="md" colspan="2"></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
Create a link between a string ID and a function to calculate the dynamic content of the string. 
<p>
The function should return a pointer to a character buffer. This should be contain only ASCII characters ( Unicode code points 1 to 127 )<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>idname</em>&nbsp;</td><td>string identifier </td></tr>
    <tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>fun</em>&nbsp;</td><td>pointer to function which calculates the string to be displayed </td></tr>
  </table>
</dl>
    </td>
  </tr>
</table>
<a class="anchor" name="4f5e8e5743442db530f544e950db9f9f"></a><!-- doxytag: member="http::server::cWebem::RegisterIncludeCodeW" ref="4f5e8e5743442db530f544e950db9f9f" args="(const char *idname, webem_include_function_w fun)" --><p>
<table class="mdTable" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top">void http::server::cWebem::RegisterIncludeCodeW           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="md" nowrap valign="top">const char *&nbsp;</td>
          <td class="mdname" nowrap> <em>idname</em>, </td>
        </tr>
        <tr>
          <td class="md" nowrap align="right"></td>
          <td class="md"></td>
          <td class="md" nowrap>webem_include_function_w&nbsp;</td>
          <td class="mdname" nowrap> <em>fun</em></td>
        </tr>
        <tr>
          <td class="md"></td>
          <td class="md">)&nbsp;</td>
          <td class="md" colspan="2"></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
Create a link between a string ID and a function to calculate the dynamic content of the string. 
<p>
The function should return a pointer to wide character buffer. This should contain a wide character UTF-16 encoded unicode string. WEBEM will convert the string to UTF-8 encoding before sending to the browser.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>idname</em>&nbsp;</td><td>string identifier </td></tr>
    <tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>fun</em>&nbsp;</td><td>pointer to function which calculates the string to be displayed </td></tr>
  </table>
</dl>
    </td>
  </tr>
</table>
<a class="anchor" name="74f874a1701e9db90def357499d2514f"></a><!-- doxytag: member="http::server::cWebem::Run" ref="74f874a1701e9db90def357499d2514f" args="()" --><p>
<table class="mdTable" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top">void http::server::cWebem::Run           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="mdname1" valign="top" nowrap>          </td>
          <td class="md" valign="top">&nbsp;)&nbsp;</td>
          <td class="md" nowrap></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
Start the server. 
<p>
This does not return.<p>
If application needs to continue, start new thread with call to this method.     </td>
  </tr>
</table>
<hr>The documentation for this class was generated from the following files:<ul>
<li>C:/Documents and Settings/james/My Documents/code/webem/world/<a class="el" href="c_webem_8h-source.html">cWebem.h</a><li>C:/Documents and Settings/james/My Documents/code/webem/world/cWebem.cpp</ul>
<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