INTRODUCTION
Overview
Download and Install
Documentation
Publications

REPOSITORY
Libraries

DEVELOPER
Dev Guide
Dashboard

PEOPLE
Contributors
Users

SourceForge.net Logo
Project
Download
Mailing lists

 

         

logfile.h

00001 /*
00002  * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics
00003  *               http://gearbox.sf.net/
00004  * Copyright (c) 2008 Geoffrey Biggs
00005  *
00006  * flexiport flexible hardware data communications library.
00007  * 
00008  * This distribution is licensed to you under the terms described in the LICENSE file included in 
00009  * this distribution.
00010  *
00011  * This work is a product of the National Institute of Advanced Industrial Science and Technology,
00012  * Japan. Registration number: H20PRO-881
00013  * 
00014  * This file is part of flexiport.
00015  *
00016  * flexiport is free software: you can redistribute it and/or modify it under the terms of the GNU
00017  * Lesser General Public License as published by the Free Software Foundation, either version 3 of 
00018  * the License, or (at your option) any later version.
00019  *
00020  * flexiport is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
00021  * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022  * Lesser General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU Lesser General Public License along with flexiport.
00025  * If not, see <http://www.gnu.org/licenses/>.
00026  */
00027 
00028 #ifndef __LOGFILE_H
00029 #define __LOGFILE_H
00030 
00031 #if defined (WIN32)
00032         #include <winsock2.h> // For timeval
00033 #else
00034         #include <sys/time.h>
00035 #endif
00036 #include <string>
00037 #include <vector>
00038 
00039 #include "timeout.h"
00040 #include "flexiport_types.h"
00041 
00042 namespace flexiport
00043 {
00044 
00045 // Class for managing a log file pair
00046 class LogFile
00047 {
00048         public:
00049                 LogFile (unsigned int debug);
00050                 ~LogFile ();
00051 
00052                 void Open (std::string fileName, bool read, bool ignoreTimes = false);
00053                 void Close ();
00054                 bool IsOpen () const;
00055                 void ResetFile ();
00056 
00057                 // File reading
00058                 ssize_t Read (void *data, size_t count, Timeout &timeout);
00059                 ssize_t BytesAvailable (const Timeout &timeout);
00060                 bool CheckWrite (const void * const data, const size_t count, size_t * const numWritten,
00061                                 const Timeout * const timeout = NULL);
00062                 void Flush ();
00063                 void Drain ();
00064 
00065                 // File writing
00066                 void WriteRead (const void * const data, size_t count);
00067                 void WriteWrite (const void * const data, size_t count);
00068 
00069         private:
00070                 std::string _fileName;
00071                 bool _read;
00072                 FILE *_readFile, *_writeFile;
00073                 long _readFileSize, _writeFileSize;
00074                 // When writing, this is the time the file was opened. When reading, it's the reset time.
00075                 struct timeval _openTime;
00076                 unsigned int _debug;
00077                 size_t _readUsage, _writeUsage;
00078                 size_t _readSize, _writeSize;
00079                 uint8_t *_readBuffer, *_writeBuffer;
00080                 bool _ignoreTimes;
00081 
00082                 void AllocateReadBuffer (unsigned int size = 0);
00083                 void AllocateWriteBuffer (unsigned int size = 0);
00084                 void DeallocateReadBuffer ();
00085                 void DeallocateWriteBuffer ();
00086 
00087                 void GetCurrentFileTime (struct timeval &dest);
00088                 bool DataAvailableWithinLimit (FILE * const file, const struct timeval &limit);
00089                 void GetNextChunkInfo (FILE * const file, struct timeval &timeStamp, size_t &size);
00090                 size_t GetChunksToTimeLimit (FILE * const file, void *data, size_t count,
00091                                                                 const struct timeval &limit);
00092                 size_t GetChunkSizesToTimeLimit (FILE * const file, const struct timeval &limit);
00093                 size_t GetSingleChunk (FILE * const file, void *data, size_t count,
00094                                                                 struct timeval &timeStamp, size_t &size);
00095                 size_t GetFileSize (FILE * const file);
00096 
00097                 void ReadFromFile (FILE * const file, void * const dest, size_t count);
00098                 void WriteToFile (FILE * const file, const void * const data, size_t count);
00099                 void WriteTimeStamp (FILE * const file);
00100 };
00101 
00102 } // namespace flexiport
00103 
00104 #endif // __LOGFILE_H
 

Generated for GearBox by  doxygen 1.4.5