Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:31

0001 //
0002 // detail/impl/buffer_sequence_adapter.ipp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_DETAIL_IMPL_BUFFER_SEQUENCE_ADAPTER_IPP
0012 #define BOOST_ASIO_DETAIL_IMPL_BUFFER_SEQUENCE_ADAPTER_IPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 
0020 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
0021 
0022 #include <robuffer.h>
0023 #include <windows.storage.streams.h>
0024 #include <wrl/implements.h>
0025 #include <boost/asio/detail/buffer_sequence_adapter.hpp>
0026 
0027 #include <boost/asio/detail/push_options.hpp>
0028 
0029 namespace boost {
0030 namespace asio {
0031 namespace detail {
0032 
0033 class winrt_buffer_impl :
0034   public Microsoft::WRL::RuntimeClass<
0035     Microsoft::WRL::RuntimeClassFlags<
0036       Microsoft::WRL::RuntimeClassType::WinRtClassicComMix>,
0037     ABI::Windows::Storage::Streams::IBuffer,
0038     Windows::Storage::Streams::IBufferByteAccess>
0039 {
0040 public:
0041   explicit winrt_buffer_impl(const boost::asio::const_buffer& b)
0042   {
0043     bytes_ = const_cast<byte*>(static_cast<const byte*>(b.data()));
0044     length_ = b.size();
0045     capacity_ = b.size();
0046   }
0047 
0048   explicit winrt_buffer_impl(const boost::asio::mutable_buffer& b)
0049   {
0050     bytes_ = static_cast<byte*>(b.data());
0051     length_ = 0;
0052     capacity_ = b.size();
0053   }
0054 
0055   ~winrt_buffer_impl()
0056   {
0057   }
0058 
0059   STDMETHODIMP Buffer(byte** value)
0060   {
0061     *value = bytes_;
0062     return S_OK;
0063   }
0064 
0065   STDMETHODIMP get_Capacity(UINT32* value)
0066   {
0067     *value = capacity_;
0068     return S_OK;
0069   }
0070 
0071   STDMETHODIMP get_Length(UINT32 *value)
0072   {
0073     *value = length_;
0074     return S_OK;
0075   }
0076 
0077   STDMETHODIMP put_Length(UINT32 value)
0078   {
0079     if (value > capacity_)
0080       return E_INVALIDARG;
0081     length_ = value;
0082     return S_OK;
0083   }
0084 
0085 private:
0086   byte* bytes_;
0087   UINT32 length_;
0088   UINT32 capacity_;
0089 };
0090 
0091 void buffer_sequence_adapter_base::init_native_buffer(
0092     buffer_sequence_adapter_base::native_buffer_type& buf,
0093     const boost::asio::mutable_buffer& buffer)
0094 {
0095   std::memset(&buf, 0, sizeof(native_buffer_type));
0096   Microsoft::WRL::ComPtr<IInspectable> insp
0097     = Microsoft::WRL::Make<winrt_buffer_impl>(buffer);
0098   buf = reinterpret_cast<Windows::Storage::Streams::IBuffer^>(insp.Get());
0099 }
0100 
0101 void buffer_sequence_adapter_base::init_native_buffer(
0102     buffer_sequence_adapter_base::native_buffer_type& buf,
0103     const boost::asio::const_buffer& buffer)
0104 {
0105   std::memset(&buf, 0, sizeof(native_buffer_type));
0106   Microsoft::WRL::ComPtr<IInspectable> insp
0107     = Microsoft::WRL::Make<winrt_buffer_impl>(buffer);
0108   Platform::Object^ buf_obj = reinterpret_cast<Platform::Object^>(insp.Get());
0109   buf = reinterpret_cast<Windows::Storage::Streams::IBuffer^>(insp.Get());
0110 }
0111 
0112 } // namespace detail
0113 } // namespace asio
0114 } // namespace boost
0115 
0116 #include <boost/asio/detail/pop_options.hpp>
0117 
0118 #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME)
0119 
0120 #endif // BOOST_ASIO_DETAIL_IMPL_BUFFER_SEQUENCE_ADAPTER_IPP