Main Page
Namespaces
Classes
Files
File List
File Members
platform
windows
libusb10emu
libusb-1.0
failguard.cpp
Go to the documentation of this file.
1
#include "
failguard.h
"
2
#include "
libusbemu_threads.h
"
3
4
int
ThreadFailGuardProc
(
void
* params);
5
6
namespace
libusbemu
7
{
8
9
namespace
failguard
10
{
11
12
static
volatile
bool
boTriggered
(
false
);
13
static
QuickEvent
hReaction
;
14
static
volatile
int
nDecision
(0);
15
16
const
bool
Check
()
17
{
18
if
(
failguard::boTriggered
)
19
return
(
true
);
20
21
// CTRL + ALT pressed?
22
if
((GetKeyState(VK_CONTROL) & 0x8000) && (GetKeyState(VK_MENU) & 0x8000))
23
{
24
// only one thread is allowed to activate the guard
25
static
QuickMutex
mutexFailGuard;
26
if
(mutexFailGuard.
TryEnter
())
27
{
28
if
(!
failguard::boTriggered
)
29
{
30
failguard::hReaction
.
Reset
();
31
failguard::boTriggered
=
true
;
32
new
QuickThread
(
ThreadFailGuardProc
, NULL,
true
);
33
}
34
mutexFailGuard.
Leave
();
35
}
36
}
37
38
return
(
failguard::boTriggered
);
39
}
40
41
void
WaitDecision
()
42
{
43
failguard::hReaction
.
Wait
();
44
}
45
46
const
bool
Abort
()
47
{
48
return
(-1 ==
nDecision
);
49
}
50
51
}
52
53
}
54
55
using namespace
libusbemu::failguard
;
56
57
int
ThreadFailGuardProc
(
void
* params)
58
{
59
int
user_option =
60
MessageBoxA(GetDesktopWindow(),
61
"The libusb_handle_events() fail guard of libusbemu was reached!\n"
62
"This was caused by pressing and holding the [CTRL] + [ALT] keys.\n"
63
"If it was unintentional, click Cancel to resume normal execution;\n"
64
"otherwise, click OK to effectively terminate the thread (note that\n"
65
"the host program might run abnormally after such termination)."
,
66
"WARNING: libusbemu thread fail guard reached!"
, MB_ICONWARNING | MB_OKCANCEL);
67
68
if
(IDOK == user_option)
69
nDecision
= -1;
70
else
71
boTriggered
=
false
;
72
73
hReaction
.
Signal
();
74
75
return
(0);
76
}
libusbemu_threads.h
libusbemu::QuickEvent
Definition:
libusbemu_threads_win32.h:36
libusbemu::failguard::nDecision
static volatile int nDecision(0)
libusbemu::QuickMutex::Leave
void Leave()
Definition:
libusbemu_threads_win32.h:233
libusbemu::QuickThread
Definition:
libusbemu_threads_win32.h:76
libusbemu::failguard::hReaction
static QuickEvent hReaction
Definition:
failguard.cpp:13
libusbemu::failguard::Abort
const bool Abort()
Definition:
failguard.cpp:46
libusbemu::failguard
Definition:
failguard.cpp:9
failguard.h
libusbemu::QuickMutex::TryEnter
const bool TryEnter()
Definition:
libusbemu_threads_win32.h:223
libusbemu
Definition:
failguard.cpp:6
libusbemu::failguard::boTriggered
static volatile bool boTriggered(false)
ThreadFailGuardProc
int ThreadFailGuardProc(void *params)
Definition:
failguard.cpp:57
libusbemu::QuickMutex
Definition:
libusbemu_threads_win32.h:207
libusbemu::QuickEvent::Wait
void Wait()
Definition:
libusbemu_threads_win32.h:68
libusbemu::failguard::WaitDecision
void WaitDecision()
Definition:
failguard.cpp:41
libusbemu::QuickEvent::Signal
void Signal()
Definition:
libusbemu_threads_win32.h:52
libusbemu::failguard::Check
const bool Check()
Definition:
failguard.cpp:16
libusbemu::QuickEvent::Reset
void Reset()
Definition:
libusbemu_threads_win32.h:56
libfreenect
Author(s): Hector Martin, Josh Blake, Kyle Machulis, OpenKinect community
autogenerated on Mon Jun 10 2019 13:46:42