summaryrefslogtreecommitdiffstats
path: root/other-licenses/7zstub/src/7zip/Common/StreamBinder.cpp
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2019-04-05 20:01:10 +0200
committerwolfbeast <mcwerewolf@wolfbeast.com>2019-04-05 20:01:10 +0200
commitc3b63b831cd2c64700e875b28540212c7c881ac6 (patch)
treeedd98fcbd2004d3b562904f822bf6c3322fc7f52 /other-licenses/7zstub/src/7zip/Common/StreamBinder.cpp
parentd432e068a21c815d5d5e7bcbc1cc8c6e77a7d1e0 (diff)
parentcc07da9cb4d6e7a53f8d953427ffc2bca2e0c2df (diff)
downloadUXP-c3b63b831cd2c64700e875b28540212c7c881ac6.tar
UXP-c3b63b831cd2c64700e875b28540212c7c881ac6.tar.gz
UXP-c3b63b831cd2c64700e875b28540212c7c881ac6.tar.lz
UXP-c3b63b831cd2c64700e875b28540212c7c881ac6.tar.xz
UXP-c3b63b831cd2c64700e875b28540212c7c881ac6.zip
Merge branch 'master' into 816
Diffstat (limited to 'other-licenses/7zstub/src/7zip/Common/StreamBinder.cpp')
-rw-r--r--other-licenses/7zstub/src/7zip/Common/StreamBinder.cpp162
1 files changed, 0 insertions, 162 deletions
diff --git a/other-licenses/7zstub/src/7zip/Common/StreamBinder.cpp b/other-licenses/7zstub/src/7zip/Common/StreamBinder.cpp
deleted file mode 100644
index dc11de8e5..000000000
--- a/other-licenses/7zstub/src/7zip/Common/StreamBinder.cpp
+++ /dev/null
@@ -1,162 +0,0 @@
-// StreamBinder.cpp
-
-#include "StdAfx.h"
-
-#include "StreamBinder.h"
-#include "../../Common/Defs.h"
-#include "../../Common/MyCom.h"
-
-using namespace NWindows;
-using namespace NSynchronization;
-
-class CSequentialInStreamForBinder:
- public ISequentialInStream,
- public CMyUnknownImp
-{
-public:
- MY_UNKNOWN_IMP
-
- STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
-private:
- CStreamBinder *m_StreamBinder;
-public:
- ~CSequentialInStreamForBinder() { m_StreamBinder->CloseRead(); }
- void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }
-};
-
-STDMETHODIMP CSequentialInStreamForBinder::Read(void *data, UInt32 size, UInt32 *processedSize)
- { return m_StreamBinder->Read(data, size, processedSize); }
-
-class CSequentialOutStreamForBinder:
- public ISequentialOutStream,
- public CMyUnknownImp
-{
-public:
- MY_UNKNOWN_IMP
-
- STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
-
-private:
- CStreamBinder *m_StreamBinder;
-public:
- ~CSequentialOutStreamForBinder() { m_StreamBinder->CloseWrite(); }
- void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }
-};
-
-STDMETHODIMP CSequentialOutStreamForBinder::Write(const void *data, UInt32 size, UInt32 *processedSize)
- { return m_StreamBinder->Write(data, size, processedSize); }
-
-
-//////////////////////////
-// CStreamBinder
-// (_thereAreBytesToReadEvent && _bufferSize == 0) means that stream is finished.
-
-void CStreamBinder::CreateEvents()
-{
- _allBytesAreWritenEvent = new CManualResetEvent(true);
- _thereAreBytesToReadEvent = new CManualResetEvent(false);
- _readStreamIsClosedEvent = new CManualResetEvent(false);
-}
-
-void CStreamBinder::ReInit()
-{
- _thereAreBytesToReadEvent->Reset();
- _readStreamIsClosedEvent->Reset();
- ProcessedSize = 0;
-}
-
-CStreamBinder::~CStreamBinder()
-{
- if (_allBytesAreWritenEvent != NULL)
- delete _allBytesAreWritenEvent;
- if (_thereAreBytesToReadEvent != NULL)
- delete _thereAreBytesToReadEvent;
- if (_readStreamIsClosedEvent != NULL)
- delete _readStreamIsClosedEvent;
-}
-
-
-
-
-void CStreamBinder::CreateStreams(ISequentialInStream **inStream,
- ISequentialOutStream **outStream)
-{
- CSequentialInStreamForBinder *inStreamSpec = new
- CSequentialInStreamForBinder;
- CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);
- inStreamSpec->SetBinder(this);
- *inStream = inStreamLoc.Detach();
-
- CSequentialOutStreamForBinder *outStreamSpec = new
- CSequentialOutStreamForBinder;
- CMyComPtr<ISequentialOutStream> outStreamLoc(outStreamSpec);
- outStreamSpec->SetBinder(this);
- *outStream = outStreamLoc.Detach();
-
- _buffer = NULL;
- _bufferSize= 0;
- ProcessedSize = 0;
-}
-
-HRESULT CStreamBinder::Read(void *data, UInt32 size, UInt32 *processedSize)
-{
- UInt32 sizeToRead = size;
- if (size > 0)
- {
- if(!_thereAreBytesToReadEvent->Lock())
- return E_FAIL;
- sizeToRead = MyMin(_bufferSize, size);
- if (_bufferSize > 0)
- {
- MoveMemory(data, _buffer, sizeToRead);
- _buffer = ((const Byte *)_buffer) + sizeToRead;
- _bufferSize -= sizeToRead;
- if (_bufferSize == 0)
- {
- _thereAreBytesToReadEvent->Reset();
- _allBytesAreWritenEvent->Set();
- }
- }
- }
- if (processedSize != NULL)
- *processedSize = sizeToRead;
- ProcessedSize += sizeToRead;
- return S_OK;
-}
-
-void CStreamBinder::CloseRead()
-{
- _readStreamIsClosedEvent->Set();
-}
-
-HRESULT CStreamBinder::Write(const void *data, UInt32 size, UInt32 *processedSize)
-{
- if (size > 0)
- {
- _buffer = data;
- _bufferSize = size;
- _allBytesAreWritenEvent->Reset();
- _thereAreBytesToReadEvent->Set();
-
- HANDLE events[2];
- events[0] = *_allBytesAreWritenEvent;
- events[1] = *_readStreamIsClosedEvent;
- DWORD waitResult = ::WaitForMultipleObjects(2, events, FALSE, INFINITE);
- if (waitResult != WAIT_OBJECT_0 + 0)
- {
- // ReadingWasClosed = true;
- return E_FAIL;
- }
- // if(!_allBytesAreWritenEvent.Lock())
- // return E_FAIL;
- }
- if (processedSize != NULL)
- *processedSize = size;
- return S_OK;
-}
-
-void CStreamBinder::CloseWrite()
-{
- // _bufferSize must be = 0
- _thereAreBytesToReadEvent->Set();
-}