RMS SDK for C++  0.2.1
A client library for using Microsoft RMS from Linux.
StdStreamAdapter.h
1 /*
2  * ======================================================================
3  * Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
4  * Licensed under the MIT License.
5  * See LICENSE.md in the project root for license information.
6  * ======================================================================
7  */
8 
9 #ifndef _CRYPTO_STREAMS_LIB_STDSTREAMADAPTER_H
10 #define _CRYPTO_STREAMS_LIB_STDSTREAMADAPTER_H
11 
12 #include <iostream>
13 #include "IStream.h"
14 
15 namespace rmscrypto {
16 namespace api {
17 class StdStreamAdapter : public IStream,
18  public std::enable_shared_from_this<StdStreamAdapter>{
19 public:
20 
21  StdStreamAdapter(std::shared_ptr<std::iostream>backingIOStream);
22  StdStreamAdapter(std::shared_ptr<std::ostream>backingOStream);
23  StdStreamAdapter(std::shared_ptr<std::istream>backingIStream);
24 
25  virtual std::shared_future<int64_t>ReadAsync(uint8_t *pbBuffer,
26  int64_t cbBuffer,
27  int64_t cbOffset,
28  std::launch launchType) override;
29  virtual std::shared_future<int64_t>WriteAsync(const uint8_t *cpbBuffer,
30  int64_t cbBuffer,
31  int64_t cbOffset,
32  std::launch launchType)
33  override;
34  virtual std::future<bool>FlushAsync(std::launch launchType) override;
35 
36  // Sync methods
37  virtual int64_t Read(uint8_t *pbBuffer,
38  int64_t cbBuffer) override;
39  virtual int64_t Write(const uint8_t *cpbBuffer,
40  int64_t cbBuffer) override;
41  virtual bool Flush() override;
42 
43  virtual SharedStream Clone() override;
44 
45  virtual void Seek(uint64_t u64Position) override;
46  virtual bool CanRead() const override;
47  virtual bool CanWrite() const override;
48  virtual uint64_t Position() override;
49  virtual uint64_t Size() override;
50  virtual void Size(uint64_t u64Value) override;
51 
52 private:
53 
54  StdStreamAdapter(std::shared_ptr<StdStreamAdapter>from);
55 
56  std::shared_ptr<std::mutex> m_locker;
57  std::shared_ptr<std::istream> m_iBackingStream;
58  std::shared_ptr<std::ostream> m_oBackingStream;
59 
60  int64_t ReadInternal(uint8_t *pbBuffer,
61  int64_t cbBuffer);
62  int64_t WriteInternal(const uint8_t *cpbBuffer,
63  int64_t cbBuffer);
64 };
65 } // namespace api
66 } // namespace rmscrypto
67 #endif // _CRYPTO_STREAMS_LIB_STDSTREAMADAPTER_H
Definition: BlockBasedProtectedStream.cpp:13
Base interface for protected streams.
Definition: IStream.h:34
Definition: StdStreamAdapter.h:17