Commit 9f8aacf6 authored by Thomas Haller's avatar Thomas Haller

libnm: implement nm_client_networking_set_enabled() by using GDBusConnection directly

parent c85f6c7e
......@@ -330,14 +330,22 @@ nm_client_networking_get_enabled (NMClient *client)
gboolean
nm_client_networking_set_enabled (NMClient *client, gboolean enable, GError **error)
{
const char *name_owner;
g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
/* FIXME(libnm-async-api): add nm_client_networking_set_enabled_async(). */
if (!_nm_client_check_nm_running (client, error))
name_owner = _nm_client_get_dbus_name_owner (client);
if (!name_owner) {
_nm_object_set_error_nm_not_running (error);
return FALSE;
}
return nm_manager_networking_set_enabled (NM_CLIENT_GET_PRIVATE (client)->manager,
enable, error);
return _nm_manager_networking_set_enabled (_nm_client_get_dbus_connection (client),
name_owner,
enable,
error);
}
/**
......
......@@ -470,18 +470,31 @@ nm_manager_networking_get_enabled (NMManager *manager)
}
gboolean
nm_manager_networking_set_enabled (NMManager *manager, gboolean enable, GError **error)
_nm_manager_networking_set_enabled (GDBusConnection *dbus_connection,
const char *name_owner,
gboolean enable,
GError **error)
{
gboolean ret;
gs_unref_variant GVariant *ret = NULL;
g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE);
ret = g_dbus_connection_call_sync (dbus_connection,
name_owner,
NM_DBUS_PATH,
NM_DBUS_INTERFACE,
"Enable",
g_variant_new ("(b)", enable),
G_VARIANT_TYPE ("()"),
G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
NULL,
error);
if (!ret) {
if (error)
g_dbus_error_strip_remote_error (*error);
return FALSE;
}
ret = nmdbus_manager_call_enable_sync (NM_MANAGER_GET_PRIVATE (manager)->proxy,
enable,
NULL, error);
if (error && *error)
g_dbus_error_strip_remote_error (*error);
return ret;
return TRUE;
}
gboolean
......@@ -1640,12 +1653,18 @@ set_property (GObject *object, guint prop_id,
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (object);
gboolean b;
const char *name_owner;
switch (prop_id) {
case PROP_NETWORKING_ENABLED:
b = g_value_get_boolean (value);
if (priv->networking_enabled != b) {
nm_manager_networking_set_enabled (NM_MANAGER (object), b, NULL);
if ((name_owner = _nm_object_get_dbus_name_owner (object))) {
_nm_manager_networking_set_enabled (_nm_object_get_dbus_connection (object),
name_owner,
b,
NULL);
}
/* Let the property value flip when we get the change signal from NM */
}
break;
......
......@@ -84,8 +84,9 @@ gboolean nm_manager_get_startup (NMManager *manager);
gboolean nm_manager_networking_get_enabled (NMManager *manager);
_NM_DEPRECATED_SYNC_METHOD_INTERNAL
gboolean nm_manager_networking_set_enabled (NMManager *manager,
gboolean enabled,
gboolean _nm_manager_networking_set_enabled (GDBusConnection *dbus_connection,
const char *name_owner,
gboolean enable,
GError **error);
gboolean nm_manager_wireless_get_enabled (NMManager *manager);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment