/
fp_fake.c
142 lines (116 loc) · 2.58 KB
/
fp_fake.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <libusb.h>
#include "fp_fake.h"
#define UNUSED __attribute__((unused))
libusb_context *fpi_usb_ctx = NULL;
void fpi_imgdev_open_complete (struct fp_img_dev *imgdev UNUSED, int status UNUSED)
{
}
void fpi_imgdev_close_complete (struct fp_img_dev *imgdev UNUSED)
{
}
void fpi_imgdev_session_error(struct fp_img_dev *imgdev UNUSED, int error UNUSED)
{
}
void fpi_log(enum fpi_log_level level, const char *component,
const char *function, const char *format, ...)
{
va_list args;
FILE *stream = stdout;
const char *prefix;
switch (level) {
case LOG_LEVEL_INFO:
prefix = "info";
break;
case LOG_LEVEL_WARNING:
stream = stderr;
prefix = "warning";
break;
case LOG_LEVEL_ERROR:
stream = stderr;
prefix = "error";
break;
case LOG_LEVEL_DEBUG:
stream = stderr;
prefix = "debug";
break;
default:
stream = stderr;
prefix = "unknown";
break;
}
fprintf(stream, "%s:%s [%s] ", component ? component : "fp", prefix,
function);
va_start (args, format);
vfprintf(stream, format, args);
va_end (args);
fprintf(stream, "\n");
}
void fpi_imgdev_activate_complete(struct fp_img_dev *imgdev UNUSED, int i UNUSED)
{
}
void fpi_imgdev_deactivate_complete(struct fp_img_dev *imgdev UNUSED)
{
}
struct fp_img *fpi_img_new(size_t length)
{
struct fp_img *img = malloc(sizeof(*img) + length);
memset(img, 0, sizeof(*img));
img->length = length;
return img;
}
void fpi_imgdev_image_captured(struct fp_img_dev *imgdev UNUSED, struct fp_img *img UNUSED)
{
}
void fpi_imgdev_report_finger_status(struct fp_img_dev *imgdev UNUSED, gboolean present UNUSED)
{
}
/* external interface for testing */
struct fp_img_dev *global_init(void)
{
int ret;
struct fp_img_dev *dev;
ret = libusb_init(&fpi_usb_ctx);
if (ret != LIBUSB_SUCCESS) {
fp_err("libusb_init failed %d", ret);
goto cantclaim;
}
dev = malloc(sizeof(struct fp_img_dev));
if (dev == NULL) {
fp_err("cannot allocate memory");
goto cantclaim;
}
dev->udev = libusb_open_device_with_vid_pid(fpi_usb_ctx, 0x1c7a, 0x0603);
if (dev->udev == NULL) {
fp_err("libusb_open_device_with_vid_pid failed");
free(dev);
dev = NULL;
goto cantclaim;
}
if (dev_init(dev, 0x0603))
dev = NULL;
cantclaim:
return dev;
}
void global_exit(struct fp_img_dev * dev)
{
dev_deinit(dev);
if (dev->udev) {
libusb_close(dev->udev);
dev->udev = NULL;
}
/* TODO how to test fpi_usb_ctx */
libusb_exit(fpi_usb_ctx);
}
#if 0
int main()
{
global_init();
/* TODO add other things here? */
global_exit();
return 0;
}
#endif