FileDevice.h
1/*
2 * Copyright (C) 2006-2007 Marc Boris Duerner
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * As a special exception, you may use this file as part of a free
10 * software library without restriction. Specifically, if other files
11 * instantiate templates or use macros or inline functions from this
12 * file, or you compile this file and link it with other files to
13 * produce an executable, this file does not by itself cause the
14 * resulting executable to be covered by the GNU General Public
15 * License. This exception does not however invalidate any other
16 * reasons why the executable file might be covered by the GNU Library
17 * General Public License.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * 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
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 */
28
29#ifndef Pt_System_FileDevice_h
30#define Pt_System_FileDevice_h
31
32#include <Pt/System/Api.h>
33#include <Pt/System/IODevice.h>
34#include <string>
35#include <ios>
36
37namespace Pt {
38
39namespace System {
40
130class PT_SYSTEM_API FileDevice : public IODevice
131{
132 public:
136
139 FileDevice(const Path& path, std::ios::openmode mode);
140
144
147 void open(const Path& path, std::ios::openmode mode);
148
151 void beginOpen(const Path& path, std::ios::openmode mode);
152
155 void endOpen();
156
160 { return _opened; }
161
164 bool isOpen() const
165 { return _isOpen; }
166
167 protected:
168 // inherit docs
169 std::size_t onBeginRead(EventLoop& loop, char* buffer, std::size_t n, bool& eof);
170
171 // inherit docs
172 std::size_t onEndRead(EventLoop& loop, char* buffer, std::size_t n, bool& eof);
173
174 // inherit docs
175 std::size_t onBeginWrite(EventLoop& loop, const char* buffer, std::size_t n);
176
177 // inherit docs
178 std::size_t onEndWrite(EventLoop& loop, const char* buffer, std::size_t n);
179
180 // inherit docs
181 void onClose();
182
183 // inherit docs
184 void onCancel();
185
186 // inherit docs
187 void onSetTimeout(std::size_t timeout);
188
189 // inherit docs
190 bool onSeekable() const;
191
192 // inherit docs
193 pos_type onSeek(off_type offset, std::ios::seekdir sd);
194
195 // inherit docs
196 std::size_t onRead(char* buffer, std::size_t count, bool& eof);
197
198 // inherit docs
199 std::size_t onWrite(const char* buffer, std::size_t count);
200
201 // inherit docs
202 std::size_t onPeek(char* buffer, std::size_t count);
203
204 // inherit docs
205 void onSync() const;
206
207 // inherit docs
208 virtual bool onRun();
209
210 private:
211 class FileDeviceImpl* _impl;
212 Signal<FileDevice&> _opened;
213 bool _opening;
214 bool _isOpen;
215};
216
217} // namespace System
218
219} // namespace Pt
220
221#endif // Pt_System_FileDevice_h
Multicast Signal to call multiple slots.
Definition Signal.h:190
Event loop of a thread or process.
Definition EventLoop.h:83
bool isOpen() const
Returns true if file is open.
Definition FileDevice.h:164
void open(const Path &path, std::ios::openmode mode)
Opens the file.
void beginOpen(const Path &path, std::ios::openmode mode)
Begin opening the file.
FileDevice()
Default Constructor.
void endOpen()
End opening the file.
FileDevice(const Path &path, std::ios::openmode mode)
Construct with path to file.
void onCancel()
Blocks until operation has cancelled.
Signal< FileDevice & > & opened()
Notifies that the file was opened.
Definition FileDevice.h:159
virtual bool onRun()
Check if ready and run.
~FileDevice()
Destructor.
IODevice()
Default Constructor.
Represents a path in the file-system.
Definition Path.h:48
System programming
Definition Connection.h:26
Core module.
Definition Allocator.h:33