Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > 3ebaf504d69f581a8834e53e04e712a5 > files > 594

gearbox-devel-9.11-6.fc14.i686.rpm

<!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>GearBox Project</title>

<link rel="icon" href="gbx_icon_cardbox_sky.png" type="image/png">
<link rel="shortcut icon" href="gbx_icon_cardbox_sky.png" type="image/png">

<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
<!-- Google Analytics -->
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3583782-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
<!-- Returning you to your regular programming -->
</head><body>

<!-- Header -->

<table border="0" cellspacing="0" cellpadding="0">

<tr><!-- create row -->

<!-- spacer cell -->
<!-- #CC CC CC -->
<td rowspan="1" colspan="1" bgcolor="#EEEEEE">&nbsp;&nbsp;&nbsp;&nbsp;</td>

<!-- menu cell -->
<td width="170" rowspan="1" colspan="1" align="left" valign="top" bgcolor="#EEEEEE">


<p>&nbsp;</p>
<p align="center"><a href="index.html"><img src="gbx_logo_cardbox_sky_150x150.png"></a></p><br>

<strong>INTRODUCTION</strong><br>
<strong><a href="gbx_doc_overview.html" style="text-decoration:none">Overview</a></strong><br>
<strong><a href="gbx_doc_getting.html" style="text-decoration:none">Download and Install</a></strong><br>
<!-- <strong><a href="gbx_doc_quickstart.html" style="text-decoration:none">Quick Start</a></strong><br> -->
<strong><a href="gbx_doc_documentation.html" style="text-decoration:none">Documentation</a></strong><br>
<strong><a href="gbx_doc_publications.html" style="text-decoration:none">Publications</a></strong><br>
<br>

<strong>REPOSITORY</strong><br>
<strong><a href="group__gbx__libs.html" style="text-decoration:none">Libraries</a></strong><br>
<!-- <strong><a href="group__gbx__utils.html" style="text-decoration:none">Utilities</a></strong><br> -->
<br>

<strong>DEVELOPER</strong><br>

<!--<strong><a href="gbx_doc_tutorials.html" style="text-decoration:none">Tutorials</a></strong><br>
<strong><a href="group__gbx__examples.html" style="text-decoration:none">Examples</a></strong><br>-->
<strong><a href="gbx_doc_devguide.html" style="text-decoration:none">Dev Guide</a></strong><br>
<!-- 
<strong><a href="gbx_doc_faq.html" style="text-decoration:none">FAQ</a></strong><br>
-->
<strong><a href="http://cdash.acfr.usyd.edu.au/index.php?project=Gearbox" style="text-decoration:none">Dashboard</a></strong><br>
<!--<strong><a href="http://wiki2.cas.edu.au/orca">Wiki</a></strong><br>
login/pass: orca/orca<br>-->
<br>

<strong>PEOPLE</strong><br>
<strong><a href="gbx_doc_contributors.html" style="text-decoration:none">Contributors</a></strong><br>
<strong><a href="gbx_doc_users.html" style="text-decoration:none">Users</a></strong><br>
<br>

<a href="http://sourceforge.net"><img src="http://sourceforge.net/sflogo.php?group_id=216468&amp;type=2" width="125" height="37" border="0" alt="SourceForge.net Logo" /></a><br>
<strong><a href="http://sourceforge.net/projects/gearbox">Project</a></strong><br>
<strong><a href="http://sourceforge.net/project/showfiles.php?group_id=216468">Download</a></strong><br>
<!--<strong><a href="http://sourceforge.net/tracker/?group_id=216468">Bugs/Feedback</a></strong><br>-->
<strong><a href="http://sourceforge.net/mail/?group_id=216468">Mailing lists</a></strong></p>
<p>&nbsp;</p>

</td><!-- /menu cell -->

<!-- one grey spacer cells -->
<td rowspan="1" colspan="1" bgcolor="#EEEEEE">&nbsp;&nbsp;&nbsp;&nbsp;</td>

<!-- one white spacer cells -->
<td rowspan="1" colspan="1">&nbsp;&nbsp;&nbsp;&nbsp;</td>

<!-- main content cell -->
<td rowspan="1" colspan="1" align="left" valign="top">


<!-- 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="pages.html"><span>Related&nbsp;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><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="dir_b8ba9ebcb71a95a44c4fd60b7d348fe1.html">src</a>&nbsp;&raquo;&nbsp;<a class="el" href="dir_26b426ffd7c02d2636b681f5b9fd4318.html">flexiport</a>
  </div>
