diff options
author | Dan Winship <danw@gnome.org> | 2014-10-11 14:44:10 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-10-22 08:29:08 -0400 |
commit | 69099f3e80dde14b4556c95fbdde7f01b913cdbc (patch) | |
tree | c22208fdc344dbe6b6875cf583308b06953cf304 /libnm/nm-device-modem.c | |
parent | 5632ac6730b2bc35c8a3ec1d40b921dfadaef110 (diff) | |
download | NetworkManager-69099f3e80dde14b4556c95fbdde7f01b913cdbc.tar.gz |
libnm: merge device-type-specific errors into NMDeviceError
As with the settings, each device type was defining its own error
type, containing either redundant or non-useful error codes. Drop all
of the subtype-specific errors, and reduce things to just
NM_DEVICE_ERROR_FAILED, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, and
NM_DEVICE_ERROR_INVALID_CONNECTION.
The device-type-specific errors were only returned from their
nm_device_connection_compatible() implementations, so this is also a
good opportunity to simplify those, by moving duplicated functionality
into the base NMDevice implementation, and then allowing the
subclasses to assume that the connection has already been validated in
their own code. Most of the implementations now just check that the
connection has the correct type for the device (which can't be done at
the NMDevice level since some device types (eg, Ethernet) support
multiple connection types.)
Also, make sure that all of the error messages are localized.
Diffstat (limited to 'libnm/nm-device-modem.c')
-rw-r--r-- | libnm/nm-device-modem.c | 43 |
1 files changed, 12 insertions, 31 deletions
diff --git a/libnm/nm-device-modem.c b/libnm/nm-device-modem.c index 1f8a91406a..25c63f753e 100644 --- a/libnm/nm-device-modem.c +++ b/libnm/nm-device-modem.c @@ -21,6 +21,7 @@ #include <config.h> #include <string.h> +#include <glib/gi18n.h> #include "nm-glib-compat.h" @@ -50,23 +51,6 @@ enum { }; /** - * nm_device_modem_error_quark: - * - * Registers an error quark for #NMDeviceModem if necessary. - * - * Returns: the error quark used for #NMDeviceModem errors. - **/ -GQuark -nm_device_modem_error_quark (void) -{ - static GQuark quark = 0; - - if (G_UNLIKELY (quark == 0)) - quark = g_quark_from_static_string ("nm-device-modem-error-quark"); - return quark; -} - -/** * nm_device_modem_get_modem_capabilities: * @self: a #NMDeviceModem * @@ -125,39 +109,36 @@ get_type_description (NMDevice *device) static gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { - NMSettingConnection *s_con; NMSettingGsm *s_gsm; NMSettingCdma *s_cdma; - const char *ctype; NMDeviceModemCapabilities current_caps; - s_con = nm_connection_get_setting_connection (connection); - g_assert (s_con); + if (!NM_DEVICE_CLASS (nm_device_modem_parent_class)->connection_compatible (device, connection, error)) + return FALSE; - ctype = nm_setting_connection_get_connection_type (s_con); - if ( strcmp (ctype, NM_SETTING_GSM_SETTING_NAME) != 0 - && strcmp (ctype, NM_SETTING_CDMA_SETTING_NAME) != 0) { - g_set_error (error, NM_DEVICE_MODEM_ERROR, NM_DEVICE_MODEM_ERROR_NOT_MODEM_CONNECTION, - "The connection was not a modem connection."); + if ( !nm_connection_is_type (connection, NM_SETTING_GSM_SETTING_NAME) + && !nm_connection_is_type (connection, NM_SETTING_CDMA_SETTING_NAME)) { + g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, + _("The connection was not a modem connection.")); return FALSE; } s_gsm = nm_connection_get_setting_gsm (connection); s_cdma = nm_connection_get_setting_cdma (connection); if (!s_cdma && !s_gsm) { - g_set_error (error, NM_DEVICE_MODEM_ERROR, NM_DEVICE_MODEM_ERROR_INVALID_MODEM_CONNECTION, - "The connection was not a valid modem connection."); + g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION, + _("The connection was not a valid modem connection.")); return FALSE; } current_caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device)); if (!(s_gsm && MODEM_CAPS_3GPP (current_caps)) && !(s_cdma && MODEM_CAPS_3GPP2 (current_caps))) { - g_set_error (error, NM_DEVICE_MODEM_ERROR, NM_DEVICE_MODEM_ERROR_MISSING_DEVICE_CAPS, - "The device missed capabilities required by the GSM/CDMA connection."); + g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, + _("The device is lacking capabilities required by the connection.")); return FALSE; } - return NM_DEVICE_CLASS (nm_device_modem_parent_class)->connection_compatible (device, connection, error); + return TRUE; } static GType |