<!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"> </td> <!-- menu cell --> <td width="170" rowspan="1" colspan="1" align="left" valign="top" bgcolor="#EEEEEE"> <p> </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&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> </p> </td><!-- /menu cell --> <!-- one grey spacer cells --> <td rowspan="1" colspan="1" bgcolor="#EEEEEE"> </td> <!-- one white spacer cells --> <td rowspan="1" colspan="1"> </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 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><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 List</span></a></li> </ul> </div> <div class="navpath"><a class="el" href="dir_b8ba9ebcb71a95a44c4fd60b7d348fe1.html">src</a> » <a class="el" href="dir_26b426ffd7c02d2636b681f5b9fd4318.html">flexiport</a> </div> </div> <div class="contents"> <h1>logfile.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 <http://www.gnu.org/licenses/>.</span> <a name="l00026"></a>00026 <span class="comment"> */</span> <a name="l00027"></a>00027 <a name="l00028"></a>00028 <span class="preprocessor">#ifndef __LOGFILE_H</span> <a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define __LOGFILE_H</span> <a name="l00030"></a>00030 <span class="preprocessor"></span> <a name="l00031"></a>00031 <span class="preprocessor">#if defined (WIN32)</span> <a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor"> #include <winsock2.h></span> <span class="comment">// For timeval</span> <a name="l00033"></a>00033 <span class="preprocessor">#else</span> <a name="l00034"></a>00034 <span class="preprocessor"></span><span class="preprocessor"> #include <sys/time.h></span> <a name="l00035"></a>00035 <span class="preprocessor">#endif</span> <a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor">#include <string></span> <a name="l00037"></a>00037 <span class="preprocessor">#include <vector></span> <a name="l00038"></a>00038 <a name="l00039"></a>00039 <span class="preprocessor">#include "timeout.h"</span> <a name="l00040"></a>00040 <span class="preprocessor">#include "flexiport_types.h"</span> <a name="l00041"></a>00041 <a name="l00042"></a>00042 <span class="keyword">namespace </span>flexiport <a name="l00043"></a>00043 { <a name="l00044"></a>00044 <a name="l00045"></a>00045 <span class="comment">// Class for managing a log file pair</span> <a name="l00046"></a>00046 <span class="keyword">class </span>LogFile <a name="l00047"></a>00047 { <a name="l00048"></a>00048 <span class="keyword">public</span>: <a name="l00049"></a>00049 LogFile (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> debug); <a name="l00050"></a>00050 ~LogFile (); <a name="l00051"></a>00051 <a name="l00052"></a>00052 <span class="keywordtype">void</span> Open (std::string fileName, <span class="keywordtype">bool</span> read, <span class="keywordtype">bool</span> ignoreTimes = <span class="keyword">false</span>); <a name="l00053"></a>00053 <span class="keywordtype">void</span> Close (); <a name="l00054"></a>00054 <span class="keywordtype">bool</span> IsOpen () <span class="keyword">const</span>; <a name="l00055"></a>00055 <span class="keywordtype">void</span> ResetFile (); <a name="l00056"></a>00056 <a name="l00057"></a>00057 <span class="comment">// File reading</span> <a name="l00058"></a>00058 ssize_t Read (<span class="keywordtype">void</span> *data, <span class="keywordtype">size_t</span> count, Timeout &timeout); <a name="l00059"></a>00059 ssize_t BytesAvailable (<span class="keyword">const</span> Timeout &timeout); <a name="l00060"></a>00060 <span class="keywordtype">bool</span> CheckWrite (<span class="keyword">const</span> <span class="keywordtype">void</span> * <span class="keyword">const</span> data, <span class="keyword">const</span> <span class="keywordtype">size_t</span> count, <span class="keywordtype">size_t</span> * <span class="keyword">const</span> numWritten, <a name="l00061"></a>00061 <span class="keyword">const</span> Timeout * <span class="keyword">const</span> timeout = NULL); <a name="l00062"></a>00062 <span class="keywordtype">void</span> Flush (); <a name="l00063"></a>00063 <span class="keywordtype">void</span> Drain (); <a name="l00064"></a>00064 <a name="l00065"></a>00065 <span class="comment">// File writing</span> <a name="l00066"></a>00066 <span class="keywordtype">void</span> WriteRead (<span class="keyword">const</span> <span class="keywordtype">void</span> * <span class="keyword">const</span> data, <span class="keywordtype">size_t</span> count); <a name="l00067"></a>00067 <span class="keywordtype">void</span> WriteWrite (<span class="keyword">const</span> <span class="keywordtype">void</span> * <span class="keyword">const</span> data, <span class="keywordtype">size_t</span> count); <a name="l00068"></a>00068 <a name="l00069"></a>00069 <span class="keyword">private</span>: <a name="l00070"></a>00070 std::string _fileName; <a name="l00071"></a>00071 <span class="keywordtype">bool</span> _read; <a name="l00072"></a>00072 FILE *_readFile, *_writeFile; <a name="l00073"></a>00073 <span class="keywordtype">long</span> _readFileSize, _writeFileSize; <a name="l00074"></a>00074 <span class="comment">// When writing, this is the time the file was opened. When reading, it's the reset time.</span> <a name="l00075"></a>00075 <span class="keyword">struct </span>timeval _openTime; <a name="l00076"></a>00076 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> _debug; <a name="l00077"></a>00077 <span class="keywordtype">size_t</span> _readUsage, _writeUsage; <a name="l00078"></a>00078 <span class="keywordtype">size_t</span> _readSize, _writeSize; <a name="l00079"></a>00079 uint8_t *_readBuffer, *_writeBuffer; <a name="l00080"></a>00080 <span class="keywordtype">bool</span> _ignoreTimes; <a name="l00081"></a>00081 <a name="l00082"></a>00082 <span class="keywordtype">void</span> AllocateReadBuffer (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> size = 0); <a name="l00083"></a>00083 <span class="keywordtype">void</span> AllocateWriteBuffer (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> size = 0); <a name="l00084"></a>00084 <span class="keywordtype">void</span> DeallocateReadBuffer (); <a name="l00085"></a>00085 <span class="keywordtype">void</span> DeallocateWriteBuffer (); <a name="l00086"></a>00086 <a name="l00087"></a>00087 <span class="keywordtype">void</span> GetCurrentFileTime (<span class="keyword">struct</span> timeval &dest); <a name="l00088"></a>00088 <span class="keywordtype">bool</span> DataAvailableWithinLimit (FILE * <span class="keyword">const</span> file, <span class="keyword">const</span> <span class="keyword">struct</span> timeval &limit); <a name="l00089"></a>00089 <span class="keywordtype">void</span> GetNextChunkInfo (FILE * <span class="keyword">const</span> file, <span class="keyword">struct</span> timeval &timeStamp, <span class="keywordtype">size_t</span> &size); <a name="l00090"></a>00090 <span class="keywordtype">size_t</span> GetChunksToTimeLimit (FILE * <span class="keyword">const</span> file, <span class="keywordtype">void</span> *data, <span class="keywordtype">size_t</span> count, <a name="l00091"></a>00091 <span class="keyword">const</span> <span class="keyword">struct</span> timeval &limit); <a name="l00092"></a>00092 <span class="keywordtype">size_t</span> GetChunkSizesToTimeLimit (FILE * <span class="keyword">const</span> file, <span class="keyword">const</span> <span class="keyword">struct</span> timeval &limit); <a name="l00093"></a>00093 <span class="keywordtype">size_t</span> GetSingleChunk (FILE * <span class="keyword">const</span> file, <span class="keywordtype">void</span> *data, <span class="keywordtype">size_t</span> count, <a name="l00094"></a>00094 <span class="keyword">struct</span> timeval &timeStamp, <span class="keywordtype">size_t</span> &size); <a name="l00095"></a>00095 <span class="keywordtype">size_t</span> GetFileSize (FILE * <span class="keyword">const</span> file); <a name="l00096"></a>00096 <a name="l00097"></a>00097 <span class="keywordtype">void</span> ReadFromFile (FILE * <span class="keyword">const</span> file, <span class="keywordtype">void</span> * <span class="keyword">const</span> dest, <span class="keywordtype">size_t</span> count); <a name="l00098"></a>00098 <span class="keywordtype">void</span> WriteToFile (FILE * <span class="keyword">const</span> file, <span class="keyword">const</span> <span class="keywordtype">void</span> * <span class="keyword">const</span> data, <span class="keywordtype">size_t</span> count); <a name="l00099"></a>00099 <span class="keywordtype">void</span> WriteTimeStamp (FILE * <span class="keyword">const</span> file); <a name="l00100"></a>00100 }; <a name="l00101"></a>00101 <a name="l00102"></a>00102 } <span class="comment">// namespace flexiport</span> <a name="l00103"></a>00103 <a name="l00104"></a>00104 <span class="preprocessor">#endif // __LOGFILE_H</span> </pre></div></div> </td> <td colspan="1"> </td> </tr> </table> <!-- end of table --> <hr size="1"><address style="align: right;"><small>Generated for GearBox by <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>