From 7be3d976a223220e8e48896a401ac7e56e40ce62 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 27 Apr 2017 22:35:21 +0300 Subject: um: reorganize projects * libservice -> service * libsimple -> wrappers/simple * libnt_path_converter -> wrappers/special/nt_path_converter --- um/libservice/src/device.cpp | 136 ------------------------------------------- 1 file changed, 136 deletions(-) delete mode 100644 um/libservice/src/device.cpp (limited to 'um/libservice/src/device.cpp') diff --git a/um/libservice/src/device.cpp b/um/libservice/src/device.cpp deleted file mode 100644 index 5643106..0000000 --- a/um/libservice/src/device.cpp +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#include "libservice/all.hpp" - -#include - -#include - -#include -#include -#include -#include -#include - -namespace libservice -{ - namespace - { - Handle open_device(const std::string& path) - { - const auto raw = CreateFileA( - path.c_str(), - GENERIC_READ | GENERIC_WRITE, - 0, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (INVALID_HANDLE_VALUE == raw) - { - const auto ec = GetLastError(); - throw std::system_error( - ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); - } - - return Handle(raw); - } - } - - Device Device::open(const std::string& path) - { - return Device(open_device(path)); - } - - std::size_t Device::get_required_output_size( - Code code, - const void* in_buf, - std::size_t in_buf_size) const - { - DWORD nbreq; - - if (in_buf_size > std::numeric_limits::max()) - throw std::range_error("input buffer size is too large"); - - std::size_t nbwritten = DeviceIoControl( - handle, - code, - const_cast(in_buf), - static_cast(in_buf_size), - NULL, - 0, - &nbreq, - NULL); - - if (0 == nbwritten) - { - const auto ec = GetLastError(); - - switch (ec) - { - case ERROR_MORE_DATA: - return nbreq; - - default: - throw std::system_error( - ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); - } - } - - return nbwritten; - } - - std::size_t Device::send_control_code( - Code code, - const void* in_buf, - std::size_t in_buf_size, - void* out_buf, - std::size_t out_buf_size) const - { - DWORD nbreq; - - if (in_buf_size > std::numeric_limits::max()) - throw std::range_error("input buffer size is too large"); - if (out_buf_size > std::numeric_limits::max()) - throw std::range_error("output buffer size is too large"); - - std::size_t nbwritten = DeviceIoControl( - handle, - code, - const_cast(in_buf), - static_cast(in_buf_size), - out_buf, - static_cast(out_buf_size), - &nbreq, - NULL); - - if (0 == nbwritten) - { - const auto ec = GetLastError(); - throw std::system_error( - ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); - } - - return nbwritten; - } - - void swap(Device& a, Device& b) LIBSERVICE_NOEXCEPT - { - a.swap(b); - } -} - -namespace std -{ - template <> - void swap( - libservice::Device& a, - libservice::Device& b) - { - a.swap(b); - } -} -- cgit v1.2.3