Sophie

Sophie

distrib > Mandriva > current > i586 > media > main-updates > by-pkgid > ed376d6842ea322c25405e7c23b3bc12 > files > 69

libcommoncpp-devel-1.8.0-5.1mdv2010.1.i586.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>GNU CommonC++: buffer.h Source File</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.3 -->
<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 class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>buffer.h</h1><a href="buffer_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Copyright (C) 1999-2005 Open Source Telecom Corporation.</span>
<a name="l00002"></a>00002 <span class="comment">// Copyright (C) 2006-2008 David Sugar, Tycho Softworks.</span>
<a name="l00003"></a>00003 <span class="comment">//</span>
<a name="l00004"></a>00004 <span class="comment">// This program is free software; you can redistribute it and/or modify</span>
<a name="l00005"></a>00005 <span class="comment">// it under the terms of the GNU General Public License as published by</span>
<a name="l00006"></a>00006 <span class="comment">// the Free Software Foundation; either version 2 of the License, or</span>
<a name="l00007"></a>00007 <span class="comment">// (at your option) any later version.</span>
<a name="l00008"></a>00008 <span class="comment">//</span>
<a name="l00009"></a>00009 <span class="comment">// This program is distributed in the hope that it will be useful,</span>
<a name="l00010"></a>00010 <span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00011"></a>00011 <span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<a name="l00012"></a>00012 <span class="comment">// GNU General Public License for more details.</span>
<a name="l00013"></a>00013 <span class="comment">//</span>
<a name="l00014"></a>00014 <span class="comment">// You should have received a copy of the GNU General Public License</span>
<a name="l00015"></a>00015 <span class="comment">// along with this program; if not, write to the Free Software</span>
<a name="l00016"></a>00016 <span class="comment">// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.</span>
<a name="l00017"></a>00017 <span class="comment">//</span>
<a name="l00018"></a>00018 <span class="comment">// As a special exception, you may use this file as part of a free software</span>
<a name="l00019"></a>00019 <span class="comment">// library without restriction.  Specifically, if other files instantiate</span>
<a name="l00020"></a>00020 <span class="comment">// templates or use macros or inline functions from this file, or you compile</span>
<a name="l00021"></a>00021 <span class="comment">// this file and link it with other files to produce an executable, this</span>
<a name="l00022"></a>00022 <span class="comment">// file does not by itself cause the resulting executable to be covered by</span>
<a name="l00023"></a>00023 <span class="comment">// the GNU General Public License.  This exception does not however</span>
<a name="l00024"></a>00024 <span class="comment">// invalidate any other reasons why the executable file might be covered by</span>
<a name="l00025"></a>00025 <span class="comment">// the GNU General Public License.</span>
<a name="l00026"></a>00026 <span class="comment">//</span>
<a name="l00027"></a>00027 <span class="comment">// This exception applies only to the code released under the name GNU</span>
<a name="l00028"></a>00028 <span class="comment">// Common C++.  If you copy code from other releases into a copy of GNU</span>
<a name="l00029"></a>00029 <span class="comment">// Common C++, as the General Public License permits, the exception does</span>
<a name="l00030"></a>00030 <span class="comment">// not apply to the code that you add in this way.  To avoid misleading</span>
<a name="l00031"></a>00031 <span class="comment">// anyone as to the status of such modified files, you must delete</span>
<a name="l00032"></a>00032 <span class="comment">// this exception notice from them.</span>
<a name="l00033"></a>00033 <span class="comment">//</span>
<a name="l00034"></a>00034 <span class="comment">// If you write modifications of your own for GNU Common C++, it is your choice</span>
<a name="l00035"></a>00035 <span class="comment">// whether to permit this exception to apply to your modifications.</span>
<a name="l00036"></a>00036 <span class="comment">// If you do not wish that, delete this exception notice.</span>
<a name="l00037"></a>00037 <span class="comment">//</span>
<a name="l00038"></a>00038 
<a name="l00044"></a>00044 <span class="preprocessor">#ifndef CCXX_BUFFER_H_</span>
<a name="l00045"></a>00045 <span class="preprocessor"></span><span class="preprocessor">#define CCXX_BUFFER_H_</span>
<a name="l00046"></a>00046 <span class="preprocessor"></span>
<a name="l00047"></a>00047 <span class="preprocessor">#ifndef CCXX_THREAD_H_</span>
<a name="l00048"></a>00048 <span class="preprocessor"></span><span class="preprocessor">#include &lt;<a class="code" href="thread_8h.html" title="Synchronization and threading services.">cc++/thread.h</a>&gt;</span>
<a name="l00049"></a>00049 <span class="preprocessor">#endif</span>
<a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor">#ifndef CCXX_STRING_H_</span>
<a name="l00051"></a>00051 <span class="preprocessor"></span><span class="preprocessor">#include &lt;<a class="code" href="string_8h.html" title="Common C++ generic string class.">cc++/string.h</a>&gt;</span>
<a name="l00052"></a>00052 <span class="preprocessor">#endif</span>
<a name="l00053"></a>00053 <span class="preprocessor"></span><span class="preprocessor">#ifdef  CCXX_NAMESPACES</span>
<a name="l00054"></a>00054 <span class="preprocessor"></span><span class="keyword">namespace </span>ost {
<a name="l00055"></a>00055 <span class="preprocessor">#endif</span>
<a name="l00056"></a>00056 <span class="preprocessor"></span>
<a name="l00078"></a>00078 <span class="preprocessor">#ifdef  WIN32</span>
<a name="l00079"></a>00079 <span class="preprocessor"></span><span class="keyword">class </span><a class="code" href="config_8h.html#ad10ef148ba8327bd530fc6c32c1e181c">__EXPORT</a> Buffer : <span class="keyword">public</span> Mutex
<a name="l00080"></a>00080 <span class="preprocessor">#else</span>
<a name="l00081"></a><a class="code" href="classost_1_1_buffer.html">00081</a> <span class="preprocessor"></span>class <a class="code" href="config_8h.html#ad10ef148ba8327bd530fc6c32c1e181c">__EXPORT</a> <a class="code" href="classost_1_1_buffer.html" title="The buffer class represents an IPC service that is built upon a buffer of fixed capacity...">Buffer</a> : <span class="keyword">public</span> <a class="code" href="classost_1_1_conditional.html" title="A conditional variable synchcronization object for one to one and one to many signal...">Conditional</a>
<a name="l00082"></a>00082 <span class="preprocessor">#endif</span>
<a name="l00083"></a>00083 <span class="preprocessor"></span>{
<a name="l00084"></a>00084 <span class="keyword">private</span>:
<a name="l00085"></a>00085 <span class="preprocessor">#ifdef  WIN32</span>
<a name="l00086"></a>00086 <span class="preprocessor"></span>        <a class="code" href="serial_8h.html#a069bb8cb95b0528d5ce0304bb5561a40">HANDLE</a>  sem_head, sem_tail;
<a name="l00087"></a>00087 <span class="preprocessor">#endif</span>
<a name="l00088"></a>00088 <span class="preprocessor"></span>        <span class="keywordtype">size_t</span> _size;
<a name="l00089"></a>00089         <span class="keywordtype">size_t</span> _used;
<a name="l00090"></a>00090 
<a name="l00091"></a>00091 <span class="keyword">protected</span>:
<a name="l00097"></a>00097         <span class="keyword">virtual</span> <span class="keywordtype">size_t</span> onPeek(<span class="keywordtype">void</span> *buf) = 0;
<a name="l00098"></a>00098 
<a name="l00104"></a>00104         <span class="keyword">virtual</span> <span class="keywordtype">size_t</span> onWait(<span class="keywordtype">void</span> *buf) = 0;
<a name="l00105"></a>00105 
<a name="l00111"></a>00111         <span class="keyword">virtual</span> <span class="keywordtype">size_t</span> onPost(<span class="keywordtype">void</span> *buf) = 0;
<a name="l00112"></a>00112 
<a name="l00113"></a>00113 <span class="keyword">public</span>:
<a name="l00118"></a><a class="code" href="classost_1_1_buffer.html#ae416c78e4d5dc50bfa3c4e0b98fd7a98">00118</a>         <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">size_t</span> timeout;
<a name="l00119"></a>00119 
<a name="l00124"></a>00124         <a class="code" href="classost_1_1_buffer.html" title="The buffer class represents an IPC service that is built upon a buffer of fixed capacity...">Buffer</a>(<span class="keywordtype">size_t</span> capacity);
<a name="l00129"></a>00129         <span class="keyword">virtual</span> ~<a class="code" href="classost_1_1_buffer.html" title="The buffer class represents an IPC service that is built upon a buffer of fixed capacity...">Buffer</a>();
<a name="l00130"></a>00130 
<a name="l00135"></a><a class="code" href="classost_1_1_buffer.html#aedd8b294e02c08a60bde023bd2c1ff47">00135</a>         <span class="keyword">inline</span> <span class="keywordtype">size_t</span> getSize(<span class="keywordtype">void</span>)
<a name="l00136"></a>00136                 {<span class="keywordflow">return</span> _size;};
<a name="l00137"></a>00137 
<a name="l00144"></a><a class="code" href="classost_1_1_buffer.html#a462525b42df6660894ccf8141d73071e">00144</a>         <span class="keyword">inline</span> <span class="keywordtype">size_t</span> getUsed(<span class="keywordtype">void</span>)
<a name="l00145"></a>00145                 {<span class="keywordflow">return</span> _used;};
<a name="l00146"></a>00146 
<a name="l00156"></a>00156         <span class="keywordtype">size_t</span> <a class="code" href="namespaceost.html#a24c7774639b3768bdd45b65a296f6369">wait</a>(<span class="keywordtype">void</span> *buf, <a class="code" href="thread_8h.html#af412159e5cef839836a5e7b19ee75d1c">timeout_t</a> timeout = 0);
<a name="l00157"></a>00157 
<a name="l00166"></a>00166         <span class="keywordtype">size_t</span> post(<span class="keywordtype">void</span> *buf, <a class="code" href="thread_8h.html#af412159e5cef839836a5e7b19ee75d1c">timeout_t</a> timeout = 0);
<a name="l00167"></a>00167 
<a name="l00174"></a>00174         <span class="keywordtype">size_t</span> peek(<span class="keywordtype">void</span> *buf);
<a name="l00175"></a>00175 
<a name="l00180"></a>00180         <span class="keyword">virtual</span> <span class="keywordtype">bool</span> isValid(<span class="keywordtype">void</span>);
<a name="l00181"></a>00181         };
<a name="l00182"></a>00182 
<a name="l00190"></a><a class="code" href="classost_1_1_fixed_buffer.html">00190</a> <span class="keyword">class </span><a class="code" href="config_8h.html#ad10ef148ba8327bd530fc6c32c1e181c">__EXPORT</a> <a class="code" href="classost_1_1_fixed_buffer.html" title="A buffer class that holds a known capacity of fixed sized objects defined during...">FixedBuffer</a> : <span class="keyword">public</span> <a class="code" href="classost_1_1_buffer.html" title="The buffer class represents an IPC service that is built upon a buffer of fixed capacity...">Buffer</a>
<a name="l00191"></a>00191 {
<a name="l00192"></a>00192 <span class="keyword">private</span>:
<a name="l00193"></a>00193         <span class="keywordtype">char</span> *buf, *head, *tail;
<a name="l00194"></a>00194         <span class="keywordtype">size_t</span> objsize;
<a name="l00195"></a>00195 
<a name="l00196"></a>00196 <span class="keyword">protected</span>:
<a name="l00202"></a>00202         <span class="keywordtype">size_t</span> onPeek(<span class="keywordtype">void</span> *buf);
<a name="l00203"></a>00203 
<a name="l00209"></a>00209         <span class="keywordtype">size_t</span> onWait(<span class="keywordtype">void</span> *buf);
<a name="l00210"></a>00210 
<a name="l00216"></a>00216         <span class="keywordtype">size_t</span> onPost(<span class="keywordtype">void</span> *buf);
<a name="l00217"></a>00217 
<a name="l00218"></a>00218 <span class="keyword">public</span>:
<a name="l00226"></a>00226         <a class="code" href="classost_1_1_fixed_buffer.html" title="A buffer class that holds a known capacity of fixed sized objects defined during...">FixedBuffer</a>(<span class="keywordtype">size_t</span> capacity, <span class="keywordtype">size_t</span> objsize);
<a name="l00227"></a>00227 
<a name="l00234"></a>00234         <a class="code" href="classost_1_1_fixed_buffer.html" title="A buffer class that holds a known capacity of fixed sized objects defined during...">FixedBuffer</a>(<span class="keyword">const</span> <a class="code" href="classost_1_1_fixed_buffer.html" title="A buffer class that holds a known capacity of fixed sized objects defined during...">FixedBuffer</a> &amp;fb);
<a name="l00235"></a>00235 
<a name="l00239"></a>00239         <span class="keyword">virtual</span> ~<a class="code" href="classost_1_1_fixed_buffer.html" title="A buffer class that holds a known capacity of fixed sized objects defined during...">FixedBuffer</a>();
<a name="l00240"></a>00240 
<a name="l00241"></a>00241         <a class="code" href="classost_1_1_fixed_buffer.html" title="A buffer class that holds a known capacity of fixed sized objects defined during...">FixedBuffer</a> &amp;operator=(<span class="keyword">const</span> <a class="code" href="classost_1_1_fixed_buffer.html" title="A buffer class that holds a known capacity of fixed sized objects defined during...">FixedBuffer</a> &amp;fb);
<a name="l00242"></a>00242 
<a name="l00243"></a>00243         <span class="keywordtype">bool</span> isValid(<span class="keywordtype">void</span>);
<a name="l00244"></a>00244         };
<a name="l00245"></a>00245 
<a name="l00261"></a><a class="code" href="classost_1_1_thread_queue.html">00261</a> <span class="keyword">class </span><a class="code" href="config_8h.html#ad10ef148ba8327bd530fc6c32c1e181c">__EXPORT</a> <a class="code" href="classost_1_1_thread_queue.html" title="Somewhat generic queue processing class to establish a producer consumer queue.">ThreadQueue</a> : <span class="keyword">public</span> <a class="code" href="classost_1_1_mutex.html" title="The Mutex class is used to protect a section of code so that at any given time only...">Mutex</a>, <span class="keyword">public</span> <a class="code" href="classost_1_1_thread.html" title="Every thread of execution in an application is created by instantiating an object...">Thread</a>, <span class="keyword">public</span> <a class="code" href="classost_1_1_semaphore.html" title="A semaphore is generally used as a synchronization object between multiple threads...">Semaphore</a>
<a name="l00262"></a>00262 {
<a name="l00263"></a>00263 <span class="keyword">private</span>:
<a name="l00264"></a>00264         <span class="keywordtype">void</span> run(<span class="keywordtype">void</span>);                 <span class="comment">// private run method</span>
<a name="l00265"></a>00265 
<a name="l00266"></a>00266 <span class="keyword">protected</span>:
<a name="l00267"></a><a class="code" href="structost_1_1_thread_queue_1_1__data.html">00267</a>         <span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="structost_1_1_thread_queue_1_1__data.html">_data</a> {
<a name="l00268"></a><a class="code" href="structost_1_1_thread_queue_1_1__data.html#a1724d1b8c31d42ce736f9d78c84b164e">00268</a>                 <span class="keyword">struct </span><a class="code" href="structost_1_1_thread_queue_1_1__data.html">_data</a> *next;
<a name="l00269"></a><a class="code" href="structost_1_1_thread_queue_1_1__data.html#a8bbe2793f83a27746e7411145447a9dc">00269</a>                 <span class="keywordtype">unsigned</span> len;
<a name="l00270"></a><a class="code" href="structost_1_1_thread_queue_1_1__data.html#a5ef8d0b38df3dbef9dc8b22d13caf724">00270</a>                 <span class="keywordtype">char</span> data[1];
<a name="l00271"></a>00271         }       <a class="code" href="structost_1_1_thread_queue_1_1__data.html">data_t</a>;
<a name="l00272"></a>00272 
<a name="l00273"></a><a class="code" href="classost_1_1_thread_queue.html#adaf42df577b955fcea0dad9dd8a61202">00273</a>         <a class="code" href="thread_8h.html#af412159e5cef839836a5e7b19ee75d1c">timeout_t</a> timeout;
<a name="l00274"></a><a class="code" href="classost_1_1_thread_queue.html#a3202a4e136cd5e9b257b393a9984f3cd">00274</a>         <span class="keywordtype">bool</span> started;
<a name="l00275"></a>00275 
<a name="l00276"></a><a class="code" href="classost_1_1_thread_queue.html#a5d34d11fd2535869d62c2c505e35f0a4">00276</a>         <a class="code" href="structost_1_1_thread_queue_1_1__data.html">data_t</a> *first, *last;           <span class="comment">// head/tail of list</span>
<a name="l00277"></a>00277 
<a name="l00278"></a><a class="code" href="classost_1_1_thread_queue.html#a1737937abcd8b410758d47d18b651e40">00278</a>         <a class="code" href="classost_1_1_string.html" title="This is a generic and portable string class.">String</a> name;
<a name="l00279"></a>00279 
<a name="l00280"></a>00280         <span class="comment">/*</span>
<a name="l00281"></a>00281 <span class="comment">         * Overloading of final(). It demarks Semaphore to avoid deadlock.</span>
<a name="l00282"></a>00282 <span class="comment">         */</span>
<a name="l00283"></a>00283         <span class="keyword">virtual</span> <span class="keywordtype">void</span> <span class="keyword">final</span>();
<a name="l00284"></a>00284 
<a name="l00289"></a>00289         <span class="keyword">virtual</span> <span class="keywordtype">void</span> startQueue(<span class="keywordtype">void</span>);
<a name="l00290"></a>00290 
<a name="l00296"></a>00296         <span class="keyword">virtual</span> <span class="keywordtype">void</span> stopQueue(<span class="keywordtype">void</span>);
<a name="l00297"></a>00297 
<a name="l00301"></a>00301         <span class="keyword">virtual</span> <span class="keywordtype">void</span> onTimer(<span class="keywordtype">void</span>);
<a name="l00302"></a>00302 
<a name="l00311"></a>00311         <span class="keyword">virtual</span> <span class="keywordtype">void</span> runQueue(<span class="keywordtype">void</span> *data) = 0;
<a name="l00312"></a>00312 
<a name="l00313"></a>00313 <span class="keyword">public</span>:
<a name="l00321"></a>00321         <a class="code" href="classost_1_1_thread_queue.html" title="Somewhat generic queue processing class to establish a producer consumer queue.">ThreadQueue</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *<span class="keywordtype">id</span>, <span class="keywordtype">int</span> pri, <span class="keywordtype">size_t</span> stack = 0);
<a name="l00322"></a>00322 
<a name="l00326"></a>00326   <span class="keyword">virtual</span>       ~<a class="code" href="classost_1_1_thread_queue.html" title="Somewhat generic queue processing class to establish a producer consumer queue.">ThreadQueue</a>();
<a name="l00327"></a>00327 
<a name="l00335"></a>00335         <span class="keywordtype">void</span> setTimer(<a class="code" href="thread_8h.html#af412159e5cef839836a5e7b19ee75d1c">timeout_t</a> timeout);
<a name="l00336"></a>00336 
<a name="l00345"></a>00345         <span class="keywordtype">void</span> post(<span class="keyword">const</span> <span class="keywordtype">void</span> *data, <span class="keywordtype">unsigned</span> len);
<a name="l00346"></a>00346 };
<a name="l00347"></a>00347 
<a name="l00348"></a>00348 
<a name="l00350"></a><a class="code" href="classost_1_1_buffer.html#abe2397b9087bd1651ee67ed5702c01dd">00350</a> <span class="keyword">inline</span> <span class="keywordtype">size_t</span> <span class="keyword">get</span>(<a class="code" href="classost_1_1_buffer.html" title="The buffer class represents an IPC service that is built upon a buffer of fixed capacity...">Buffer</a> &amp;b, <span class="keywordtype">void</span> *o, <a class="code" href="thread_8h.html#af412159e5cef839836a5e7b19ee75d1c">timeout_t</a> t = 0)
<a name="l00351"></a>00351         {<span class="keywordflow">return</span> b.wait(o, t);}
<a name="l00352"></a>00352 
<a name="l00354"></a><a class="code" href="classost_1_1_buffer.html#a1dc4ad52b6f17817e4afa981d1db6fae">00354</a> <span class="keyword">inline</span> <span class="keywordtype">size_t</span> put(<a class="code" href="classost_1_1_buffer.html" title="The buffer class represents an IPC service that is built upon a buffer of fixed capacity...">Buffer</a> &amp;b, <span class="keywordtype">void</span> *o, <a class="code" href="thread_8h.html#af412159e5cef839836a5e7b19ee75d1c">timeout_t</a> t = 0)
<a name="l00355"></a>00355         {<span class="keywordflow">return</span> b.<a class="code" href="classost_1_1_buffer.html#a9d106bd44d9bee8d9ef049cfa264e5b7" title="Post an object into the buffer and enable a waiting thread to receive it.">post</a>(o, t);}
<a name="l00356"></a>00356 
<a name="l00358"></a><a class="code" href="classost_1_1_buffer.html#a2066fdf67ab3b6727be90a51fc5c4d64">00358</a> <span class="keyword">inline</span> <span class="keywordtype">size_t</span> peek(<a class="code" href="classost_1_1_buffer.html" title="The buffer class represents an IPC service that is built upon a buffer of fixed capacity...">Buffer</a> &amp;b, <span class="keywordtype">void</span> *o)
<a name="l00359"></a>00359         {<span class="keywordflow">return</span> b.<a class="code" href="classost_1_1_buffer.html#ae613b6a13146b782ce5749b810cceba8" title="Peek at the current content (first object) in the buffer.">peek</a>(o);}
<a name="l00360"></a>00360 
<a name="l00361"></a>00361 
<a name="l00362"></a>00362 <span class="preprocessor">#ifdef  CCXX_NAMESPACES</span>
<a name="l00363"></a>00363 <span class="preprocessor"></span>}
<a name="l00364"></a>00364 <span class="preprocessor">#endif</span>
<a name="l00365"></a>00365 <span class="preprocessor"></span>
<a name="l00366"></a>00366 <span class="preprocessor">#endif</span>
<a name="l00367"></a>00367 <span class="preprocessor"></span>
</pre></div></div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Fri Nov 12 09:55:46 2010 for GNU CommonC++ by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>