Skip to content

Commit

Permalink
Merge pull request #32 from tsmoreland/development
Browse files Browse the repository at this point in the history
Code documentation + nuspec files
  • Loading branch information
tsmoreland authored Jun 27, 2022
2 parents ee09ec4 + 5e60fe0 commit f71bfc6
Show file tree
Hide file tree
Showing 29 changed files with 301 additions and 116 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,17 @@ Using CMake to build the project which is primarily header file based so the pro
## Testing

Testing will eventually be done using boost test and possibly google test just as an excuse to try out different testing frameworks

## Nuget Package

To build run:

```
nuget.exe pack modern_win32_vc143.nuspec
```

The above command will build the 64-bit release build package. Use modern_win32_debug_vc143.nuspec to
build the debug equivalent.

Versions should be kept in sync between these two as they are intended to represent the same build just in different
configurations
19 changes: 10 additions & 9 deletions include/modern_win32/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#ifndef MODERN_WIN32_ENVIRONMENT_H_
#define MODERN_WIN32_ENVIRONMENT_H_
#ifndef MODERN_WIN32_ENVIRONMENT_H
#define MODERN_WIN32_ENVIRONMENT_H
#ifdef _WIN32

#include <map>
#include <modern_win32/modern_win32_export.h>
#include <string>


namespace modern_win32 {
template <typename TCHAR>
using environment_map = std::map<std::basic_string<TCHAR>, std::basic_string<TCHAR>>;
Expand All @@ -30,34 +31,34 @@ namespace modern_win32 {
/// attempts to retrieve all system and user environment variables storing them in <parmref name="environment"/>
/// </summary>
/// <typeparam name="TCHAR">character type</typeparam>
/// <param name="environment">on success stores all system and user environment variables</param
/// <returns>on success true; otherwise false
/// <param name="environment">on success stores all system and user environment variables</param>
/// <returns>on success true; otherwise false</returns>
template <typename TCHAR>
[[nodiscard]] bool try_get_all_environment_variables(environment_map<TCHAR>& environment);

/// <summary>
/// attempts to retrieve all system and user environment variables storing them in <parmref name="environment"/>
/// </summary>
/// <typeparam name="TCHAR">character type</typeparam>
/// <param name="environment">on success stores all system and user environment variables</param
/// <returns>on success true; otherwise false
/// <param name="environment">on success stores all system and user environment variables</param>
/// <returns>on success true; otherwise false</returns>
template <>
[[nodiscard]] MODERN_WIN32_EXPORT bool try_get_all_environment_variables(environment_map<char>& environment);

/// <summary>
/// attempts to retrieve all system and user environment variables storing them in <parmref name="environment"/>
/// </summary>
/// <typeparam name="TCHAR">character type</typeparam>
/// <param name="environment">on success stores all system and user environment variables</param
/// <returns>on success true; otherwise false
/// <param name="environment">on success stores all system and user environment variables</param>
/// <returns>on success true; otherwise false</returns>
template <>
[[nodiscard]] MODERN_WIN32_EXPORT bool try_get_all_environment_variables(environment_map<wchar_t>& environment);

/// <summary>
/// attempts to retrieve all system and user environment variables storing them in <parmref name="environment"/>
/// </summary>
/// <typeparam name="TCHAR">character type</typeparam>
/// <param name="environment">on success stores all system and user environment variables</param
/// <param name="environment">on success stores all system and user environment variables</param>
/// <returns>on success true; otherwise false</returns>
template <typename TCHAR>
[[nodiscard]] bool try_get_all_environment_variables(environment_map<TCHAR>& environment) {
Expand Down
4 changes: 2 additions & 2 deletions include/modern_win32/module_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ namespace modern_win32 {
using module_handle = unique_handle<module_traits>;

inline std::optional<module_handle> get_module(char const* module_name) {
typename module_traits::native_handle_type native_handle;
module_traits::native_handle_type native_handle;
return GetModuleHandleExA(0, module_name, &native_handle) == TRUE ? std::optional(module_handle{native_handle})
: std::nullopt;
}
inline std::optional<module_handle> get_module(wchar_t const* module_name) {
typename module_traits::native_handle_type native_handle;
module_traits::native_handle_type native_handle;
return GetModuleHandleExW(0, module_name, &native_handle) == TRUE ? std::optional(module_handle{native_handle})
: std::nullopt;
}
Expand Down
82 changes: 48 additions & 34 deletions include/modern_win32/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ namespace modern_win32 {

explicit process(native_handle_type const& handle = process_handle::invalid());
explicit process(process_id_type const& id);
explicit process(
process_id_type const& id, process_access_rights const access_rights, bool const inherit_handles = false);
explicit process(process_id_type const& id, process_access_rights access_rights, bool inherit_handles = false);
explicit process(process_id_type const& id, native_handle_type const& handle);
explicit process(deconstruct_type const& id_handle_pair);
process(process const&) = delete;
Expand Down Expand Up @@ -79,7 +78,7 @@ namespace modern_win32 {

/// <summary>replaces the managed object</summary>
/// <returns>true if the replacement represents a valid process; otherwise, false</returns>
[[nodiscard]] bool reset(native_handle_type const handle = process_handle::invalid());
[[nodiscard]] bool reset(native_handle_type handle = process_handle::invalid());

/// <summary>
/// releases the ownership of the process handle if any,
Expand Down Expand Up @@ -174,36 +173,50 @@ namespace modern_win32 {
void close() noexcept;
};

/**
* \brief Opens an existing local process object, or throws an exception if unable to
* \param id The identifier of the local process to be opened.
* \param access_rights The access to the process object. This access right is checked against the security
* descriptor for the process. This parameter can be one or more of the <see
* cref="process_access_rights"/>. \param inherit_handles If this value is true, processes created by this process
* will inherit the handle. Otherwise, the processes do not inherit this handle. \return processs instance
* \exception std::invalid_argument if process_id is 0
* \exception access_denied_exception if insufficent access to open process
*/
/// <summary>
/// Opens an existing local process object, or throws an exception if unable to
/// </summary>
/// <param name="id">The identifier of the local process to be opened.</param>
/// <param name="access_rights">
/// The access to the process object. This access right is checked against the security
/// descriptor for the process. This parameter can be one or more of the <see cref="process_access_rights"/>.
/// </param>
/// <param name="inherit_handles">
/// If this value is true, processes created by this process
/// will inherit the handle. Otherwise, the processes do not inherit this handle.
/// </param>
/// <returns>processs instance</returns>
/// <exception cref="std::invalid_argument">
/// if process_id is 0
/// </exception
/// <exception cref="access_denied_exception">
/// if insufficent access to open process
/// </exception
[[nodiscard]] MODERN_WIN32_EXPORT process open_process_or_throw(
process_id_type const& id, process_access_rights const access_rights, bool const inherit_handles = false);

/**
* \brief Opens an existing local process object or an empty optional
* \param id The identifier of the local process to be opened.
* \param access_rights The access to the process object. This access right is checked against the security
* descriptor for the process. This parameter can be one or more of the <see
* cref="process_access_rights"/>. \param inherit_handles If this value is true, processes created by this process
* will inherit the handle. Otherwise, the processes do not inherit this handle.</param> \return process if able to
* open or empty optional
*/
process_id_type const& id, process_access_rights access_rights, bool inherit_handles = false);


/// <summary>
/// Opens an existing local process object or an empty optional
/// </summary>
/// <param name="id">The identifier of the local process to be opened.</param>
/// <param name="access_rights">
/// The access to the process object. This access right is checked against the security
/// descriptor for the process. This parameter can be one or more of the <see cref="process_access_rights"/>.
/// </param>
/// <param name="inherit_handles">
/// If this value is true, processes created by this process
/// will inherit the handle. Otherwise, the processes do not inherit this handle.
/// </param>
/// <returns>process if able to open or empty optional</returns>
[[nodiscard]] MODERN_WIN32_EXPORT std::optional<process> open_process(
process_id_type const& id, process_access_rights const access_rights, bool const inherit_handles = false);
process_id_type const& id, process_access_rights access_rights, bool inherit_handles = false);

/**
* \brief opens first process matching process_name
* \param process_name name of the process to open
* \return std::optional containing the process matching process_name; otherwise, std::nullopt
*/
/// <summary>
/// opens first process matching process_name
/// </summary>
/// <param name="process_name">name of the process to open</param>
/// <returns>std::optional containing the process matching process_name; otherwise, std::nullopt</returns>
[[nodiscard]] MODERN_WIN32_EXPORT std::optional<process> open_process_by_name(wchar_t const* process_name);

/// <summary>
Expand Down Expand Up @@ -272,10 +285,11 @@ namespace modern_win32 {
/// </exception
[[nodiscard]] MODERN_WIN32_EXPORT process start_process_or_throw(wchar_t const* filename, wchar_t const* arguments);

/**
* \brief gets all active process ids
* \return std::vector containing active process ids;
*/

/// <summary>
/// gets all active process ids
/// </summary>
/// <returns>std::vector containing active process ids;</returns>
[[nodiscard]] MODERN_WIN32_EXPORT std::vector<process_id_type> get_proccess_ids();

} // namespace modern_win32
Expand Down
2 changes: 1 addition & 1 deletion include/modern_win32/process_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace modern_win32 {

template <typename ENUM>
[[nodiscard]] constexpr auto to_underlying_type(ENUM enum_value) {
return static_cast<typename std::underlying_type<ENUM>::type>(enum_value);
return static_cast<std::underlying_type_t<ENUM>>(enum_value);
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion include/modern_win32/process_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#define MODERN_WIN32_PROCESS_MODULE_H_ // NOLINT(clang-diagnostic-unused-macros)
#ifdef _WIN32

#include "windows_exception.h"
#include <modern_win32/modern_win32_export.h>
#include <string>

Expand Down
5 changes: 2 additions & 3 deletions include/modern_win32/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#ifndef MODERN_WIN32_STRING_H_
#define MODERN_WIN32_STRING_H_
#ifndef MODERN_WIN32_STRING_H
#define MODERN_WIN32_STRING_H
#ifdef _WIN32

#include <modern_win32/windows_exception.h>
#include <optional>
#include <string>
#include <string_view>

#include <Windows.h>

Expand Down
2 changes: 1 addition & 1 deletion include/modern_win32/threading/semaphore.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace modern_win32::threading {
using modern_handle_type = modern_win32::null_handle;
using native_handle_type = modern_win32::null_handle::native_handle_type;

[[nodiscard]] static auto create(int const initial_count, int const maximum_count) -> native_handle_type;
[[nodiscard]] static auto create(int initial_count, int maximum_count) -> native_handle_type;

[[nodiscard]] static auto release(modern_handle_type handle, int count) -> bool;
};
Expand Down
23 changes: 11 additions & 12 deletions include/modern_win32/threading/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#ifndef MODERN_WIN32_THREADING_THREAD_H_
#define MODERN_WIN32_THREADING_THREAD_H_
#ifndef MODERN_WIN32_THREADING_THREAD_H
#define MODERN_WIN32_THREADING_THREAD_H
#ifdef _WIN32

#include <chrono>
Expand All @@ -38,7 +38,7 @@ namespace modern_win32::threading {
/// <returns>true on success; otherwise, false</returns>
/// <remarks>only works on Windows Server 2016+ or Windows 10 1607+</remarks>
[[nodiscard]] MODERN_WIN32_EXPORT bool set_thread_name(
thread_handle::native_handle_type const handle, wchar_t const* name);
thread_handle::native_handle_type handle, wchar_t const* name);

/// <summary>
/// Sets the description (or name) of the thread represented by this objet to <parmref name="name"/>
Expand All @@ -47,8 +47,7 @@ namespace modern_win32::threading {
/// <param name="name">the name to apply to the thread represented by this object</param>
/// <returns>true on success; otherwise, false</returns>
/// <remarks>only works on Windows Server 2016+ or Windows 10 1607+</remarks>
[[nodiscard]] MODERN_WIN32_EXPORT bool set_thread_name(
thread_handle::native_handle_type const handle, char const* name);
[[nodiscard]] MODERN_WIN32_EXPORT bool set_thread_name(thread_handle::native_handle_type handle, char const* name);

/// <summary>
/// returns the current name for the thread represented by this object
Expand All @@ -57,7 +56,7 @@ namespace modern_win32::threading {
/// <returns>optional containing the thread name on success; otherwise <see cref="std::nullopt"/></returns>
/// <remarks>only works on Windows Server 2016+ or Windows 10 1607+</remarks>
[[nodiscard]] MODERN_WIN32_EXPORT std::optional<std::wstring> get_thread_name(
thread_handle::native_handle_type const handle);
thread_handle::native_handle_type handle);

class MODERN_WIN32_EXPORT thread final {
public:
Expand Down Expand Up @@ -130,8 +129,8 @@ namespace modern_win32::threading {
/// </remarks>
template <typename WORKER>
[[nodiscard]] bool start_stateless(WORKER worker) {
static_assert(std::is_convertible<decltype(worker), thread_worker>::value,
"WORKER must be assignable to thread_worker");
static_assert(
std::is_convertible_v<decltype(worker), thread_worker>, "WORKER must be assignable to thread_worker");
if (is_running() || thread_start_ != nullptr)
return false;
return handle_.reset(CreateThread(nullptr, 0, thread_adapter, static_cast<thread_worker>(worker), 0,
Expand Down Expand Up @@ -206,8 +205,8 @@ namespace modern_win32::threading {
/// <exception cref="windows_exception">thrown if unable to create thread</exception>
template <typename WORKER>
auto start_stateless_thread(WORKER worker) {
static_assert(std::is_invocable<decltype(worker)>::value, "WORKER must be invokable");
static_assert(std::is_convertible<decltype(worker), thread::thread_worker>::value,
static_assert(std::is_invocable_v<decltype(worker)>, "WORKER must be invokable");
static_assert(std::is_convertible_v<decltype(worker), thread::thread_worker>,
"WORKER must be assignable to thread_worker");
thread new_thread;
if (!new_thread.start(worker))
Expand All @@ -223,7 +222,7 @@ namespace modern_win32::threading {
/// <returns>the running thread</returns>
/// <exception cref="windows_exception">thrown if unable to create thread</exception>
[[nodiscard]] MODERN_WIN32_EXPORT thread start_thread(
thread::thread_proc const worker, thread::thread_parameter parameter);
thread::thread_proc worker, thread::thread_parameter parameter);

/// <summary>
/// starts the thread using <paramref name="worker"/> if not already running
Expand All @@ -235,7 +234,7 @@ namespace modern_win32::threading {
/// thread does not maintain lifetime of thread_start it is up to the caller to ensure that object exists until the
/// thread completes
/// </remarks>
[[nodiscard]] MODERN_WIN32_EXPORT thread start_thread(thread_start* const worker);
[[nodiscard]] MODERN_WIN32_EXPORT thread start_thread(thread_start* worker);

} // namespace modern_win32::threading

Expand Down
4 changes: 2 additions & 2 deletions include/modern_win32/threading/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace modern_win32::threading {
}

[[nodiscard]] static auto set_waitable_timer(native_handle_type handle, LARGE_INTEGER& due_time, LONG period,
_In_opt_ PTIMERAPCROUTINE callback, void* state, bool const restore) -> bool;
_In_opt_ PTIMERAPCROUTINE callback, void* state, bool restore) -> bool;

[[nodiscard]] static bool cancel_waitable_timer(native_handle_type handle);
};
Expand Down Expand Up @@ -170,7 +170,7 @@ namespace modern_win32::threading {
timer(timer&& other) noexcept
: handle_{other.handle_.release()}, callback_{other.callback_}, state_{(other.state_)},
callback_thread_{std::move(other.callback_thread_)}, timer_settings_{std::move(other.timer_settings_)},
stopped_{other.stopped_.load()}, lock_{}, stop_event_{std::move(other.stop_event_)} {
stopped_{other.stopped_.load()}, stop_event_{std::move(other.stop_event_)} {
other.stopped_ = true;
}
timer& operator=(timer&& other) noexcept {
Expand Down
4 changes: 2 additions & 2 deletions include/modern_win32/windows_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -11490,8 +11490,8 @@ namespace modern_win32 {
class MODERN_WIN32_EXPORT windows_error_details final {
public:
explicit windows_error_details() noexcept;
explicit windows_error_details(windows_error const error_code) noexcept;
explicit windows_error_details(native_windows_error const error_code) noexcept;
explicit windows_error_details(windows_error error_code) noexcept;
explicit windows_error_details(native_windows_error error_code) noexcept;

/// <summary>
/// Returns the native windows error code value
Expand Down
Loading

0 comments on commit f71bfc6

Please sign in to comment.