From b3eef140da853414776c8e03a70629a613a25ed0 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 15 Jun 2026 14:05:29 +0200 Subject: workflows/ci: add clang-format job --- um/service/src/device.cpp | 181 +++++++++++++++++++++++----------------------- 1 file changed, 89 insertions(+), 92 deletions(-) (limited to 'um/service/src/device.cpp') diff --git a/um/service/src/device.cpp b/um/service/src/device.cpp index 870930f..2634a9a 100644 --- a/um/service/src/device.cpp +++ b/um/service/src/device.cpp @@ -8,108 +8,105 @@ #include #include - #include #include #include -namespace service -{ - 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 windows_error::make(ec, __FILE__, __LINE__, __FUNCTION__); - } - - return Handle(raw); - } +namespace service { +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 windows_error::make(ec, __FILE__, __LINE__, __FUNCTION__); } - Device Device::open(const std::string& path) - { - return Device(open_device(path)); - } + return Handle(raw); +} - 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 windows_error::make(ec, __FILE__, __LINE__, __FUNCTION__); - } - } +} // namespace - return nbwritten; - } +Device Device::open(const std::string& path) { + return Device(open_device(path)); +} - 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 windows_error::make(ec, __FILE__, __LINE__, __FUNCTION__); +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 windows_error::make(ec, __FILE__, __LINE__, __FUNCTION__); } + } - return nbwritten; + 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 windows_error::make(ec, __FILE__, __LINE__, __FUNCTION__); } + + return nbwritten; } + +} // namespace service -- cgit v1.3