FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
eeprom-programmer/eeprom_programmer_PC/src/signalhandler.cpp at main · feer9/eeprom-programmer · GitHub
feer9
/
eeprom-programmer
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
4
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
eeprom-programmer
/
eeprom_programmer_PC
/
src
/
signalhandler.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
84 lines (73 loc) · 1.73 KB
Breadcrumbs
eeprom-programmer
/
eeprom_programmer_PC
/
src
/
signalhandler.cpp
Copy path
File metadata and controls
84 lines (73 loc) · 1.73 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#
include
"
signalhandler.h
"
#
include
<
assert.h
>
#
include
<
set
>
#
include
<
windows.h
>
//
There can be only ONE SignalHandler per process
SignalHandler*
g_handler
(
NULL
);
BOOL
WINAPI
WIN32_handleFunc
(
DWORD
);
int
WIN32_physicalToLogical
(
DWORD
);
DWORD
WIN32_logicalToPhysical
(
int
);
std::set<
int
> g_registry;
SignalHandler::SignalHandler
(
int
mask) : _mask(mask)
{
assert
(g_handler ==
NULL
);
g_handler =
this
;
SetConsoleCtrlHandler
(WIN32_handleFunc,
TRUE
);
for
(
int
i=
0
;i<numSignals;i++)
{
int
logical =
0x1
<< i;
if
(_mask & logical)
{
g_registry.
insert
(logical);
}
}
}
SignalHandler::~SignalHandler
()
{
SetConsoleCtrlHandler
(WIN32_handleFunc,
FALSE
);
}
DWORD
WIN32_logicalToPhysical
(
int
signal)
{
switch
(signal)
{
case
SignalHandler::
SIG_INT
:
return
CTRL_C_EVENT
;
case
SignalHandler::
SIG_TERM
:
return
CTRL_BREAK_EVENT
;
case
SignalHandler::
SIG_CLOSE
:
return
CTRL_CLOSE_EVENT
;
default
:
return
~(
unsigned
int
)
0
;
//
SIG_ERR = -1
}
}
int
WIN32_physicalToLogical
(
DWORD
signal)
{
switch
(signal)
{
case
CTRL_C_EVENT
:
return
SignalHandler::
SIG_INT
;
case
CTRL_BREAK_EVENT
:
return
SignalHandler::
SIG_TERM
;
case
CTRL_CLOSE_EVENT
:
return
SignalHandler::
SIG_CLOSE
;
default
:
return
SignalHandler::
SIG_UNHANDLED
;
}
}
BOOL
WINAPI
WIN32_handleFunc
(
DWORD
signal)
{
if
(g_handler)
{
int
signo =
WIN32_physicalToLogical
(signal);
//
The std::set is thread-safe in const reading access and we never
//
write to it after the program has started so we don't need to
//
protect this search by a mutex
std::set<
int
>::const_iterator found = g_registry.
find
(signo);
if
(signo != -
1
&& found != g_registry.
end
())
{
return
g_handler->
handleSignal
(signo) ?
TRUE
:
FALSE
;
}
else
{
return
FALSE
;
}
}
else
{
return
FALSE
;
}
}
Back
|
FazBrowse Home
|
New Git URL