-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
124 lines (102 loc) · 2.35 KB
/
main.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <curl/curl.h>
#include "server.h"
#include "device.h"
#include "fingerprint.h"
DEVICE* gDevice = NULL;
SERVER* gServer = NULL;
char* gUrl = "https://siglaufscar.herokuapp.com";
char* gPassword = "testelabpesquisa";
void
SignalHandler(
int Signal
)
{
printf("Exiting...\n");
if (gDevice != NULL) {
gDevice->Dispose(gDevice);
}
exit(0);
}
void*
WebServiceThread (
void* Value
)
{
printf("WebServiceThread Begin\n");
PROCESS_TYPE Type = *(PROCESS_TYPE*) Value;
gServer = InitializeServer(8000);
if (gServer != NULL) {
gServer->Start(gServer);
}
printf("WebServiceThread End\n");
return NULL;
}
void*
DeviceFingerprintThread (
void* Value
)
{
PROCESS_TYPE Type = *(PROCESS_TYPE*) Value;
printf("DeviceFingerprintThread Begin\n");
gDevice = Device_Init(Type);
if (gDevice == NULL) {
printf("Something wrong happened...\n");
goto FINISH;
}
switch(Type) {
case ENROLL_PROCESS:
gDevice->Enroll(gDevice);
break;
case VERIFY_PROCESS:
while(1) {
gDevice->Verify(gDevice);
usleep(3000000);
if (gDevice->Outdated == 1) {
gDevice->Fingerprint->Update(gDevice->Fingerprint);
gDevice->Fingerprint->Load(gDevice->Fingerprint);
}
}
break;
}
FINISH:
if (gDevice != NULL) {
gDevice->Dispose(gDevice);
gDevice = NULL;
}
printf("DeviceFingerprintThread End\n");
return NULL;
}
int main(int argc, char* argv[]) {
PROCESS_TYPE Type = 0;
if (argc <= 1) {
printf("%s <enroll or verify>\n", argv[0]);
goto FINISH;
}
if (strstr(argv[1], "enroll") != NULL) {
Type = ENROLL_PROCESS;
} else if (strstr(argv[1], "verify") != NULL) {
Type = VERIFY_PROCESS;
} else {
printf("%s <enroll or verify>\n", argv[0]);
goto FINISH;
}
printf ("Initializing libcurl... ");
if (curl_global_init(CURL_GLOBAL_ALL) < 0) {
printf("FAILED!\n");
goto FINISH;
}
printf ("OK!\n");
//pthread_t WebService;
pthread_t DeviceFingerprint;
//pthread_create(&WebService, NULL, WebServiceThread, (void*)&Type);
pthread_create(&DeviceFingerprint, NULL, DeviceFingerprintThread, (void*)&Type);
//pthread_join(WebService, NULL);
pthread_join(DeviceFingerprint, NULL);
curl_global_cleanup();
FINISH:
return 0;
}