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
1 /*
2  * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics
3  * http://gearbox.sf.net/
4  * Copyright (c) 2008 Geoffrey Biggs
5  *
6  * flexiport flexible hardware data communications library.
7  *
8  * This distribution is licensed to you under the terms described in the LICENSE file included in
9  * this distribution.
10  *
11  * This work is a product of the National Institute of Advanced Industrial Science and Technology,
12  * Japan. Registration number: H20PRO-881
13  *
14  * This file is part of flexiport.
15  *
16  * flexiport is free software: you can redistribute it and/or modify it under the terms of the GNU
17  * Lesser General Public License as published by the Free Software Foundation, either version 3 of
18  * the License, or (at your option) any later version.
19  *
20  * flexiport is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
21  * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public License along with flexiport.
25  * If not, see <http://www.gnu.org/licenses/>.
26  */
27 
28 #ifndef __LOGFILE_H
29 #define __LOGFILE_H
30 
31 #if defined (WIN32)
32  #include <winsock2.h> // For timeval
33 #else
34  #include <unistd.h>
35  #include <sys/time.h>
36 #endif
37 #include <string>
38 #include <vector>
39 
40 #include "timeout.h"
41 #include "flexiport_types.h"
42 
43 namespace flexiport
44 {
45 
46 // Class for managing a log file pair
47 class LogFile
48 {
49  public:
50  LogFile (unsigned int debug);
51  ~LogFile ();
52 
53  void Open (std::string fileName, bool read, bool ignoreTimes = false);
54  void Close ();
55  bool IsOpen () const;
56  void ResetFile ();
57 
58  // File reading
59  ssize_t Read (void *data, size_t count, Timeout &timeout);
60  ssize_t BytesAvailable (const Timeout &timeout);
61  bool CheckWrite (const void * const data, const size_t count, size_t * const numWritten,
62  const Timeout * const timeout = NULL);
63  void Flush ();
64  void Drain ();
65 
66  // File writing
67  void WriteRead (const void * const data, size_t count);
68  void WriteWrite (const void * const data, size_t count);
69 
70  private:
71  std::string _fileName;
72  bool _read;
73  FILE *_readFile, *_writeFile;
74  long _readFileSize, _writeFileSize;
75  // When writing, this is the time the file was opened. When reading, it's the reset time.
76  struct timeval _openTime;
77  unsigned int _debug;
78  size_t _readUsage, _writeUsage;
79  size_t _readSize, _writeSize;
80  uint8_t *_readBuffer, *_writeBuffer;
81  bool _ignoreTimes;
82 
83  void AllocateReadBuffer (unsigned int size = 0);
84  void AllocateWriteBuffer (unsigned int size = 0);
85  void DeallocateReadBuffer ();
86  void DeallocateWriteBuffer ();
87 
88  void GetCurrentFileTime (struct timeval &dest);
89  bool DataAvailableWithinLimit (FILE * const file, const struct timeval &limit);
90  void GetNextChunkInfo (FILE * const file, struct timeval &timeStamp, size_t &size);
91  size_t GetChunksToTimeLimit (FILE * const file, void *data, size_t count,
92  const struct timeval &limit);
93  size_t GetChunkSizesToTimeLimit (FILE * const file, const struct timeval &limit);
94  size_t GetSingleChunk (FILE * const file, void *data, size_t count,
95  struct timeval &timeStamp, size_t &size);
96  size_t GetFileSize (FILE * const file);
97 
98  void ReadFromFile (FILE * const file, void * const dest, size_t count);
99  void WriteToFile (FILE * const file, const void * const data, size_t count);
100  void WriteTimeStamp (FILE * const file);
101 };
102 
103 } // namespace flexiport
104 
105 #endif // __LOGFILE_H
FlexiPort data communications library.
 

Generated for GearBox by  doxygen 1.4.5