Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > os > by-pkgid > 9c481c872fb0ae0cbadccdc2f4a18ab6 > files > 108

libasync-devel-0.17.0-5.fc14.x86_64.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>Async: AsyncFdWatch_demo.cpp</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&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><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>
<div class="contents">
<h1>AsyncFdWatch_demo.cpp</h1><p>An example of how to use the <a class="el" href="classAsync_1_1FdWatch.html" title="A class for watching file descriptors.">Async::FdWatch</a> class</p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &lt;unistd.h&gt;</span>
<span class="preprocessor">#include &lt;cstdio&gt;</span>
<span class="preprocessor">#include &lt;iostream&gt;</span>
<span class="preprocessor">#include &lt;<a class="code" href="AsyncCppApplication_8h.html" title="The core class for writing asyncronous cpp applications.">AsyncCppApplication.h</a>&gt;</span>
<span class="preprocessor">#include &lt;<a class="code" href="AsyncFdWatch_8h.html" title="Contains a watch for file descriptors.">AsyncFdWatch.h</a>&gt;</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 name="_a0"></a><a class="code" href="classAsync_1_1FdWatch.html" title="A class for watching file descriptors.">FdWatch</a>(STDIN_FILENO, FdWatch::FD_WATCH_RD);
      stdin_watch-&gt;activity.connect(slot(*<span class="keyword">this</span>, &amp;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" title="A class for watching file descriptors.">FdWatch</a> *stdin_watch;
    
    <span class="keywordtype">void</span> onActivity(<a class="code" href="classAsync_1_1FdWatch.html" title="A class for watching file descriptors.">FdWatch</a> *watch)
    {
      <span class="keywordtype">char</span> buf[1024];
      <span class="keywordtype">int</span> cnt = read(watch-&gt;<a name="a1"></a><a class="code" href="classAsync_1_1FdWatch.html#ad49d35413fe844ea5496bddef69ce98a" title="Return the file descriptor being watched.">fd</a>(), buf, <span class="keyword">sizeof</span>(buf)-1);
      <span class="keywordflow">if</span> (cnt == -1)
      {
        perror(<span class="stringliteral">&quot;read&quot;</span>);
        Application::app().quit();
        <span class="keywordflow">return</span>;
      }
      buf[cnt] = 0;
      cout &lt;&lt; <span class="stringliteral">&quot;Read from STDIN: &quot;</span> &lt;&lt; buf &lt;&lt; endl;
    }
};

<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
{
  <a name="_a2"></a><a class="code" href="classAsync_1_1CppApplication.html" title="An application class for writing non GUI applications.">CppApplication</a> app;
  MyClass my_class;
  app.<a name="a3"></a><a class="code" href="classAsync_1_1CppApplication.html#a9a921d33644bbb18767fb4d599f53bf4" title="Execute the application main loop.">exec</a>();
}
</pre></div> </div>
<hr class="footer"/><address style="text-align: right;"><small>Generated by&nbsp;
<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>