<!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"/> <meta http-equiv="X-UA-Compatible" content="IE=9"/> <title>edelib: SipcServer 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">edelib  <span id="projectnumber">2.0.0</span> </div> </td> </tr> </tbody> </table> </div> <!-- Generated by Doxygen 1.7.6.1 --> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</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="hierarchy.html"><span>Class Hierarchy</span></a></li> <li><a href="functions.html"><span>Class Members</span></a></li> </ul> </div> <div id="nav-path" class="navpath"> <ul> <li class="navelem"><a class="el" href="namespaceedelib.html">edelib</a> </li> <li class="navelem"><a class="el" href="classedelib_1_1SipcServer.html">SipcServer</a> </li> </ul> </div> </div> <div class="header"> <div class="summary"> <a href="#pub-methods">Public Member Functions</a> </div> <div class="headertitle"> <div class="title">SipcServer Class Reference</div> </div> </div><!--header--> <div class="contents"> <!-- doxytag: class="edelib::SipcServer" --> <p>Simple IPC server. <a href="classedelib_1_1SipcServer.html#details">More...</a></p> <p><code>#include <<a class="el" href="Sipc_8h_source.html">edelib/Sipc.h</a>></code></p> <p><a href="classedelib_1_1SipcServer-members.html">List of all members.</a></p> <table class="memberdecls"> <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="classedelib_1_1SipcServer.html#a55ec303b03a5b8cf2733c0382dc48d9a">SipcServer</a> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classedelib_1_1SipcServer.html#ac3b5126bc0b448211b0a0e21c04d46c1">~SipcServer</a> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="classedelib_1_1SipcServer.html#ac877aad60c2c5325e65c787cb8b1a539">request_name</a> (const char *prefix)</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classedelib_1_1SipcServer.html#a985146f61c2bdc1f0c955917b3a84de3">callback</a> (<a class="el" href="namespaceedelib.html#ad6e1092cccc914885e1eefbc2b7377ce">SipcCallback</a> cb, void *data)</td></tr> </table> <hr/><a name="details" id="details"></a><h2>Detailed Description</h2> <div class="textblock"><p>Simple IPC server. </p> <p>Sipc stands for Simple IPC (Inter Process Communication) and is very lighweight communication system between two processes by exchanging character messages based on UNIX domain sockets.</p> <p>Sipc main purpose is to allow quick message exchanging when messages are simple (like simple notifications for refresh or quit) and there is no need for D-BUS, as heavier alternative (see <a class="el" href="classedelib_1_1EdbusConnection.html" title="D-Bus connection and data sender.">EdbusConnection</a>). It also minimizes linkage depenedencies (in D-BUS case) and can provide some sort of IPC support in places where D-BUS libraries does not exists.</p> <p><a class="el" href="classedelib_1_1SipcServer.html" title="Simple IPC server.">SipcServer</a> will listen incomming messages and will report them via registered callback. Before listening starts, you have to <em>register</em> name via <a class="el" href="classedelib_1_1SipcServer.html#ac877aad60c2c5325e65c787cb8b1a539">request_name()</a> adding prefix parameter; this name will be used by clients to connects to (same like port numbers, as you concluded already ;)).</p> <p>If name is already taken, <a class="el" href="classedelib_1_1SipcServer.html#ac877aad60c2c5325e65c787cb8b1a539">request_name()</a> will fail and you will have to try with another one.</p> <p>To listen for incomming connections, make sure you call <a class="el" href="namespaceedelib.html#a37e92457471ddae1a3d1e7ed242ddf6a">listener_wait()</a>.</p> <p>Here is the short sample: </p> <div class="fragment"><pre class="fragment"> <span class="keywordtype">void</span> message_cb(<span class="keyword">const</span> <span class="keywordtype">char</span>* msg, <span class="keywordtype">void</span>* arg) { <span class="comment">// sent messages will be in msg parameter</span> } <span class="comment">// in some function...</span> <a class="code" href="classedelib_1_1SipcServer.html#a55ec303b03a5b8cf2733c0382dc48d9a">SipcServer</a> s; <span class="keywordflow">if</span>(!s.request_name(<span class="stringliteral">"demo"</span>)) <span class="comment">// fail</span> s.callback(message_cb); <span class="comment">// now listen infinitely for connections</span> <span class="keywordflow">while</span>(1) <a class="code" href="namespaceedelib.html#a37e92457471ddae1a3d1e7ed242ddf6a">listener_wait</a>(); </pre></div><p>Bidirectional communication is not possible (a case when server wants to reply); for that D-BUS exists :P </p> </div><hr/><h2>Constructor & Destructor Documentation</h2> <a class="anchor" id="a55ec303b03a5b8cf2733c0382dc48d9a"></a><!-- doxytag: member="edelib::SipcServer::SipcServer" ref="a55ec303b03a5b8cf2733c0382dc48d9a" args="()" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname"><a class="el" href="classedelib_1_1SipcServer.html">SipcServer</a> </td> <td>(</td> <td class="paramname"></td><td>)</td> <td></td> </tr> </table> </div> <div class="memdoc"> <p>Constructor; prepares internal data </p> </div> </div> <a class="anchor" id="ac3b5126bc0b448211b0a0e21c04d46c1"></a><!-- doxytag: member="edelib::SipcServer::~SipcServer" ref="ac3b5126bc0b448211b0a0e21c04d46c1" args="()" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">~<a class="el" href="classedelib_1_1SipcServer.html">SipcServer</a> </td> <td>(</td> <td class="paramname"></td><td>)</td> <td></td> </tr> </table> </div> <div class="memdoc"> <p>Cleans internal stuff, closes connections </p> </div> </div> <hr/><h2>Member Function Documentation</h2> <a class="anchor" id="a985146f61c2bdc1f0c955917b3a84de3"></a><!-- doxytag: member="edelib::SipcServer::callback" ref="a985146f61c2bdc1f0c955917b3a84de3" args="(SipcCallback cb, void *data)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">void <a class="el" href="classedelib_1_1SipcServer.html#a985146f61c2bdc1f0c955917b3a84de3">callback</a> </td> <td>(</td> <td class="paramtype"><a class="el" href="namespaceedelib.html#ad6e1092cccc914885e1eefbc2b7377ce">SipcCallback</a> </td> <td class="paramname"><em>cb</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">void * </td> <td class="paramname"><em>data</em> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td> </tr> </table> </div> <div class="memdoc"> <p>Register callback, called when message arrives.</p> <dl class="params"><dt><b>Parameters:</b></dt><dd> <table class="params"> <tr><td class="paramname">cb</td><td>is callback </td></tr> <tr><td class="paramname">data</td><td>is optional data passet to the callback </td></tr> </table> </dd> </dl> </div> </div> <a class="anchor" id="ac877aad60c2c5325e65c787cb8b1a539"></a><!-- doxytag: member="edelib::SipcServer::request_name" ref="ac877aad60c2c5325e65c787cb8b1a539" args="(const char *prefix)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">bool <a class="el" href="classedelib_1_1SipcServer.html#ac877aad60c2c5325e65c787cb8b1a539">request_name</a> </td> <td>(</td> <td class="paramtype">const char * </td> <td class="paramname"><em>prefix</em></td><td>)</td> <td></td> </tr> </table> </div> <div class="memdoc"> <p>Register name to be listening on. The name should be unique and not taken by other listener.</p> <dl class="return"><dt><b>Returns:</b></dt><dd>false if failed or true otherwise </dd></dl> <dl class="params"><dt><b>Parameters:</b></dt><dd> <table class="params"> <tr><td class="paramname">prefix</td><td>is name clients will use for connection </td></tr> </table> </dd> </dl> </div> </div> <hr/>The documentation for this class was generated from the following file:<ul> <li>edelib/<a class="el" href="Sipc_8h_source.html">Sipc.h</a></li> </ul> </div><!-- contents --> <hr class="footer"/><address class="footer"><small> Generated on Tue Jun 5 2012 17:49:03 for edelib by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/> </a> 1.7.6.1 </small></address> </body> </html>