aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/utils/libservice/include
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2015-07-15 22:08:33 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2015-07-15 22:08:33 +0300
commit01c1146276f7319843c357480c4374fe555f07c5 (patch)
treeca04e44b03b126de4ad3071e3e70df3982f9f174 /utils/libservice/include
parentREADME updates (diff)
downloadwindows7-drivers-01c1146276f7319843c357480c4374fe555f07c5.tar.gz
windows7-drivers-01c1146276f7319843c357480c4374fe555f07c5.zip
utils: code style
Diffstat (limited to '')
-rw-r--r--utils/libservice/include/libservice/device.hpp35
-rw-r--r--utils/libservice/include/libservice/handle.hpp18
-rw-r--r--utils/libservice/include/libservice/service.hpp26
-rw-r--r--utils/libservice/include/libservice/service_handle.hpp18
-rw-r--r--utils/libservice/include/libservice/service_manager.hpp12
-rw-r--r--utils/libservice/include/libservice/singleton.hpp16
-rw-r--r--utils/libservice/include/libservice/windows_error.hpp17
7 files changed, 75 insertions, 67 deletions
diff --git a/utils/libservice/include/libservice/device.hpp b/utils/libservice/include/libservice/device.hpp
index 3a9540e..9a6f278 100644
--- a/utils/libservice/include/libservice/device.hpp
+++ b/utils/libservice/include/libservice/device.hpp
@@ -13,6 +13,8 @@
#include <Windows.h>
+#include <cstddef>
+
#include <string>
#include <utility>
@@ -21,6 +23,8 @@ namespace libservice
class Device
{
public:
+ typedef DWORD Code;
+
static Device open(const std::string& path);
Device(Device&& other) LIBSERVICE_NOEXCEPT
@@ -37,35 +41,38 @@ namespace libservice
void swap(Device& other) LIBSERVICE_NOEXCEPT
{
using std::swap;
- swap(m_handle, other.m_handle);
+ swap(handle, other.handle);
}
- DWORD get_required_output_size(DWORD code,
- const void* in_buf,
- DWORD in_buf_size) const;
+ std::size_t get_required_output_size(
+ Code code,
+ const void* in_buf,
+ std::size_t 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;
+ 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:
- explicit Device(Handle h)
- : m_handle(std::move(h))
+ Device(Handle handle)
+ : handle(std::move(handle))
{ }
- Handle m_handle;
+ Handle handle;
Device(const Device&) = delete;
};
- void swap(libservice::Device&, libservice::Device&) LIBSERVICE_NOEXCEPT;
+ void swap(Device&, Device&) LIBSERVICE_NOEXCEPT;
}
namespace std
{
template <>
void swap<libservice::Device>(
- libservice::Device&, libservice::Device&) LIBSERVICE_NOEXCEPT;
+ libservice::Device&,
+ libservice::Device&) LIBSERVICE_NOEXCEPT;
}
diff --git a/utils/libservice/include/libservice/handle.hpp b/utils/libservice/include/libservice/handle.hpp
index 1292090..26aba77 100644
--- a/utils/libservice/include/libservice/handle.hpp
+++ b/utils/libservice/include/libservice/handle.hpp
@@ -23,8 +23,8 @@ namespace libservice
public:
Handle() = default;
- explicit Handle(HANDLE raw)
- : m_impl(raw)
+ Handle(HANDLE raw)
+ : impl(raw)
{ }
Handle(Handle&& other) LIBSERVICE_NOEXCEPT
@@ -38,20 +38,20 @@ namespace libservice
return *this;
}
- explicit operator bool() const
+ operator bool() const
{
- return static_cast<bool>(m_impl);
+ return static_cast<bool>(impl);
}
- explicit operator HANDLE() const
+ operator HANDLE() const
{
- return m_impl.get();
+ return impl.get();
}
void swap(Handle& other) LIBSERVICE_NOEXCEPT
{
using std::swap;
- swap(m_impl, other.m_impl);
+ swap(impl, other.impl);
}
private:
@@ -59,11 +59,11 @@ namespace libservice
{
void operator()(HANDLE raw)
{
- ::CloseHandle(raw);
+ CloseHandle(raw);
}
};
- std::unique_ptr<std::remove_pointer<HANDLE>::type, Deleter> m_impl;
+ std::unique_ptr<std::remove_pointer<HANDLE>::type, Deleter> impl;
Handle(const Handle&) = delete;
};
diff --git a/utils/libservice/include/libservice/service.hpp b/utils/libservice/include/libservice/service.hpp
index d350c91..6e4d268 100644
--- a/utils/libservice/include/libservice/service.hpp
+++ b/utils/libservice/include/libservice/service.hpp
@@ -20,14 +20,18 @@ namespace libservice
class Service
{
public:
- static bool does_exist(const ServiceManager&,
- const std::string& name);
+ 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);
+ 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;
@@ -47,15 +51,15 @@ namespace libservice
void swap(Service& other) LIBSERVICE_NOEXCEPT
{
using std::swap;
- swap(m_handle, other.m_handle);
+ swap(handle, other.handle);
}
private:
- explicit Service(ServiceHandle h)
- : m_handle(std::move(h))
+ Service(ServiceHandle handle)
+ : handle(std::move(handle))
{ }
- ServiceHandle m_handle;
+ ServiceHandle handle;
Service(const Service&) = delete;
};
diff --git a/utils/libservice/include/libservice/service_handle.hpp b/utils/libservice/include/libservice/service_handle.hpp
index 37e69ce..0f2cf59 100644
--- a/utils/libservice/include/libservice/service_handle.hpp
+++ b/utils/libservice/include/libservice/service_handle.hpp
@@ -22,8 +22,8 @@ namespace libservice
public:
ServiceHandle() = default;
- explicit ServiceHandle(SC_HANDLE raw)
- : m_impl(raw)
+ ServiceHandle(SC_HANDLE raw)
+ : impl(raw)
{ }
ServiceHandle(ServiceHandle&& other) LIBSERVICE_NOEXCEPT
@@ -37,20 +37,20 @@ namespace libservice
return *this;
}
- explicit operator bool() const
+ operator bool() const
{
- return static_cast<bool>(m_impl);
+ return static_cast<bool>(impl);
}
- explicit operator SC_HANDLE() const
+ operator SC_HANDLE() const
{
- return m_impl.get();
+ return impl.get();
}
void swap(ServiceHandle& other) LIBSERVICE_NOEXCEPT
{
using std::swap;
- swap(m_impl, other.m_impl);
+ swap(impl, other.impl);
}
private:
@@ -58,11 +58,11 @@ namespace libservice
{
void operator()(SC_HANDLE raw)
{
- ::CloseServiceHandle(raw);
+ CloseServiceHandle(raw);
}
};
- std::unique_ptr<SC_HANDLE__, Deleter> m_impl;
+ std::unique_ptr<SC_HANDLE__, Deleter> impl;
ServiceHandle(const ServiceHandle&) = delete;
};
diff --git a/utils/libservice/include/libservice/service_manager.hpp b/utils/libservice/include/libservice/service_manager.hpp
index c39b99e..8d8b862 100644
--- a/utils/libservice/include/libservice/service_manager.hpp
+++ b/utils/libservice/include/libservice/service_manager.hpp
@@ -36,20 +36,20 @@ namespace libservice
void swap(ServiceManager& other) LIBSERVICE_NOEXCEPT
{
using std::swap;
- swap(m_handle, other.m_handle);
+ swap(handle, other.handle);
}
- explicit operator SC_HANDLE() const
+ operator SC_HANDLE() const
{
- return static_cast<SC_HANDLE>(m_handle);
+ return handle;
}
private:
- explicit ServiceManager(ServiceHandle h)
- : m_handle(std::move(h))
+ ServiceManager(ServiceHandle handle)
+ : handle(std::move(handle))
{ }
- ServiceHandle m_handle;
+ ServiceHandle handle;
ServiceManager(const ServiceManager&) = delete;
};
diff --git a/utils/libservice/include/libservice/singleton.hpp b/utils/libservice/include/libservice/singleton.hpp
index a9d55ad..81e6445 100644
--- a/utils/libservice/include/libservice/singleton.hpp
+++ b/utils/libservice/include/libservice/singleton.hpp
@@ -12,13 +12,13 @@
namespace libservice
{
- template <typename DerivedType>
+ template <typename DerivedT>
class Singleton
{
public:
- static DerivedType& get()
+ static DerivedT& get()
{
- std::call_once(is_initialized, initialize);
+ std::call_once(initialized, initialize);
return get_unsafe();
}
@@ -32,15 +32,15 @@ namespace libservice
get_unsafe();
}
- static DerivedType& get_unsafe()
+ static DerivedT& get_unsafe()
{
- static DerivedType instance;
+ static DerivedT instance;
return instance;
}
- static std::once_flag is_initialized;
+ static std::once_flag initialized;
};
- template <typename DerivedType>
- std::once_flag Singleton<DerivedType>::is_initialized;
+ template <typename DerivedT>
+ std::once_flag Singleton<DerivedT>::initialized;
}
diff --git a/utils/libservice/include/libservice/windows_error.hpp b/utils/libservice/include/libservice/windows_error.hpp
index 907c7e7..430705a 100644
--- a/utils/libservice/include/libservice/windows_error.hpp
+++ b/utils/libservice/include/libservice/windows_error.hpp
@@ -16,22 +16,19 @@
namespace libservice
{
- class WinErrorCategory : public std::error_category
- , public Singleton<WinErrorCategory>
+ class WindowsErrorCategory
+ : public std::error_category
+ , public Singleton<WindowsErrorCategory>
{
public:
- const char* name() const LIBSERVICE_NOEXCEPT { return "windows"; }
+ const char* name() const LIBSERVICE_NOEXCEPT { return "Windows"; }
std::string message(int) const;
private:
- friend class Singleton<WinErrorCategory>;
+ friend class Singleton<WindowsErrorCategory>;
};
}
-#define LIBSERVICE_ERROR_PREFIX "Error in function '" \
- LIBSERVICE_FUNCTION_NAME \
- "' at file '" \
- LIBSERVICE_FILE_PATH \
- "', line " \
- LIBSERVICE_LINE_NUMBER_STRING
+#define LIBSERVICE_ERROR_PREFIX \
+ "Error in function '" LIBSERVICE_FUNCTION_NAME "' at file '" LIBSERVICE_FILE_PATH "', line " LIBSERVICE_LINE_NUMBER_STRING