From 2293d0875ee3bb27b923d51550ff4ba4bf2b9669 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 1 May 2017 15:39:00 +0300 Subject: um: strip the 'lib' prefix from include/ dirs --- um/service/include/libservice/all.hpp | 15 ---- um/service/include/libservice/common.hpp | 17 ----- um/service/include/libservice/device.hpp | 81 ---------------------- um/service/include/libservice/handle.hpp | 83 ----------------------- um/service/include/libservice/service.hpp | 79 --------------------- um/service/include/libservice/service_handle.hpp | 82 ---------------------- um/service/include/libservice/service_manager.hpp | 69 ------------------- um/service/include/libservice/singleton.hpp | 43 ------------ um/service/include/libservice/windows_error.hpp | 54 --------------- um/service/include/service/all.hpp | 15 ++++ um/service/include/service/common.hpp | 17 +++++ um/service/include/service/device.hpp | 81 ++++++++++++++++++++++ um/service/include/service/handle.hpp | 83 +++++++++++++++++++++++ um/service/include/service/service.hpp | 79 +++++++++++++++++++++ um/service/include/service/service_handle.hpp | 82 ++++++++++++++++++++++ um/service/include/service/service_manager.hpp | 69 +++++++++++++++++++ um/service/include/service/singleton.hpp | 43 ++++++++++++ um/service/include/service/windows_error.hpp | 54 +++++++++++++++ um/service/src/device.cpp | 2 +- um/service/src/service.cpp | 2 +- um/service/src/service_manager.cpp | 2 +- um/service/src/windows_error.cpp | 2 +- um/service/test/windows_error.cpp | 2 +- um/service/utils/install_service.cpp | 2 +- um/service/utils/start_service.cpp | 2 +- um/service/utils/stop_service.cpp | 2 +- um/service/utils/uninstall_service.cpp | 2 +- 27 files changed, 532 insertions(+), 532 deletions(-) delete mode 100644 um/service/include/libservice/all.hpp delete mode 100644 um/service/include/libservice/common.hpp delete mode 100644 um/service/include/libservice/device.hpp delete mode 100644 um/service/include/libservice/handle.hpp delete mode 100644 um/service/include/libservice/service.hpp delete mode 100644 um/service/include/libservice/service_handle.hpp delete mode 100644 um/service/include/libservice/service_manager.hpp delete mode 100644 um/service/include/libservice/singleton.hpp delete mode 100644 um/service/include/libservice/windows_error.hpp create mode 100644 um/service/include/service/all.hpp create mode 100644 um/service/include/service/common.hpp create mode 100644 um/service/include/service/device.hpp create mode 100644 um/service/include/service/handle.hpp create mode 100644 um/service/include/service/service.hpp create mode 100644 um/service/include/service/service_handle.hpp create mode 100644 um/service/include/service/service_manager.hpp create mode 100644 um/service/include/service/singleton.hpp create mode 100644 um/service/include/service/windows_error.hpp (limited to 'um/service') diff --git a/um/service/include/libservice/all.hpp b/um/service/include/libservice/all.hpp deleted file mode 100644 index a5761e0..0000000 --- a/um/service/include/libservice/all.hpp +++ /dev/null @@ -1,15 +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. - -#pragma once - -#include "common.hpp" -#include "device.hpp" -#include "handle.hpp" -#include "service.hpp" -#include "service_handle.hpp" -#include "service_manager.hpp" -#include "singleton.hpp" -#include "windows_error.hpp" diff --git a/um/service/include/libservice/common.hpp b/um/service/include/libservice/common.hpp deleted file mode 100644 index a1c46fb..0000000 --- a/um/service/include/libservice/common.hpp +++ /dev/null @@ -1,17 +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. - -#pragma once - -#define LIBSERVICE_FILE_PATH __FILE__ -#define LIBSERVICE_LINE_NUMBER __LINE__ -#define LIBSERVICE_FUNCTION_NAME __FUNCTION__ - -#define LIBSERVICE_TO_STRING(s) LIBSERVICE_TO_STRING_(s) -#define LIBSERVICE_TO_STRING_(s) #s - -#define LIBSERVICE_LINE_NUMBER_STRING LIBSERVICE_TO_STRING(LIBSERVICE_LINE_NUMBER) - -#define LIBSERVICE_NOEXCEPT throw() diff --git a/um/service/include/libservice/device.hpp b/um/service/include/libservice/device.hpp deleted file mode 100644 index f61c59a..0000000 --- a/um/service/include/libservice/device.hpp +++ /dev/null @@ -1,81 +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. - -#pragma once - -#include "common.hpp" -#include "handle.hpp" - -#include - -#include - -#include -#include - -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; - }; - - inline void swap(Device& a, Device& b) LIBSERVICE_NOEXCEPT - { - a.swap(b); - } -} - -namespace std -{ - template <> - inline void swap( - libservice::Device& a, - libservice::Device& b) LIBSERVICE_NOEXCEPT - { - a.swap(b); - } -} diff --git a/um/service/include/libservice/handle.hpp b/um/service/include/libservice/handle.hpp deleted file mode 100644 index abd1d5a..0000000 --- a/um/service/include/libservice/handle.hpp +++ /dev/null @@ -1,83 +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. - -#pragma once - -#include "common.hpp" - -#include - -#include -#include -#include - -namespace libservice -{ - class Handle - { - public: - Handle() = default; - - Handle(HANDLE raw) - : impl(raw) - { } - - Handle(Handle&& other) LIBSERVICE_NOEXCEPT - { - swap(other); - } - - Handle& operator=(Handle other) LIBSERVICE_NOEXCEPT - { - swap(other); - return *this; - } - - operator bool() const - { - return static_cast(impl); - } - - operator HANDLE() const - { - return impl.get(); - } - - void swap(Handle& other) LIBSERVICE_NOEXCEPT - { - using std::swap; - swap(impl, other.impl); - } - - private: - struct Deleter - { - void operator()(HANDLE raw) - { - CloseHandle(raw); - } - }; - - std::unique_ptr::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( - libservice::Handle& a, - libservice::Handle& b) LIBSERVICE_NOEXCEPT - { - a.swap(b); - } -} diff --git a/um/service/include/libservice/service.hpp b/um/service/include/libservice/service.hpp deleted file mode 100644 index ca01ab4..0000000 --- a/um/service/include/libservice/service.hpp +++ /dev/null @@ -1,79 +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. - -#pragma once - -#include "common.hpp" -#include "service_handle.hpp" -#include "service_manager.hpp" - -#include -#include - -namespace libservice -{ - class Service - { - public: - static bool exists( - const ServiceManager&, - const std::string& name); - - static Service open( - const ServiceManager&, - const std::string& name); - - static Service install( - const ServiceManager&, - const std::string& name, - const std::string& bin_path); - - void start() const; - void stop() const; - void uninstall() const; - - Service(Service&& other) LIBSERVICE_NOEXCEPT - { - swap(other); - } - - Service& operator=(Service other) LIBSERVICE_NOEXCEPT - { - swap(other); - return *this; - } - - void swap(Service& other) LIBSERVICE_NOEXCEPT - { - using std::swap; - swap(handle, other.handle); - } - - private: - Service(ServiceHandle handle) - : handle(std::move(handle)) - { } - - ServiceHandle handle; - - Service(const Service&) = delete; - }; - - inline void swap(Service& a, Service& b) LIBSERVICE_NOEXCEPT - { - a.swap(b); - } -} - -namespace std -{ - template <> - inline void swap( - libservice::Service& a, - libservice::Service& b) LIBSERVICE_NOEXCEPT - { - a.swap(b); - } -} diff --git a/um/service/include/libservice/service_handle.hpp b/um/service/include/libservice/service_handle.hpp deleted file mode 100644 index 52e37f4..0000000 --- a/um/service/include/libservice/service_handle.hpp +++ /dev/null @@ -1,82 +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. - -#pragma once - -#include "common.hpp" - -#include - -#include -#include - -namespace libservice -{ - class ServiceHandle - { - public: - ServiceHandle() = default; - - ServiceHandle(SC_HANDLE raw) - : impl(raw) - { } - - ServiceHandle(ServiceHandle&& other) LIBSERVICE_NOEXCEPT - { - swap(other); - } - - ServiceHandle& operator=(ServiceHandle other) LIBSERVICE_NOEXCEPT - { - swap(other); - return *this; - } - - operator bool() const - { - return static_cast(impl); - } - - operator SC_HANDLE() const - { - return impl.get(); - } - - void swap(ServiceHandle& other) LIBSERVICE_NOEXCEPT - { - using std::swap; - swap(impl, other.impl); - } - - private: - struct Deleter - { - void operator()(SC_HANDLE raw) - { - CloseServiceHandle(raw); - } - }; - - std::unique_ptr impl; - - ServiceHandle(const ServiceHandle&) = delete; - }; - - inline void swap(ServiceHandle& a, ServiceHandle& b) LIBSERVICE_NOEXCEPT - { - a.swap(b); - } -} - -namespace std -{ - template <> - inline void swap( - libservice::ServiceHandle& a, - libservice::ServiceHandle& b) LIBSERVICE_NOEXCEPT - { - a.swap(b); - } -} diff --git a/um/service/include/libservice/service_manager.hpp b/um/service/include/libservice/service_manager.hpp deleted file mode 100644 index 3d4fe3a..0000000 --- a/um/service/include/libservice/service_manager.hpp +++ /dev/null @@ -1,69 +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. - -#pragma once - -#include "common.hpp" -#include "service_handle.hpp" - -#include - -#include - -namespace libservice -{ - class ServiceManager - { - public: - static ServiceManager open(); - - ServiceManager(ServiceManager&& other) LIBSERVICE_NOEXCEPT - { - swap(other); - } - - ServiceManager& operator=(ServiceManager other) LIBSERVICE_NOEXCEPT - { - swap(other); - return *this; - } - - void swap(ServiceManager& other) LIBSERVICE_NOEXCEPT - { - using std::swap; - swap(handle, other.handle); - } - - operator SC_HANDLE() const - { - return handle; - } - - private: - ServiceManager(ServiceHandle handle) - : handle(std::move(handle)) - { } - - ServiceHandle handle; - - ServiceManager(const ServiceManager&) = delete; - }; - - inline void swap(ServiceManager& a, ServiceManager& b) LIBSERVICE_NOEXCEPT - { - a.swap(b); - } -} - -namespace std -{ - template <> - inline void swap( - libservice::ServiceManager& a, - libservice::ServiceManager& b) LIBSERVICE_NOEXCEPT - { - a.swap(b); - } -} diff --git a/um/service/include/libservice/singleton.hpp b/um/service/include/libservice/singleton.hpp deleted file mode 100644 index 1c7b1a7..0000000 --- a/um/service/include/libservice/singleton.hpp +++ /dev/null @@ -1,43 +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. - -#pragma once - -#include - -namespace libservice -{ - template - class Singleton - { - public: - static DerivedT& get() - { - std::call_once(initialized, initialize); - return get_unsafe(); - } - - protected: - Singleton() = default; - virtual ~Singleton() = default; - - private: - static void initialize() - { - get_unsafe(); - } - - static DerivedT& get_unsafe() - { - static DerivedT instance; - return instance; - } - - static std::once_flag initialized; - }; - - template - std::once_flag Singleton::initialized; -} diff --git a/um/service/include/libservice/windows_error.hpp b/um/service/include/libservice/windows_error.hpp deleted file mode 100644 index 13d7f47..0000000 --- a/um/service/include/libservice/windows_error.hpp +++ /dev/null @@ -1,54 +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. - -#pragma once - -#include "common.hpp" -#include "singleton.hpp" - -#include -#include -#include - -namespace libservice -{ - class WindowsErrorCategory - : public std::error_category - , public Singleton - { - public: - const char* name() const LIBSERVICE_NOEXCEPT { return "Windows"; } - - std::string message(int) const; - - private: - friend class Singleton; - }; - - namespace error - { - inline std::string build_what( - const char* function, - const char* file, - int line) - { - std::ostringstream oss; - oss << "Error in function '" << function - << "' at file '" << file - << "', line " << line; - return oss.str(); - } - } -} - -#if defined(_MSC_VER) -#define LIBSERVICE_ERROR_PREFIX \ - "Error in function '" LIBSERVICE_FUNCTION_NAME "' at file '" LIBSERVICE_FILE_PATH "', line " LIBSERVICE_LINE_NUMBER_STRING -#elif defined(__GNUC__) -#define LIBSERVICE_ERROR_PREFIX \ - libservice::error::build_what(LIBSERVICE_FUNCTION_NAME, LIBSERVICE_FILE_PATH, LIBSERVICE_LINE_NUMBER) -#else -#define LIBSERVICE_ERROR_PREFIX "Error" -#endif diff --git a/um/service/include/service/all.hpp b/um/service/include/service/all.hpp new file mode 100644 index 0000000..a5761e0 --- /dev/null +++ b/um/service/include/service/all.hpp @@ -0,0 +1,15 @@ +// 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. + +#pragma once + +#include "common.hpp" +#include "device.hpp" +#include "handle.hpp" +#include "service.hpp" +#include "service_handle.hpp" +#include "service_manager.hpp" +#include "singleton.hpp" +#include "windows_error.hpp" diff --git a/um/service/include/service/common.hpp b/um/service/include/service/common.hpp new file mode 100644 index 0000000..a1c46fb --- /dev/null +++ b/um/service/include/service/common.hpp @@ -0,0 +1,17 @@ +// 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. + +#pragma once + +#define LIBSERVICE_FILE_PATH __FILE__ +#define LIBSERVICE_LINE_NUMBER __LINE__ +#define LIBSERVICE_FUNCTION_NAME __FUNCTION__ + +#define LIBSERVICE_TO_STRING(s) LIBSERVICE_TO_STRING_(s) +#define LIBSERVICE_TO_STRING_(s) #s + +#define LIBSERVICE_LINE_NUMBER_STRING LIBSERVICE_TO_STRING(LIBSERVICE_LINE_NUMBER) + +#define LIBSERVICE_NOEXCEPT throw() diff --git a/um/service/include/service/device.hpp b/um/service/include/service/device.hpp new file mode 100644 index 0000000..f61c59a --- /dev/null +++ b/um/service/include/service/device.hpp @@ -0,0 +1,81 @@ +// 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. + +#pragma once + +#include "common.hpp" +#include "handle.hpp" + +#include + +#include + +#include +#include + +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; + }; + + inline void swap(Device& a, Device& b) LIBSERVICE_NOEXCEPT + { + a.swap(b); + } +} + +namespace std +{ + template <> + inline void swap( + libservice::Device& a, + libservice::Device& b) LIBSERVICE_NOEXCEPT + { + a.swap(b); + } +} diff --git a/um/service/include/service/handle.hpp b/um/service/include/service/handle.hpp new file mode 100644 index 0000000..abd1d5a --- /dev/null +++ b/um/service/include/service/handle.hpp @@ -0,0 +1,83 @@ +// 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. + +#pragma once + +#include "common.hpp" + +#include + +#include +#include +#include + +namespace libservice +{ + class Handle + { + public: + Handle() = default; + + Handle(HANDLE raw) + : impl(raw) + { } + + Handle(Handle&& other) LIBSERVICE_NOEXCEPT + { + swap(other); + } + + Handle& operator=(Handle other) LIBSERVICE_NOEXCEPT + { + swap(other); + return *this; + } + + operator bool() const + { + return static_cast(impl); + } + + operator HANDLE() const + { + return impl.get(); + } + + void swap(Handle& other) LIBSERVICE_NOEXCEPT + { + using std::swap; + swap(impl, other.impl); + } + + private: + struct Deleter + { + void operator()(HANDLE raw) + { + CloseHandle(raw); + } + }; + + std::unique_ptr::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( + libservice::Handle& a, + libservice::Handle& b) LIBSERVICE_NOEXCEPT + { + a.swap(b); + } +} diff --git a/um/service/include/service/service.hpp b/um/service/include/service/service.hpp new file mode 100644 index 0000000..ca01ab4 --- /dev/null +++ b/um/service/include/service/service.hpp @@ -0,0 +1,79 @@ +// 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. + +#pragma once + +#include "common.hpp" +#include "service_handle.hpp" +#include "service_manager.hpp" + +#include +#include + +namespace libservice +{ + class Service + { + public: + static bool exists( + const ServiceManager&, + const std::string& name); + + static Service open( + const ServiceManager&, + const std::string& name); + + static Service install( + const ServiceManager&, + const std::string& name, + const std::string& bin_path); + + void start() const; + void stop() const; + void uninstall() const; + + Service(Service&& other) LIBSERVICE_NOEXCEPT + { + swap(other); + } + + Service& operator=(Service other) LIBSERVICE_NOEXCEPT + { + swap(other); + return *this; + } + + void swap(Service& other) LIBSERVICE_NOEXCEPT + { + using std::swap; + swap(handle, other.handle); + } + + private: + Service(ServiceHandle handle) + : handle(std::move(handle)) + { } + + ServiceHandle handle; + + Service(const Service&) = delete; + }; + + inline void swap(Service& a, Service& b) LIBSERVICE_NOEXCEPT + { + a.swap(b); + } +} + +namespace std +{ + template <> + inline void swap( + libservice::Service& a, + libservice::Service& b) LIBSERVICE_NOEXCEPT + { + a.swap(b); + } +} diff --git a/um/service/include/service/service_handle.hpp b/um/service/include/service/service_handle.hpp new file mode 100644 index 0000000..52e37f4 --- /dev/null +++ b/um/service/include/service/service_handle.hpp @@ -0,0 +1,82 @@ +// 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. + +#pragma once + +#include "common.hpp" + +#include + +#include +#include + +namespace libservice +{ + class ServiceHandle + { + public: + ServiceHandle() = default; + + ServiceHandle(SC_HANDLE raw) + : impl(raw) + { } + + ServiceHandle(ServiceHandle&& other) LIBSERVICE_NOEXCEPT + { + swap(other); + } + + ServiceHandle& operator=(ServiceHandle other) LIBSERVICE_NOEXCEPT + { + swap(other); + return *this; + } + + operator bool() const + { + return static_cast(impl); + } + + operator SC_HANDLE() const + { + return impl.get(); + } + + void swap(ServiceHandle& other) LIBSERVICE_NOEXCEPT + { + using std::swap; + swap(impl, other.impl); + } + + private: + struct Deleter + { + void operator()(SC_HANDLE raw) + { + CloseServiceHandle(raw); + } + }; + + std::unique_ptr impl; + + ServiceHandle(const ServiceHandle&) = delete; + }; + + inline void swap(ServiceHandle& a, ServiceHandle& b) LIBSERVICE_NOEXCEPT + { + a.swap(b); + } +} + +namespace std +{ + template <> + inline void swap( + libservice::ServiceHandle& a, + libservice::ServiceHandle& b) LIBSERVICE_NOEXCEPT + { + a.swap(b); + } +} diff --git a/um/service/include/service/service_manager.hpp b/um/service/include/service/service_manager.hpp new file mode 100644 index 0000000..3d4fe3a --- /dev/null +++ b/um/service/include/service/service_manager.hpp @@ -0,0 +1,69 @@ +// 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. + +#pragma once + +#include "common.hpp" +#include "service_handle.hpp" + +#include + +#include + +namespace libservice +{ + class ServiceManager + { + public: + static ServiceManager open(); + + ServiceManager(ServiceManager&& other) LIBSERVICE_NOEXCEPT + { + swap(other); + } + + ServiceManager& operator=(ServiceManager other) LIBSERVICE_NOEXCEPT + { + swap(other); + return *this; + } + + void swap(ServiceManager& other) LIBSERVICE_NOEXCEPT + { + using std::swap; + swap(handle, other.handle); + } + + operator SC_HANDLE() const + { + return handle; + } + + private: + ServiceManager(ServiceHandle handle) + : handle(std::move(handle)) + { } + + ServiceHandle handle; + + ServiceManager(const ServiceManager&) = delete; + }; + + inline void swap(ServiceManager& a, ServiceManager& b) LIBSERVICE_NOEXCEPT + { + a.swap(b); + } +} + +namespace std +{ + template <> + inline void swap( + libservice::ServiceManager& a, + libservice::ServiceManager& b) LIBSERVICE_NOEXCEPT + { + a.swap(b); + } +} diff --git a/um/service/include/service/singleton.hpp b/um/service/include/service/singleton.hpp new file mode 100644 index 0000000..1c7b1a7 --- /dev/null +++ b/um/service/include/service/singleton.hpp @@ -0,0 +1,43 @@ +// 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. + +#pragma once + +#include + +namespace libservice +{ + template + class Singleton + { + public: + static DerivedT& get() + { + std::call_once(initialized, initialize); + return get_unsafe(); + } + + protected: + Singleton() = default; + virtual ~Singleton() = default; + + private: + static void initialize() + { + get_unsafe(); + } + + static DerivedT& get_unsafe() + { + static DerivedT instance; + return instance; + } + + static std::once_flag initialized; + }; + + template + std::once_flag Singleton::initialized; +} diff --git a/um/service/include/service/windows_error.hpp b/um/service/include/service/windows_error.hpp new file mode 100644 index 0000000..13d7f47 --- /dev/null +++ b/um/service/include/service/windows_error.hpp @@ -0,0 +1,54 @@ +// 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. + +#pragma once + +#include "common.hpp" +#include "singleton.hpp" + +#include +#include +#include + +namespace libservice +{ + class WindowsErrorCategory + : public std::error_category + , public Singleton + { + public: + const char* name() const LIBSERVICE_NOEXCEPT { return "Windows"; } + + std::string message(int) const; + + private: + friend class Singleton; + }; + + namespace error + { + inline std::string build_what( + const char* function, + const char* file, + int line) + { + std::ostringstream oss; + oss << "Error in function '" << function + << "' at file '" << file + << "', line " << line; + return oss.str(); + } + } +} + +#if defined(_MSC_VER) +#define LIBSERVICE_ERROR_PREFIX \ + "Error in function '" LIBSERVICE_FUNCTION_NAME "' at file '" LIBSERVICE_FILE_PATH "', line " LIBSERVICE_LINE_NUMBER_STRING +#elif defined(__GNUC__) +#define LIBSERVICE_ERROR_PREFIX \ + libservice::error::build_what(LIBSERVICE_FUNCTION_NAME, LIBSERVICE_FILE_PATH, LIBSERVICE_LINE_NUMBER) +#else +#define LIBSERVICE_ERROR_PREFIX "Error" +#endif diff --git a/um/service/src/device.cpp b/um/service/src/device.cpp index f1ecccb..a6333c7 100644 --- a/um/service/src/device.cpp +++ b/um/service/src/device.cpp @@ -3,7 +3,7 @@ // For details, see https://github.com/egor-tensin/windows7-drivers. // Distributed under the MIT License. -#include "libservice/all.hpp" +#include "service/all.hpp" #include diff --git a/um/service/src/service.cpp b/um/service/src/service.cpp index 1cdfe71..f45436a 100644 --- a/um/service/src/service.cpp +++ b/um/service/src/service.cpp @@ -3,7 +3,7 @@ // For details, see https://github.com/egor-tensin/windows7-drivers. // Distributed under the MIT License. -#include "libservice/all.hpp" +#include "service/all.hpp" #include diff --git a/um/service/src/service_manager.cpp b/um/service/src/service_manager.cpp index 530976c..96e0f75 100644 --- a/um/service/src/service_manager.cpp +++ b/um/service/src/service_manager.cpp @@ -3,7 +3,7 @@ // For details, see https://github.com/egor-tensin/windows7-drivers. // Distributed under the MIT License. -#include "libservice/all.hpp" +#include "service/all.hpp" #include diff --git a/um/service/src/windows_error.cpp b/um/service/src/windows_error.cpp index f27018b..90ebd7c 100644 --- a/um/service/src/windows_error.cpp +++ b/um/service/src/windows_error.cpp @@ -3,7 +3,7 @@ // For details, see https://github.com/egor-tensin/windows7-drivers. // Distributed under the MIT License. -#include "libservice/all.hpp" +#include "service/all.hpp" #include diff --git a/um/service/test/windows_error.cpp b/um/service/test/windows_error.cpp index b909670..019939b 100644 --- a/um/service/test/windows_error.cpp +++ b/um/service/test/windows_error.cpp @@ -3,7 +3,7 @@ // For details, see https://github.com/egor-tensin/windows7-drivers. // Distributed under the MIT License. -#include "libservice/all.hpp" +#include "service/all.hpp" #include diff --git a/um/service/utils/install_service.cpp b/um/service/utils/install_service.cpp index f36af75..aed0ae1 100644 --- a/um/service/utils/install_service.cpp +++ b/um/service/utils/install_service.cpp @@ -3,7 +3,7 @@ // For details, see https://github.com/egor-tensin/windows7-drivers. // Distributed under the MIT License. -#include "libservice/all.hpp" +#include "service/all.hpp" #include #include diff --git a/um/service/utils/start_service.cpp b/um/service/utils/start_service.cpp index fafee53..7f23fd4 100644 --- a/um/service/utils/start_service.cpp +++ b/um/service/utils/start_service.cpp @@ -3,7 +3,7 @@ // For details, see https://github.com/egor-tensin/windows7-drivers. // Distributed under the MIT License. -#include "libservice/all.hpp" +#include "service/all.hpp" #include #include diff --git a/um/service/utils/stop_service.cpp b/um/service/utils/stop_service.cpp index 800c7a9..0f11878 100644 --- a/um/service/utils/stop_service.cpp +++ b/um/service/utils/stop_service.cpp @@ -3,7 +3,7 @@ // For details, see https://github.com/egor-tensin/windows7-drivers. // Distributed under the MIT License. -#include "libservice/all.hpp" +#include "service/all.hpp" #include #include diff --git a/um/service/utils/uninstall_service.cpp b/um/service/utils/uninstall_service.cpp index 395bb51..58a879c 100644 --- a/um/service/utils/uninstall_service.cpp +++ b/um/service/utils/uninstall_service.cpp @@ -3,7 +3,7 @@ // For details, see https://github.com/egor-tensin/windows7-drivers. // Distributed under the MIT License. -#include "libservice/all.hpp" +#include "service/all.hpp" #include #include -- cgit v1.2.3