</div>
<div class="contents">
<h1>port.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics</span>
<a name="l00003"></a>00003 <span class="comment"> *               http://gearbox.sf.net/</span>
<a name="l00004"></a>00004 <span class="comment"> * Copyright (c) 2008 Geoffrey Biggs</span>
<a name="l00005"></a>00005 <span class="comment"> *</span>
<a name="l00006"></a>00006 <span class="comment"> * flexiport flexible hardware data communications library.</span>
<a name="l00007"></a>00007 <span class="comment"> *</span>
<a name="l00008"></a>00008 <span class="comment"> * This distribution is licensed to you under the terms described in the LICENSE file included in</span>
<a name="l00009"></a>00009 <span class="comment"> * this distribution.</span>
<a name="l00010"></a>00010 <span class="comment"> *</span>
<a name="l00011"></a>00011 <span class="comment"> * This work is a product of the National Institute of Advanced Industrial Science and Technology,</span>
<a name="l00012"></a>00012 <span class="comment"> * Japan. Registration number: H20PRO-881</span>
<a name="l00013"></a>00013 <span class="comment"> *</span>
<a name="l00014"></a>00014 <span class="comment"> * This file is part of flexiport.</span>
<a name="l00015"></a>00015 <span class="comment"> *</span>
<a name="l00016"></a>00016 <span class="comment"> * flexiport is free software: you can redistribute it and/or modify it under the terms of the GNU</span>
<a name="l00017"></a>00017 <span class="comment"> * Lesser General Public License as published by the Free Software Foundation, either version 3 of</span>
<a name="l00018"></a>00018 <span class="comment"> * the License, or (at your option) any later version.</span>
<a name="l00019"></a>00019 <span class="comment"> *</span>
<a name="l00020"></a>00020 <span class="comment"> * flexiport is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without</span>
<a name="l00021"></a>00021 <span class="comment"> * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
<a name="l00022"></a>00022 <span class="comment"> * Lesser General Public License for more details.</span>
<a name="l00023"></a>00023 <span class="comment"> *</span>
<a name="l00024"></a>00024 <span class="comment"> * You should have received a copy of the GNU Lesser General Public License along with flexiport.</span>
<a name="l00025"></a>00025 <span class="comment"> * If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<a name="l00026"></a>00026 <span class="comment"> */</span>
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 <span class="preprocessor">#ifndef __PORT_H</span>
<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define __PORT_H</span>
<a name="l00030"></a>00030 <span class="preprocessor"></span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;string&gt;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;map&gt;</span>
<a name="l00033"></a>00033 
<a name="l00034"></a>00034 <span class="preprocessor">#if defined (WIN32)</span>
<a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor">        #if defined (FLEXIPORT_STATIC)</span>
<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor">                #define FLEXIPORT_EXPORT</span>
<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">        #elif defined (FLEXIPORT_EXPORTS)</span>
<a name="l00038"></a>00038 <span class="preprocessor"></span><span class="preprocessor">                #define FLEXIPORT_EXPORT    __declspec (dllexport)</span>
<a name="l00039"></a>00039 <span class="preprocessor"></span><span class="preprocessor">        #else</span>
<a name="l00040"></a>00040 <span class="preprocessor"></span><span class="preprocessor">                #define FLEXIPORT_EXPORT    __declspec (dllimport)</span>
<a name="l00041"></a>00041 <span class="preprocessor"></span><span class="preprocessor">        #endif</span>
<a name="l00042"></a>00042 <span class="preprocessor"></span><span class="preprocessor">#else</span>
<a name="l00043"></a>00043 <span class="preprocessor"></span><span class="preprocessor">        #define FLEXIPORT_EXPORT</span>
<a name="l00044"></a>00044 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00045"></a>00045 <span class="preprocessor"></span>
<a name="l00046"></a>00046 <span class="preprocessor">#include &quot;flexiport_types.h&quot;</span>
<a name="l00047"></a>00047 <span class="preprocessor">#include &quot;timeout.h&quot;</span>
<a name="l00048"></a>00048 
<a name="l00053"></a>00053 <span class="keyword">namespace </span>flexiport
<a name="l00054"></a>00054 {
<a name="l00055"></a>00055 
<a name="l00078"></a><a class="code" href="classflexiport_1_1Port.html">00078</a> <span class="keyword">class </span>FLEXIPORT_EXPORT <a class="code" href="classflexiport_1_1Port.html" title="Base Port class.">Port</a>
<a name="l00079"></a>00079 {
<a name="l00080"></a>00080         <span class="keyword">public</span>:
<a name="l00081"></a>00081                 <span class="keyword">virtual</span> ~<a class="code" href="classflexiport_1_1Port.html" title="Base Port class.">Port</a> ();
<a name="l00082"></a>00082 
<a name="l00083"></a>00083                 <span class="comment">// API common to all ports</span>
<a name="l00085"></a>00085 <span class="comment"></span>                <span class="keyword">virtual</span> <span class="keywordtype">void</span> Open () = 0;
<a name="l00086"></a>00086 
<a name="l00088"></a>00088                 <span class="keyword">virtual</span> <span class="keywordtype">void</span> Close () = 0;
<a name="l00089"></a>00089 
<a name="l00100"></a>00100                 <span class="keyword">virtual</span> ssize_t Read (<span class="keywordtype">void</span> * <span class="keyword">const</span> buffer, <span class="keywordtype">size_t</span> count) = 0;
<a name="l00101"></a>00101 
<a name="l00112"></a>00112                 <span class="keyword">virtual</span> ssize_t ReadFull (<span class="keywordtype">void</span> * <span class="keyword">const</span> buffer, <span class="keywordtype">size_t</span> count) = 0;
<a name="l00113"></a>00113 
<a name="l00120"></a>00120                 <span class="keyword">virtual</span> ssize_t ReadString (std::string &amp;buffer);
<a name="l00121"></a>00121 
<a name="l00137"></a>00137                 <span class="keyword">virtual</span> ssize_t ReadUntil (<span class="keywordtype">void</span> * <span class="keyword">const</span> buffer, <span class="keywordtype">size_t</span> count, uint8_t terminator);
<a name="l00138"></a>00138 
<a name="l00154"></a>00154                 <span class="keyword">virtual</span> ssize_t ReadStringUntil (std::string &amp;buffer, <span class="keywordtype">char</span> terminator);
<a name="l00155"></a>00155 
<a name="l00178"></a>00178                 <span class="keyword">virtual</span> ssize_t ReadLine (<span class="keywordtype">char</span> * <span class="keyword">const</span> buffer, <span class="keywordtype">size_t</span> count);
<a name="l00179"></a>00179 
<a name="l00194"></a><a class="code" href="classflexiport_1_1Port.html#a36dedbec727a975c5828d5d4573d934d">00194</a>                 <span class="keyword">virtual</span> ssize_t <a class="code" href="classflexiport_1_1Port.html#a36dedbec727a975c5828d5d4573d934d" title="Read a new-line terminated string of data.">ReadLine</a> (std::string &amp;buffer) { <span class="keywordflow">return</span> ReadStringUntil (buffer, <span class="charliteral">&#39;\n&#39;</span>); }
<a name="l00195"></a>00195 
<a name="l00199"></a>00199                 <span class="keyword">virtual</span> ssize_t Skip (<span class="keywordtype">size_t</span> count);
<a name="l00200"></a>00200 
<a name="l00205"></a>00205                 <span class="keyword">virtual</span> ssize_t SkipUntil (uint8_t terminator, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> count);
<a name="l00206"></a>00206 
<a name="l00210"></a>00210                 <span class="keyword">virtual</span> ssize_t BytesAvailable () = 0;
<a name="l00211"></a>00211 
<a name="l00218"></a>00218                 <span class="keyword">virtual</span> ssize_t BytesAvailableWait () = 0;
<a name="l00219"></a>00219 
<a name="l00229"></a>00229                 <span class="keyword">virtual</span> ssize_t Write (<span class="keyword">const</span> <span class="keywordtype">void</span> * <span class="keyword">const</span> buffer, <span class="keywordtype">size_t</span> count) = 0;
<a name="l00230"></a>00230 
<a name="l00237"></a>00237                 <span class="keyword">virtual</span> ssize_t WriteFull (<span class="keyword">const</span> <span class="keywordtype">void</span> * <span class="keyword">const</span> buffer, <span class="keywordtype">size_t</span> count);
<a name="l00238"></a>00238 
<a name="l00248"></a>00248                 <span class="keyword">virtual</span> ssize_t WriteString (<span class="keyword">const</span> <span class="keywordtype">char</span> * <span class="keyword">const</span> buffer);
<a name="l00249"></a>00249                 <span class="keyword">virtual</span> ssize_t WriteString (<span class="keyword">const</span> std::string &amp;buffer)
<a name="l00250"></a>00250                         { <span class="keywordflow">return</span> WriteString (buffer.c_str ()); }
<a name="l00251"></a>00251 
<a name="l00253"></a>00253                 <span class="keyword">virtual</span> <span class="keywordtype">void</span> Flush () = 0;
<a name="l00254"></a>00254 
<a name="l00258"></a>00258                 <span class="keyword">virtual</span> <span class="keywordtype">void</span> Drain () = 0;
<a name="l00259"></a>00259 
<a name="l00261"></a>00261                 <span class="keyword">virtual</span> std::string GetStatus () <span class="keyword">const</span>;
<a name="l00262"></a>00262 
<a name="l00263"></a>00263                 <span class="comment">// Accessor methods.</span>
<a name="l00265"></a><a class="code" href="classflexiport_1_1Port.html#a10305d725ccd4f53e872ef3316eabbcb">00265</a> <span class="comment"></span>                std::string <a class="code" href="classflexiport_1_1Port.html#a10305d725ccd4f53e872ef3316eabbcb" title="Get the port type.">GetPortType</a> ()<span class="keyword"> const        </span>{ <span class="keywordflow">return</span> _type; }
<a name="l00267"></a><a class="code" href="classflexiport_1_1Port.html#ad5d41a53a55a2d727237ad8d7e80cf1b">00267</a>                 <span class="keywordtype">void</span> <a class="code" href="classflexiport_1_1Port.html#ad5d41a53a55a2d727237ad8d7e80cf1b" title="Set the debug level.">SetDebug</a> (<span class="keywordtype">int</span> debug)               { _debug = debug; }
<a name="l00269"></a><a class="code" href="classflexiport_1_1Port.html#aa258404292ed68d0aa75398539accecb">00269</a>                 <span class="keywordtype">int</span> <a class="code" href="classflexiport_1_1Port.html#aa258404292ed68d0aa75398539accecb" title="Get the debug level.">GetDebug</a> ()<span class="keyword"> const                   </span>{ <span class="keywordflow">return</span> _debug; }
<a name="l00276"></a>00276                 <span class="keyword">virtual</span> <span class="keywordtype">void</span> SetTimeout (<a class="code" href="classflexiport_1_1Timeout.html" title="An object used to represent timeouts.">Timeout</a> timeout) = 0;
<a name="l00278"></a><a class="code" href="classflexiport_1_1Port.html#a65d32c9aaebb37eaebf32c2a95f5ebeb">00278</a>                 <span class="keyword">virtual</span> <a class="code" href="classflexiport_1_1Timeout.html" title="An object used to represent timeouts.">Timeout</a> <a class="code" href="classflexiport_1_1Port.html#a65d32c9aaebb37eaebf32c2a95f5ebeb" title="Get the timeout.">GetTimeout</a> ()<span class="keyword"> const     </span>{ <span class="keywordflow">return</span> _timeout; }
<a name="l00281"></a><a class="code" href="classflexiport_1_1Port.html#ab3371d50dde81994f079b6ed80f42922">00281</a>                 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="classflexiport_1_1Port.html#ab3371d50dde81994f079b6ed80f42922" title="Get the blocking property of the port. If the timeout is non-zero, the port will...">IsBlocking</a> ()<span class="keyword"> const        </span>{ <span class="keywordflow">return</span> (_timeout._sec != 0 ||
<a name="l00282"></a>00282                                                           _timeout._usec != 0); }
<a name="l00284"></a>00284                 <span class="keyword">virtual</span> <span class="keywordtype">void</span> SetCanRead (<span class="keywordtype">bool</span> canRead) = 0;
<a name="l00286"></a><a class="code" href="classflexiport_1_1Port.html#a4789e79b0f0e5f393c0dd2a08a00ffc0">00286</a>                 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="classflexiport_1_1Port.html#a4789e79b0f0e5f393c0dd2a08a00ffc0" title="Get the read permissions of the port.">CanRead</a> ()<span class="keyword"> const           </span>{ <span class="keywordflow">return</span> _canRead; }
<a name="l00288"></a>00288                 <span class="keyword">virtual</span> <span class="keywordtype">void</span> SetCanWrite (<span class="keywordtype">bool</span> canWrite) = 0;
<a name="l00290"></a><a class="code" href="classflexiport_1_1Port.html#a0b97b8b3e58ad487dabb491c353faf0f">00290</a>                 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="classflexiport_1_1Port.html#a0b97b8b3e58ad487dabb491c353faf0f" title="Get the write permissions of the port.">CanWrite</a> ()<span class="keyword"> const          </span>{ <span class="keywordflow">return</span> _canWrite; }
<a name="l00292"></a>00292                 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> IsOpen () <span class="keyword">const</span> = 0;
<a name="l00293"></a>00293 
<a name="l00294"></a>00294         <span class="keyword">protected</span>:
<a name="l00295"></a>00295                 std::string _type;  <span class="comment">// Port type string (e.g. &quot;tcp&quot; or &quot;serial&quot; or &quot;usb&quot;)</span>
<a name="l00296"></a>00296                 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> _debug;
<a name="l00297"></a>00297                 <a class="code" href="classflexiport_1_1Timeout.html" title="An object used to represent timeouts.">Timeout</a> _timeout;   <span class="comment">// Timeout in milliseconds. Set to zero for non-blocking operation.</span>
<a name="l00298"></a>00298                 <span class="keywordtype">bool</span> _canRead;      <span class="comment">// If true, this port can be read from.</span>
<a name="l00299"></a>00299                 <span class="keywordtype">bool</span> _canWrite;     <span class="comment">// If true, this port can be written to.</span>
<a name="l00300"></a>00300                 <span class="keywordtype">bool</span> _alwaysOpen;   <span class="comment">// If the port should be kept open for the life of the object (including</span>
<a name="l00301"></a>00301                                     <span class="comment">// reopening it if necessary).</span>
<a name="l00302"></a>00302 
<a name="l00303"></a>00303                 <span class="comment">// Protected constructor to prevent direct creation of this class.</span>
<a name="l00304"></a>00304                 <a class="code" href="classflexiport_1_1Port.html" title="Base Port class.">Port</a> ();
<a name="l00305"></a>00305                 <span class="comment">// Constructor for more-direct creation.</span>
<a name="l00306"></a>00306                 <a class="code" href="classflexiport_1_1Port.html" title="Base Port class.">Port</a> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> debug, <a class="code" href="classflexiport_1_1Timeout.html" title="An object used to represent timeouts.">Timeout</a> timeout, <span class="keywordtype">bool</span> canRead, <span class="keywordtype">bool</span> canWrite, <span class="keywordtype">bool</span> alwaysOpen);
<a name="l00307"></a>00307 
<a name="l00308"></a>00308                 <span class="keywordtype">void</span> ProcessOptions (<span class="keyword">const</span> std::map&lt;std::string, std::string&gt; &amp;options);
<a name="l00309"></a>00309                 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> ProcessOption (<span class="keyword">const</span> std::string &amp;option, <span class="keyword">const</span> std::string &amp;value);
<a name="l00310"></a>00310                 <span class="keyword">virtual</span> <span class="keywordtype">void</span> CheckPort (<span class="keywordtype">bool</span> read) = 0;
<a name="l00311"></a>00311 
<a name="l00312"></a>00312         <span class="keyword">private</span>:
<a name="l00313"></a>00313                 <span class="comment">// Private copy constructor to prevent unintended copying.</span>
<a name="l00314"></a>00314                 <a class="code" href="classflexiport_1_1Port.html" title="Base Port class.">Port</a> (<span class="keyword">const</span> <a class="code" href="classflexiport_1_1Port.html" title="Base Port class.">Port</a>&amp;);
<a name="l00315"></a>00315                 <span class="keywordtype">void</span> operator= (<span class="keyword">const</span> <a class="code" href="classflexiport_1_1Port.html" title="Base Port class.">Port</a>&amp;);
<a name="l00316"></a>00316 };
<a name="l00317"></a>00317 
<a name="l00318"></a>00318 } <span class="comment">// namespace flexiport</span>
<a name="l00319"></a>00319 
<a name="l00322"></a>00322 <span class="preprocessor">#endif // __PORT_H</span>
</pre></div></div>

            </td>
            <td colspan="1">&nbsp;</td>
         </tr>
        </table>
<!-- end of table -->

 <hr size="1"><address style="align: right;"><small>Generated for GearBox by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.5 </small></address>
</body>
</html>