summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-10-15 15:27:25 -0400
committerDan Winship <danw@gnome.org>2014-10-22 08:29:09 -0400
commit862d4efeac8b340205b3cccdfd56b3c8c0279227 (patch)
tree0ee29371424207b78faa1b78530153cc33162bcc
parentfd7b9df47d6598af91b76af64584039ddc5037dc (diff)
downloadNetworkManager-862d4efeac8b340205b3cccdfd56b3c8c0279227.tar.gz
libnm-core, core: move NMManagerError to nm-errors
Move the definition of NMManagerError to nm-errors, register it with D-Bus, and verify in the tests that it maps correctly. NM_MANAGER_ERROR_INTERNAL gets renamed to NM_MANAGER_ERROR_FAILED for consistency. NM_MANAGER_ERROR_UNMANAGED_DEVICE is dropped since that name doesn't really describe the one place it was previously used in. NM_MANAGER_ERROR_SYSTEM_CONNECTION is dropped because it was't being used. NM_MANAGER_ERROR_UNSUPPORTED_CONNECTION_TYPE is dropped because it can be replaced with an NM_CONNECTION_ERROR. NM_MANAGER_ERROR_AUTOCONNECT_NOT_ALLOWED is turned into the more generic NM_MANAGER_ERROR_CONNECTION_NOT_AVAILABLE. Also, remove the <tp:possible-errors> sections from nm-manager.xml, since they were completely out of date.
-rw-r--r--clients/cli/devices.c7
-rw-r--r--introspection/nm-manager.xml17
-rw-r--r--libnm-core/nm-errors.c4
-rw-r--r--libnm-core/nm-errors.h40
-rw-r--r--libnm/libnm.ver2
-rw-r--r--src/nm-manager.c30
-rw-r--r--src/nm-manager.h16
7 files changed, 56 insertions, 60 deletions
diff --git a/clients/cli/devices.c b/clients/cli/devices.c
index 4949691264..6d5f3a397e 100644
--- a/clients/cli/devices.c
+++ b/clients/cli/devices.c
@@ -1472,16 +1472,11 @@ connect_device_cb (GObject *client, GAsyncResult *result, gpointer user_data)
active = nm_client_activate_connection_finish (NM_CLIENT (client), result, &error);
if (error) {
- char *dbus_err;
-
/* If no connection existed for the device, create one and activate it */
- dbus_err = g_dbus_error_get_remote_error (error);
- if (g_strcmp0 (dbus_err, "org.freedesktop.NetworkManager.UnknownConnection") == 0) {
+ if (g_error_matches (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_CONNECTION)) {
create_connect_connection_for_device (info);
- g_free (dbus_err);
return;
}
- g_free (dbus_err);
g_dbus_error_strip_remote_error (error);
g_string_printf (nmc->return_text, _("Error: Device activation failed: %s"),
diff --git a/introspection/nm-manager.xml b/introspection/nm-manager.xml
index ac9bec6676..05bcc99a36 100644
--- a/introspection/nm-manager.xml
+++ b/introspection/nm-manager.xml
@@ -73,16 +73,6 @@
The path of the active connection object representing this active connection.
</tp:docstring>
</arg>
- <tp:possible-errors>
- <tp:error name="org.freedesktop.NetworkManager.Error.UnknownConnection"/>
- <tp:error name="org.freedesktop.NetworkManager.Error.UnknownDevice"/>
- <tp:error name="org.freedesktop.NetworkManager.Error.ConnectionActivating">
- <tp:docstring>Another connection is already activating or the same connection is already active. FIXME: check if the error name is correct. FIXME: split into 2 errors?</tp:docstring>
- </tp:error>
- <tp:error name="org.freedesktop.NetworkManager.Error.ConnectionInvalid">
- <tp:docstring>The connection is invalid for this device.</tp:docstring>
- </tp:error>
- </tp:possible-errors>
</method>
<method name="AddAndActivateConnection">
@@ -125,13 +115,6 @@
The path of the active connection object representing this active connection.
</tp:docstring>
</arg>
- <tp:possible-errors>
- <tp:error name="org.freedesktop.NetworkManager.Error.UnknownConnection"/>
- <tp:error name="org.freedesktop.NetworkManager.Error.UnknownDevice"/>
- <tp:error name="org.freedesktop.NetworkManager.Error.ConnectionInvalid">
- <tp:docstring>The connection is invalid for this device.</tp:docstring>
- </tp:error>
- </tp:possible-errors>
</method>
<method name="DeactivateConnection">
diff --git a/libnm-core/nm-errors.c b/libnm-core/nm-errors.c
index cf980e106b..cfbfd8533d 100644
--- a/libnm-core/nm-errors.c
+++ b/libnm-core/nm-errors.c
@@ -29,6 +29,7 @@
G_DEFINE_QUARK (nm-connection-error-quark, nm_connection_error)
G_DEFINE_QUARK (nm-crypto-error-quark, nm_crypto_error)
G_DEFINE_QUARK (nm-device-error-quark, nm_device_error)
+G_DEFINE_QUARK (nm-manager-error-quark, nm_manager_error)
static void
register_error_domain (GQuark domain,
@@ -61,4 +62,7 @@ _nm_dbus_errors_init (void)
register_error_domain (NM_DEVICE_ERROR,
NM_DBUS_INTERFACE_DEVICE,
NM_TYPE_DEVICE_ERROR);
+ register_error_domain (NM_MANAGER_ERROR,
+ NM_DBUS_INTERFACE,
+ NM_TYPE_MANAGER_ERROR);
}
diff --git a/libnm-core/nm-errors.h b/libnm-core/nm-errors.h
index 5c9e4a10b0..7a2e5ba0f1 100644
--- a/libnm-core/nm-errors.h
+++ b/libnm-core/nm-errors.h
@@ -131,4 +131,44 @@ typedef enum {
#define NM_DEVICE_ERROR nm_device_error_quark ()
GQuark nm_device_error_quark (void);
+/**
+ * NMManagerError:
+ * @NM_MANAGER_ERROR_FAILED: unknown or unclassified error
+ * @NM_MANAGER_ERROR_PERMISSION_DENIED: Permission denied.
+ * @NM_MANAGER_ERROR_UNKNOWN_CONNECTION: The requested connection is not known.
+ * @NM_MANAGER_ERROR_UNKNOWN_DEVICE: The requested device is not known.
+ * @NM_MANAGER_ERROR_CONNECTION_NOT_AVAILABLE: The requested connection cannot be
+ * activated at this time.
+ * @NM_MANAGER_ERROR_CONNECTION_NOT_ACTIVE: The request could not be completed
+ * because a required connection is not active.
+ * @NM_MANAGER_ERROR_CONNECTION_ALREADY_ACTIVE: The connection to be activated was
+ * already active on another device.
+ * @NM_MANAGER_ERROR_DEPENDENCY_FAILED: An activation request failed due to a
+ * dependency being unavailable.
+ * @NM_MANAGER_ERROR_ALREADY_ASLEEP_OR_AWAKE: The manager is already in the requested
+ * sleep/wake state.
+ * @NM_MANAGER_ERROR_ALREADY_ENABLED_OR_DISABLED: The network is already
+ * enabled/disabled.
+ *
+ * Errors related to the main "network management" interface of NetworkManager.
+ * These may be returned from #NMClient methods that invoke D-Bus operations on
+ * the "org.freedesktop.NetworkManager" interface, and correspond to D-Bus
+ * errors in that namespace.
+ */
+typedef enum {
+ NM_MANAGER_ERROR_FAILED = 0, /*< nick=Failed >*/
+ NM_MANAGER_ERROR_PERMISSION_DENIED, /*< nick=PermissionDenied >*/
+ NM_MANAGER_ERROR_UNKNOWN_CONNECTION, /*< nick=UnknownConnection >*/
+ NM_MANAGER_ERROR_UNKNOWN_DEVICE, /*< nick=UnknownDevice >*/
+ NM_MANAGER_ERROR_CONNECTION_NOT_AVAILABLE, /*< nick=ConnectionNotAvailable >*/
+ NM_MANAGER_ERROR_CONNECTION_NOT_ACTIVE, /*< nick=ConnectionNotActive >*/
+ NM_MANAGER_ERROR_CONNECTION_ALREADY_ACTIVE, /*< nick=ConnectionAlreadyActive >*/
+ NM_MANAGER_ERROR_DEPENDENCY_FAILED, /*< nick=DependencyFailed >*/
+ NM_MANAGER_ERROR_ALREADY_ASLEEP_OR_AWAKE, /*< nick=AlreadyAsleepOrAwake >*/
+ NM_MANAGER_ERROR_ALREADY_ENABLED_OR_DISABLED, /*< nick=AlreadyEnabledOrDisabled >*/
+} NMManagerError;
+
+GQuark nm_manager_error_quark (void);
+#define NM_MANAGER_ERROR (nm_manager_error_quark ())
+
#endif /* __NM_ERRORS_H__ */
diff --git a/libnm/libnm.ver b/libnm/libnm.ver
index ff56819b0d..aa1b80e4b9 100644
--- a/libnm/libnm.ver
+++ b/libnm/libnm.ver
@@ -333,6 +333,8 @@ global:
nm_ip6_route_set_next_hop;
nm_ip6_route_set_prefix;
nm_ip6_route_unref;
+ nm_manager_error_get_type;
+ nm_manager_error_quark;
nm_object_error_get_type;
nm_object_error_quark;
nm_object_get_path;
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 959bc551f8..86777ea435 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -250,19 +250,6 @@ enum {
/************************************************************************/
-#define NM_MANAGER_ERROR (nm_manager_error_quark ())
-
-static GQuark
-nm_manager_error_quark (void)
-{
- static GQuark quark = 0;
- if (!quark)
- quark = g_quark_from_static_string ("nm-manager-error");
- return quark;
-}
-
-/************************************************************************/
-
static void active_connection_state_changed (NMActiveConnection *active,
GParamSpec *pspec,
NMManager *self);
@@ -1997,7 +1984,7 @@ _register_device_factory (NMManager *self,
ftype = nm_device_factory_get_device_type (factory);
for (iter = priv->factories; iter; iter = iter->next) {
if (ftype == nm_device_factory_get_device_type (iter->data)) {
- g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_INTERNAL,
+ g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED,
"multiple plugins for same type (using '%s' instead of '%s')",
(char *) g_object_get_data (G_OBJECT (iter->data), PLUGIN_PATH_TAG),
path);
@@ -2517,7 +2504,7 @@ ensure_master_active_connection (NMManager *self,
/* Otherwise, the device is unmanaged, unavailable, or disconnecting */
g_set_error (error,
NM_MANAGER_ERROR,
- NM_MANAGER_ERROR_UNMANAGED_DEVICE,
+ NM_MANAGER_ERROR_DEPENDENCY_FAILED,
"Master device %s unmanaged or not available for activation",
nm_device_get_iface (master_device));
} else if (master_connection) {
@@ -2692,7 +2679,7 @@ _internal_activate_device (NMManager *self, NMActiveConnection *active, GError *
*/
if (!nm_active_connection_get_user_requested (active) &&
!nm_device_autoconnect_allowed (device)) {
- g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_AUTOCONNECT_NOT_ALLOWED,
+ g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_CONNECTION_NOT_AVAILABLE,
"%s does not allow automatic connections at this time",
nm_device_get_iface (device));
return FALSE;
@@ -3361,9 +3348,10 @@ impl_manager_add_and_activate_connection (NMManager *self,
if (vpn) {
/* Try to fill the VPN's connection setting and name at least */
if (!nm_connection_get_setting_vpn (connection)) {
- error = g_error_new_literal (NM_MANAGER_ERROR,
- NM_MANAGER_ERROR_UNSUPPORTED_CONNECTION_TYPE,
+ error = g_error_new_literal (NM_CONNECTION_ERROR,
+ NM_CONNECTION_ERROR_MISSING_SETTING,
"VPN connections require a 'vpn' setting");
+ g_prefix_error (&error, "%s: ", NM_SETTING_VPN_SETTING_NAME);
goto error;
}
@@ -4677,7 +4665,7 @@ nm_manager_new (NMSettings *settings,
bus = nm_dbus_manager_get_connection (priv->dbus_mgr);
if (!bus) {
- g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_INTERNAL,
+ g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED,
"Failed to initialize D-Bus connection");
g_object_unref (singleton);
return NULL;
@@ -4701,7 +4689,7 @@ nm_manager_new (NMSettings *settings,
G_CALLBACK (connectivity_changed), singleton);
if (!dbus_connection_add_filter (dbus_connection, prop_filter, singleton, NULL)) {
- g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_INTERNAL,
+ g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED,
"Failed to register DBus connection filter");
g_object_unref (singleton);
return NULL;
@@ -5261,7 +5249,7 @@ nm_manager_class_init (NMManagerClass *manager_class)
G_TYPE_FROM_CLASS (manager_class),
&dbus_glib_nm_manager_object_info);
- dbus_g_error_domain_register (NM_MANAGER_ERROR, NULL, NM_TYPE_MANAGER_ERROR);
+ dbus_g_error_domain_register (NM_MANAGER_ERROR, NM_DBUS_INTERFACE, NM_TYPE_MANAGER_ERROR);
dbus_g_error_domain_register (NM_LOGGING_ERROR, "org.freedesktop.NetworkManager.Logging", NM_TYPE_LOGGING_ERROR);
}
diff --git a/src/nm-manager.h b/src/nm-manager.h
index 55b0b3fc9f..6413c71449 100644
--- a/src/nm-manager.h
+++ b/src/nm-manager.h
@@ -35,22 +35,6 @@
#define NM_IS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_MANAGER))
#define NM_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_MANAGER, NMManagerClass))
-typedef enum {
- NM_MANAGER_ERROR_UNKNOWN_CONNECTION = 0, /*< nick=UnknownConnection >*/
- NM_MANAGER_ERROR_UNKNOWN_DEVICE, /*< nick=UnknownDevice >*/
- NM_MANAGER_ERROR_UNMANAGED_DEVICE, /*< nick=UnmanagedDevice >*/
- NM_MANAGER_ERROR_SYSTEM_CONNECTION, /*< nick=SystemConnection >*/
- NM_MANAGER_ERROR_PERMISSION_DENIED, /*< nick=PermissionDenied >*/
- NM_MANAGER_ERROR_CONNECTION_NOT_ACTIVE, /*< nick=ConnectionNotActive >*/
- NM_MANAGER_ERROR_ALREADY_ASLEEP_OR_AWAKE, /*< nick=AlreadyAsleepOrAwake >*/
- NM_MANAGER_ERROR_ALREADY_ENABLED_OR_DISABLED, /*< nick=AlreadyEnabledOrDisabled >*/
- NM_MANAGER_ERROR_UNSUPPORTED_CONNECTION_TYPE, /*< nick=UnsupportedConnectionType >*/
- NM_MANAGER_ERROR_DEPENDENCY_FAILED, /*< nick=DependencyFailed >*/
- NM_MANAGER_ERROR_AUTOCONNECT_NOT_ALLOWED, /*< nick=AutoconnectNotAllowed >*/
- NM_MANAGER_ERROR_CONNECTION_ALREADY_ACTIVE, /*< nick=ConnectionAlreadyActive >*/
- NM_MANAGER_ERROR_INTERNAL, /*< nick=Internal >*/
-} NMManagerError;
-
#define NM_MANAGER_VERSION "version"
#define NM_MANAGER_STATE "state"
#define NM_MANAGER_STARTUP "startup"