mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-03-22 05:40:35 +01:00
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.
This commit is contained in:
parent
2ff4a7d4b0
commit
388a0c5e78
11 changed files with 42 additions and 113 deletions
|
|
@ -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"));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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 ()
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue