Chris@16
|
1 //
|
Chris@16
|
2 // detail/impl/buffer_sequence_adapter.ipp
|
Chris@16
|
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
Chris@16
|
4 //
|
Chris@101
|
5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
Chris@16
|
6 //
|
Chris@16
|
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
9 //
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_ASIO_DETAIL_IMPL_BUFFER_SEQUENCE_ADAPTER_IPP
|
Chris@16
|
12 #define BOOST_ASIO_DETAIL_IMPL_BUFFER_SEQUENCE_ADAPTER_IPP
|
Chris@16
|
13
|
Chris@16
|
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
15 # pragma once
|
Chris@16
|
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/asio/detail/config.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
|
Chris@16
|
21
|
Chris@16
|
22 #include <robuffer.h>
|
Chris@16
|
23 #include <windows.storage.streams.h>
|
Chris@16
|
24 #include <wrl/implements.h>
|
Chris@16
|
25 #include <boost/asio/detail/buffer_sequence_adapter.hpp>
|
Chris@16
|
26
|
Chris@16
|
27 #include <boost/asio/detail/push_options.hpp>
|
Chris@16
|
28
|
Chris@16
|
29 namespace boost {
|
Chris@16
|
30 namespace asio {
|
Chris@16
|
31 namespace detail {
|
Chris@16
|
32
|
Chris@16
|
33 class winrt_buffer_impl :
|
Chris@16
|
34 public Microsoft::WRL::RuntimeClass<
|
Chris@16
|
35 Microsoft::WRL::RuntimeClassFlags<
|
Chris@16
|
36 Microsoft::WRL::RuntimeClassType::WinRtClassicComMix>,
|
Chris@16
|
37 ABI::Windows::Storage::Streams::IBuffer,
|
Chris@16
|
38 Windows::Storage::Streams::IBufferByteAccess>
|
Chris@16
|
39 {
|
Chris@16
|
40 public:
|
Chris@16
|
41 explicit winrt_buffer_impl(const boost::asio::const_buffer& b)
|
Chris@16
|
42 {
|
Chris@16
|
43 bytes_ = const_cast<byte*>(boost::asio::buffer_cast<const byte*>(b));
|
Chris@16
|
44 length_ = boost::asio::buffer_size(b);
|
Chris@16
|
45 capacity_ = boost::asio::buffer_size(b);
|
Chris@16
|
46 }
|
Chris@16
|
47
|
Chris@16
|
48 explicit winrt_buffer_impl(const boost::asio::mutable_buffer& b)
|
Chris@16
|
49 {
|
Chris@16
|
50 bytes_ = const_cast<byte*>(boost::asio::buffer_cast<const byte*>(b));
|
Chris@16
|
51 length_ = 0;
|
Chris@16
|
52 capacity_ = boost::asio::buffer_size(b);
|
Chris@16
|
53 }
|
Chris@16
|
54
|
Chris@16
|
55 ~winrt_buffer_impl()
|
Chris@16
|
56 {
|
Chris@16
|
57 }
|
Chris@16
|
58
|
Chris@16
|
59 STDMETHODIMP Buffer(byte** value)
|
Chris@16
|
60 {
|
Chris@16
|
61 *value = bytes_;
|
Chris@16
|
62 return S_OK;
|
Chris@16
|
63 }
|
Chris@16
|
64
|
Chris@16
|
65 STDMETHODIMP get_Capacity(UINT32* value)
|
Chris@16
|
66 {
|
Chris@16
|
67 *value = capacity_;
|
Chris@16
|
68 return S_OK;
|
Chris@16
|
69 }
|
Chris@16
|
70
|
Chris@16
|
71 STDMETHODIMP get_Length(UINT32 *value)
|
Chris@16
|
72 {
|
Chris@16
|
73 *value = length_;
|
Chris@16
|
74 return S_OK;
|
Chris@16
|
75 }
|
Chris@16
|
76
|
Chris@16
|
77 STDMETHODIMP put_Length(UINT32 value)
|
Chris@16
|
78 {
|
Chris@16
|
79 if (value > capacity_)
|
Chris@16
|
80 return E_INVALIDARG;
|
Chris@16
|
81 length_ = value;
|
Chris@16
|
82 return S_OK;
|
Chris@16
|
83 }
|
Chris@16
|
84
|
Chris@16
|
85 private:
|
Chris@16
|
86 byte* bytes_;
|
Chris@16
|
87 UINT32 length_;
|
Chris@16
|
88 UINT32 capacity_;
|
Chris@16
|
89 };
|
Chris@16
|
90
|
Chris@16
|
91 void buffer_sequence_adapter_base::init_native_buffer(
|
Chris@16
|
92 buffer_sequence_adapter_base::native_buffer_type& buf,
|
Chris@16
|
93 const boost::asio::mutable_buffer& buffer)
|
Chris@16
|
94 {
|
Chris@16
|
95 std::memset(&buf, 0, sizeof(native_buffer_type));
|
Chris@16
|
96 Microsoft::WRL::ComPtr<IInspectable> insp
|
Chris@16
|
97 = Microsoft::WRL::Make<winrt_buffer_impl>(buffer);
|
Chris@16
|
98 buf = reinterpret_cast<Windows::Storage::Streams::IBuffer^>(insp.Get());
|
Chris@16
|
99 }
|
Chris@16
|
100
|
Chris@16
|
101 void buffer_sequence_adapter_base::init_native_buffer(
|
Chris@16
|
102 buffer_sequence_adapter_base::native_buffer_type& buf,
|
Chris@16
|
103 const boost::asio::const_buffer& buffer)
|
Chris@16
|
104 {
|
Chris@16
|
105 std::memset(&buf, 0, sizeof(native_buffer_type));
|
Chris@16
|
106 Microsoft::WRL::ComPtr<IInspectable> insp
|
Chris@16
|
107 = Microsoft::WRL::Make<winrt_buffer_impl>(buffer);
|
Chris@16
|
108 Platform::Object^ buf_obj = reinterpret_cast<Platform::Object^>(insp.Get());
|
Chris@16
|
109 buf = reinterpret_cast<Windows::Storage::Streams::IBuffer^>(insp.Get());
|
Chris@16
|
110 }
|
Chris@16
|
111
|
Chris@16
|
112 } // namespace detail
|
Chris@16
|
113 } // namespace asio
|
Chris@16
|
114 } // namespace boost
|
Chris@16
|
115
|
Chris@16
|
116 #include <boost/asio/detail/pop_options.hpp>
|
Chris@16
|
117
|
Chris@16
|
118 #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME)
|
Chris@16
|
119
|
Chris@16
|
120 #endif // BOOST_ASIO_DETAIL_IMPL_BUFFER_SEQUENCE_ADAPTER_IPP
|