1 | /* $Id: DataStreamImpl.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox COM class implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2018-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef MAIN_INCLUDED_DataStreamImpl_h
|
---|
29 | #define MAIN_INCLUDED_DataStreamImpl_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include "DataStreamWrap.h"
|
---|
35 |
|
---|
36 | #include <iprt/circbuf.h>
|
---|
37 | #include <iprt/semaphore.h>
|
---|
38 |
|
---|
39 | class ATL_NO_VTABLE DataStream
|
---|
40 | : public DataStreamWrap
|
---|
41 | {
|
---|
42 | public:
|
---|
43 | DECLARE_COMMON_CLASS_METHODS(DataStream)
|
---|
44 |
|
---|
45 | HRESULT FinalConstruct();
|
---|
46 | void FinalRelease();
|
---|
47 |
|
---|
48 | HRESULT init(unsigned long aBufferSize);
|
---|
49 | void uninit();
|
---|
50 |
|
---|
51 | /// Feed data into the stream, used by the stream source.
|
---|
52 | /// Blocks if the internal buffer cannot take anything, otherwise
|
---|
53 | /// as much as the internal buffer can hold is taken (if smaller
|
---|
54 | /// than @a cbWrite). Modeled after RTStrmWriteEx.
|
---|
55 | int i_write(const void *pvBuf, size_t cbWrite, size_t *pcbWritten);
|
---|
56 |
|
---|
57 | /// Marks the end of the stream.
|
---|
58 | int i_close();
|
---|
59 |
|
---|
60 | private:
|
---|
61 | // wrapped IDataStream attributes and methods
|
---|
62 | HRESULT getReadSize(ULONG *aReadSize);
|
---|
63 | HRESULT read(ULONG aSize, ULONG aTimeoutMS, std::vector<BYTE> &aData);
|
---|
64 |
|
---|
65 | private:
|
---|
66 | /** The temporary buffer the conversion process writes into and the user reads from. */
|
---|
67 | PRTCIRCBUF m_pBuffer;
|
---|
68 | /** Event semaphore for waiting until data is available. */
|
---|
69 | RTSEMEVENT m_hSemEvtDataAvail;
|
---|
70 | /** Event semaphore for waiting until there is room in the buffer for writing. */
|
---|
71 | RTSEMEVENT m_hSemEvtBufSpcAvail;
|
---|
72 | /** Flag whether the end of stream flag is set. */
|
---|
73 | bool m_fEos;
|
---|
74 | };
|
---|
75 |
|
---|
76 | #endif /* !MAIN_INCLUDED_DataStreamImpl_h */
|
---|
77 |
|
---|
78 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|