<!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>Async: Async::FdWatch Class Reference</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.6.2-20100208 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</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> <li><a href="dirs.html"><span>Directories</span></a></li> <li><a href="examples.html"><span>Examples</span></a></li> </ul> </div> <div class="tabs"> <ul> <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 class="navpath"><a class="el" href="namespaceAsync.html">Async</a>::<a class="el" href="classAsync_1_1FdWatch.html">FdWatch</a> </div> </div> <div class="contents"> <h1>Async::FdWatch Class Reference</h1><!-- doxytag: class="Async::FdWatch" --> <p>A class for watching file descriptors. <a href="#_details">More...</a></p> <p><code>#include <<a class="el" href="AsyncFdWatch_8h_source.html">AsyncFdWatch.h</a>></code></p> <p><a href="classAsync_1_1FdWatch-members.html">List of all members.</a></p> <h2>Public Types</h2> <ul> <li>enum <a class="el" href="classAsync_1_1FdWatch.html#aa5497682aece47dcc8782a3908dc4cdc">FdWatchType</a> { <a class="el" href="classAsync_1_1FdWatch.html#aa5497682aece47dcc8782a3908dc4cdca1459a8e82710b70d173daf0a7a4a32b9">FD_WATCH_RD</a>, <a class="el" href="classAsync_1_1FdWatch.html#aa5497682aece47dcc8782a3908dc4cdca5999783f1c1f33dfcbb5fac2ebf594b0">FD_WATCH_WR</a> } <dl class="el"><dd class="mdescRight"><p>The type of the file descriptor watch. </p> <a href="classAsync_1_1FdWatch.html#aa5497682aece47dcc8782a3908dc4cdc">More...</a><br/></dl></ul> <h2>Public Member Functions</h2> <ul> <li><a class="el" href="classAsync_1_1FdWatch.html#af6a8fb263b3cf9255619fd61b12b8666">FdWatch</a> (int fd, <a class="el" href="classAsync_1_1FdWatch.html#aa5497682aece47dcc8782a3908dc4cdc">FdWatchType</a> type) <dl class="el"><dd class="mdescRight">Constructor. <a href="#af6a8fb263b3cf9255619fd61b12b8666"></a><br/></dl><li><a class="el" href="classAsync_1_1FdWatch.html#a61a95547c45d1d853f7dbd6df03d840c">~FdWatch</a> (void) <dl class="el"><dd class="mdescRight">Destructor. <a href="#a61a95547c45d1d853f7dbd6df03d840c"></a><br/></dl><li>int <a class="el" href="classAsync_1_1FdWatch.html#ad49d35413fe844ea5496bddef69ce98a">fd</a> (void) const <dl class="el"><dd class="mdescRight">Return the file descriptor being watched. <a href="#ad49d35413fe844ea5496bddef69ce98a"></a><br/></dl><li><a class="el" href="classAsync_1_1FdWatch.html#aa5497682aece47dcc8782a3908dc4cdc">FdWatchType</a> <a class="el" href="classAsync_1_1FdWatch.html#ab1643257dc0ea7d6bf7822a4704fb4a9">type</a> (void) const <dl class="el"><dd class="mdescRight">Return the type of this watch. <a href="#ab1643257dc0ea7d6bf7822a4704fb4a9"></a><br/></dl><li>void <a class="el" href="classAsync_1_1FdWatch.html#aa0e7c59dae8b5d41823def7e6340ac1c">setEnabled</a> (bool enabled) <dl class="el"><dd class="mdescRight">Enable or disable the watch. <a href="#aa0e7c59dae8b5d41823def7e6340ac1c"></a><br/></dl><li>bool <a class="el" href="classAsync_1_1FdWatch.html#a410d273d8f6a6e09a6f6e0525cec3db0">isEnabled</a> (void) const <dl class="el"><dd class="mdescRight">Check if the watch is enabled or not. <a href="#a410d273d8f6a6e09a6f6e0525cec3db0"></a><br/></dl></ul> <h2>Public Attributes</h2> <ul> <li>SigC::Signal1< void, <a class="el" href="classAsync_1_1FdWatch.html">FdWatch</a> * > <a class="el" href="classAsync_1_1FdWatch.html#a499711b028fc46593d66e9cc50cd0bb2">activity</a> <dl class="el"><dd class="mdescRight">Signal to indicate that the descriptor is active. <a href="#a499711b028fc46593d66e9cc50cd0bb2"></a><br/></dl></ul> <hr/><a name="_details"></a><h2>Detailed Description</h2> <p>A class for watching file descriptors. </p> <dl class="author"><dt><b>Author:</b></dt><dd>Tobias Blomberg </dd></dl> <dl class="date"><dt><b>Date:</b></dt><dd>2003-03-19</dd></dl> <p>Use this class to watch a file descriptor for activity. The example below creates a read watch on the standard input file descriptor. That is, every time a character is typed on the keyboard (or something is piped to the application) the <em>onActivity</em> method in instance <em>this</em> of class <em>MyClass</em> will be called. In the handler function, the data on the file descriptor should be read. Otherwise the handler function will be called over and over again. </p> <dl class="note"><dt><b>Note:</b></dt><dd>Since the stdin is line buffered, the ENTER key has to be pressed before anything will be shown.</dd></dl> <div class="fragment"><pre class="fragment"><span class="preprocessor">#include <unistd.h></span> <span class="preprocessor">#include <cstdio></span> <span class="preprocessor">#include <iostream></span> <span class="preprocessor">#include <<a class="code" href="AsyncCppApplication_8h.html" title="The core class for writing asyncronous cpp applications.">AsyncCppApplication.h</a>></span> <span class="preprocessor">#include <<a class="code" href="AsyncFdWatch_8h.html" title="Contains a watch for file descriptors.">AsyncFdWatch.h</a>></span> <span class="keyword">using namespace </span>std; <span class="keyword">using namespace </span>Async; <span class="keyword">class </span>MyClass : <span class="keyword">public</span> SigC::Object { <span class="keyword">public</span>: MyClass(<span class="keywordtype">void</span>) { stdin_watch = <span class="keyword">new</span> <a class="code" href="classAsync_1_1FdWatch.html#af6a8fb263b3cf9255619fd61b12b8666" title="Constructor.">FdWatch</a>(STDIN_FILENO, <a class="code" href="classAsync_1_1FdWatch.html#aa5497682aece47dcc8782a3908dc4cdca1459a8e82710b70d173daf0a7a4a32b9" title="File descriptor watch for incoming data.">FdWatch::FD_WATCH_RD</a>); stdin_watch->activity.connect(slot(*<span class="keyword">this</span>, &MyClass::onActivity)); } ~MyClass(<span class="keywordtype">void</span>) { <span class="keyword">delete</span> stdin_watch; } <span class="keyword">private</span>: <a class="code" href="classAsync_1_1FdWatch.html#af6a8fb263b3cf9255619fd61b12b8666" title="Constructor.">FdWatch</a> *stdin_watch; <span class="keywordtype">void</span> onActivity(<a class="code" href="classAsync_1_1FdWatch.html#af6a8fb263b3cf9255619fd61b12b8666" title="Constructor.">FdWatch</a> *watch) { <span class="keywordtype">char</span> buf[1024]; <span class="keywordtype">int</span> cnt = read(watch->fd(), buf, <span class="keyword">sizeof</span>(buf)-1); <span class="keywordflow">if</span> (cnt == -1) { perror(<span class="stringliteral">"read"</span>); <a class="code" href="classAsync_1_1Application.html#aa6d446d6b333e0a1e5cc1400c07aa898" title="Get the one and only application instance.">Application::app</a>().quit(); <span class="keywordflow">return</span>; } buf[cnt] = 0; cout << <span class="stringliteral">"Read from STDIN: "</span> << buf << endl; } }; <span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv) { CppApplication app; MyClass my_class; app.exec(); } </pre></div> <dl><dt><b>Examples: </b></dt><dd> <p><a class="el" href="AsyncFdWatch__demo_8cpp-example.html#_a0">AsyncFdWatch_demo.cpp</a>.</p> </dd> </dl> <p>Definition at line <a class="el" href="AsyncFdWatch_8h_source.html#l00119">119</a> of file <a class="el" href="AsyncFdWatch_8h_source.html">AsyncFdWatch.h</a>.</p> <hr/><h2>Member Enumeration Documentation</h2> <a class="anchor" id="aa5497682aece47dcc8782a3908dc4cdc"></a><!-- doxytag: member="Async::FdWatch::FdWatchType" ref="aa5497682aece47dcc8782a3908dc4cdc" args="" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">enum <a class="el" href="classAsync_1_1FdWatch.html#aa5497682aece47dcc8782a3908dc4cdc">Async::FdWatch::FdWatchType</a></td> </tr> </table> </div> <div class="memdoc"> <p>The type of the file descriptor watch. </p> <dl><dt><b>Enumerator: </b></dt><dd><table border="0" cellspacing="2" cellpadding="0"> <tr><td valign="top"><em><a class="anchor" id="aa5497682aece47dcc8782a3908dc4cdca1459a8e82710b70d173daf0a7a4a32b9"></a><!-- doxytag: member="FD_WATCH_RD" ref="aa5497682aece47dcc8782a3908dc4cdca1459a8e82710b70d173daf0a7a4a32b9" args="" -->FD_WATCH_RD</em> </td><td> <p>File descriptor watch for incoming data. </p> </td></tr> <tr><td valign="top"><em><a class="anchor" id="aa5497682aece47dcc8782a3908dc4cdca5999783f1c1f33dfcbb5fac2ebf594b0"></a><!-- doxytag: member="FD_WATCH_WR" ref="aa5497682aece47dcc8782a3908dc4cdca5999783f1c1f33dfcbb5fac2ebf594b0" args="" -->FD_WATCH_WR</em> </td><td> <p>File descriptor watch for outgoing data. </p> </td></tr> </table> </dd> </dl> <p>Definition at line <a class="el" href="AsyncFdWatch_8h_source.html#l00125">125</a> of file <a class="el" href="AsyncFdWatch_8h_source.html">AsyncFdWatch.h</a>.</p> </div> </div> <hr/><h2>Constructor & Destructor Documentation</h2> <a class="anchor" id="af6a8fb263b3cf9255619fd61b12b8666"></a><!-- doxytag: member="Async::FdWatch::FdWatch" ref="af6a8fb263b3cf9255619fd61b12b8666" args="(int fd, FdWatchType type)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">Async::FdWatch::FdWatch </td> <td>(</td> <td class="paramtype">int </td> <td class="paramname"> <em>fd</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype"><a class="el" href="classAsync_1_1FdWatch.html#aa5497682aece47dcc8782a3908dc4cdc">FdWatchType</a> </td> <td class="paramname"> <em>type</em></td><td> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td><td></td> </tr> </table> </div> <div class="memdoc"> <p>Constructor. </p> <p>Add the given file descriptor to the watch list and watch it for incoming data (FD_WATCH_RD) or write buffer space available (FD_WATCH_WR). </p> <dl><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign="top"></td><td valign="top"><em>fd</em> </td><td>The file descriptor to watch </td></tr> <tr><td valign="top"></td><td valign="top"><em>type</em> </td><td>The type of watch to create (see <a class="el" href="classAsync_1_1FdWatch.html#aa5497682aece47dcc8782a3908dc4cdc">FdWatchType</a>) </td></tr> </table> </dd> </dl> </div> </div> <a class="anchor" id="a61a95547c45d1d853f7dbd6df03d840c"></a><!-- doxytag: member="Async::FdWatch::~FdWatch" ref="a61a95547c45d1d853f7dbd6df03d840c" args="(void)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">Async::FdWatch::~FdWatch </td> <td>(</td> <td class="paramtype">void </td> <td class="paramname"></td> <td> ) </td> <td></td> </tr> </table> </div> <div class="memdoc"> <p>Destructor. </p> </div> </div> <hr/><h2>Member Function Documentation</h2> <a class="anchor" id="ad49d35413fe844ea5496bddef69ce98a"></a><!-- doxytag: member="Async::FdWatch::fd" ref="ad49d35413fe844ea5496bddef69ce98a" args="(void) const " --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">int Async::FdWatch::fd </td> <td>(</td> <td class="paramtype">void </td> <td class="paramname"></td> <td> ) </td> <td> const<code> [inline]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Return the file descriptor being watched. </p> <dl class="return"><dt><b>Returns:</b></dt><dd>Returns the file descriptor </dd></dl> <dl><dt><b>Examples: </b></dt><dd><a class="el" href="AsyncFdWatch__demo_8cpp-example.html#a1">AsyncFdWatch_demo.cpp</a>.</dd> </dl> <p>Definition at line <a class="el" href="AsyncFdWatch_8h_source.html#l00151">151</a> of file <a class="el" href="AsyncFdWatch_8h_source.html">AsyncFdWatch.h</a>.</p> </div> </div> <a class="anchor" id="a410d273d8f6a6e09a6f6e0525cec3db0"></a><!-- doxytag: member="Async::FdWatch::isEnabled" ref="a410d273d8f6a6e09a6f6e0525cec3db0" args="(void) const " --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">bool Async::FdWatch::isEnabled </td> <td>(</td> <td class="paramtype">void </td> <td class="paramname"></td> <td> ) </td> <td> const<code> [inline]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Check if the watch is enabled or not. </p> <dl class="return"><dt><b>Returns:</b></dt><dd>Returns true if the watch is enabled, or else false. </dd></dl> <p>Definition at line <a class="el" href="AsyncFdWatch_8h_source.html#l00170">170</a> of file <a class="el" href="AsyncFdWatch_8h_source.html">AsyncFdWatch.h</a>.</p> </div> </div> <a class="anchor" id="aa0e7c59dae8b5d41823def7e6340ac1c"></a><!-- doxytag: member="Async::FdWatch::setEnabled" ref="aa0e7c59dae8b5d41823def7e6340ac1c" args="(bool enabled)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">void Async::FdWatch::setEnabled </td> <td>(</td> <td class="paramtype">bool </td> <td class="paramname"> <em>enabled</em></td> <td> ) </td> <td></td> </tr> </table> </div> <div class="memdoc"> <p>Enable or disable the watch. </p> <dl><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign="top"></td><td valign="top"><em>enabled</em> </td><td>Set to <em>true</em> to enable the watch or <em>false</em> to disable it. </td></tr> </table> </dd> </dl> </div> </div> <a class="anchor" id="ab1643257dc0ea7d6bf7822a4704fb4a9"></a><!-- doxytag: member="Async::FdWatch::type" ref="ab1643257dc0ea7d6bf7822a4704fb4a9" args="(void) const " --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname"><a class="el" href="classAsync_1_1FdWatch.html#aa5497682aece47dcc8782a3908dc4cdc">FdWatchType</a> Async::FdWatch::type </td> <td>(</td> <td class="paramtype">void </td> <td class="paramname"></td> <td> ) </td> <td> const<code> [inline]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Return the type of this watch. </p> <dl class="return"><dt><b>Returns:</b></dt><dd>Returns the type (see <a class="el" href="classAsync_1_1FdWatch.html#aa5497682aece47dcc8782a3908dc4cdc">FdWatchType</a>) </dd></dl> <p>Definition at line <a class="el" href="AsyncFdWatch_8h_source.html#l00157">157</a> of file <a class="el" href="AsyncFdWatch_8h_source.html">AsyncFdWatch.h</a>.</p> </div> </div> <hr/><h2>Member Data Documentation</h2> <a class="anchor" id="a499711b028fc46593d66e9cc50cd0bb2"></a><!-- doxytag: member="Async::FdWatch::activity" ref="a499711b028fc46593d66e9cc50cd0bb2" args="" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">SigC::Signal1<void, <a class="el" href="classAsync_1_1FdWatch.html">FdWatch</a>*> <a class="el" href="classAsync_1_1FdWatch.html#a499711b028fc46593d66e9cc50cd0bb2">Async::FdWatch::activity</a></td> </tr> </table> </div> <div class="memdoc"> <p>Signal to indicate that the descriptor is active. </p> <dl><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign="top"></td><td valign="top"><em>watch</em> </td><td>Pointer to the watch object </td></tr> </table> </dd> </dl> <p>Definition at line <a class="el" href="AsyncFdWatch_8h_source.html#l00176">176</a> of file <a class="el" href="AsyncFdWatch_8h_source.html">AsyncFdWatch.h</a>.</p> </div> </div> <hr/>The documentation for this class was generated from the following file:<ul> <li><a class="el" href="AsyncFdWatch_8h_source.html">AsyncFdWatch.h</a></li> </ul> </div> <hr class="footer"/><address style="text-align: right;"><small>Generated by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2-20100208 </small></address> </body> </html>