PageRenderTime 66ms CodeModel.GetById 36ms app.highlight 5ms RepoModel.GetById 15ms app.codeStats 0ms

/mordor/streams/efs.h

http://github.com/mozy/mordor
C Header | 54 lines | 43 code | 10 blank | 1 comment | 0 complexity | baa194eb5c9b57122e281a52a3e3b0f0 MD5 | raw file
 1#ifndef __MORDOR_EFS_STREAM__
 2#define __MORDOR_EFS_STREAM__
 3// Copyright (c) 2009 - Mozy, Inc.
 4
 5#include "stream.h"
 6
 7namespace Mordor {
 8
 9class Fiber;
10
11class EFSStream : public Stream
12{
13public:
14    EFSStream(void *context, bool read = true, bool ownContext = true);
15    EFSStream(const char *filename, bool read = true);
16    EFSStream(const wchar_t *filename, bool read = true);
17    EFSStream(const std::string &filename, bool read = true);
18    EFSStream(const std::wstring &filename, bool read = true);
19    ~EFSStream();
20
21    bool supportsRead() { return m_read; }
22    bool supportsWrite() { return !m_read; }
23    bool supportsSeek() { return m_read; }
24
25    void close(CloseType type = BOTH);
26    size_t read(Buffer &b, size_t len);
27    size_t write(const Buffer &b, size_t len);
28    long long seek(long long offset, Anchor anchor = BEGIN);
29
30private:
31    void init();
32    void readFiber();
33    static DWORD WINAPI ExportCallback(PBYTE pbData, PVOID pvCallbackContext,
34        ULONG ulLength);
35    void writeFiber();
36    static DWORD WINAPI ImportCallback(PBYTE pbData, PVOID pvCallbackContext,
37        PULONG ulLength);
38
39private:
40    boost::shared_ptr<Fiber> m_fiber;
41    void *m_context;
42    bool m_read, m_own;
43    union {
44        Buffer *m_readBuffer;
45        const Buffer *m_writeBuffer;
46    };
47    size_t m_todo;
48    long long m_pos;
49    long long m_seekTarget;
50};
51
52}
53
54#endif