refactor: improve variable names
This commit is contained in:
parent
30760be328
commit
5126a8ab61
3 changed files with 25 additions and 21 deletions
|
|
@ -21,7 +21,6 @@ EnterDevice::EnterDevice()
|
||||||
strerror(-err));
|
strerror(-err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
raw_uinput_device.reset(uinput_dev_ptr);
|
raw_uinput_device.reset(uinput_dev_ptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,12 @@ enum class ConfirmationType { Unset, Howdy, Pam };
|
||||||
enum class Workaround { Off, Input, Native };
|
enum class Workaround { Off, Input, Native };
|
||||||
|
|
||||||
// Exit status codes returned by the compare process
|
// Exit status codes returned by the compare process
|
||||||
enum CompareError: int { NO_FACE_MODEL = 10, TIMEOUT_REACHED = 11, ABORT = 12, TOO_DARK = 13 };
|
enum CompareError : int {
|
||||||
|
NO_FACE_MODEL = 10,
|
||||||
|
TIMEOUT_REACHED = 11,
|
||||||
|
ABORT = 12,
|
||||||
|
TOO_DARK = 13
|
||||||
|
};
|
||||||
|
|
||||||
inline auto get_workaround(const std::string &workaround) -> Workaround {
|
inline auto get_workaround(const std::string &workaround) -> Workaround {
|
||||||
if (workaround == "input") {
|
if (workaround == "input") {
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,11 @@
|
||||||
|
|
||||||
// A task executed only if activated.
|
// A task executed only if activated.
|
||||||
template <typename T> class optional_task {
|
template <typename T> class optional_task {
|
||||||
std::thread _thread;
|
std::thread thread;
|
||||||
std::packaged_task<T()> _task;
|
std::packaged_task<T()> task;
|
||||||
std::future<T> _future;
|
std::future<T> future;
|
||||||
bool _spawned;
|
bool spawned;
|
||||||
bool _is_active;
|
bool is_active;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit optional_task(std::function<T()> fn);
|
explicit optional_task(std::function<T()> fn);
|
||||||
|
|
@ -26,14 +26,14 @@ public:
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
optional_task<T>::optional_task(std::function<T()> fn)
|
optional_task<T>::optional_task(std::function<T()> fn)
|
||||||
: _task(std::packaged_task<T()>(std::move(fn))),
|
: task(std::packaged_task<T()>(std::move(fn))), future(task.get_future()),
|
||||||
_future(_task.get_future()), _is_active(false), _spawned(false) {}
|
spawned(false), is_active(false) {}
|
||||||
|
|
||||||
// Create a new thread and launch the task on it.
|
// Create a new thread and launch the task on it.
|
||||||
template <typename T> void optional_task<T>::activate() {
|
template <typename T> void optional_task<T>::activate() {
|
||||||
_thread = std::thread(std::move(_task));
|
thread = std::thread(std::move(task));
|
||||||
_spawned = true;
|
spawned = true;
|
||||||
_is_active = true;
|
is_active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for `dur` time and return a `future` status.
|
// Wait for `dur` time and return a `future` status.
|
||||||
|
|
@ -41,15 +41,15 @@ template <typename T>
|
||||||
template <typename R, typename P>
|
template <typename R, typename P>
|
||||||
auto optional_task<T>::wait(std::chrono::duration<R, P> dur)
|
auto optional_task<T>::wait(std::chrono::duration<R, P> dur)
|
||||||
-> std::future_status {
|
-> std::future_status {
|
||||||
return _future.wait_for(dur);
|
return future.wait_for(dur);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the value.
|
// Get the value.
|
||||||
// WARNING: The function hould be run only if the task has successfully been
|
// WARNING: The function hould be run only if the task has successfully been
|
||||||
// stopped.
|
// stopped.
|
||||||
template <typename T> auto optional_task<T>::get() -> T {
|
template <typename T> auto optional_task<T>::get() -> T {
|
||||||
assert(!_is_active && _spawned);
|
assert(!is_active && spawned);
|
||||||
return _future.get();
|
return future.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop the thread:
|
// Stop the thread:
|
||||||
|
|
@ -58,22 +58,22 @@ template <typename T> auto optional_task<T>::get() -> T {
|
||||||
// WARNING: This function should be used with extreme caution when `force` is
|
// WARNING: This function should be used with extreme caution when `force` is
|
||||||
// set to `true`.
|
// set to `true`.
|
||||||
template <typename T> void optional_task<T>::stop(bool force) {
|
template <typename T> void optional_task<T>::stop(bool force) {
|
||||||
if (!(_is_active && _thread.joinable()) && _spawned) {
|
if (!(is_active && thread.joinable()) && spawned) {
|
||||||
_is_active = false;
|
is_active = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We use pthread to cancel the thread
|
// We use pthread to cancel the thread
|
||||||
if (force) {
|
if (force) {
|
||||||
auto native_hd = _thread.native_handle();
|
auto native_hd = thread.native_handle();
|
||||||
pthread_cancel(native_hd);
|
pthread_cancel(native_hd);
|
||||||
}
|
}
|
||||||
_thread.join();
|
thread.join();
|
||||||
_is_active = false;
|
is_active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> optional_task<T>::~optional_task<T>() {
|
template <typename T> optional_task<T>::~optional_task<T>() {
|
||||||
if (_is_active && _spawned) {
|
if (is_active && spawned) {
|
||||||
stop(false);
|
stop(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue