summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-10-20 14:03:30 -0400
committerDan Winship <danw@gnome.org>2014-10-22 08:29:10 -0400
commit388a0c5e784b4babd80b57f8a66250bd3db37262 (patch)
tree66cdb311d3429f7fda237560de19fca6dc458146
parent2ff4a7d4b0a7892fb08291d34e28df1cce31dbb9 (diff)
libnm: consolidate NMClientError and NMObjectError
Consolidate NMClientError and NMObjectError (such that there is now only one libnm-API-specific error domain). In particular, merge NM_CONNECTION_ERROR_CONNECTION_REMOVED with NM_OBJECT_ERROR_OBJECT_CREATION_FAILURE as the new NM_CONNECTION_ERROR_OBJECT_CREATION_FAILED. Also make object_creation_failed() be a plain method rather than a signal, since there's no reason for anyone to be connecting to it on another object. And remove its GError argument because the subclass can just create its own more-specific error.
-rw-r--r--clients/tui/nmtui-connect.c2
-rw-r--r--libnm/libnm.ver2
-rw-r--r--libnm/nm-client.c11
-rw-r--r--libnm/nm-client.h20
-rw-r--r--libnm/nm-manager.c13
-rw-r--r--libnm/nm-object.c66
-rw-r--r--libnm/nm-object.h28
-rw-r--r--libnm/nm-remote-settings.c7
-rw-r--r--libnm/tests/test-nm-client.c2
-rw-r--r--libnm/tests/test-remote-settings-client.c2
-rw-r--r--po/POTFILES.in2
11 files changed, 42 insertions, 113 deletions
diff --git a/clients/tui/nmtui-connect.c b/clients/tui/nmtui-connect.c
index 7e04657aff..be03796986 100644
--- a/clients/tui/nmtui-connect.c
+++ b/clients/tui/nmtui-connect.c
@@ -86,7 +86,7 @@ activate_ac_state_changed (GObject *object,
return;
if (state != NM_ACTIVE_CONNECTION_STATE_ACTIVATED) {
- error = g_error_new_literal (NM_CLIENT_ERROR, NM_CLIENT_ERROR_UNKNOWN,
+ error = g_error_new_literal (NM_CLIENT_ERROR, NM_CLIENT_ERROR_FAILED,
_("Activation failed"));
}
diff --git a/libnm/libnm.ver b/libnm/libnm.ver
index 9e50b15380..54d6057327 100644
--- a/libnm/libnm.ver
+++ b/libnm/libnm.ver
@@ -337,8 +337,6 @@ global:
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;
nm_object_get_type;
nm_remote_connection_commit_changes;
diff --git a/libnm/nm-client.c b/libnm/nm-client.c
index cf4e9b28de..dad101b00b 100644
--- a/libnm/nm-client.c
+++ b/libnm/nm-client.c
@@ -1634,17 +1634,8 @@ nm_client_new_finish (GAsyncResult *result, GError **error)
{
GSimpleAsyncResult *simple;
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
-
- if (!result) {
- g_set_error_literal (error,
- NM_CLIENT_ERROR,
- NM_CLIENT_ERROR_UNKNOWN,
- "NMClient initialization failed (or you passed NULL 'result' by mistake)");
- return NULL;
- }
-
g_return_val_if_fail (g_simple_async_result_is_valid (result, NULL, nm_client_new_async), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
diff --git a/libnm/nm-client.h b/libnm/nm-client.h
index 64bd0a0d32..2f22289c1f 100644
--- a/libnm/nm-client.h
+++ b/libnm/nm-client.h
@@ -131,21 +131,23 @@ typedef enum {
/**
* NMClientError:
- * @NM_CLIENT_ERROR_UNKNOWN: unknown or unclassified error
+ * @NM_CLIENT_ERROR_FAILED: unknown or unclassified error
* @NM_CLIENT_ERROR_MANAGER_NOT_RUNNING: an operation that requires NetworkManager
* failed because NetworkManager is not running
- * @NM_CLIENT_ERROR_CONNECTION_REMOVED: the #NMRemoteConnection object
- * was removed before it was completely initialized
- * @NM_CLIENT_ERROR_CONNECTION_UNAVAILABLE: the #NMRemoteConnection object
- * is not visible or otherwise unreadable
+ * @NM_CLIENT_ERROR_OBJECT_CREATION_FAILED: NetworkManager claimed that an
+ * operation succeeded, but the object that was allegedly created (eg,
+ * #NMRemoteConnection, #NMActiveConnection) was apparently destroyed before
+ * #NMClient could create a representation of it.
*
* Describes errors that may result from operations involving a #NMClient.
+ *
+ * D-Bus operations may also return errors from other domains, including
+ * #NMManagerError, #NMSettingsError, #NMAgentManagerError, and #NMConnectionError.
**/
typedef enum {
- NM_CLIENT_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
- NM_CLIENT_ERROR_MANAGER_NOT_RUNNING, /*< nick=ManagerNotRunning >*/
- NM_CLIENT_ERROR_CONNECTION_REMOVED, /*< nick=ConnectionRemoved >*/
- NM_CLIENT_ERROR_CONNECTION_UNAVAILABLE, /*< nick=ConnectionUnavailable >*/
+ NM_CLIENT_ERROR_FAILED = 0,
+ NM_CLIENT_ERROR_MANAGER_NOT_RUNNING,
+ NM_CLIENT_ERROR_OBJECT_CREATION_FAILED,
} NMClientError;
#define NM_CLIENT_ERROR nm_client_error_quark ()
diff --git a/libnm/nm-manager.c b/libnm/nm-manager.c
index 7e8d1bbf2b..3f6ef585c0 100644
--- a/libnm/nm-manager.c
+++ b/libnm/nm-manager.c
@@ -20,6 +20,7 @@
*/
#include <string.h>
+#include <glib/gi18n.h>
#include <nm-utils.h>
#include "nm-manager.h"
@@ -1034,25 +1035,29 @@ active_connection_removed (NMManager *self, NMActiveConnection *ac)
}
static void
-object_creation_failed_cb (GObject *object, GError *error, char *failed_path)
+object_creation_failed (NMObject *object, const char *failed_path)
{
NMManager *self = NM_MANAGER (object);
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
+ GError *error;
GSList *iter;
- g_return_if_fail (error != NULL);
g_return_if_fail (find_active_connection_by_path (self, failed_path) == NULL);
/* A newly activated connection failed due to some immediate error
* and disappeared from active connection list. Make sure the
* callback gets called.
*/
+ error = g_error_new_literal (NM_CLIENT_ERROR,
+ NM_CLIENT_ERROR_OBJECT_CREATION_FAILED,
+ _("Active connection removed before it was initialized"));
for (iter = priv->pending_activations; iter; iter = iter->next) {
ActivateInfo *info = iter->data;
if (g_strcmp0 (failed_path, info->active_path) == 0) {
activate_info_complete (info, NULL, error);
+ g_error_free (error);
return;
}
}
@@ -1258,9 +1263,6 @@ constructed (GObject *object)
g_signal_connect (object, "notify::" NM_MANAGER_WIRELESS_ENABLED,
G_CALLBACK (wireless_enabled_cb), NULL);
-
- g_signal_connect (object, "object-creation-failed",
- G_CALLBACK (object_creation_failed_cb), NULL);
}
static gboolean
@@ -1534,6 +1536,7 @@ nm_manager_class_init (NMManagerClass *manager_class)
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
+ nm_object_class->object_creation_failed = object_creation_failed;
manager_class->device_added = device_added;
manager_class->device_removed = device_removed;
diff --git a/libnm/nm-object.c b/libnm/nm-object.c
index 3bb62336b5..735881b227 100644
--- a/libnm/nm-object.c
+++ b/libnm/nm-object.c
@@ -31,6 +31,7 @@
#include "nm-object-private.h"
#include "nm-glib-compat.h"
#include "nm-dbus-helpers.h"
+#include "nm-client.h"
static gboolean debug = FALSE;
#define dbgmsg(f,...) if (G_UNLIKELY (debug)) { g_message (f, ## __VA_ARGS__ ); }
@@ -99,31 +100,6 @@ enum {
LAST_PROP
};
-enum {
- OBJECT_CREATION_FAILED,
-
- LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = { 0 };
-
-/**
- * nm_object_error_quark:
- *
- * Registers an error quark for #NMObject if necessary.
- *
- * Returns: the error quark used for #NMObject errors.
- **/
-GQuark
-nm_object_error_quark (void)
-{
- static GQuark quark;
-
- if (G_UNLIKELY (!quark))
- quark = g_quark_from_static_string ("nm-object-error-quark");
- return quark;
-}
-
static void
on_name_owner_changed (GObject *proxy,
GParamSpec *pspec,
@@ -171,7 +147,7 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
GSList *iter;
if (!priv->path) {
- g_set_error_literal (error, NM_OBJECT_ERROR, NM_OBJECT_ERROR_OBJECT_CREATION_FAILURE,
+ g_set_error_literal (error, NM_CLIENT_ERROR, NM_CLIENT_ERROR_OBJECT_CREATION_FAILED,
_("Caller did not specify D-Bus path for object"));
return FALSE;
}
@@ -313,8 +289,8 @@ init_async (GAsyncInitable *initable, int io_priority,
if (!priv->path) {
g_simple_async_report_error_in_idle (G_OBJECT (initable),
callback, user_data,
- NM_OBJECT_ERROR,
- NM_OBJECT_ERROR_OBJECT_CREATION_FAILURE,
+ NM_CLIENT_ERROR,
+ NM_CLIENT_ERROR_OBJECT_CREATION_FAILED,
"%s",
_("Caller did not specify D-Bus path for object"));
return;
@@ -468,28 +444,6 @@ nm_object_class_init (NMObjectClass *nm_object_class)
FALSE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
-
- /* signals */
-
- /**
- * NMObject::object-creation-failed:
- * @master_object: the object that received the signal
- * @error: the error that occured while creating object
- * @failed_path: object path of the failed object
- *
- * Indicates that an error occured while creating an #NMObject object
- * during property handling of @master_object.
- *
- * Note: Be aware that the signal is private for libnm's internal
- * use.
- **/
- signals[OBJECT_CREATION_FAILED] =
- g_signal_new ("object-creation-failed",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (NMObjectClass, object_creation_failed),
- NULL, NULL, NULL,
- G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER);
}
static void
@@ -1038,14 +992,10 @@ object_created (GObject *obj, const char *path, gpointer user_data)
/* We assume that on error, the creator_func printed something */
if (obj == NULL && g_strcmp0 (path, "/") != 0 ) {
- GError *error;
- error = g_error_new (NM_OBJECT_ERROR,
- NM_OBJECT_ERROR_OBJECT_CREATION_FAILURE,
- "Creating object for path '%s' failed in libnm.",
- path);
- /* Emit a signal about the error. */
- g_signal_emit (odata->self, signals[OBJECT_CREATION_FAILED], 0, error, path);
- g_error_free (error);
+ NMObjectClass *object_class = NM_OBJECT_GET_CLASS (odata->self);
+
+ if (object_class->object_creation_failed)
+ object_class->object_creation_failed (odata->self, path);
}
odata->objects[--odata->remaining] = obj;
diff --git a/libnm/nm-object.h b/libnm/nm-object.h
index 829c539229..b42f160d5c 100644
--- a/libnm/nm-object.h
+++ b/libnm/nm-object.h
@@ -37,22 +37,6 @@ G_BEGIN_DECLS
#define NM_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_OBJECT))
#define NM_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_OBJECT, NMObjectClass))
-/**
- * NMObjectError:
- * @NM_OBJECT_ERROR_UNKNOWN: unknown or unclassified error
- * @NM_OBJECT_ERROR_OBJECT_CREATION_FAILURE: an error ocured while creating an #NMObject
- *
- * Describes errors that may result from operations involving a #NMObject.
- *
- **/
-typedef enum {
- NM_OBJECT_ERROR_UNKNOWN = 0,
- NM_OBJECT_ERROR_OBJECT_CREATION_FAILURE,
-} NMObjectError;
-
-#define NM_OBJECT_ERROR nm_object_error_quark ()
-GQuark nm_object_error_quark (void);
-
#define NM_OBJECT_PATH "path"
#define NM_OBJECT_DBUS_CONNECTION "dbus-connection"
@@ -63,17 +47,15 @@ struct _NMObject {
typedef struct {
GObjectClass parent;
- /* Signals */
- /* The "object-creation-failed" signal is PRIVATE for libnm and
+ /* Methods */
+ void (*init_dbus) (NMObject *object);
+
+ /* The "object-creation-failed" method is PRIVATE for libnm and
* is not meant for any external usage. It indicates that an error
* occured during creation of an object.
*/
void (*object_creation_failed) (NMObject *master_object,
- GError *error,
- char *failed_path);
-
- /* Methods */
- void (*init_dbus) (NMObject *object);
+ const char *failed_path);
/*< private >*/
gpointer padding[8];
diff --git a/libnm/nm-remote-settings.c b/libnm/nm-remote-settings.c
index 1119e8a7d8..62a3853d69 100644
--- a/libnm/nm-remote-settings.c
+++ b/libnm/nm-remote-settings.c
@@ -20,6 +20,7 @@
*/
#include <string.h>
+#include <glib/gi18n.h>
#include <nm-dbus-interface.h>
#include <nm-connection.h>
@@ -244,7 +245,7 @@ connection_added (NMRemoteSettings *self,
}
static void
-object_creation_failed (NMObject *object, GError *error, char *failed_path)
+object_creation_failed (NMObject *object, const char *failed_path)
{
NMRemoteSettings *self = NM_REMOTE_SETTINGS (object);
AddConnectionInfo *addinfo;
@@ -253,8 +254,8 @@ object_creation_failed (NMObject *object, GError *error, char *failed_path)
addinfo = add_connection_info_find (self, failed_path);
if (addinfo) {
add_error = g_error_new_literal (NM_CLIENT_ERROR,
- NM_CLIENT_ERROR_CONNECTION_REMOVED,
- "Connection removed before it was initialized");
+ NM_CLIENT_ERROR_OBJECT_CREATION_FAILED,
+ _("Connection removed before it was initialized"));
add_connection_info_complete (self, addinfo, NULL, add_error);
g_error_free (add_error);
}
diff --git a/libnm/tests/test-nm-client.c b/libnm/tests/test-nm-client.c
index bad9e83997..2c5b91246c 100644
--- a/libnm/tests/test-nm-client.c
+++ b/libnm/tests/test-nm-client.c
@@ -1023,7 +1023,7 @@ activate_failed_cb (GObject *object,
ac = nm_client_activate_connection_finish (client, result, &error);
g_assert (ac == NULL);
- g_assert_error (error, NM_OBJECT_ERROR, NM_OBJECT_ERROR_OBJECT_CREATION_FAILURE);
+ g_assert_error (error, NM_CLIENT_ERROR, NM_CLIENT_ERROR_OBJECT_CREATION_FAILED);
g_clear_error (&error);
g_main_loop_quit (loop);
diff --git a/libnm/tests/test-remote-settings-client.c b/libnm/tests/test-remote-settings-client.c
index 7c3c1222ad..f521dbc1c0 100644
--- a/libnm/tests/test-remote-settings-client.c
+++ b/libnm/tests/test-remote-settings-client.c
@@ -368,7 +368,7 @@ add_remove_cb (GObject *s,
GError *error = NULL;
connection = nm_client_add_connection_finish (client, result, &error);
- g_assert_error (error, NM_CLIENT_ERROR, NM_CLIENT_ERROR_CONNECTION_REMOVED);
+ g_assert_error (error, NM_CLIENT_ERROR, NM_CLIENT_ERROR_OBJECT_CREATION_FAILED);
g_assert (connection == NULL);
*done = TRUE;
diff --git a/po/POTFILES.in b/po/POTFILES.in
index fe6b57e2bd..c97e05de54 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -114,8 +114,10 @@ libnm/nm-device-vlan.c
libnm/nm-device-wifi.c
libnm/nm-device-wimax.c
libnm/nm-device.c
+libnm/nm-manager.c
libnm/nm-object.c
libnm/nm-remote-connection.c
+libnm/nm-remote-settings.c
libnm/nm-vpn-plugin.c
policy/org.freedesktop.NetworkManager.policy.in.in
src/NetworkManagerUtils.c