aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/um/service/include
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-06-15 14:05:29 +0200
committerEgor Tensin <egor@tensin.name>2026-06-15 14:12:29 +0200
commitb3eef140da853414776c8e03a70629a613a25ed0 (patch)
treedcdb314d2fdd92f501c09f3ae5681a731cb00dee /um/service/include
parentwdk10: disable the packaging target (diff)
downloadwindows7-drivers-b3eef140da853414776c8e03a70629a613a25ed0.tar.gz
windows7-drivers-b3eef140da853414776c8e03a70629a613a25ed0.zip
workflows/ci: add clang-format job
Diffstat (limited to 'um/service/include')
-rw-r--r--um/service/include/service/device.hpp97
-rw-r--r--um/service/include/service/handle.hpp98
-rw-r--r--um/service/include/service/service.hpp93
-rw-r--r--um/service/include/service/service_handle.hpp98
-rw-r--r--um/service/include/service/service_manager.hpp79
-rw-r--r--um/service/include/service/singleton.hpp55
-rw-r--r--um/service/include/service/windows_error.hpp61
7 files changed, 257 insertions, 324 deletions
diff --git a/um/service/include/service/device.hpp b/um/service/include/service/device.hpp
index ee46354..29d03c1 100644
--- a/um/service/include/service/device.hpp
+++ b/um/service/include/service/device.hpp
@@ -11,71 +11,64 @@
#include <Windows.h>
#include <cstddef>
-
#include <string>
#include <utility>
-namespace service
-{
- class Device
- {
- public:
- typedef DWORD Code;
+namespace service {
- static Device open(const std::string& path);
+class Device {
+public:
+ typedef DWORD Code;
- Device(Device&& other) LIBSERVICE_NOEXCEPT
- {
- swap(other);
- }
+ static Device open(const std::string& path);
- Device& operator=(Device other) LIBSERVICE_NOEXCEPT
- {
- swap(other);
- return *this;
- }
+ Device(Device&& other) LIBSERVICE_NOEXCEPT {
+ swap(other);
+ }
- void swap(Device& other) LIBSERVICE_NOEXCEPT
- {
- using std::swap;
- swap(handle, other.handle);
- }
+ Device& operator=(Device other) LIBSERVICE_NOEXCEPT {
+ swap(other);
+ return *this;
+ }
- std::size_t get_required_output_size(
- Code code,
- const void* in_buf,
- std::size_t in_buf_size) const;
+ void swap(Device& other) LIBSERVICE_NOEXCEPT {
+ using std::swap;
+ swap(handle, other.handle);
+ }
- 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;
+ std::size_t get_required_output_size(
+ Code code,
+ const void* in_buf,
+ std::size_t in_buf_size
+ ) const;
- private:
- Device(Handle handle)
- : handle(std::move(handle))
- { }
+ 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;
- Handle handle;
+private:
+ Device(Handle handle) : handle(std::move(handle)) {}
- Device(const Device&) = delete;
- };
+ Handle handle;
- inline void swap(Device& a, Device& b) LIBSERVICE_NOEXCEPT
- {
- a.swap(b);
- }
+ Device(const Device&) = delete;
+};
+
+inline void swap(Device& a, Device& b) LIBSERVICE_NOEXCEPT {
+ a.swap(b);
}
-namespace std
-{
- template <>
- inline void swap(
- service::Device& a,
- service::Device& b) LIBSERVICE_NOEXCEPT
- {
- a.swap(b);
- }
+} // namespace service
+
+namespace std {
+
+template <>
+inline void swap(service::Device& a, service::Device& b) LIBSERVICE_NOEXCEPT {
+ a.swap(b);
}
+
+} // namespace std
diff --git a/um/service/include/service/handle.hpp b/um/service/include/service/handle.hpp
index 2ca3754..ef4c152 100644
--- a/um/service/include/service/handle.hpp
+++ b/um/service/include/service/handle.hpp
@@ -13,71 +13,59 @@
#include <type_traits>
#include <utility>
-namespace service
-{
- class Handle
- {
- public:
- Handle() = default;
+namespace service {
- Handle(HANDLE raw)
- : impl(raw)
- { }
+class Handle {
+public:
+ Handle() = default;
- Handle(Handle&& other) LIBSERVICE_NOEXCEPT
- {
- swap(other);
- }
-
- Handle& operator=(Handle other) LIBSERVICE_NOEXCEPT
- {
- swap(other);
- return *this;
- }
+ Handle(HANDLE raw) : impl(raw) {}
- operator bool() const
- {
- return static_cast<bool>(impl);
- }
+ Handle(Handle&& other) LIBSERVICE_NOEXCEPT {
+ swap(other);
+ }
- operator HANDLE() const
- {
- return impl.get();
- }
+ Handle& operator=(Handle other) LIBSERVICE_NOEXCEPT {
+ swap(other);
+ return *this;
+ }
- void swap(Handle& other) LIBSERVICE_NOEXCEPT
- {
- using std::swap;
- swap(impl, other.impl);
- }
+ operator bool() const {
+ return static_cast<bool>(impl);
+ }
- private:
- struct Deleter
- {
- void operator()(HANDLE raw)
- {
- CloseHandle(raw);
- }
- };
+ operator HANDLE() const {
+ return impl.get();
+ }
- std::unique_ptr<std::remove_pointer<HANDLE>::type, Deleter> impl;
+ void swap(Handle& other) LIBSERVICE_NOEXCEPT {
+ using std::swap;
+ swap(impl, other.impl);
+ }
- Handle(const Handle&) = delete;
+private:
+ struct Deleter {
+ void operator()(HANDLE raw) {
+ CloseHandle(raw);
+ }
};
- inline void swap(Handle& a, Handle& b) LIBSERVICE_NOEXCEPT
- {
- a.swap(b);
- }
+ std::unique_ptr<std::remove_pointer<HANDLE>::type, Deleter> impl;
+
+ Handle(const Handle&) = delete;
+};
+
+inline void swap(Handle& a, Handle& b) LIBSERVICE_NOEXCEPT {
+ a.swap(b);
}
-namespace std
-{
- template <>
- inline void swap(
- service::Handle& a,
- service::Handle& b) LIBSERVICE_NOEXCEPT
- {
- a.swap(b);
- }
+} // namespace service
+
+namespace std {
+
+template <>
+inline void swap(service::Handle& a, service::Handle& b) LIBSERVICE_NOEXCEPT {
+ a.swap(b);
}
+
+} // namespace std
diff --git a/um/service/include/service/service.hpp b/um/service/include/service/service.hpp
index 2d5f776..58f2fa4 100644
--- a/um/service/include/service/service.hpp
+++ b/um/service/include/service/service.hpp
@@ -12,68 +12,57 @@
#include <string>
#include <utility>
-namespace service
-{
- class Service
- {
- public:
- static bool exists(
- const ServiceManager&,
- const std::string& name);
+namespace service {
- static Service open(
- const ServiceManager&,
- const std::string& name);
+class Service {
+public:
+ static bool exists(const ServiceManager&, const std::string& name);
- static Service install(
- const ServiceManager&,
- const std::string& name,
- const std::string& bin_path);
+ static Service open(const ServiceManager&, const std::string& name);
- void start() const;
- void stop() const;
- void uninstall() const;
+ static Service install(
+ const ServiceManager&,
+ const std::string& name,
+ const std::string& bin_path
+ );
- Service(Service&& other) LIBSERVICE_NOEXCEPT
- {
- swap(other);
- }
+ void start() const;
+ void stop() const;
+ void uninstall() const;
- Service& operator=(Service other) LIBSERVICE_NOEXCEPT
- {
- swap(other);
- return *this;
- }
+ Service(Service&& other) LIBSERVICE_NOEXCEPT {
+ swap(other);
+ }
- void swap(Service& other) LIBSERVICE_NOEXCEPT
- {
- using std::swap;
- swap(handle, other.handle);
- }
+ Service& operator=(Service other) LIBSERVICE_NOEXCEPT {
+ swap(other);
+ return *this;
+ }
- private:
- Service(ServiceHandle handle)
- : handle(std::move(handle))
- { }
+ void swap(Service& other) LIBSERVICE_NOEXCEPT {
+ using std::swap;
+ swap(handle, other.handle);
+ }
- ServiceHandle handle;
+private:
+ Service(ServiceHandle handle) : handle(std::move(handle)) {}
- Service(const Service&) = delete;
- };
+ ServiceHandle handle;
- inline void swap(Service& a, Service& b) LIBSERVICE_NOEXCEPT
- {
- a.swap(b);
- }
+ Service(const Service&) = delete;
+};
+
+inline void swap(Service& a, Service& b) LIBSERVICE_NOEXCEPT {
+ a.swap(b);
}
-namespace std
-{
- template <>
- inline void swap(
- service::Service& a,
- service::Service& b) LIBSERVICE_NOEXCEPT
- {
- a.swap(b);
- }
+} // namespace service
+
+namespace std {
+
+template <>
+inline void swap(service::Service& a, service::Service& b) LIBSERVICE_NOEXCEPT {
+ a.swap(b);
}
+
+} // namespace std
diff --git a/um/service/include/service/service_handle.hpp b/um/service/include/service/service_handle.hpp
index 4be58c6..38e6a96 100644
--- a/um/service/include/service/service_handle.hpp
+++ b/um/service/include/service/service_handle.hpp
@@ -12,71 +12,59 @@
#include <memory>
#include <utility>
-namespace service
-{
- class ServiceHandle
- {
- public:
- ServiceHandle() = default;
+namespace service {
- ServiceHandle(SC_HANDLE raw)
- : impl(raw)
- { }
+class ServiceHandle {
+public:
+ ServiceHandle() = default;
- ServiceHandle(ServiceHandle&& other) LIBSERVICE_NOEXCEPT
- {
- swap(other);
- }
-
- ServiceHandle& operator=(ServiceHandle other) LIBSERVICE_NOEXCEPT
- {
- swap(other);
- return *this;
- }
+ ServiceHandle(SC_HANDLE raw) : impl(raw) {}
- operator bool() const
- {
- return static_cast<bool>(impl);
- }
+ ServiceHandle(ServiceHandle&& other) LIBSERVICE_NOEXCEPT {
+ swap(other);
+ }
- operator SC_HANDLE() const
- {
- return impl.get();
- }
+ ServiceHandle& operator=(ServiceHandle other) LIBSERVICE_NOEXCEPT {
+ swap(other);
+ return *this;
+ }
- void swap(ServiceHandle& other) LIBSERVICE_NOEXCEPT
- {
- using std::swap;
- swap(impl, other.impl);
- }
+ operator bool() const {
+ return static_cast<bool>(impl);
+ }
- private:
- struct Deleter
- {
- void operator()(SC_HANDLE raw)
- {
- CloseServiceHandle(raw);
- }
- };
+ operator SC_HANDLE() const {
+ return impl.get();
+ }
- std::unique_ptr<SC_HANDLE__, Deleter> impl;
+ void swap(ServiceHandle& other) LIBSERVICE_NOEXCEPT {
+ using std::swap;
+ swap(impl, other.impl);
+ }
- ServiceHandle(const ServiceHandle&) = delete;
+private:
+ struct Deleter {
+ void operator()(SC_HANDLE raw) {
+ CloseServiceHandle(raw);
+ }
};
- inline void swap(ServiceHandle& a, ServiceHandle& b) LIBSERVICE_NOEXCEPT
- {
- a.swap(b);
- }
+ std::unique_ptr<SC_HANDLE__, Deleter> impl;
+
+ ServiceHandle(const ServiceHandle&) = delete;
+};
+
+inline void swap(ServiceHandle& a, ServiceHandle& b) LIBSERVICE_NOEXCEPT {
+ a.swap(b);
}
-namespace std
-{
- template <>
- inline void swap(
- service::ServiceHandle& a,
- service::ServiceHandle& b) LIBSERVICE_NOEXCEPT
- {
- a.swap(b);
- }
+} // namespace service
+
+namespace std {
+
+template <>
+inline void swap(service::ServiceHandle& a, service::ServiceHandle& b) LIBSERVICE_NOEXCEPT {
+ a.swap(b);
}
+
+} // namespace std
diff --git a/um/service/include/service/service_manager.hpp b/um/service/include/service/service_manager.hpp
index 2aa9312..a408d12 100644
--- a/um/service/include/service/service_manager.hpp
+++ b/um/service/include/service/service_manager.hpp
@@ -12,58 +12,49 @@
#include <utility>
-namespace service
-{
- class ServiceManager
- {
- public:
- static ServiceManager open();
+namespace service {
- ServiceManager(ServiceManager&& other) LIBSERVICE_NOEXCEPT
- {
- swap(other);
- }
+class ServiceManager {
+public:
+ static ServiceManager open();
- ServiceManager& operator=(ServiceManager other) LIBSERVICE_NOEXCEPT
- {
- swap(other);
- return *this;
- }
+ ServiceManager(ServiceManager&& other) LIBSERVICE_NOEXCEPT {
+ swap(other);
+ }
- void swap(ServiceManager& other) LIBSERVICE_NOEXCEPT
- {
- using std::swap;
- swap(handle, other.handle);
- }
+ ServiceManager& operator=(ServiceManager other) LIBSERVICE_NOEXCEPT {
+ swap(other);
+ return *this;
+ }
- operator SC_HANDLE() const
- {
- return handle;
- }
+ void swap(ServiceManager& other) LIBSERVICE_NOEXCEPT {
+ using std::swap;
+ swap(handle, other.handle);
+ }
- private:
- ServiceManager(ServiceHandle handle)
- : handle(std::move(handle))
- { }
+ operator SC_HANDLE() const {
+ return handle;
+ }
- ServiceHandle handle;
+private:
+ ServiceManager(ServiceHandle handle) : handle(std::move(handle)) {}
- ServiceManager(const ServiceManager&) = delete;
- };
+ ServiceHandle handle;
- inline void swap(ServiceManager& a, ServiceManager& b) LIBSERVICE_NOEXCEPT
- {
- a.swap(b);
- }
+ ServiceManager(const ServiceManager&) = delete;
+};
+
+inline void swap(ServiceManager& a, ServiceManager& b) LIBSERVICE_NOEXCEPT {
+ a.swap(b);
}
-namespace std
-{
- template <>
- inline void swap(
- service::ServiceManager& a,
- service::ServiceManager& b) LIBSERVICE_NOEXCEPT
- {
- a.swap(b);
- }
+} // namespace service
+
+namespace std {
+
+template <>
+inline void swap(service::ServiceManager& a, service::ServiceManager& b) LIBSERVICE_NOEXCEPT {
+ a.swap(b);
}
+
+} // namespace std
diff --git a/um/service/include/service/singleton.hpp b/um/service/include/service/singleton.hpp
index c76d54b..3eaacbf 100644
--- a/um/service/include/service/singleton.hpp
+++ b/um/service/include/service/singleton.hpp
@@ -7,37 +7,34 @@
#include <mutex>
-namespace service
-{
- template <typename DerivedT>
- class Singleton
- {
- public:
- static DerivedT& get()
- {
- std::call_once(initialized, initialize);
- return get_unsafe();
- }
+namespace service {
- protected:
- Singleton() = default;
- virtual ~Singleton() = default;
+template <typename DerivedT>
+class Singleton {
+public:
+ static DerivedT& get() {
+ std::call_once(initialized, initialize);
+ return get_unsafe();
+ }
- private:
- static void initialize()
- {
- get_unsafe();
- }
+protected:
+ Singleton() = default;
+ virtual ~Singleton() = default;
- static DerivedT& get_unsafe()
- {
- static DerivedT instance;
- return instance;
- }
+private:
+ static void initialize() {
+ get_unsafe();
+ }
- static std::once_flag initialized;
- };
+ static DerivedT& get_unsafe() {
+ static DerivedT instance;
+ return instance;
+ }
- template <typename DerivedT>
- std::once_flag Singleton<DerivedT>::initialized;
-}
+ static std::once_flag initialized;
+};
+
+template <typename DerivedT>
+std::once_flag Singleton<DerivedT>::initialized;
+
+} // namespace service
diff --git a/um/service/include/service/windows_error.hpp b/um/service/include/service/windows_error.hpp
index ab46cfd..d884ea7 100644
--- a/um/service/include/service/windows_error.hpp
+++ b/um/service/include/service/windows_error.hpp
@@ -14,45 +14,32 @@
#include <string>
#include <system_error>
-namespace service
-{
- namespace windows_error
- {
- class Category
- : public std::error_category
- , public Singleton<Category>
- {
- public:
- const char* name() const LIBSERVICE_NOEXCEPT { return "Windows"; }
+namespace service {
+namespace windows_error {
- std::string message(int) const;
+class Category
+ : public std::error_category
+ , public Singleton<Category> {
+public:
+ const char* name() const LIBSERVICE_NOEXCEPT {
+ return "Windows";
+ }
- private:
- friend class Singleton<Category>;
- };
+ std::string message(int) const;
- inline std::string build_message_prefix(
- const char* file,
- int line,
- const char* function)
- {
- std::ostringstream oss;
- oss << "Error in function '" << function
- << "' at file '" << file
- << "', line " << line;
- return oss.str();
- }
+private:
+ friend class Singleton<Category>;
+};
- inline std::system_error make(
- DWORD code,
- const char* file,
- int line,
- const char* function)
- {
- return std::system_error(
- code,
- Category::get(),
- build_message_prefix(file, line, function));
- }
- }
+inline std::string build_message_prefix(const char* file, int line, const char* function) {
+ std::ostringstream oss;
+ oss << "Error in function '" << function << "' at file '" << file << "', line " << line;
+ return oss.str();
}
+
+inline std::system_error make(DWORD code, const char* file, int line, const char* function) {
+ return std::system_error(code, Category::get(), build_message_prefix(file, line, function));
+}
+
+} // namespace windows_error
+} // namespace service