mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-27 15:10:09 +01:00
settings: refactor virtual delete() function
Don't delegate so much to the virtual function delete().
This commit is contained in:
parent
ede1e08ac1
commit
36f5d440fd
5 changed files with 50 additions and 74 deletions
|
|
@ -597,13 +597,6 @@ nm_settings_connection_replace_settings (NMSettingsConnection *self,
|
|||
return success;
|
||||
}
|
||||
|
||||
static void
|
||||
ignore_cb (NMSettingsConnection *self,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
nm_settings_connection_replace_and_commit (NMSettingsConnection *self,
|
||||
NMConnection *new_connection,
|
||||
|
|
@ -678,27 +671,6 @@ out:
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
nm_settings_connection_delete (NMSettingsConnection *self,
|
||||
NMSettingsConnectionDeleteFunc callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_return_if_fail (NM_IS_SETTINGS_CONNECTION (self));
|
||||
|
||||
if (NM_SETTINGS_CONNECTION_GET_CLASS (self)->delete) {
|
||||
NM_SETTINGS_CONNECTION_GET_CLASS (self)->delete (self,
|
||||
callback ? callback : ignore_cb,
|
||||
user_data);
|
||||
} else {
|
||||
GError *error = g_error_new (NM_SETTINGS_ERROR,
|
||||
NM_SETTINGS_ERROR_FAILED,
|
||||
"%s: %s:%d delete() unimplemented", __func__, __FILE__, __LINE__);
|
||||
if (callback)
|
||||
callback (self, error, user_data);
|
||||
g_error_free (error);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
remove_entry_from_db (NMSettingsConnection *self, const char* db_name)
|
||||
{
|
||||
|
|
@ -735,15 +707,34 @@ remove_entry_from_db (NMSettingsConnection *self, const char* db_name)
|
|||
g_key_file_free (key_file);
|
||||
}
|
||||
|
||||
static void
|
||||
do_delete (NMSettingsConnection *self,
|
||||
NMSettingsConnectionDeleteFunc callback,
|
||||
gpointer user_data)
|
||||
void
|
||||
nm_settings_connection_delete (NMSettingsConnection *self,
|
||||
NMSettingsConnectionDeleteFunc callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
gs_unref_object NMSettingsConnection *self_keep_alive = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
NMSettingsConnectionClass *klass;
|
||||
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
|
||||
NMConnection *for_agents;
|
||||
|
||||
g_object_ref (self);
|
||||
g_return_if_fail (NM_IS_SETTINGS_CONNECTION (self));
|
||||
|
||||
klass = NM_SETTINGS_CONNECTION_GET_CLASS (self);
|
||||
|
||||
self_keep_alive = g_object_ref (self);
|
||||
|
||||
if (!klass->delete) {
|
||||
g_set_error (&error,
|
||||
NM_SETTINGS_ERROR,
|
||||
NM_SETTINGS_ERROR_FAILED,
|
||||
"delete not supported");
|
||||
goto out;
|
||||
}
|
||||
if (!klass->delete (self,
|
||||
&error))
|
||||
goto out;
|
||||
|
||||
set_visible (self, FALSE);
|
||||
|
||||
/* Tell agents to remove secrets for this connection */
|
||||
|
|
@ -762,11 +753,12 @@ do_delete (NMSettingsConnection *self,
|
|||
|
||||
nm_settings_connection_signal_remove (self, FALSE);
|
||||
|
||||
callback (self, NULL, user_data);
|
||||
|
||||
g_object_unref (self);
|
||||
out:
|
||||
if (callback)
|
||||
callback (self, error, user_data);
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
|
@ -2897,7 +2889,6 @@ nm_settings_connection_class_init (NMSettingsConnectionClass *class)
|
|||
object_class->get_property = get_property;
|
||||
object_class->set_property = set_property;
|
||||
|
||||
class->delete = do_delete;
|
||||
class->supports_secrets = supports_secrets;
|
||||
|
||||
obj_properties[PROP_VISIBLE] =
|
||||
|
|
|
|||
|
|
@ -119,9 +119,8 @@ struct _NMSettingsConnectionClass {
|
|||
NMSettingsConnectionCommitReason commit_reason,
|
||||
GError **error);
|
||||
|
||||
void (*delete) (NMSettingsConnection *self,
|
||||
NMSettingsConnectionDeleteFunc callback,
|
||||
gpointer user_data);
|
||||
gboolean (*delete) (NMSettingsConnection *self,
|
||||
GError **error);
|
||||
|
||||
gboolean (*supports_secrets) (NMSettingsConnection *self,
|
||||
const char *setting_name);
|
||||
|
|
|
|||
|
|
@ -353,10 +353,9 @@ commit_changes (NMSettingsConnection *connection,
|
|||
error);
|
||||
}
|
||||
|
||||
static void
|
||||
do_delete (NMSettingsConnection *connection,
|
||||
NMSettingsConnectionDeleteFunc callback,
|
||||
gpointer user_data)
|
||||
static gboolean
|
||||
delete (NMSettingsConnection *connection,
|
||||
GError **error)
|
||||
{
|
||||
NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE ((NMIfcfgConnection *) connection);
|
||||
const char *filename;
|
||||
|
|
@ -372,7 +371,7 @@ do_delete (NMSettingsConnection *connection,
|
|||
g_unlink (priv->route6file);
|
||||
}
|
||||
|
||||
NM_SETTINGS_CONNECTION_CLASS (nm_ifcfg_connection_parent_class)->delete (connection, callback, user_data);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
@ -511,7 +510,7 @@ nm_ifcfg_connection_class_init (NMIfcfgConnectionClass *ifcfg_connection_class)
|
|||
object_class->get_property = get_property;
|
||||
object_class->dispose = dispose;
|
||||
|
||||
settings_class->delete = do_delete;
|
||||
settings_class->delete = delete;
|
||||
settings_class->can_commit = can_commit;
|
||||
settings_class->commit_changes = commit_changes;
|
||||
|
||||
|
|
|
|||
|
|
@ -115,35 +115,26 @@ commit_changes (NMSettingsConnection *connection,
|
|||
return success;
|
||||
}
|
||||
|
||||
static void
|
||||
do_delete (NMSettingsConnection *connection,
|
||||
NMSettingsConnectionDeleteFunc callback,
|
||||
gpointer user_data)
|
||||
static gboolean
|
||||
delete (NMSettingsConnection *connection,
|
||||
GError **error)
|
||||
{
|
||||
GError *error = NULL;
|
||||
NMIfnetConnectionPrivate *priv = NM_IFNET_CONNECTION_GET_PRIVATE ((NMIfnetConnection *) connection);
|
||||
|
||||
g_signal_emit (connection, signals[IFNET_CANCEL_MONITORS], 0);
|
||||
|
||||
/* Only connections which exist in /etc/conf.d/net will have a conn_name */
|
||||
if (priv->conn_name) {
|
||||
g_signal_emit (connection, signals[IFNET_CANCEL_MONITORS], 0);
|
||||
|
||||
if (!ifnet_delete_connection_in_parsers (priv->conn_name, CONF_NET_FILE, WPA_SUPPLICANT_CONF, NULL)) {
|
||||
nm_log_warn (LOGD_SETTINGS, "Failed to delete %s", priv->conn_name);
|
||||
reload_parsers ();
|
||||
callback (connection, error, user_data);
|
||||
g_error_free (error);
|
||||
g_signal_emit (connection, signals[IFNET_SETUP_MONITORS], 0);
|
||||
return;
|
||||
/* let's not return an error. */
|
||||
}
|
||||
|
||||
g_signal_emit (connection, signals[IFNET_SETUP_MONITORS], 0);
|
||||
}
|
||||
|
||||
NM_SETTINGS_CONNECTION_CLASS (nm_ifnet_connection_parent_class)->delete (connection, callback, user_data);
|
||||
|
||||
g_signal_emit (connection, signals[IFNET_SETUP_MONITORS], 0);
|
||||
|
||||
nm_log_info (LOGD_SETTINGS, "Successfully deleted %s",
|
||||
priv->conn_name ? priv->conn_name :
|
||||
nm_connection_get_id (NM_CONNECTION (connection)));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
@ -209,7 +200,7 @@ nm_ifnet_connection_class_init (NMIfnetConnectionClass * ifnet_connection_class)
|
|||
|
||||
object_class->finalize = finalize;
|
||||
|
||||
settings_class->delete = do_delete;
|
||||
settings_class->delete = delete;
|
||||
settings_class->commit_changes = commit_changes;
|
||||
|
||||
signals[IFNET_SETUP_MONITORS] =
|
||||
|
|
|
|||
|
|
@ -103,20 +103,16 @@ commit_changes (NMSettingsConnection *connection,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
do_delete (NMSettingsConnection *connection,
|
||||
NMSettingsConnectionDeleteFunc callback,
|
||||
gpointer user_data)
|
||||
static gboolean
|
||||
delete (NMSettingsConnection *connection,
|
||||
GError **error)
|
||||
{
|
||||
const char *path;
|
||||
|
||||
path = nm_settings_connection_get_filename (connection);
|
||||
if (path)
|
||||
g_unlink (path);
|
||||
|
||||
NM_SETTINGS_CONNECTION_CLASS (nms_keyfile_connection_parent_class)->delete (connection,
|
||||
callback,
|
||||
user_data);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
@ -182,5 +178,5 @@ nms_keyfile_connection_class_init (NMSKeyfileConnectionClass *keyfile_connection
|
|||
NMSettingsConnectionClass *settings_class = NM_SETTINGS_CONNECTION_CLASS (keyfile_connection_class);
|
||||
|
||||
settings_class->commit_changes = commit_changes;
|
||||
settings_class->delete = do_delete;
|
||||
settings_class->delete = delete;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue