aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/um/libservice/include/libservice/device.hpp
blob: ac292c884ca698d6f58d29f89d218c519179cfcc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) 2015 Egor Tensin <Egor.Tensin@gmail.com>
// 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.

#pragma once

#include "common.hpp"
#include "handle.hpp"

#include <Windows.h>

#include <cstddef>

#include <string>
#include <utility>

namespace libservice
{
    class Device
    {
    public:
        typedef DWORD Code;

        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(handle, other.handle);
        }

        std::size_t get_required_output_size(
            Code code,
            const void* in_buf,
            std::size_t in_buf_size) const;

        std::size_t 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;

    private:
        Device(Handle handle)
            : handle(std::move(handle))
        { }

        Handle handle;

        Device(const Device&) = delete;
    };

    void swap(Device&, Device&) LIBSERVICE_NOEXCEPT;
}

namespace std
{
    template <>
    void swap<libservice::Device>(
        libservice::Device&,
        libservice::Device&) LIBSERVICE_NOEXCEPT;
}