1// StreamBinder.h
2
3#ifndef __STREAM_BINDER_H
4#define __STREAM_BINDER_H
5
6#include "../../Windows/Synchronization.h"
7
8#include "../IStream.h"
9
10class CStreamBinder
11{
12  NWindows::NSynchronization::CManualResetEvent _canWrite_Event;
13  NWindows::NSynchronization::CManualResetEvent _canRead_Event;
14  NWindows::NSynchronization::CManualResetEvent _readingWasClosed_Event;
15  bool _waitWrite;
16  UInt32 _bufSize;
17  const void *_buf;
18public:
19  UInt64 ProcessedSize;
20
21  WRes CreateEvents();
22  void CreateStreams(ISequentialInStream **inStream, ISequentialOutStream **outStream);
23  void ReInit();
24  HRESULT Read(void *data, UInt32 size, UInt32 *processedSize);
25  HRESULT Write(const void *data, UInt32 size, UInt32 *processedSize);
26  void CloseRead() { _readingWasClosed_Event.Set(); }
27  void CloseWrite()
28  {
29    // _bufSize must be = 0
30    _canRead_Event.Set();
31  }
32};
33
34#endif
35