PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 6ms RepoModel.GetById 35ms app.codeStats 0ms

/mordor/streams/handle.h

http://github.com/mozy/mordor
C Header | 64 lines | 51 code | 12 blank | 1 comment | 1 complexity | 291947c29b810f0d73001b00d3952210 MD5 | raw file
 1#ifndef __MORDOR_HANDLE_STREAM_H__
 2#define __MORDOR_HANDLE_STREAM_H__
 3// Copyright (c) 2009 - Mozy, Inc.
 4
 5#include <windows.h>
 6
 7#include "mordor/iomanager.h"
 8#include "stream.h"
 9
10namespace Mordor {
11
12class HandleStream : public Stream
13{
14public:
15    typedef boost::shared_ptr<HandleStream> ptr;
16
17protected:
18    HandleStream();
19    void init(HANDLE hFile, IOManager *ioManager = NULL,
20        Scheduler *scheduler = NULL, bool own = true);
21public:
22    HandleStream(HANDLE hFile, IOManager *ioManager = NULL,
23        Scheduler *scheduler = NULL, bool own = true) :
24        m_maxOpSize(0xffffffff)
25    { init(hFile, ioManager, scheduler, own); }
26    ~HandleStream();
27
28    bool supportsRead() { return true; }
29    bool supportsWrite() { return true; }
30    bool supportsCancel();
31    bool supportsSeek() { return GetFileType(m_hFile) == FILE_TYPE_DISK; }
32    bool supportsSize() { return supportsSeek(); }
33    bool supportsTruncate() { return supportsSeek(); }
34
35    void close(CloseType type = BOTH);
36    size_t read(void *buffer, size_t length);
37    void cancelRead();
38    size_t write(const void *buffer, size_t length);
39    void cancelWrite();
40    long long seek(long long offset, Anchor anchor = BEGIN);
41    long long size();
42    void truncate(long long size);
43    void flush(bool flushParent = true);
44
45    HANDLE handle() { return m_hFile; }
46
47protected:
48    IOManager *m_ioManager;
49    bool m_skipCompletionPortOnSuccess;
50    Scheduler *m_scheduler;
51    AsyncEvent m_readEvent;
52    AsyncEvent m_writeEvent;
53    long long m_pos;
54    HANDLE m_hFile;
55    bool m_own, m_cancelRead, m_cancelWrite;
56    size_t m_maxOpSize;
57};
58
59typedef HandleStream NativeStream;
60typedef HANDLE NativeHandle;
61
62}
63
64#endif