aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/utils/libservice/include
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2015-05-11 13:32:30 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2015-05-11 13:32:30 +0300
commit9bf7f2bfeb3057ad8b49fc0361fee5036639dfe1 (patch)
tree5b13e2c7a9ec6298da8050c217009517e25f10c4 /utils/libservice/include
parentnt_path_converter: logging & \0-termination (diff)
downloadwindows7-drivers-9bf7f2bfeb3057ad8b49fc0361fee5036639dfe1.tar.gz
windows7-drivers-9bf7f2bfeb3057ad8b49fc0361fee5036639dfe1.zip
libservice: add virtual device wrappers
Diffstat (limited to 'utils/libservice/include')
-rw-r--r--utils/libservice/include/libservice/device.hpp71
-rw-r--r--utils/libservice/include/libservice/handle.hpp80
-rw-r--r--utils/libservice/include/libservice/interface.hpp2
3 files changed, 153 insertions, 0 deletions
diff --git a/utils/libservice/include/libservice/device.hpp b/utils/libservice/include/libservice/device.hpp
new file mode 100644
index 0000000..3a9540e
--- /dev/null
+++ b/utils/libservice/include/libservice/device.hpp
@@ -0,0 +1,71 @@
+/**
+ * \file
+ * \author Egor Tensin <Egor.Tensin@gmail.com>
+ * \date 2015
+ * \copyright This file is licensed under the terms of the MIT License.
+ * See LICENSE.txt for details.
+ */
+
+#pragma once
+
+#include "common.hpp"
+#include "handle.hpp"
+
+#include <Windows.h>
+
+#include <string>
+#include <utility>
+
+namespace libservice
+{
+ class Device
+ {
+ public:
+ static Device open(const std::string& path);
+
+ Device(Device&& other) LIBSERVICE_NOEXCEPT
+ {
+ swap(other);
+ }
+
+ Device& operator=(Device other) LIBSERVICE_NOEXCEPT
+ {
+ swap(other);
+ return *this;
+ }
+
+ void swap(Device& other) LIBSERVICE_NOEXCEPT
+ {
+ using std::swap;
+ swap(m_handle, other.m_handle);
+ }
+
+ DWORD get_required_output_size(DWORD code,
+ const void* in_buf,
+ DWORD in_buf_size) const;
+
+ DWORD send_control_code(DWORD code,
+ const void* in_buf,
+ DWORD in_buf_size,
+ void* out_buf,
+ DWORD out_buf_size) const;
+
+ private:
+ explicit Device(Handle h)
+ : m_handle(std::move(h))
+ { }
+
+ Handle m_handle;
+
+ Device(const Device&) = delete;
+ };
+
+ void swap(libservice::Device&, libservice::Device&) LIBSERVICE_NOEXCEPT;
+}
+
+namespace std
+{
+ template <>
+ void swap<libservice::Device>(
+ libservice::Device&, libservice::Device&) LIBSERVICE_NOEXCEPT;
+}
diff --git a/utils/libservice/include/libservice/handle.hpp b/utils/libservice/include/libservice/handle.hpp
new file mode 100644
index 0000000..1292090
--- /dev/null
+++ b/utils/libservice/include/libservice/handle.hpp
@@ -0,0 +1,80 @@
+/**
+ * \file
+ * \author Egor Tensin <Egor.Tensin@gmail.com>
+ * \date 2015
+ * \copyright This file is licensed under the terms of the MIT License.
+ * See LICENSE.txt for details.
+ */
+
+#pragma once
+
+#include "common.hpp"
+
+#include <Windows.h>
+
+#include <memory>
+#include <type_traits>
+#include <utility>
+
+namespace libservice
+{
+ class Handle
+ {
+ public:
+ Handle() = default;
+
+ explicit Handle(HANDLE raw)
+ : m_impl(raw)
+ { }
+
+ Handle(Handle&& other) LIBSERVICE_NOEXCEPT
+ {
+ swap(other);
+ }
+
+ Handle& operator=(Handle other) LIBSERVICE_NOEXCEPT
+ {
+ swap(other);
+ return *this;
+ }
+
+ explicit operator bool() const
+ {
+ return static_cast<bool>(m_impl);
+ }
+
+ explicit operator HANDLE() const
+ {
+ return m_impl.get();
+ }
+
+ void swap(Handle& other) LIBSERVICE_NOEXCEPT
+ {
+ using std::swap;
+ swap(m_impl, other.m_impl);
+ }
+
+ private:
+ struct Deleter
+ {
+ void operator()(HANDLE raw)
+ {
+ ::CloseHandle(raw);
+ }
+ };
+
+ std::unique_ptr<std::remove_pointer<HANDLE>::type, Deleter> m_impl;
+
+ Handle(const Handle&) = delete;
+ };
+
+ void swap(Handle& a, Handle& b) LIBSERVICE_NOEXCEPT;
+}
+
+namespace std
+{
+ template <>
+ void swap<libservice::Handle>(
+ libservice::Handle& a,
+ libservice::Handle& b) LIBSERVICE_NOEXCEPT;
+}
diff --git a/utils/libservice/include/libservice/interface.hpp b/utils/libservice/include/libservice/interface.hpp
index 53751b2..e68439b 100644
--- a/utils/libservice/include/libservice/interface.hpp
+++ b/utils/libservice/include/libservice/interface.hpp
@@ -9,6 +9,8 @@
#pragma once
#include "common.hpp"
+#include "device.hpp"
+#include "handle.hpp"
#include "service.hpp"
#include "service_handle.hpp"
#include "service_manager.hpp"