1 | /* $Id: DataStreamImpl.h 74776 2018-10-11 17:30:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox COM class implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2018 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | #ifndef ____H_DATASTREAMIMPL
|
---|
20 | #define ____H_DATASTREAMIMPL
|
---|
21 |
|
---|
22 | #include "DataStreamWrap.h"
|
---|
23 |
|
---|
24 | #include <iprt/semaphore.h>
|
---|
25 |
|
---|
26 | class ATL_NO_VTABLE DataStream
|
---|
27 | : public DataStreamWrap
|
---|
28 | {
|
---|
29 | public:
|
---|
30 | DECLARE_EMPTY_CTOR_DTOR(DataStream)
|
---|
31 |
|
---|
32 | HRESULT FinalConstruct();
|
---|
33 | void FinalRelease();
|
---|
34 |
|
---|
35 | HRESULT init(unsigned long aBufferSize);
|
---|
36 | void uninit();
|
---|
37 |
|
---|
38 | /// Feed data into the stream, used by the stream source.
|
---|
39 | /// Blocks if the internal buffer cannot take anything, otherwise
|
---|
40 | /// as much as the internal buffer can hold is taken (if smaller
|
---|
41 | /// than @a cbWrite). Modeled after RTStrmWriteEx.
|
---|
42 | int i_write(const void *pvBuf, size_t cbWrite, size_t *pcbWritten);
|
---|
43 |
|
---|
44 | /// Marks the end of the stream.
|
---|
45 | int i_close();
|
---|
46 |
|
---|
47 | private:
|
---|
48 | // wrapped IDataStream attributes and methods
|
---|
49 | HRESULT getReadSize(ULONG *aReadSize);
|
---|
50 | HRESULT read(ULONG aSize, ULONG aTimeoutMS, std::vector<BYTE> &aData);
|
---|
51 |
|
---|
52 | private:
|
---|
53 | /** Maximum number of bytes the buffer can hold. */
|
---|
54 | unsigned long m_aBufferSize;
|
---|
55 | /** The temporary buffer the conversion process writes into and the user reads from. */
|
---|
56 | std::vector<BYTE> m_aBuffer;
|
---|
57 | /** Event semaphore for waiting until data is available. */
|
---|
58 | RTSEMEVENT m_hSemEvtDataAvail;
|
---|
59 | /** Event semaphore for waiting until there is room in the buffer for writing. */
|
---|
60 | RTSEMEVENT m_hSemEvtBufSpcAvail;
|
---|
61 | /** Flag whether the end of stream flag is set. */
|
---|
62 | bool m_fEos;
|
---|
63 | };
|
---|
64 |
|
---|
65 | #endif // !____H_DATASTREAMIMPL
|
---|
66 |
|
---|
67 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|