Async 1.8.0
AsyncFileReader.h
Go to the documentation of this file.
1
31#ifndef FILE_READER_INCLUDED
32#define FILE_READER_INCLUDED
33
34
35/****************************************************************************
36 *
37 * System Includes
38 *
39 ****************************************************************************/
40
41#include <sigc++/sigc++.h>
42#include <unistd.h>
43
44#include <string>
45
46
47/****************************************************************************
48 *
49 * Project Includes
50 *
51 ****************************************************************************/
52
53
54
55/****************************************************************************
56 *
57 * Local Includes
58 *
59 ****************************************************************************/
60
61
62
63/****************************************************************************
64 *
65 * Forward declarations
66 *
67 ****************************************************************************/
68
69
70
71/****************************************************************************
72 *
73 * Namespace
74 *
75 ****************************************************************************/
76
77namespace Async
78{
79
80
81/****************************************************************************
82 *
83 * Forward declarations of classes inside of the declared namespace
84 *
85 ****************************************************************************/
86
87class FdWatch;
88
89
90/****************************************************************************
91 *
92 * Defines & typedefs
93 *
94 ****************************************************************************/
95
96
97
98/****************************************************************************
99 *
100 * Exported Global Variables
101 *
102 ****************************************************************************/
103
104
105
106/****************************************************************************
107 *
108 * Class definitions
109 *
110 ****************************************************************************/
111
112class FileReader : public sigc::trackable
113{
114 public:
115
124 FileReader(int buf_size);
125
130
136 bool open(const std::string& name);
137
142 bool close(void);
143
150 bool isOpen(void) const { return (fd != -1); }
151
159 int read(void *buf, int len);
160
161
162 private:
163 int fd;
164 FdWatch *rd_watch;
165 char *buffer;
166 int head, tail;
167 int buf_size;
168 bool is_full;
169 bool is_eof;
170
171 void onDataAvail(FdWatch *watch);
172 bool fillBuffer(void);
173 int bytesInBuffer(void) const;
174
175}; /* class FileReader */
176
177
178} /* namespace */
179
180#endif /* FILE_READER_INCLUDED */
181
182
183
184/*
185 * This file has not been truncated
186 */
187
A class for watching file descriptors.
bool open(const std::string &name)
Open a file for binary reading.
bool isOpen(void) const
Check if a file is currently opened.
int read(void *buf, int len)
Read data from a previously opened file.
~FileReader(void)
Destructor.
FileReader(int buf_size)
Constuctor.
bool close(void)
Close a previously opened file.
Namespace for the asynchronous programming classes.