Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Copyright (C) 2025 Marco Trevisan <marco.trevisan@canonical.com> | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * This library is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * Lesser General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public | ||
15 | * License along with this library; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
17 | */ | ||
18 | |||
19 | #include "glib.h" | ||
20 | #include "fpi-context.h" | ||
21 | #include "fpi-device.h" | ||
22 | |||
23 | #define METAINFO_BASE \ | ||
24 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" \ | ||
25 | "<component>\n" \ | ||
26 | " <id>org.freedesktop.libfprint</id>\n" \ | ||
27 | " <name>libfprint</name>\n" \ | ||
28 | " <metadata_license>CC0-1.0</metadata_license>\n" \ | ||
29 | " <project_license>LGPL-2.1-or-later</project_license>\n" \ | ||
30 | " <url type=\"homepage\">https://fprint.freedesktop.org</url>\n" \ | ||
31 | " <url type=\"vcs-browser\">https://gitlab.freedesktop.org/libfprint/libfprint</url>\n" \ | ||
32 | " <url type=\"help\">https://fprint.freedesktop.org/libfprint-dev</url>\n" \ | ||
33 | " <url type=\"bugtracker\">https://gitlab.freedesktop.org/libfprint/libfprint/-/issues</url>\n" \ | ||
34 | " <summary>Async fingerprint readers library</summary>\n" \ | ||
35 | " <description>\n" \ | ||
36 | " <p>\n" \ | ||
37 | " The fprint project aims to support for consumer fingerprint reader devices.\n" \ | ||
38 | " </p>\n" \ | ||
39 | " </description>\n" \ | ||
40 | " <provides>\n" \ | ||
41 | "%s\n" \ | ||
42 | " </provides>\n" \ | ||
43 | "</component>\n" | ||
44 | |||
45 | static int | ||
46 | 120 | driver_compare (gconstpointer p1, gconstpointer p2) | |
47 | { | ||
48 | 120 | g_autoptr(FpDeviceClass) cls1 = g_type_class_ref (*(GType *) p1); | |
49 | 240 | g_autoptr(FpDeviceClass) cls2 = g_type_class_ref (*(GType *) p2); | |
50 | |||
51 | 120 | return g_strcmp0 (cls1->id, cls2->id); | |
52 | } | ||
53 | |||
54 | static void | ||
55 | 29 | usb_driver_devices_append (GPtrArray *devices_list, | |
56 | const FpDeviceClass *cls) | ||
57 | { | ||
58 | 29 | const FpIdEntry *entry; | |
59 | |||
60 |
1/2✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
|
29 | if (cls->type != FP_DEVICE_TYPE_USB) |
61 | return; | ||
62 | |||
63 |
2/2✓ Branch 0 taken 222 times.
✓ Branch 1 taken 29 times.
|
251 | for (entry = cls->id_table; entry->vid != 0; entry++) |
64 | { | ||
65 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 222 times.
|
222 | if (entry->vid == 0 || entry->pid == 0) |
66 | ✗ | continue; | |
67 | |||
68 | 222 | g_ptr_array_add (devices_list, | |
69 | 222 | g_strdup_printf ("v%04xp%04x", entry->vid, entry->pid)); | |
70 | } | ||
71 | } | ||
72 | |||
73 | int | ||
74 | 1 | main (void) | |
75 | { | ||
76 | 1 | g_autoptr(GPtrArray) devices_list = g_ptr_array_new_with_free_func (g_free); | |
77 | 2 | g_autoptr(GArray) drivers = fpi_get_driver_types (); | |
78 | 2 | g_autoptr(GString) provided_modules = g_string_new (NULL); | |
79 | 1 | g_autoptr(GError) error = NULL; | |
80 | |||
81 | 1 | g_array_sort (drivers, driver_compare); | |
82 | |||
83 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 1 times.
|
34 | for (guint i = 0; i < drivers->len; ++i) |
84 | { | ||
85 | 33 | GType driver = g_array_index (drivers, GType, i); | |
86 | 66 | g_autoptr(FpDeviceClass) cls = g_type_class_ref (driver); | |
87 | |||
88 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 29 times.
|
33 | if (cls->type != FP_DEVICE_TYPE_USB) |
89 | 4 | continue; | |
90 | |||
91 | 29 | usb_driver_devices_append (devices_list, cls); | |
92 | } | ||
93 | |||
94 |
2/2✓ Branch 0 taken 222 times.
✓ Branch 1 taken 1 times.
|
223 | for (guint i = 0; i < devices_list->len; ++i) |
95 | { | ||
96 | 222 | const char *device_id = g_ptr_array_index (devices_list, i); | |
97 | |||
98 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 222 times.
|
222 | g_string_append (provided_modules, " "); |
99 | 222 | g_string_append_printf (provided_modules, "<modalias>usb:%s*</modalias>", | |
100 | device_id); | ||
101 | |||
102 |
2/2✓ Branch 0 taken 221 times.
✓ Branch 1 taken 1 times.
|
222 | if (i < devices_list->len - 1) |
103 |
1/2✓ Branch 0 taken 221 times.
✗ Branch 1 not taken.
|
443 | g_string_append_c (provided_modules, '\n'); |
104 | } | ||
105 | |||
106 | 1 | g_print (METAINFO_BASE, provided_modules->str); | |
107 | } | ||
108 |