forked from juj/fbcp-ili9341
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fbcp.c
65 lines (53 loc) · 1.22 KB
/
fbcp.c
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
//
// Created by cpasjuste on 03/07/19.
//
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <signal.h>
#include "../libfbcp/fbcp.h"
static bool quit = false;
static bool exited = false;
const char* SignalToString(int signal)
{
if (signal==SIGINT) return "SIGINT";
if (signal==SIGQUIT) return "SIGQUIT";
if (signal==SIGUSR1) return "SIGUSR1";
if (signal==SIGUSR2) return "SIGUSR2";
if (signal==SIGTERM) return "SIGTERM";
return "?";
}
void ProgramInterruptHandler(int signal)
{
printf("Signal %s(%d) received, quitting\n", SignalToString(signal), signal);
static int quitHandlerCalled = 0;
if (++quitHandlerCalled>=5)
{
printf(
"Ctrl-C handler invoked five times, looks like fbcp-ili9341 is not gracefully quitting - performing a forcible shutdown!\n");
exit(1);
}
if (!exited)
{
exited = true;
fbcp_exit();
}
}
int main()
{
signal(SIGINT, ProgramInterruptHandler);
signal(SIGQUIT, ProgramInterruptHandler);
signal(SIGUSR1, ProgramInterruptHandler);
signal(SIGUSR2, ProgramInterruptHandler);
signal(SIGTERM, ProgramInterruptHandler);
fbcp_init(NULL, 0, 0, 0);
while (!quit)
{
fbcp_process();
}
if (!exited)
{
fbcp_exit();
}
return 0;
}