1 | /* $Id: DataStreamImpl.h 76487 2018-12-27 03:31:39Z 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 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
22 | # pragma once
|
---|
23 | #endif
|
---|
24 |
|
---|
25 | #include "DataStreamWrap.h"
|
---|
26 |
|
---|
27 | #include <iprt/circbuf.h>
|
---|
28 | #include <iprt/semaphore.h>
|
---|
29 |
|
---|
30 | class ATL_NO_VTABLE DataStream
|
---|
31 | : public DataStreamWrap
|
---|
32 | {
|
---|
33 | public:
|
---|
34 | DECLARE_EMPTY_CTOR_DTOR(DataStream)
|
---|
35 |
|
---|
36 | HRESULT FinalConstruct();
|
---|
37 | void FinalRelease();
|
---|
38 |
|
---|
39 | HRESULT init(unsigned long aBufferSize);
|
---|
40 | void uninit();
|
---|
41 |
|
---|
42 | /// Feed data into the stream, used by the stream source.
|
---|
43 | /// Blocks if the internal buffer cannot take anything, otherwise
|
---|
44 | /// as much as the internal buffer can hold is taken (if smaller
|
---|
45 | /// than @a cbWrite). Modeled after RTStrmWriteEx.
|
---|
46 | int i_write(const void *pvBuf, size_t cbWrite, size_t *pcbWritten);
|
---|
47 |
|
---|
48 | /// Marks the end of the stream.
|
---|
49 | int i_close();
|
---|
50 |
|
---|
51 | private:
|
---|
52 | // wrapped IDataStream attributes and methods
|
---|
53 | HRESULT getReadSize(ULONG *aReadSize);
|
---|
54 | HRESULT read(ULONG aSize, ULONG aTimeoutMS, std::vector<BYTE> &aData);
|
---|
55 |
|
---|
56 | private:
|
---|
57 | /** The temporary buffer the conversion process writes into and the user reads from. */
|
---|
58 | PRTCIRCBUF m_pBuffer;
|
---|
59 | /** Event semaphore for waiting until data is available. */
|
---|
60 | RTSEMEVENT m_hSemEvtDataAvail;
|
---|
61 | /** Event semaphore for waiting until there is room in the buffer for writing. */
|
---|
62 | RTSEMEVENT m_hSemEvtBufSpcAvail;
|
---|
63 | /** Flag whether the end of stream flag is set. */
|
---|
64 | bool m_fEos;
|
---|
65 | };
|
---|
66 |
|
---|
67 | #endif // !____H_DATASTREAMIMPL
|
---|
68 |
|
---|
69 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|