libfprint/fp-image-device.c
| 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 |
4/6fp_image_device_class_intern_init:
✓ Branch 3 → 4 taken 126 times.
✗ Branch 3 → 5 not taken.
fp_image_device_get_type:
✓ Branch 2 → 3 taken 126 times.
✓ Branch 2 → 7 taken 3612 times.
✓ Branch 4 → 5 taken 126 times.
✗ Branch 4 → 7 not taken.
|
4179 | 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 | 42 | fp_image_device_open (FpDevice *device) | |
| 62 | { | ||
| 63 | 42 | FpImageDeviceClass *cls = FP_IMAGE_DEVICE_GET_CLASS (device); | |
| 64 | |||
| 65 | /* Nothing special about opening an image device, just | ||
| 66 | * forward the request. */ | ||
| 67 | 42 | cls->img_open (FP_IMAGE_DEVICE (device)); | |
| 68 | 42 | } | |
| 69 | |||
| 70 | static void | ||
| 71 | 42 | fp_image_device_close (FpDevice *device) | |
| 72 | { | ||
| 73 | 42 | FpImageDevice *self = FP_IMAGE_DEVICE (device); | |
| 74 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 42 times.
|
42 | FpImageDeviceClass *cls = FP_IMAGE_DEVICE_GET_CLASS (self); |
| 75 | 42 | FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self); | |
| 76 | |||
| 77 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 42 times.
|
42 | g_assert (priv->active == FALSE); |
| 78 | 42 | cls->img_close (self); | |
| 79 | 42 | } | |
| 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 |
2/4✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 5 not taken.
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 6 not taken.
|
1 | action == FPI_DEVICE_ACTION_IDENTIFY || |
| 93 | action == FPI_DEVICE_ACTION_CAPTURE) | ||
| 94 | 1 | fpi_image_device_deactivate (self, TRUE); | |
| 95 | 1 | } | |
| 96 | |||
| 97 | static void | ||
| 98 | 35 | fp_image_device_start_capture_action (FpDevice *device) | |
| 99 | { | ||
| 100 | 35 | FpImageDevice *self = FP_IMAGE_DEVICE (device); | |
| 101 | 35 | FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self); | |
| 102 | 35 | FpiDeviceAction action; | |
| 103 | 35 | FpiPrintType print_type; | |
| 104 | |||
| 105 | /* There is just one action that we cannot support out | ||
| 106 | * of the box, which is a capture without first waiting | ||
| 107 | * for a finger to be on the device. | ||
| 108 | */ | ||
| 109 | 35 | action = fpi_device_get_current_action (device); | |
| 110 |
2/2✓ Branch 3 → 4 taken 17 times.
✓ Branch 3 → 10 taken 18 times.
|
35 | if (action == FPI_DEVICE_ACTION_CAPTURE) |
| 111 | { | ||
| 112 | 17 | gboolean wait_for_finger; | |
| 113 | |||
| 114 | 17 | fpi_device_get_capture_data (device, &wait_for_finger); | |
| 115 | |||
| 116 |
1/2✗ Branch 5 → 6 not taken.
✓ Branch 5 → 9 taken 17 times.
|
17 | if (!wait_for_finger) |
| 117 | { | ||
| 118 | ✗ | fpi_device_action_error (device, fpi_device_error_new (FP_DEVICE_ERROR_NOT_SUPPORTED)); | |
| 119 | ✗ | return; | |
| 120 | } | ||
| 121 | } | ||
| 122 |
2/2✓ Branch 10 → 11 taken 6 times.
✓ Branch 10 → 16 taken 12 times.
|
18 | else if (action == FPI_DEVICE_ACTION_ENROLL) |
| 123 | { | ||
| 124 | 6 | FpPrint *enroll_print = NULL; | |
| 125 | |||
| 126 | 6 | fpi_device_get_enroll_data (device, &enroll_print); | |
| 127 | 6 | g_object_get (enroll_print, "fpi-type", &print_type, NULL); | |
| 128 |
2/2✓ Branch 13 → 14 taken 5 times.
✓ Branch 13 → 15 taken 1 time.
|
6 | if (print_type != FPI_PRINT_NBIS) |
| 129 | 5 | fpi_print_set_type (enroll_print, FPI_PRINT_NBIS); | |
| 130 | } | ||
| 131 | |||
| 132 | 35 | priv->enroll_stage = 0; | |
| 133 | /* The internal state machine guarantees both of these. */ | ||
| 134 |
1/2✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 35 times.
|
35 | g_assert (!priv->finger_present); |
| 135 |
1/2✓ Branch 18 → 19 taken 35 times.
✗ Branch 18 → 21 not taken.
|
35 | g_assert (!priv->minutiae_scan_active); |
| 136 | |||
| 137 | /* And activate the device; we rely on fpi_image_device_activate_complete() | ||
| 138 | * to be called when done (or immediately). */ | ||
| 139 | 35 | fpi_image_device_activate (self); | |
| 140 | } | ||
| 141 | |||
| 142 | |||
| 143 | /*********************************************************/ | ||
| 144 | |||
| 145 | static void | ||
| 146 | 45 | fp_image_device_finalize (GObject *object) | |
| 147 | { | ||
| 148 | 45 | FpImageDevice *self = (FpImageDevice *) object; | |
| 149 | 45 | FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self); | |
| 150 | |||
| 151 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 45 times.
|
45 | g_assert (priv->active == FALSE); |
| 152 | |||
| 153 | 45 | G_OBJECT_CLASS (fp_image_device_parent_class)->finalize (object); | |
| 154 | 45 | } | |
| 155 | |||
| 156 | static void | ||
| 157 | ✗ | fp_image_device_default_activate (FpImageDevice *self) | |
| 158 | { | ||
| 159 | ✗ | fpi_image_device_activate_complete (self, NULL); | |
| 160 | ✗ | } | |
| 161 | |||
| 162 | static void | ||
| 163 | ✗ | fp_image_device_default_deactivate (FpImageDevice *self) | |
| 164 | { | ||
| 165 | ✗ | fpi_image_device_deactivate_complete (self, NULL); | |
| 166 | ✗ | } | |
| 167 | |||
| 168 | static void | ||
| 169 | 22 | fp_image_device_get_property (GObject *object, | |
| 170 | guint prop_id, | ||
| 171 | GValue *value, | ||
| 172 | GParamSpec *pspec) | ||
| 173 | { | ||
| 174 | 22 | FpImageDevice *self = FP_IMAGE_DEVICE (object); | |
| 175 | 22 | FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self); | |
| 176 | |||
| 177 |
1/2✓ Branch 2 → 3 taken 22 times.
✗ Branch 2 → 5 not taken.
|
22 | switch (prop_id) |
| 178 | { | ||
| 179 | 22 | case PROP_FPI_STATE: | |
| 180 | 22 | g_value_set_enum (value, priv->state); | |
| 181 | 22 | break; | |
| 182 | |||
| 183 | ✗ | default: | |
| 184 | ✗ | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | |
| 185 | } | ||
| 186 | 22 | } | |
| 187 | |||
| 188 | static void | ||
| 189 | 45 | fp_image_device_constructed (GObject *obj) | |
| 190 | { | ||
| 191 | 45 | FpImageDevice *self = FP_IMAGE_DEVICE (obj); | |
| 192 | 45 | FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self); | |
| 193 |
2/2✓ Branch 2 → 3 taken 13 times.
✓ Branch 2 → 4 taken 32 times.
|
45 | FpImageDeviceClass *cls = FP_IMAGE_DEVICE_GET_CLASS (self); |
| 194 | |||
| 195 | /* Set default threshold. */ | ||
| 196 | 45 | priv->bz3_threshold = BOZORTH3_DEFAULT_THRESHOLD; | |
| 197 |
2/2✓ Branch 2 → 3 taken 13 times.
✓ Branch 2 → 4 taken 32 times.
|
45 | if (cls->bz3_threshold > 0) |
| 198 | 13 | priv->bz3_threshold = cls->bz3_threshold; | |
| 199 | |||
| 200 | 45 | G_OBJECT_CLASS (fp_image_device_parent_class)->constructed (obj); | |
| 201 | 45 | } | |
| 202 | |||
| 203 | static void | ||
| 204 | 126 | fp_image_device_class_init (FpImageDeviceClass *klass) | |
| 205 | { | ||
| 206 | 126 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
| 207 | 126 | FpDeviceClass *fp_device_class = FP_DEVICE_CLASS (klass); | |
| 208 | |||
| 209 | 126 | object_class->finalize = fp_image_device_finalize; | |
| 210 | 126 | object_class->get_property = fp_image_device_get_property; | |
| 211 | 126 | object_class->constructed = fp_image_device_constructed; | |
| 212 | |||
| 213 | /* Set default enroll stage count. */ | ||
| 214 | 126 | fp_device_class->nr_enroll_stages = IMG_ENROLL_STAGES; | |
| 215 | |||
| 216 | 126 | fp_device_class->open = fp_image_device_open; | |
| 217 | 126 | fp_device_class->close = fp_image_device_close; | |
| 218 | 126 | fp_device_class->enroll = fp_image_device_start_capture_action; | |
| 219 | 126 | fp_device_class->identify = fp_image_device_start_capture_action; | |
| 220 | 126 | fp_device_class->capture = fp_image_device_start_capture_action; | |
| 221 | |||
| 222 | 126 | fp_device_class->cancel = fp_image_device_cancel_action; | |
| 223 | |||
| 224 | 126 | fpi_device_class_auto_initialize_features (fp_device_class); | |
| 225 | 126 | fp_device_class->features |= FP_DEVICE_FEATURE_UPDATE_PRINT; | |
| 226 | |||
| 227 | /* Default implementations */ | ||
| 228 | 126 | klass->activate = fp_image_device_default_activate; | |
| 229 | 126 | klass->deactivate = fp_image_device_default_deactivate; | |
| 230 | |||
| 231 | /** | ||
| 232 | * FpImageDevice::fpi-image-device-state: (skip) | ||
| 233 | * | ||
| 234 | * This property is only for internal purposes. | ||
| 235 | * | ||
| 236 | * Stability: private | ||
| 237 | */ | ||
| 238 | 252 | properties[PROP_FPI_STATE] = | |
| 239 | 126 | g_param_spec_enum ("fpi-image-device-state", | |
| 240 | "Image Device State", | ||
| 241 | "Private: The state of the image device", | ||
| 242 | FPI_TYPE_IMAGE_DEVICE_STATE, | ||
| 243 | FPI_IMAGE_DEVICE_STATE_INACTIVE, | ||
| 244 | G_PARAM_STATIC_STRINGS | G_PARAM_READABLE); | ||
| 245 | |||
| 246 | /** | ||
| 247 | * FpImageDevice::fpi-image-device-state-changed: (skip) | ||
| 248 | * @image_device: A #FpImageDevice | ||
| 249 | * @new_state: The new state of the device | ||
| 250 | * | ||
| 251 | * This signal is only for internal purposes. | ||
| 252 | * | ||
| 253 | * Stability: private | ||
| 254 | */ | ||
| 255 | 252 | signals[FPI_STATE_CHANGED] = | |
| 256 | 126 | g_signal_new ("fpi-image-device-state-changed", | |
| 257 | G_TYPE_FROM_CLASS (object_class), | ||
| 258 | G_SIGNAL_RUN_FIRST, | ||
| 259 | G_STRUCT_OFFSET (FpImageDeviceClass, change_state), | ||
| 260 | NULL, NULL, NULL, | ||
| 261 | G_TYPE_NONE, 1, FPI_TYPE_IMAGE_DEVICE_STATE); | ||
| 262 | |||
| 263 | 126 | g_object_class_install_properties (object_class, N_PROPS, properties); | |
| 264 | 126 | } | |
| 265 | |||
| 266 | static void | ||
| 267 | 45 | fp_image_device_init (FpImageDevice *self) | |
| 268 | { | ||
| 269 | 45 | } | |
| 270 |