GCC Code Coverage Report


Directory: ./
File: libfprint/fp-image-device.c
Date: 2024-09-16 14:36:32
Exec Total Coverage
Lines: 89 99 89.9%
Functions: 12 14 85.7%
Branches: 21 31 67.7%

Line Branch Exec Source
1 /*
2 * FpImageDevice - An image based fingerprint reader device
3 * Copyright (C) 2019 Benjamin Berg <bberg@redhat.com>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #define FP_COMPONENT "image_device"
21 #include "fpi-log.h"
22
23 #include "fp-image-device-private.h"
24
25 #define BOZORTH3_DEFAULT_THRESHOLD 40
26
27 /**
28 * SECTION: fp-image-device
29 * @title: FpImageDevice
30 * @short_description: Image device subclass
31 *
32 * This is a helper class for the commonly found image based devices.
33 */
34
35
3/5
✓ Branch 0 taken 121 times.
✓ Branch 1 taken 3487 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 121 times.
✗ Branch 4 not taken.
7643 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (FpImageDevice, fp_image_device, FP_TYPE_DEVICE)
36
37 enum {
38 PROP_0,
39 PROP_FPI_STATE,
40 N_PROPS
41 };
42
43 static GParamSpec *properties[N_PROPS];
44
45 enum {
46 FPI_STATE_CHANGED,
47
48 LAST_SIGNAL
49 };
50
51 static guint signals[LAST_SIGNAL] = { 0 };
52
53 /*******************************************************/
54
55 /* TODO:
56 * - sanitize_image seems a bit odd, in particular the sizing stuff.
57 **/
58
59 /* Callbacks/vfuncs */
60 static void
61 41 fp_image_device_open (FpDevice *device)
62 {
63 41 FpImageDeviceClass *cls = FP_IMAGE_DEVICE_GET_CLASS (device);
64
65 /* Nothing special about opening an image device, just
66 * forward the request. */
67 41 cls->img_open (FP_IMAGE_DEVICE (device));
68 41 }
69
70 static void
71 41 fp_image_device_close (FpDevice *device)
72 {
73 41 FpImageDevice *self = FP_IMAGE_DEVICE (device);
74
1/2
✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
41 FpImageDeviceClass *cls = FP_IMAGE_DEVICE_GET_CLASS (self);
75 41 FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
76
77
1/2
✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
41 g_assert (priv->active == FALSE);
78 41 cls->img_close (self);
79 41 }
80
81 static void
82 1 fp_image_device_cancel_action (FpDevice *device)
83 {
84 1 FpImageDevice *self = FP_IMAGE_DEVICE (device);
85 1 FpiDeviceAction action;
86
87 1 action = fpi_device_get_current_action (device);
88
89 /* We can only cancel capture operations, in that case, deactivate and return
90 * an error immediately. */
91 1 if (action == FPI_DEVICE_ACTION_ENROLL ||
92 action == FPI_DEVICE_ACTION_VERIFY ||
93
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 action == FPI_DEVICE_ACTION_IDENTIFY ||
94 action == FPI_DEVICE_ACTION_CAPTURE)
95 1 fpi_image_device_deactivate (self, TRUE);
96 1 }
97
98 static void
99 34 fp_image_device_start_capture_action (FpDevice *device)
100 {
101 34 FpImageDevice *self = FP_IMAGE_DEVICE (device);
102 34 FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
103 34 FpiDeviceAction action;
104 34 FpiPrintType print_type;
105
106 /* There is just one action that we cannot support out
107 * of the box, which is a capture without first waiting
108 * for a finger to be on the device.
109 */
110 34 action = fpi_device_get_current_action (device);
111
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 18 times.
34 if (action == FPI_DEVICE_ACTION_CAPTURE)
112 {
113 16 gboolean wait_for_finger;
114
115 16 fpi_device_get_capture_data (device, &wait_for_finger);
116
117
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (!wait_for_finger)
118 {
119 fpi_device_action_error (device, fpi_device_error_new (FP_DEVICE_ERROR_NOT_SUPPORTED));
120 return;
121 }
122 }
123
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 else if (action == FPI_DEVICE_ACTION_ENROLL)
124 {
125 6 FpPrint *enroll_print = NULL;
126
127 6 fpi_device_get_enroll_data (device, &enroll_print);
128 6 g_object_get (enroll_print, "fpi-type", &print_type, NULL);
129
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
6 if (print_type != FPI_PRINT_NBIS)
130 5 fpi_print_set_type (enroll_print, FPI_PRINT_NBIS);
131 }
132
133 34 priv->enroll_stage = 0;
134 /* The internal state machine guarantees both of these. */
135
1/2
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
34 g_assert (!priv->finger_present);
136
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34 times.
34 g_assert (!priv->minutiae_scan_active);
137
138 /* And activate the device; we rely on fpi_image_device_activate_complete()
139 * to be called when done (or immediately). */
140 34 fpi_image_device_activate (self);
141 }
142
143
144 /*********************************************************/
145
146 static void
147 44 fp_image_device_finalize (GObject *object)
148 {
149 44 FpImageDevice *self = (FpImageDevice *) object;
150 44 FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
151
152
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
44 g_assert (priv->active == FALSE);
153
154 44 G_OBJECT_CLASS (fp_image_device_parent_class)->finalize (object);
155 44 }
156
157 static void
158 fp_image_device_default_activate (FpImageDevice *self)
159 {
160 fpi_image_device_activate_complete (self, NULL);
161 }
162
163 static void
164 fp_image_device_default_deactivate (FpImageDevice *self)
165 {
166 fpi_image_device_deactivate_complete (self, NULL);
167 }
168
169 static void
170 22 fp_image_device_get_property (GObject *object,
171 guint prop_id,
172 GValue *value,
173 GParamSpec *pspec)
174 {
175 22 FpImageDevice *self = FP_IMAGE_DEVICE (object);
176 22 FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
177
178
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 switch (prop_id)
179 {
180 22 case PROP_FPI_STATE:
181 22 g_value_set_enum (value, priv->state);
182 22 break;
183
184 default:
185 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
186 }
187 22 }
188
189 static void
190 44 fp_image_device_constructed (GObject *obj)
191 {
192 44 FpImageDevice *self = FP_IMAGE_DEVICE (obj);
193 44 FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
194
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 32 times.
44 FpImageDeviceClass *cls = FP_IMAGE_DEVICE_GET_CLASS (self);
195
196 /* Set default threshold. */
197 44 priv->bz3_threshold = BOZORTH3_DEFAULT_THRESHOLD;
198
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 32 times.
44 if (cls->bz3_threshold > 0)
199 12 priv->bz3_threshold = cls->bz3_threshold;
200
201 44 G_OBJECT_CLASS (fp_image_device_parent_class)->constructed (obj);
202 44 }
203
204 static void
205 121 fp_image_device_class_init (FpImageDeviceClass *klass)
206 {
207 121 GObjectClass *object_class = G_OBJECT_CLASS (klass);
208 121 FpDeviceClass *fp_device_class = FP_DEVICE_CLASS (klass);
209
210 121 object_class->finalize = fp_image_device_finalize;
211 121 object_class->get_property = fp_image_device_get_property;
212 121 object_class->constructed = fp_image_device_constructed;
213
214 /* Set default enroll stage count. */
215 121 fp_device_class->nr_enroll_stages = IMG_ENROLL_STAGES;
216
217 121 fp_device_class->open = fp_image_device_open;
218 121 fp_device_class->close = fp_image_device_close;
219 121 fp_device_class->enroll = fp_image_device_start_capture_action;
220 121 fp_device_class->verify = fp_image_device_start_capture_action;
221 121 fp_device_class->identify = fp_image_device_start_capture_action;
222 121 fp_device_class->capture = fp_image_device_start_capture_action;
223
224 121 fp_device_class->cancel = fp_image_device_cancel_action;
225
226 121 fpi_device_class_auto_initialize_features (fp_device_class);
227 121 fp_device_class->features |= FP_DEVICE_FEATURE_UPDATE_PRINT;
228
229 /* Default implementations */
230 121 klass->activate = fp_image_device_default_activate;
231 121 klass->deactivate = fp_image_device_default_deactivate;
232
233 /**
234 * FpImageDevice::fpi-image-device-state: (skip)
235 *
236 * This property is only for internal purposes.
237 *
238 * Stability: private
239 */
240 242 properties[PROP_FPI_STATE] =
241 121 g_param_spec_enum ("fpi-image-device-state",
242 "Image Device State",
243 "Private: The state of the image device",
244 FPI_TYPE_IMAGE_DEVICE_STATE,
245 FPI_IMAGE_DEVICE_STATE_INACTIVE,
246 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
247
248 /**
249 * FpImageDevice::fpi-image-device-state-changed: (skip)
250 * @image_device: A #FpImageDevice
251 * @new_state: The new state of the device
252 *
253 * This signal is only for internal purposes.
254 *
255 * Stability: private
256 */
257 242 signals[FPI_STATE_CHANGED] =
258 121 g_signal_new ("fpi-image-device-state-changed",
259 G_TYPE_FROM_CLASS (object_class),
260 G_SIGNAL_RUN_FIRST,
261 G_STRUCT_OFFSET (FpImageDeviceClass, change_state),
262 NULL, NULL, NULL,
263 G_TYPE_NONE, 1, FPI_TYPE_IMAGE_DEVICE_STATE);
264
265 121 g_object_class_install_properties (object_class, N_PROPS, properties);
266 121 }
267
268 static void
269 44 fp_image_device_init (FpImageDevice *self)
270 {
271 44 }
272