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);
14 static volatile int nDecision (0);
15 
16 const bool Check()
17 {
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  {
29  {
32  new QuickThread(ThreadFailGuardProc, NULL, true);
33  }
34  mutexFailGuard.Leave();
35  }
36  }
37 
38  return(failguard::boTriggered);
39 }
40 
42 {
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 }
static volatile int nDecision(0)
static QuickEvent hReaction
Definition: failguard.cpp:13
const bool Abort()
Definition: failguard.cpp:46
static volatile bool boTriggered(false)
int ThreadFailGuardProc(void *params)
Definition: failguard.cpp:57
const bool Check()
Definition: failguard.cpp:16


libfreenect
Author(s): Hector Martin, Josh Blake, Kyle Machulis, OpenKinect community
autogenerated on Mon Jun 10 2019 13:46:42