Register the local error codes with D-Bus to return a nice error message

This commit is contained in:
Richard Hughes 2015-03-04 22:16:05 +00:00
parent d3d0165259
commit 9849d2bb61
4 changed files with 59 additions and 3 deletions

View File

@ -24,6 +24,8 @@ AM_CPPFLAGS = \
bin_PROGRAMS = fwupdmgr
fwupdmgr_SOURCES = \
fu-common.c \
fu-common.h \
fu-device.c \
fu-device.h \
fu-util.c
@ -61,6 +63,7 @@ libexec_PROGRAMS = \
fwupd_SOURCES = \
fu-cleanup.h \
fu-common.c \
fu-common.h \
fu-debug.c \
fu-debug.h \

47
src/fu-common.c Normal file
View File

@ -0,0 +1,47 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2015 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU General Public License Version 2
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include <glib-object.h>
#include <gio/gio.h>
#include "fu-common.h"
/**
* fu_error_quark:
*
* Return value: An error quark.
*
* Since: 0.1.0
**/
GQuark
fu_error_quark (void)
{
static GQuark quark = 0;
if (!quark) {
quark = g_quark_from_static_string ("FuError");
g_dbus_error_register_error (quark,
FU_ERROR_INTERNAL,
"org.freedesktop.fwupd.InternalError");
}
return quark;
}

View File

@ -26,12 +26,19 @@
#define FWUPD_DBUS_SERVICE "org.freedesktop.fwupd"
#define FWUPD_DBUS_INTERFACE "org.freedesktop.fwupd"
#define FU_ERROR 1
#define FU_ERROR_INTERNAL 0
#define FU_ERROR fu_error_quark()
#define FU_DEVICE_KEY_VERSION "Version"
#define FU_DEVICE_KEY_PROVIDER "Provider"
#define FU_DEVICE_KEY_GUID "Guid"
#define FU_DEVICE_KEY_ONLY_OFFLINE "OnlyOffline"
typedef enum {
FU_ERROR_INTERNAL,
/* private */
FU_ERROR_LAST
} FuError;
GQuark fu_error_quark (void);
#endif /* __FU_COMMON_H */

View File

@ -33,7 +33,6 @@
#include "fu-common.h"
#include "fu-provider.h"
#define FU_ERROR 1
#define FU_ERROR_INVALID_ARGUMENTS 0
#define FU_ERROR_NO_SUCH_CMD 1