manager: Use GEnum to register DBus errors from FprintError

Given that mk_genenum already parses FprintError, add the nick metadata
to the errors so that it matches the wanted DBus error and automatically
generate the errors list.

In this way we'll have to only touch one definition to get everything
updated
This commit is contained in:
Marco Trevisan (Treviño)
2020-11-06 19:19:24 +01:00
committed by Benjamin Berg
parent 4c78012103
commit 4e707f0d31
3 changed files with 33 additions and 29 deletions

View File

@ -30,7 +30,6 @@
#include <errno.h> #include <errno.h>
#include "fprintd.h" #include "fprintd.h"
#include "fprintd-enums.h"
#include "storage.h" #include "storage.h"
static const char *FINGERS_NAMES[] = { static const char *FINGERS_NAMES[] = {

View File

@ -22,6 +22,7 @@
#include <glib.h> #include <glib.h>
#include <gio/gio.h> #include <gio/gio.h>
#include <fprint.h> #include <fprint.h>
#include "fprintd-enums.h"
#include "fprintd-dbus.h" #include "fprintd-dbus.h"
/* General */ /* General */
@ -33,16 +34,23 @@
GQuark fprint_error_quark(void); GQuark fprint_error_quark(void);
#define FPRINT_ERROR fprint_error_quark() #define FPRINT_ERROR fprint_error_quark()
#define FPRINT_ERROR_DBUS_INTERFACE "net.reactivated.Fprint.Error"
typedef enum { typedef enum {
FPRINT_ERROR_CLAIM_DEVICE, /* developer didn't claim the device */ /* developer didn't claim the device */
FPRINT_ERROR_ALREADY_IN_USE, /* device is already claimed by somebody else */ FPRINT_ERROR_CLAIM_DEVICE, /*< nick=net.reactivated.Fprint.Error.ClaimDevice >*/
FPRINT_ERROR_INTERNAL, /* internal error occurred */ /* device is already claimed by somebody else */
FPRINT_ERROR_PERMISSION_DENIED, /* PolicyKit refused the action */ FPRINT_ERROR_ALREADY_IN_USE, /*< nick=net.reactivated.Fprint.Error.AlreadyInUse >*/
FPRINT_ERROR_NO_ENROLLED_PRINTS, /* No prints are enrolled */ /* internal error occurred */
FPRINT_ERROR_NO_ACTION_IN_PROGRESS, /* No actions currently in progress */ FPRINT_ERROR_INTERNAL, /*< nick=net.reactivated.Fprint.Error.Internal >*/
FPRINT_ERROR_INVALID_FINGERNAME, /* the finger name passed was invalid */ /* PolicyKit refused the action */
FPRINT_ERROR_NO_SUCH_DEVICE, /* device does not exist */ FPRINT_ERROR_PERMISSION_DENIED, /*< nick=net.reactivated.Fprint.Error.PermissionDenied >*/
/* No prints are enrolled */
FPRINT_ERROR_NO_ENROLLED_PRINTS, /*< nick=net.reactivated.Fprint.Error.NoEnrolledPrints >*/
/* No actions currently in progress */
FPRINT_ERROR_NO_ACTION_IN_PROGRESS, /*< nick=net.reactivated.Fprint.Error.NoActionInProgress >*/
/* the finger name passed was invalid */
FPRINT_ERROR_INVALID_FINGERNAME, /*< nick=net.reactivated.Fprint.Error.InvalidFingername >*/
/* device does not exist */
FPRINT_ERROR_NO_SUCH_DEVICE, /*< nick=net.reactivated.Fprint.Error.NoSuchDevice >*/
} FprintError; } FprintError;
typedef enum { typedef enum {

View File

@ -394,28 +394,25 @@ static gboolean fprint_manager_get_default_device(FprintManager *manager,
} }
} }
#define ERROR_ENTRY(name, dbus_name) \
{ FPRINT_ERROR_ ## name, FPRINT_ERROR_DBUS_INTERFACE "." dbus_name }
GDBusErrorEntry fprint_error_entries[] =
{
ERROR_ENTRY (CLAIM_DEVICE, "ClaimDevice"),
ERROR_ENTRY (ALREADY_IN_USE, "AlreadyInUse"),
ERROR_ENTRY (INTERNAL, "Internal"),
ERROR_ENTRY (PERMISSION_DENIED, "PermissionDenied"),
ERROR_ENTRY (NO_ENROLLED_PRINTS, "NoEnrolledPrints"),
ERROR_ENTRY (NO_ACTION_IN_PROGRESS, "NoActionInProgress"),
ERROR_ENTRY (INVALID_FINGERNAME, "InvalidFingername"),
ERROR_ENTRY (NO_SUCH_DEVICE, "NoSuchDevice"),
};
GQuark fprint_error_quark (void) GQuark fprint_error_quark (void)
{ {
static volatile gsize quark = 0; static volatile gsize quark = 0;
if (!quark) { if (g_once_init_enter (&quark)) {
g_dbus_error_register_error_domain ("fprintd-error-quark", g_autoptr(GEnumClass) errors_enum = NULL;
&quark, GQuark domain;
fprint_error_entries, unsigned i;
G_N_ELEMENTS (fprint_error_entries));
domain = g_quark_from_static_string ("fprintd-error-quark");
errors_enum = g_type_class_ref (FPRINT_TYPE_ERROR);
for (i = 0; i < errors_enum->n_values; ++i) {
GEnumValue *value = &errors_enum->values[i];
g_dbus_error_register_error (domain, value->value,
value->value_nick);
}
g_once_init_leave (&quark, domain);
} }
return (GQuark) quark; return (GQuark) quark;
} }