libnm: make sync/async APIs more GLib-like (bgo #736988)

This commit is contained in:
Dan Winship 2014-09-25 09:29:21 -04:00
commit c772530ec5
21 changed files with 1738 additions and 882 deletions

View file

@ -1678,11 +1678,13 @@ active_connection_state_cb (NMActiveConnection *active, GParamSpec *pspec, gpoin
nmc_terminal_erase_line (); nmc_terminal_erase_line ();
printf (_("Connection successfully activated (D-Bus active path: %s)\n"), printf (_("Connection successfully activated (D-Bus active path: %s)\n"),
nm_object_get_path (NM_OBJECT (active))); nm_object_get_path (NM_OBJECT (active)));
g_object_unref (active);
quit (); quit ();
} else if ( state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED } else if ( state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED
|| state == NM_ACTIVE_CONNECTION_STATE_UNKNOWN) { || state == NM_ACTIVE_CONNECTION_STATE_UNKNOWN) {
g_string_printf (nmc->return_text, _("Error: Connection activation failed.")); g_string_printf (nmc->return_text, _("Error: Connection activation failed."));
nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION;
g_object_unref (active);
quit (); quit ();
} else if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATING) { } else if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATING) {
/* activating master connection does not automatically activate any slaves, so their /* activating master connection does not automatically activate any slaves, so their
@ -1726,6 +1728,7 @@ vpn_connection_state_cb (NMVpnConnection *vpn,
nmc_terminal_erase_line (); nmc_terminal_erase_line ();
printf (_("VPN connection successfully activated (D-Bus active path: %s)\n"), printf (_("VPN connection successfully activated (D-Bus active path: %s)\n"),
nm_object_get_path (NM_OBJECT (vpn))); nm_object_get_path (NM_OBJECT (vpn)));
g_object_unref (vpn);
quit (); quit ();
break; break;
@ -1734,6 +1737,7 @@ vpn_connection_state_cb (NMVpnConnection *vpn,
g_string_printf (nmc->return_text, _("Error: Connection activation failed: %s."), g_string_printf (nmc->return_text, _("Error: Connection activation failed: %s."),
vpn_connection_state_reason_to_string (reason)); vpn_connection_state_reason_to_string (reason));
nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION;
g_object_unref (vpn);
quit (); quit ();
break; break;
@ -1796,16 +1800,21 @@ typedef struct {
} ActivateConnectionInfo; } ActivateConnectionInfo;
static void static void
activate_connection_cb (NMClient *client, NMActiveConnection *active, GError *error, gpointer user_data) activate_connection_cb (GObject *client, GAsyncResult *result, gpointer user_data)
{ {
ActivateConnectionInfo *info = (ActivateConnectionInfo *) user_data; ActivateConnectionInfo *info = (ActivateConnectionInfo *) user_data;
NmCli *nmc = info->nmc; NmCli *nmc = info->nmc;
NMDevice *device = info->device; NMDevice *device = info->device;
NMActiveConnection *active;
NMActiveConnectionState state; NMActiveConnectionState state;
const GPtrArray *ac_devs; const GPtrArray *ac_devs;
GError *error = NULL;
active = nm_client_activate_connection_finish (NM_CLIENT (client), result, &error);
if (error) { if (error) {
g_string_printf (nmc->return_text, _("Error: Connection activation failed: %s"), error->message); g_string_printf (nmc->return_text, _("Error: Connection activation failed: %s"), error->message);
g_error_free (error);
nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION;
quit (); quit ();
} else { } else {
@ -1824,6 +1833,7 @@ activate_connection_cb (NMClient *client, NMActiveConnection *active, GError *er
printf (_("Connection successfully activated (D-Bus active path: %s)\n"), printf (_("Connection successfully activated (D-Bus active path: %s)\n"),
nm_object_get_path (NM_OBJECT (active))); nm_object_get_path (NM_OBJECT (active)));
} }
g_object_unref (active);
quit (); quit ();
} else { } else {
if (NM_IS_VPN_CONNECTION (active)) { if (NM_IS_VPN_CONNECTION (active)) {
@ -1860,7 +1870,7 @@ nmc_activate_connection (NmCli *nmc,
const char *ifname, const char *ifname,
const char *ap, const char *ap,
const char *nsp, const char *nsp,
NMClientActivateFn callback, GAsyncReadyCallback callback,
GError **error) GError **error)
{ {
ActivateConnectionInfo *info; ActivateConnectionInfo *info;
@ -1899,12 +1909,13 @@ nmc_activate_connection (NmCli *nmc,
info->nmc = nmc; info->nmc = nmc;
info->device = device; info->device = device;
nm_client_activate_connection (nmc->client, nm_client_activate_connection_async (nmc->client,
connection, connection,
device, device,
spec_object, spec_object,
callback, NULL,
info); callback,
info);
return TRUE; return TRUE;
} }
@ -2061,7 +2072,7 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
active = find_active_connection (active_cons, nmc->system_connections, selector, *arg_ptr, &idx); active = find_active_connection (active_cons, nmc->system_connections, selector, *arg_ptr, &idx);
if (active) { if (active) {
nm_client_deactivate_connection (nmc->client, active); nm_client_deactivate_connection (nmc->client, active, NULL, NULL);
} else { } else {
g_string_printf (nmc->return_text, _("Error: '%s' is not an active connection."), *arg_ptr); g_string_printf (nmc->return_text, _("Error: '%s' is not an active connection."), *arg_ptr);
nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND; nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND;
@ -4865,23 +4876,28 @@ typedef struct {
} AddConnectionInfo; } AddConnectionInfo;
static void static void
add_connection_cb (NMRemoteSettings *settings, add_connection_cb (GObject *settings,
NMRemoteConnection *connection, GAsyncResult *result,
GError *error,
gpointer user_data) gpointer user_data)
{ {
AddConnectionInfo *info = (AddConnectionInfo *) user_data; AddConnectionInfo *info = (AddConnectionInfo *) user_data;
NmCli *nmc = info->nmc; NmCli *nmc = info->nmc;
NMRemoteConnection *connection;
GError *error = NULL;
connection = nm_remote_settings_add_connection_finish (NM_REMOTE_SETTINGS (settings),
result, &error);
if (error) { if (error) {
g_string_printf (nmc->return_text, g_string_printf (nmc->return_text,
_("Error: Failed to add '%s' connection: (%d) %s"), _("Error: Failed to add '%s' connection: %s"),
info->con_name, error->code, error->message); info->con_name, error->message);
g_error_free (error);
nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION;
} else { } else {
printf (_("Connection '%s' (%s) successfully added.\n"), printf (_("Connection '%s' (%s) successfully added.\n"),
nm_connection_get_id (NM_CONNECTION (connection)), nm_connection_get_id (NM_CONNECTION (connection)),
nm_connection_get_uuid (NM_CONNECTION (connection))); nm_connection_get_uuid (NM_CONNECTION (connection)));
g_object_unref (connection);
} }
g_free (info->con_name); g_free (info->con_name);
@ -4889,29 +4905,25 @@ add_connection_cb (NMRemoteSettings *settings,
quit (); quit ();
} }
static gboolean static void
add_new_connection (gboolean persistent, add_new_connection (gboolean persistent,
NMRemoteSettings *settings, NMRemoteSettings *settings,
NMConnection *connection, NMConnection *connection,
NMRemoteSettingsAddConnectionFunc callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
if (persistent) nm_remote_settings_add_connection_async (settings, connection, persistent,
return nm_remote_settings_add_connection (settings, connection, callback, user_data); NULL, callback, user_data);
else
return nm_remote_settings_add_connection_unsaved (settings, connection, callback, user_data);
} }
static void static void
update_connection (gboolean persistent, update_connection (gboolean persistent,
NMRemoteConnection *connection, NMRemoteConnection *connection,
NMRemoteConnectionResultFunc callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
if (persistent) nm_remote_connection_commit_changes_async (connection, persistent,
nm_remote_connection_commit_changes (connection, callback, user_data); NULL, callback, user_data);
else
nm_remote_connection_commit_changes_unsaved (connection, callback, user_data);
} }
static char * static char *
@ -6304,20 +6316,32 @@ set_info_and_signal_editor_thread (GError *error, MonitorACInfo *monitor_ac_info
} }
static void static void
add_connection_editor_cb (NMRemoteSettings *settings, add_connection_editor_cb (GObject *settings,
NMRemoteConnection *connection, GAsyncResult *result,
GError *error,
gpointer user_data) gpointer user_data)
{ {
NMRemoteConnection *connection;
GError *error = NULL;
connection = nm_remote_settings_add_connection_finish (NM_REMOTE_SETTINGS (settings),
result, &error);
set_info_and_signal_editor_thread (error, NULL); set_info_and_signal_editor_thread (error, NULL);
g_clear_object (&connection);
g_clear_error (&error);
} }
static void static void
update_connection_editor_cb (NMRemoteConnection *connection, update_connection_editor_cb (GObject *connection,
GError *error, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
GError *error = NULL;
nm_remote_connection_commit_changes_finish (NM_REMOTE_CONNECTION (connection),
result, &error);
set_info_and_signal_editor_thread (error, NULL); set_info_and_signal_editor_thread (error, NULL);
g_clear_error (&error);
} }
static gboolean static gboolean
@ -6361,15 +6385,18 @@ finish:
} }
static void static void
activate_connection_editor_cb (NMClient *client, activate_connection_editor_cb (GObject *client,
NMActiveConnection *active, GAsyncResult *result,
GError *error,
gpointer user_data) gpointer user_data)
{ {
ActivateConnectionInfo *info = (ActivateConnectionInfo *) user_data; ActivateConnectionInfo *info = (ActivateConnectionInfo *) user_data;
NMDevice *device = info->device; NMDevice *device = info->device;
const GPtrArray *ac_devs; const GPtrArray *ac_devs;
MonitorACInfo *monitor_ac_info = NULL; MonitorACInfo *monitor_ac_info = NULL;
NMActiveConnection *active;
GError *error = NULL;
active = nm_client_activate_connection_finish (NM_CLIENT (client), result, &error);
if (!error) { if (!error) {
if (!device) { if (!device) {
@ -6379,11 +6406,13 @@ activate_connection_editor_cb (NMClient *client,
if (device) { if (device) {
monitor_ac_info = g_malloc0 (sizeof (AddConnectionInfo)); monitor_ac_info = g_malloc0 (sizeof (AddConnectionInfo));
monitor_ac_info->device = g_object_ref (device); monitor_ac_info->device = g_object_ref (device);
monitor_ac_info->ac = active ? g_object_ref (active) : NULL; monitor_ac_info->ac = active;
monitor_ac_info->monitor_id = g_timeout_add (120, progress_activation_editor_cb, monitor_ac_info); monitor_ac_info->monitor_id = g_timeout_add (120, progress_activation_editor_cb, monitor_ac_info);
} } else
g_object_unref (active);
} }
set_info_and_signal_editor_thread (error, monitor_ac_info); set_info_and_signal_editor_thread (error, monitor_ac_info);
g_clear_error (&error);
} }
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@ -7894,17 +7923,20 @@ error:
static void static void
modify_connection_cb (NMRemoteConnection *connection, modify_connection_cb (GObject *connection,
GError *error, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
NmCli *nmc = (NmCli *) user_data; NmCli *nmc = (NmCli *) user_data;
GError *error = NULL;
if (error) { if (!nm_remote_connection_commit_changes_finish (NM_REMOTE_CONNECTION (connection),
result, &error)) {
g_string_printf (nmc->return_text, g_string_printf (nmc->return_text,
_("Error: Failed to modify connection '%s': (%d) %s"), _("Error: Failed to modify connection '%s': %s"),
nm_connection_get_id (NM_CONNECTION (connection)), nm_connection_get_id (NM_CONNECTION (connection)),
error->code, error->message); error->message);
g_error_free (error);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
} else { } else {
if (nmc->print_output == NMC_PRINT_PRETTY) if (nmc->print_output == NMC_PRINT_PRETTY)
@ -8106,12 +8138,14 @@ typedef struct {
} DeleteStateInfo; } DeleteStateInfo;
static void static void
delete_cb (NMRemoteConnection *con, GError *err, gpointer user_data) delete_cb (GObject *con, GAsyncResult *result, gpointer user_data)
{ {
DeleteStateInfo *info = (DeleteStateInfo *) user_data; DeleteStateInfo *info = (DeleteStateInfo *) user_data;
GError *error = NULL;
if (err) { if (!nm_remote_connection_delete_finish (NM_REMOTE_CONNECTION (con), result, &error)) {
g_string_printf (info->nmc->return_text, _("Error: Connection deletion failed: %s"), err->message); g_string_printf (info->nmc->return_text, _("Error: Connection deletion failed: %s"), error->message);
g_error_free (error);
info->nmc->return_value = NMC_RESULT_ERROR_CON_DEL; info->nmc->return_value = NMC_RESULT_ERROR_CON_DEL;
} }
@ -8195,7 +8229,8 @@ do_connection_delete (NmCli *nmc, int argc, char **argv)
del_info->counter++; del_info->counter++;
/* Delete the connection */ /* Delete the connection */
nm_remote_connection_delete (NM_REMOTE_CONNECTION (connection), delete_cb, del_info); nm_remote_connection_delete_async (NM_REMOTE_CONNECTION (connection),
NULL, delete_cb, del_info);
/* Take next argument (if there's no other connection of the same name) */ /* Take next argument (if there's no other connection of the same name) */
if (!pos) if (!pos)
@ -8231,7 +8266,7 @@ do_connection_reload (NmCli *nmc, int argc, char **argv)
return nmc->return_value; return nmc->return_value;
} }
if (!nm_remote_settings_reload_connections (nmc->system_settings, &error)) { if (!nm_remote_settings_reload_connections (nmc->system_settings, NULL, &error)) {
g_string_printf (nmc->return_text, _("Error: %s."), error->message); g_string_printf (nmc->return_text, _("Error: %s."), error->message);
if (error->code == NM_REMOTE_SETTINGS_ERROR_SERVICE_UNAVAILABLE) if (error->code == NM_REMOTE_SETTINGS_ERROR_SERVICE_UNAVAILABLE)
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING; nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
@ -8270,7 +8305,7 @@ do_connection_load (NmCli *nmc, int argc, char **argv)
filenames[i] = argv[i]; filenames[i] = argv[i];
filenames[i] = NULL; filenames[i] = NULL;
nm_remote_settings_load_connections (nmc->system_settings, filenames, &failures, &error); nm_remote_settings_load_connections (nmc->system_settings, filenames, &failures, NULL, &error);
g_free (filenames); g_free (filenames);
if (error) { if (error) {
g_string_printf (nmc->return_text, _("Error: %s."), error->message); g_string_printf (nmc->return_text, _("Error: %s."), error->message);

View file

@ -1287,6 +1287,7 @@ connected_state_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data)
printf (_("Device '%s' successfully activated with '%s'.\n"), printf (_("Device '%s' successfully activated with '%s'.\n"),
nm_device_get_iface (device), nm_device_get_iface (device),
nm_active_connection_get_uuid (active)); nm_active_connection_get_uuid (active));
g_object_unref (active);
quit (); quit ();
} }
} }
@ -1323,20 +1324,23 @@ typedef struct {
} AddAndActivateInfo; } AddAndActivateInfo;
static void static void
add_and_activate_cb (NMClient *client, add_and_activate_cb (GObject *client,
NMActiveConnection *active, GAsyncResult *result,
const char *connection_path,
GError *error,
gpointer user_data) gpointer user_data)
{ {
AddAndActivateInfo *info = (AddAndActivateInfo *) user_data; AddAndActivateInfo *info = (AddAndActivateInfo *) user_data;
NmCli *nmc = info->nmc; NmCli *nmc = info->nmc;
NMDevice *device = info->device; NMDevice *device = info->device;
NMActiveConnectionState state; NMActiveConnectionState state;
NMActiveConnection *active;
GError *error = NULL;
if (error) { active = nm_client_add_and_activate_connection_finish (NM_CLIENT (client), result, &error);
g_string_printf (nmc->return_text, _("Error: Failed to add/activate new connection: (%d) %s"),
error->code, error->message); if (error) {
g_string_printf (nmc->return_text, _("Error: Failed to add/activate new connection: %s"),
error->message);
g_error_free (error);
nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION;
quit (); quit ();
} else { } else {
@ -1356,6 +1360,7 @@ add_and_activate_cb (NMClient *client,
printf (_("Connection with UUID '%s' created and activated on device '%s'\n"), printf (_("Connection with UUID '%s' created and activated on device '%s'\n"),
nm_active_connection_get_uuid (active), nm_device_get_iface (device)); nm_active_connection_get_uuid (active), nm_device_get_iface (device));
} }
g_object_unref (active);
quit (); quit ();
} else { } else {
g_signal_connect (device, "notify::state", G_CALLBACK (monitor_device_state_cb), nmc); g_signal_connect (device, "notify::state", G_CALLBACK (monitor_device_state_cb), nmc);
@ -1363,6 +1368,7 @@ add_and_activate_cb (NMClient *client,
if (nmc->print_output == NMC_PRINT_PRETTY) if (nmc->print_output == NMC_PRINT_PRETTY)
progress_id = g_timeout_add (120, progress_cb, device); progress_id = g_timeout_add (120, progress_cb, device);
g_object_unref (active);
} }
} }
@ -1384,23 +1390,28 @@ create_connect_connection_for_device (AddAndActivateInfo *info)
NM_SETTING_CONNECTION_INTERFACE_NAME, nm_device_get_iface (info->device), NM_SETTING_CONNECTION_INTERFACE_NAME, nm_device_get_iface (info->device),
NULL); NULL);
nm_client_add_and_activate_connection (info->nmc->client, nm_client_add_and_activate_connection_async (info->nmc->client,
connection, connection,
info->device, info->device,
NULL, NULL,
add_and_activate_cb, NULL,
info); add_and_activate_cb,
info);
} }
static void static void
connect_device_cb (NMClient *client, NMActiveConnection *active, GError *error, gpointer user_data) connect_device_cb (GObject *client, GAsyncResult *result, gpointer user_data)
{ {
AddAndActivateInfo *info = (AddAndActivateInfo *) user_data; AddAndActivateInfo *info = (AddAndActivateInfo *) user_data;
NmCli *nmc = info->nmc; NmCli *nmc = info->nmc;
NMActiveConnection *active;
GError *error = NULL;
const GPtrArray *devices; const GPtrArray *devices;
NMDevice *device; NMDevice *device;
NMDeviceState state; NMDeviceState state;
active = nm_client_activate_connection_finish (NM_CLIENT (client), result, &error);
if (error) { if (error) {
char *dbus_err; char *dbus_err;
@ -1414,7 +1425,8 @@ connect_device_cb (NMClient *client, NMActiveConnection *active, GError *error,
g_free (dbus_err); g_free (dbus_err);
g_string_printf (nmc->return_text, _("Error: Device activation failed: %s"), g_string_printf (nmc->return_text, _("Error: Device activation failed: %s"),
error->message ? error->message : _("(unknown)")); error->message);
g_error_free (error);
nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION;
quit (); quit ();
} else { } else {
@ -1513,12 +1525,13 @@ do_device_connect (NmCli *nmc, int argc, char **argv)
info->nmc = nmc; info->nmc = nmc;
info->device = device; info->device = device;
nm_client_activate_connection (nmc->client, nm_client_activate_connection_async (nmc->client,
NULL, /* let NM find a connection automatically */ NULL, /* let NM find a connection automatically */
device, device,
NULL, NULL,
connect_device_cb, NULL,
info); connect_device_cb,
info);
/* Start progress indication */ /* Start progress indication */
if (nmc->print_output == NMC_PRINT_PRETTY) if (nmc->print_output == NMC_PRINT_PRETTY)
@ -1545,16 +1558,19 @@ disconnect_state_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data)
} }
static void static void
disconnect_device_cb (NMDevice *device, GError *error, gpointer user_data) disconnect_device_cb (GObject *object, GAsyncResult *result, gpointer user_data)
{ {
NMDevice *device = NM_DEVICE (object);
NmCli *nmc = (NmCli *) user_data; NmCli *nmc = (NmCli *) user_data;
NMDeviceState state; NMDeviceState state;
GError *error = NULL;
if (error) { if (!nm_device_disconnect_finish (device, result, &error)) {
g_string_printf (nmc->return_text, _("Error: Device '%s' (%s) disconnecting failed: %s"), g_string_printf (nmc->return_text, _("Error: Device '%s' (%s) disconnecting failed: %s"),
nm_device_get_iface (device), nm_device_get_iface (device),
nm_object_get_path (NM_OBJECT (device)), nm_object_get_path (NM_OBJECT (device)),
error->message ? error->message : _("(unknown)")); error->message);
g_error_free (error);
nmc->return_value = NMC_RESULT_ERROR_DEV_DISCONNECT; nmc->return_value = NMC_RESULT_ERROR_DEV_DISCONNECT;
quit (); quit ();
} else { } else {
@ -1637,7 +1653,7 @@ do_device_disconnect (NmCli *nmc, int argc, char **argv)
*/ */
nmc->nowait_flag = (nmc->timeout == 0); nmc->nowait_flag = (nmc->timeout == 0);
nmc->should_wait = TRUE; nmc->should_wait = TRUE;
nm_device_disconnect (device, disconnect_device_cb, nmc); nm_device_disconnect_async (device, NULL, disconnect_device_cb, nmc);
/* Start progress indication */ /* Start progress indication */
if (nmc->print_output == NMC_PRINT_PRETTY) if (nmc->print_output == NMC_PRINT_PRETTY)
@ -1648,15 +1664,18 @@ error:
} }
static void static void
delete_device_cb (NMDevice *device, GError *error, gpointer user_data) delete_device_cb (GObject *object, GAsyncResult *result, gpointer user_data)
{ {
NMDevice *device = NM_DEVICE (object);
NmCli *nmc = (NmCli *) user_data; NmCli *nmc = (NmCli *) user_data;
GError *error = NULL;
if (error) { if (!nm_device_delete_finish (device, result, &error)) {
g_string_printf (nmc->return_text, _("Error: Device '%s' (%s) deletion failed: %s"), g_string_printf (nmc->return_text, _("Error: Device '%s' (%s) deletion failed: %s"),
nm_device_get_iface (device), nm_device_get_iface (device),
nm_object_get_path (NM_OBJECT (device)), nm_object_get_path (NM_OBJECT (device)),
error->message ? error->message : _("(unknown)")); error->message);
g_error_free (error);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
} }
quit (); quit ();
@ -1727,7 +1746,7 @@ do_device_delete (NmCli *nmc, int argc, char **argv)
*/ */
nmc->nowait_flag = (nmc->timeout == 0); nmc->nowait_flag = (nmc->timeout == 0);
nmc->should_wait = TRUE; nmc->should_wait = TRUE;
nm_device_delete (device, delete_device_cb, nmc); nm_device_delete_async (device, NULL, delete_device_cb, nmc);
/* Start progress indication */ /* Start progress indication */
if (nmc->print_output == NMC_PRINT_PRETTY) if (nmc->print_output == NMC_PRINT_PRETTY)
@ -2308,12 +2327,13 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv)
info->nmc = nmc; info->nmc = nmc;
info->device = device; info->device = device;
nm_client_add_and_activate_connection (nmc->client, nm_client_add_and_activate_connection_async (nmc->client,
connection, connection,
device, device,
nm_object_get_path (NM_OBJECT (ap)), nm_object_get_path (NM_OBJECT (ap)),
add_and_activate_cb, NULL,
info); add_and_activate_cb,
info);
error: error:
if (bssid1_arr) if (bssid1_arr)
@ -2327,14 +2347,16 @@ error:
} }
static void static void
request_rescan_cb (NMDeviceWifi *device, GError *error, gpointer user_data) request_rescan_cb (GObject *object, GAsyncResult *result, gpointer user_data)
{ {
NmCli *nmc = (NmCli *) user_data; NmCli *nmc = (NmCli *) user_data;
GError *error = NULL;
nm_device_wifi_request_scan_finish (NM_DEVICE_WIFI (object), result, &error);
if (error) { if (error) {
g_string_printf (nmc->return_text, _("Error: %s."), g_string_printf (nmc->return_text, _("Error: %s."), error->message);
error->message ? error->message : _("unknown"));
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
g_error_free (error);
} }
quit (); quit ();
} }
@ -2375,7 +2397,8 @@ do_device_wifi_rescan (NmCli *nmc, int argc, char **argv)
goto error; goto error;
} }
nm_device_wifi_request_scan_simple (NM_DEVICE_WIFI (device), request_rescan_cb, nmc); nm_device_wifi_request_scan_async (NM_DEVICE_WIFI (device), NULL,
request_rescan_cb, nmc);
return nmc->return_value; return nmc->return_value;
error: error:

View file

@ -550,14 +550,17 @@ show_general_logging (NmCli *nmc)
} }
static void static void
save_hostname_cb (NMRemoteSettings *settings, GError *error, gpointer user_data) save_hostname_cb (GObject *object, GAsyncResult *result, gpointer user_data)
{ {
NmCli *nmc = (NmCli *) user_data; NmCli *nmc = (NmCli *) user_data;
GError *error = NULL;
nm_remote_settings_save_hostname_finish (NM_REMOTE_SETTINGS (object), result, &error);
if (error) { if (error) {
g_string_printf (nmc->return_text, _("Error: failed to set hostname: (%d) %s"), g_string_printf (nmc->return_text, _("Error: failed to set hostname: (%d) %s"),
error->code, error->message); error->code, error->message);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
g_error_free (error);
} }
quit (); quit ();
} }
@ -627,7 +630,7 @@ do_general (NmCli *nmc, int argc, char **argv)
printf ("Warning: ignoring extra garbage after '%s' hostname\n", hostname); printf ("Warning: ignoring extra garbage after '%s' hostname\n", hostname);
nmc->should_wait = TRUE; nmc->should_wait = TRUE;
nm_remote_settings_save_hostname (rem_settings, hostname, save_hostname_cb, nmc); nm_remote_settings_save_hostname_async (rem_settings, hostname, NULL, save_hostname_cb, nmc);
} }
} }
else if (matches (*argv, "permissions") == 0) { else if (matches (*argv, "permissions") == 0) {

View file

@ -103,20 +103,30 @@ nmt_editor_init (NmtEditor *entry)
} }
static void static void
connection_updated (NMRemoteConnection *connection, connection_updated (GObject *connection,
GError *error, GAsyncResult *result,
gpointer op) gpointer op)
{ {
GError *error = NULL;
nm_remote_connection_commit_changes_finish (NM_REMOTE_CONNECTION (connection), result, &error);
nmt_sync_op_complete_boolean (op, error == NULL, error); nmt_sync_op_complete_boolean (op, error == NULL, error);
g_clear_error (&error);
} }
static void static void
connection_added (NMRemoteSettings *settings, connection_added (GObject *settings,
NMRemoteConnection *connection, GAsyncResult *result,
GError *error, gpointer op)
gpointer op)
{ {
NMRemoteConnection *connection;
GError *error = NULL;
connection = nm_remote_settings_add_connection_finish (NM_REMOTE_SETTINGS (settings),
result, &error);
nmt_sync_op_complete_boolean (op, error == NULL, error); nmt_sync_op_complete_boolean (op, error == NULL, error);
g_clear_object (&connection);
g_clear_error (&error);
} }
static void static void
@ -133,8 +143,8 @@ save_connection_and_exit (NmtNewtButton *button,
nmt_sync_op_init (&op); nmt_sync_op_init (&op);
if (NM_IS_REMOTE_CONNECTION (priv->orig_connection)) { if (NM_IS_REMOTE_CONNECTION (priv->orig_connection)) {
nm_remote_connection_commit_changes (NM_REMOTE_CONNECTION (priv->orig_connection), nm_remote_connection_commit_changes_async (NM_REMOTE_CONNECTION (priv->orig_connection),
connection_updated, &op); TRUE, NULL, connection_updated, &op);
if (!nmt_sync_op_wait_boolean (&op, &error)) { if (!nmt_sync_op_wait_boolean (&op, &error)) {
nmt_newt_message_dialog (_("Unable to save connection: %s"), nmt_newt_message_dialog (_("Unable to save connection: %s"),
error->message); error->message);
@ -147,8 +157,8 @@ save_connection_and_exit (NmtNewtButton *button,
*/ */
nm_connection_clear_secrets (priv->orig_connection); nm_connection_clear_secrets (priv->orig_connection);
} else { } else {
nm_remote_settings_add_connection (nm_settings, priv->orig_connection, nm_remote_settings_add_connection_async (nm_settings, priv->orig_connection, TRUE,
connection_added, &op); NULL, connection_added, &op);
if (!nmt_sync_op_wait_boolean (&op, &error)) { if (!nmt_sync_op_wait_boolean (&op, &error)) {
nmt_newt_message_dialog (_("Unable to add new connection: %s"), nmt_newt_message_dialog (_("Unable to add new connection: %s"),
error->message); error->message);
@ -161,14 +171,19 @@ save_connection_and_exit (NmtNewtButton *button,
} }
static void static void
got_secrets (NMRemoteConnection *connection, got_secrets (GObject *object,
GVariant *secrets, GAsyncResult *result,
GError *error, gpointer op)
gpointer op)
{ {
GVariant *secrets;
GError *error = NULL;
secrets = nm_remote_connection_get_secrets_finish (NM_REMOTE_CONNECTION (object),
result, &error);
if (secrets) if (secrets)
g_variant_ref (secrets); g_variant_ref (secrets);
nmt_sync_op_complete_pointer (op, secrets, error); nmt_sync_op_complete_pointer (op, secrets, error);
g_clear_error (&error);
} }
static NMConnection * static NMConnection *
@ -189,8 +204,8 @@ build_edit_connection (NMConnection *orig_connection)
g_variant_iter_init (&iter, settings); g_variant_iter_init (&iter, settings);
while (g_variant_iter_next (&iter, "{&s@a{sv}}", &setting_name, NULL)) { while (g_variant_iter_next (&iter, "{&s@a{sv}}", &setting_name, NULL)) {
nmt_sync_op_init (&op); nmt_sync_op_init (&op);
nm_remote_connection_get_secrets (NM_REMOTE_CONNECTION (orig_connection), nm_remote_connection_get_secrets_async (NM_REMOTE_CONNECTION (orig_connection),
setting_name, got_secrets, &op); setting_name, NULL, got_secrets, &op);
/* FIXME: error handling */ /* FIXME: error handling */
secrets = nmt_sync_op_wait_pointer (&op, NULL); secrets = nmt_sync_op_wait_pointer (&op, NULL);
if (secrets) { if (secrets) {

View file

@ -95,28 +95,35 @@ activate_ac_state_changed (GObject *object,
} }
static void static void
activate_callback (NMClient *client, activate_callback (GObject *client,
NMActiveConnection *ac, GAsyncResult *result,
GError *error, gpointer user_data)
gpointer user_data)
{ {
NmtSyncOp *op = user_data; NmtSyncOp *op = user_data;
NMActiveConnection *ac;
GError *error = NULL;
ac = nm_client_activate_connection_finish (NM_CLIENT (client), result, &error);
if (error) if (error)
nmt_sync_op_complete_pointer (op, NULL, error); nmt_sync_op_complete_pointer (op, NULL, error);
else else
nmt_sync_op_complete_pointer (op, g_object_ref (ac), NULL); nmt_sync_op_complete_pointer (op, ac, NULL);
} }
static void static void
add_and_activate_callback (NMClient *client, add_and_activate_callback (GObject *client,
NMActiveConnection *ac, GAsyncResult *result,
const char *new_connection_path, gpointer user_data)
GError *error,
gpointer user_data)
{ {
/* We don't care about @new_connection_path, so... */ NmtSyncOp *op = user_data;
activate_callback (client, ac, error, user_data); NMActiveConnection *ac;
GError *error = NULL;
ac = nm_client_add_and_activate_connection_finish (NM_CLIENT (client), result, &error);
if (error)
nmt_sync_op_complete_pointer (op, NULL, error);
else
nmt_sync_op_complete_pointer (op, ac, NULL);
} }
static void static void
@ -151,13 +158,13 @@ activate_connection (NMConnection *connection,
nmt_sync_op_init (&op); nmt_sync_op_init (&op);
if (connection) { if (connection) {
nm_client_activate_connection (nm_client, nm_client_activate_connection_async (nm_client,
connection, device, specific_object_path, connection, device, specific_object_path,
activate_callback, &op); NULL, activate_callback, &op);
} else { } else {
nm_client_add_and_activate_connection (nm_client, nm_client_add_and_activate_connection_async (nm_client,
NULL, device, specific_object_path, NULL, device, specific_object_path,
add_and_activate_callback, &op); NULL, add_and_activate_callback, &op);
} }
nmt_newt_form_show (form); nmt_newt_form_show (form);
@ -221,7 +228,7 @@ listbox_activated (NmtNewtListbox *listbox,
return; return;
if (ac) if (ac)
nm_client_deactivate_connection (nm_client, ac); nm_client_deactivate_connection (nm_client, ac, NULL, NULL);
else else
activate_connection (connection, device, specific_object); activate_connection (connection, device, specific_object);
} }

View file

@ -430,13 +430,14 @@ typedef struct {
} ConnectionDeleteData; } ConnectionDeleteData;
static void static void
connection_deleted_callback (NMRemoteConnection *connection, connection_deleted_callback (GObject *connection,
GError *error, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
ConnectionDeleteData *data = user_data; ConnectionDeleteData *data = user_data;
GError *error = NULL;
if (error) { if (!nm_remote_connection_delete_finish (data->connection, result, NULL)) {
nmt_newt_message_dialog (_("Unable to delete connection: %s"), nmt_newt_message_dialog (_("Unable to delete connection: %s"),
error->message); error->message);
} else } else
@ -444,6 +445,7 @@ connection_deleted_callback (NMRemoteConnection *connection,
if (error || (data->got_callback && data->got_signal)) if (error || (data->got_callback && data->got_signal))
nmt_sync_op_complete_boolean (&data->op, error == NULL, error); nmt_sync_op_complete_boolean (&data->op, error == NULL, error);
g_clear_error (&error);
} }
static void static void
@ -480,7 +482,7 @@ nmt_remove_connection (NMRemoteConnection *connection)
data.connection = connection; data.connection = connection;
g_signal_connect (nm_settings, NM_REMOTE_SETTINGS_CONNECTION_REMOVED, g_signal_connect (nm_settings, NM_REMOTE_SETTINGS_CONNECTION_REMOVED,
G_CALLBACK (connection_removed_signal), &data); G_CALLBACK (connection_removed_signal), &data);
nm_remote_connection_delete (connection, connection_deleted_callback, &data); nm_remote_connection_delete_async (connection, NULL, connection_deleted_callback, &data);
if (!nmt_sync_op_wait_boolean (&data.op, &error)) { if (!nmt_sync_op_wait_boolean (&data.op, &error)) {
nmt_newt_message_dialog (_("Could not delete connection: %s"), nmt_newt_message_dialog (_("Could not delete connection: %s"),

View file

@ -86,11 +86,15 @@ nmtui_hostname_run_dialog (void)
} }
static void static void
hostname_set (NMRemoteSettings *settings, hostname_set (GObject *object,
GError *error, GAsyncResult *result,
gpointer op) gpointer op)
{ {
GError *error = NULL;
nm_remote_settings_save_hostname_finish (NM_REMOTE_SETTINGS (object), result, &error);
nmt_sync_op_complete_boolean (op, error == NULL, error); nmt_sync_op_complete_boolean (op, error == NULL, error);
g_clear_error (&error);
} }
NmtNewtForm * NmtNewtForm *
@ -108,7 +112,7 @@ nmtui_hostname (int argc, char **argv)
if (hostname) { if (hostname) {
nmt_sync_op_init (&op); nmt_sync_op_init (&op);
nm_remote_settings_save_hostname (nm_settings, hostname, hostname_set, &op); nm_remote_settings_save_hostname_async (nm_settings, hostname, NULL, hostname_set, &op);
if (nmt_sync_op_wait_boolean (&op, &error)) { if (nmt_sync_op_wait_boolean (&op, &error)) {
/* Translators: this indicates the result. ie, "I have set the hostname to ..." */ /* Translators: this indicates the result. ie, "I have set the hostname to ..." */
nmt_newt_message_dialog (_("Set hostname to '%s'"), hostname); nmt_newt_message_dialog (_("Set hostname to '%s'"), hostname);

View file

@ -31,27 +31,33 @@
#include <NetworkManager.h> #include <NetworkManager.h>
static void static void
added_cb (NMRemoteSettings *settings, added_cb (GObject *settings,
NMRemoteConnection *remote, GAsyncResult *result,
GError *error,
gpointer user_data) gpointer user_data)
{ {
GMainLoop *loop = user_data; GMainLoop *loop = user_data;
NMRemoteConnection *remote;
GError *error;
/* NM responded to our request; either handle the resulting error or /* NM responded to our request; either handle the resulting error or
* print out the object path of the connection we just added. * print out the object path of the connection we just added.
*/ */
remote = nm_remote_settings_add_connection_finish (NM_REMOTE_SETTINGS (settings),
result, &error);
if (error) if (error) {
g_print ("Error adding connection: %s", error->message); g_print ("Error adding connection: %s", error->message);
else g_error_free (error);
} else {
g_print ("Added: %s\n", nm_connection_get_path (NM_CONNECTION (remote))); g_print ("Added: %s\n", nm_connection_get_path (NM_CONNECTION (remote)));
g_object_unref (remote);
}
/* Tell the mainloop we're done and we can quit now */ /* Tell the mainloop we're done and we can quit now */
g_main_loop_quit (loop); g_main_loop_quit (loop);
} }
static gboolean static void
add_connection (NMRemoteSettings *settings, GMainLoop *loop, const char *con_name) add_connection (NMRemoteSettings *settings, GMainLoop *loop, const char *con_name)
{ {
NMConnection *connection; NMConnection *connection;
@ -59,7 +65,6 @@ add_connection (NMRemoteSettings *settings, GMainLoop *loop, const char *con_nam
NMSettingWired *s_wired; NMSettingWired *s_wired;
NMSettingIP4Config *s_ip4; NMSettingIP4Config *s_ip4;
char *uuid; char *uuid;
gboolean success;
/* Create a new connection object */ /* Create a new connection object */
connection = nm_simple_connection_new (); connection = nm_simple_connection_new ();
@ -89,12 +94,8 @@ add_connection (NMRemoteSettings *settings, GMainLoop *loop, const char *con_nam
/* Ask the settings service to add the new connection; we'll quit the /* Ask the settings service to add the new connection; we'll quit the
* mainloop and exit when the callback is called. * mainloop and exit when the callback is called.
*/ */
success = nm_remote_settings_add_connection (settings, connection, added_cb, loop); nm_remote_settings_add_connection_async (settings, connection, TRUE, NULL, added_cb, loop);
if (!success)
g_print ("Error adding connection\n");
g_object_unref (connection); g_object_unref (connection);
return success;
} }
@ -121,11 +122,9 @@ main (int argc, char *argv[])
} }
/* Ask the settings service to add the new connection */ /* Ask the settings service to add the new connection */
if (add_connection (settings, loop, "__Test connection__")) { add_connection (settings, loop, "__Test connection__");
/* Wait for the connection to be added */ /* Wait for the connection to be added */
g_main_loop_run (loop); g_main_loop_run (loop);
} else
g_print ("Error adding connection to NetworkManager\n");
/* Clean up */ /* Clean up */
g_object_unref (settings); g_object_unref (settings);

View file

@ -33,12 +33,16 @@ global:
nm_active_connection_get_vpn; nm_active_connection_get_vpn;
nm_active_connection_state_get_type; nm_active_connection_state_get_type;
nm_bluetooth_capabilities_get_type; nm_bluetooth_capabilities_get_type;
nm_client_activate_connection; nm_client_activate_connection_async;
nm_client_add_and_activate_connection; nm_client_activate_connection_finish;
nm_client_add_and_activate_connection_async;
nm_client_add_and_activate_connection_finish;
nm_client_check_connectivity; nm_client_check_connectivity;
nm_client_check_connectivity_async; nm_client_check_connectivity_async;
nm_client_check_connectivity_finish; nm_client_check_connectivity_finish;
nm_client_deactivate_connection; nm_client_deactivate_connection;
nm_client_deactivate_connection_async;
nm_client_deactivate_connection_finish;
nm_client_error_get_type; nm_client_error_get_type;
nm_client_error_quark; nm_client_error_quark;
nm_client_get_activating_connection; nm_client_get_activating_connection;
@ -156,8 +160,12 @@ global:
nm_device_connection_compatible; nm_device_connection_compatible;
nm_device_connection_valid; nm_device_connection_valid;
nm_device_delete; nm_device_delete;
nm_device_delete_async;
nm_device_delete_finish;
nm_device_disambiguate_names; nm_device_disambiguate_names;
nm_device_disconnect; nm_device_disconnect;
nm_device_disconnect_async;
nm_device_disconnect_finish;
nm_device_error_get_type; nm_device_error_get_type;
nm_device_error_quark; nm_device_error_quark;
nm_device_ethernet_error_get_type; nm_device_ethernet_error_get_type;
@ -246,7 +254,9 @@ global:
nm_device_wifi_get_mode; nm_device_wifi_get_mode;
nm_device_wifi_get_permanent_hw_address; nm_device_wifi_get_permanent_hw_address;
nm_device_wifi_get_type; nm_device_wifi_get_type;
nm_device_wifi_request_scan_simple; nm_device_wifi_request_scan;
nm_device_wifi_request_scan_async;
nm_device_wifi_request_scan_finish;
nm_device_wimax_error_get_type; nm_device_wimax_error_get_type;
nm_device_wimax_error_quark; nm_device_wimax_error_quark;
nm_device_wimax_get_active_nsp; nm_device_wimax_get_active_nsp;
@ -337,17 +347,24 @@ global:
nm_object_get_path; nm_object_get_path;
nm_object_get_type; nm_object_get_type;
nm_remote_connection_commit_changes; nm_remote_connection_commit_changes;
nm_remote_connection_commit_changes_unsaved; nm_remote_connection_commit_changes_async;
nm_remote_connection_commit_changes_finish;
nm_remote_connection_delete; nm_remote_connection_delete;
nm_remote_connection_delete_async;
nm_remote_connection_delete_finish;
nm_remote_connection_error_get_type; nm_remote_connection_error_get_type;
nm_remote_connection_error_quark; nm_remote_connection_error_quark;
nm_remote_connection_get_secrets; nm_remote_connection_get_secrets;
nm_remote_connection_get_secrets_async;
nm_remote_connection_get_secrets_finish;
nm_remote_connection_get_type; nm_remote_connection_get_type;
nm_remote_connection_get_unsaved; nm_remote_connection_get_unsaved;
nm_remote_connection_get_visible; nm_remote_connection_get_visible;
nm_remote_connection_save; nm_remote_connection_save;
nm_remote_settings_add_connection; nm_remote_connection_save_async;
nm_remote_settings_add_connection_unsaved; nm_remote_connection_save_finish;
nm_remote_settings_add_connection_async;
nm_remote_settings_add_connection_finish;
nm_remote_settings_error_get_type; nm_remote_settings_error_get_type;
nm_remote_settings_error_quark; nm_remote_settings_error_quark;
nm_remote_settings_get_connection_by_id; nm_remote_settings_get_connection_by_id;
@ -356,11 +373,17 @@ global:
nm_remote_settings_get_type; nm_remote_settings_get_type;
nm_remote_settings_list_connections; nm_remote_settings_list_connections;
nm_remote_settings_load_connections; nm_remote_settings_load_connections;
nm_remote_settings_load_connections_async;
nm_remote_settings_load_connections_finish;
nm_remote_settings_new; nm_remote_settings_new;
nm_remote_settings_new_async; nm_remote_settings_new_async;
nm_remote_settings_new_finish; nm_remote_settings_new_finish;
nm_remote_settings_reload_connections; nm_remote_settings_reload_connections;
nm_remote_settings_reload_connections_async;
nm_remote_settings_reload_connections_finish;
nm_remote_settings_save_hostname; nm_remote_settings_save_hostname;
nm_remote_settings_save_hostname_async;
nm_remote_settings_save_hostname_finish;
nm_secret_agent_capabilities_get_type; nm_secret_agent_capabilities_get_type;
nm_secret_agent_delete_secrets; nm_secret_agent_delete_secrets;
nm_secret_agent_error_get_type; nm_secret_agent_error_get_type;

View file

@ -473,25 +473,13 @@ nm_client_get_device_by_iface (NMClient *client, const char *iface)
typedef struct { typedef struct {
NMClient *client; NMClient *client;
NMClientActivateFn act_fn; GSimpleAsyncResult *simple;
NMClientAddActivateFn add_act_fn; GCancellable *cancellable;
gulong cancelled_id;
char *active_path; char *active_path;
char *new_connection_path; char *new_connection_path;
guint idle_id;
gpointer user_data;
} ActivateInfo; } ActivateInfo;
static void
activate_info_free (ActivateInfo *info)
{
if (info->idle_id)
g_source_remove (info->idle_id);
g_free (info->active_path);
g_free (info->new_connection_path);
memset (info, 0, sizeof (*info));
g_slice_free (ActivateInfo, info);
}
static void static void
activate_info_complete (ActivateInfo *info, activate_info_complete (ActivateInfo *info,
NMActiveConnection *active, NMActiveConnection *active,
@ -499,18 +487,23 @@ activate_info_complete (ActivateInfo *info,
{ {
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (info->client); NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (info->client);
if (info->act_fn) if (active)
info->act_fn (info->client, error ? NULL : active, error, info->user_data); g_simple_async_result_set_op_res_gpointer (info->simple, g_object_ref (active), g_object_unref);
else if (info->add_act_fn) { else
info->add_act_fn (info->client, g_simple_async_result_set_from_error (info->simple, error);
error ? NULL : active, g_simple_async_result_complete (info->simple);
error ? NULL : info->new_connection_path,
error,
info->user_data);
} else if (error)
g_warning ("Device activation failed: (%d) %s", error->code, error->message);
priv->pending_activations = g_slist_remove (priv->pending_activations, info); priv->pending_activations = g_slist_remove (priv->pending_activations, info);
g_free (info->active_path);
g_free (info->new_connection_path);
g_object_unref (info->simple);
if (info->cancellable) {
if (info->cancelled_id)
g_signal_handler_disconnect (info->cancellable, info->cancelled_id);
g_object_unref (info->cancellable);
}
g_slice_free (ActivateInfo, info);
} }
static void static void
@ -552,7 +545,6 @@ recheck_pending_activations (NMClient *self, const char *failed_path, GError *er
if (g_strcmp0 (info->active_path, active_path) == 0) { if (g_strcmp0 (info->active_path, active_path) == 0) {
/* Call the pending activation's callback and it all up */ /* Call the pending activation's callback and it all up */
activate_info_complete (info, active, NULL); activate_info_complete (info, active, NULL);
activate_info_free (info);
break; break;
} }
} }
@ -564,10 +556,23 @@ recheck_pending_activations (NMClient *self, const char *failed_path, GError *er
* callback gets called. * callback gets called.
*/ */
activate_info_complete (ainfo, NULL, error); activate_info_complete (ainfo, NULL, error);
activate_info_free (ainfo);
} }
} }
static void
activation_cancelled (GCancellable *cancellable,
gpointer user_data)
{
ActivateInfo *info = user_data;
GError *error = NULL;
if (!g_cancellable_set_error_if_cancelled (cancellable, &error))
return;
activate_info_complete (info, NULL, error);
g_clear_error (&error);
}
static void static void
activate_cb (GObject *object, activate_cb (GObject *object,
GAsyncResult *result, GAsyncResult *result,
@ -579,33 +584,20 @@ activate_cb (GObject *object,
if (nmdbus_manager_call_activate_connection_finish (NMDBUS_MANAGER (object), if (nmdbus_manager_call_activate_connection_finish (NMDBUS_MANAGER (object),
&info->active_path, &info->active_path,
result, &error)) { result, &error)) {
if (info->cancellable) {
info->cancelled_id = g_signal_connect (info->cancellable, "cancelled",
G_CALLBACK (activation_cancelled), info);
}
recheck_pending_activations (info->client, NULL, NULL); recheck_pending_activations (info->client, NULL, NULL);
} else { } else {
activate_info_complete (info, NULL, error); activate_info_complete (info, NULL, error);
activate_info_free (info);
g_clear_error (&error); g_clear_error (&error);
} }
} }
static gboolean
activate_nm_not_running (gpointer user_data)
{
ActivateInfo *info = user_data;
GError *error;
info->idle_id = 0;
error = g_error_new_literal (NM_CLIENT_ERROR,
NM_CLIENT_ERROR_MANAGER_NOT_RUNNING,
"NetworkManager is not running");
activate_info_complete (info, NULL, error);
activate_info_free (info);
g_clear_error (&error);
return FALSE;
}
/** /**
* nm_client_activate_connection: * nm_client_activate_connection_async:
* @client: a #NMClient * @client: a #NMClient
* @connection: (allow-none): an #NMConnection * @connection: (allow-none): an #NMConnection
* @device: (allow-none): the #NMDevice * @device: (allow-none): the #NMDevice
@ -616,27 +608,34 @@ activate_nm_not_running (gpointer user_data)
* path of a #NMAccessPoint or #NMWimaxNsp owned by @device, which you can * path of a #NMAccessPoint or #NMWimaxNsp owned by @device, which you can
* get using nm_object_get_path(), and which will be used to complete the * get using nm_object_get_path(), and which will be used to complete the
* details of the newly added connection. * details of the newly added connection.
* @callback: (scope async) (allow-none): the function to call when the call is done * @cancellable: a #GCancellable, or %NULL
* @user_data: (closure): user data to pass to the callback function * @callback: callback to be called when the activation has started
* @user_data: caller-specific data passed to @callback
* *
* Starts a connection to a particular network using the configuration settings * Asynchronously starts a connection to a particular network using the
* from @connection and the network device @device. Certain connection types * configuration settings from @connection and the network device @device.
* also take a "specific object" which is the object path of a connection- * Certain connection types also take a "specific object" which is the object
* specific object, like an #NMAccessPoint for Wi-Fi connections, or an * path of a connection- specific object, like an #NMAccessPoint for Wi-Fi
* #NMWimaxNsp for WiMAX connections, to which you wish to connect. If the * connections, or an #NMWimaxNsp for WiMAX connections, to which you wish to
* specific object is not given, NetworkManager can, in some cases, automatically * connect. If the specific object is not given, NetworkManager can, in some
* determine which network to connect to given the settings in @connection. * cases, automatically determine which network to connect to given the settings
* in @connection.
* *
* If @connection is not given for a device-based activation, NetworkManager * If @connection is not given for a device-based activation, NetworkManager
* picks the best available connection for the device and activates it. * picks the best available connection for the device and activates it.
*
* Note that the callback is invoked when NetworkManager has started activating
* the new connection, not when it finishes. You can used the returned
* #NMActiveConnection object to track the activation to its completion.
**/ **/
void void
nm_client_activate_connection (NMClient *client, nm_client_activate_connection_async (NMClient *client,
NMConnection *connection, NMConnection *connection,
NMDevice *device, NMDevice *device,
const char *specific_object, const char *specific_object,
NMClientActivateFn callback, GCancellable *cancellable,
gpointer user_data) GAsyncReadyCallback callback,
gpointer user_data)
{ {
NMClientPrivate *priv; NMClientPrivate *priv;
ActivateInfo *info; ActivateInfo *info;
@ -647,27 +646,58 @@ nm_client_activate_connection (NMClient *client,
if (connection) if (connection)
g_return_if_fail (NM_IS_CONNECTION (connection)); g_return_if_fail (NM_IS_CONNECTION (connection));
if (!nm_client_get_nm_running (client)) {
g_simple_async_report_error_in_idle (G_OBJECT (client), callback, user_data,
NM_CLIENT_ERROR,
NM_CLIENT_ERROR_MANAGER_NOT_RUNNING,
"NetworkManager is not running");
return;
}
info = g_slice_new0 (ActivateInfo); info = g_slice_new0 (ActivateInfo);
info->act_fn = callback;
info->user_data = user_data;
info->client = client; info->client = client;
info->simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
nm_client_activate_connection_async);
info->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
priv = NM_CLIENT_GET_PRIVATE (client); priv = NM_CLIENT_GET_PRIVATE (client);
priv->pending_activations = g_slist_prepend (priv->pending_activations, info); priv->pending_activations = g_slist_prepend (priv->pending_activations, info);
if (!nm_client_get_nm_running (client)) {
info->idle_id = g_idle_add (activate_nm_not_running, info);
return;
}
nmdbus_manager_call_activate_connection (priv->manager_proxy, nmdbus_manager_call_activate_connection (priv->manager_proxy,
connection ? nm_connection_get_path (connection) : "/", connection ? nm_connection_get_path (connection) : "/",
device ? nm_object_get_path (NM_OBJECT (device)) : "/", device ? nm_object_get_path (NM_OBJECT (device)) : "/",
specific_object ? specific_object : "/", specific_object ? specific_object : "/",
NULL, cancellable,
activate_cb, info); activate_cb, info);
} }
/**
* nm_client_activate_connection_finish:
* @client: an #NMClient
* @result: the result passed to the #GAsyncReadyCallback
* @error: location for a #GError, or %NULL
*
* Gets the result of a call to nm_client_activate_connection_async().
*
* Returns: (transfer full): the new #NMActiveConnection on success, %NULL on
* failure, in which case @error will be set.
**/
NMActiveConnection *
nm_client_activate_connection_finish (NMClient *client,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), nm_client_activate_connection_async), NULL);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return NULL;
else
return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
}
static void static void
add_activate_cb (GObject *object, add_activate_cb (GObject *object,
GAsyncResult *result, GAsyncResult *result,
@ -677,19 +707,23 @@ add_activate_cb (GObject *object,
GError *error = NULL; GError *error = NULL;
if (nmdbus_manager_call_add_and_activate_connection_finish (NMDBUS_MANAGER (object), if (nmdbus_manager_call_add_and_activate_connection_finish (NMDBUS_MANAGER (object),
&info->new_connection_path, NULL,
&info->active_path, &info->active_path,
result, &error)) { result, &error)) {
if (info->cancellable) {
info->cancelled_id = g_signal_connect (info->cancellable, "cancelled",
G_CALLBACK (activation_cancelled), info);
}
recheck_pending_activations (info->client, NULL, NULL); recheck_pending_activations (info->client, NULL, NULL);
} else { } else {
activate_info_complete (info, NULL, error); activate_info_complete (info, NULL, error);
activate_info_free (info);
g_clear_error (&error); g_clear_error (&error);
} }
} }
/** /**
* nm_client_add_and_activate_connection: * nm_client_add_and_activate_connection_async:
* @client: a #NMClient * @client: a #NMClient
* @partial: (allow-none): an #NMConnection to add; the connection may be * @partial: (allow-none): an #NMConnection to add; the connection may be
* partially filled (or even %NULL) and will be completed by NetworkManager * partially filled (or even %NULL) and will be completed by NetworkManager
@ -702,51 +736,96 @@ add_activate_cb (GObject *object,
* path of a #NMAccessPoint or #NMWimaxNsp owned by @device, which you can * path of a #NMAccessPoint or #NMWimaxNsp owned by @device, which you can
* get using nm_object_get_path(), and which will be used to complete the * get using nm_object_get_path(), and which will be used to complete the
* details of the newly added connection. * details of the newly added connection.
* @callback: (scope async) (allow-none): the function to call when the call is done * @cancellable: a #GCancellable, or %NULL
* @user_data: (closure): user data to pass to the callback function * @callback: callback to be called when the activation has started
* @user_data: caller-specific data passed to @callback
* *
* Adds a new connection using the given details (if any) as a template, * Adds a new connection using the given details (if any) as a template,
* automatically filling in missing settings with the capabilities of the * automatically filling in missing settings with the capabilities of the given
* given device and specific object. The new connection is then activated. * device and specific object. The new connection is then asynchronously
* Cannot be used for VPN connections at this time. * activated as with nm_client_activate_connection_async(). Cannot be used for
* VPN connections at this time.
*
* Note that the callback is invoked when NetworkManager has started activating
* the new connection, not when it finishes. You can used the returned
* #NMActiveConnection object to track the activation to its completion.
**/ **/
void void
nm_client_add_and_activate_connection (NMClient *client, nm_client_add_and_activate_connection_async (NMClient *client,
NMConnection *partial, NMConnection *partial,
NMDevice *device, NMDevice *device,
const char *specific_object, const char *specific_object,
NMClientAddActivateFn callback, GCancellable *cancellable,
gpointer user_data) GAsyncReadyCallback callback,
gpointer user_data)
{ {
NMClientPrivate *priv; NMClientPrivate *priv;
ActivateInfo *info;
GVariant *dict = NULL; GVariant *dict = NULL;
ActivateInfo *info;
g_return_if_fail (NM_IS_CLIENT (client)); g_return_if_fail (NM_IS_CLIENT (client));
g_return_if_fail (NM_IS_DEVICE (device)); g_return_if_fail (NM_IS_DEVICE (device));
if (partial)
g_return_if_fail (NM_IS_CONNECTION (partial));
if (!nm_client_get_nm_running (client)) {
g_simple_async_report_error_in_idle (G_OBJECT (client), callback, user_data,
NM_CLIENT_ERROR,
NM_CLIENT_ERROR_MANAGER_NOT_RUNNING,
"NetworkManager is not running");
return;
}
info = g_slice_new0 (ActivateInfo); info = g_slice_new0 (ActivateInfo);
info->add_act_fn = callback;
info->user_data = user_data;
info->client = client; info->client = client;
info->simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
nm_client_add_and_activate_connection_async);
info->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
priv = NM_CLIENT_GET_PRIVATE (client);
priv->pending_activations = g_slist_prepend (priv->pending_activations, info);
if (partial) if (partial)
dict = nm_connection_to_dbus (partial, NM_CONNECTION_SERIALIZE_ALL); dict = nm_connection_to_dbus (partial, NM_CONNECTION_SERIALIZE_ALL);
if (!dict) if (!dict)
dict = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0); dict = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0);
priv = NM_CLIENT_GET_PRIVATE (client); nmdbus_manager_call_add_and_activate_connection (priv->manager_proxy,
priv->pending_activations = g_slist_prepend (priv->pending_activations, info); dict,
nm_object_get_path (NM_OBJECT (device)),
specific_object ? specific_object : "/",
cancellable,
add_activate_cb, info);
}
if (nm_client_get_nm_running (client)) { /**
nmdbus_manager_call_add_and_activate_connection (priv->manager_proxy, * nm_client_add_and_activate_connection_finish:
dict, * @client: an #NMClient
nm_object_get_path (NM_OBJECT (device)), * @result: the result passed to the #GAsyncReadyCallback
specific_object ? specific_object : "/", * @error: location for a #GError, or %NULL
NULL, *
add_activate_cb, info); * Gets the result of a call to nm_client_add_and_activate_connection_async().
} else *
info->idle_id = g_idle_add (activate_nm_not_running, info); * You can call nm_active_connection_get_connection() on the returned
* #NMActiveConnection to find the path of the created #NMConnection.
*
* Returns: (transfer full): the new #NMActiveConnection on success, %NULL on
* failure, in which case @error will be set.
**/
NMActiveConnection *
nm_client_add_and_activate_connection_finish (NMClient *client,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), nm_client_add_and_activate_connection_async), NULL);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return NULL;
else
return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
} }
static void static void
@ -766,30 +845,118 @@ object_creation_failed_cb (GObject *object, GError *error, char *failed_path)
* nm_client_deactivate_connection: * nm_client_deactivate_connection:
* @client: a #NMClient * @client: a #NMClient
* @active: the #NMActiveConnection to deactivate * @active: the #NMActiveConnection to deactivate
* @cancellable: a #GCancellable, or %NULL
* @error: location for a #GError, or %NULL
* *
* Deactivates an active #NMActiveConnection. * Deactivates an active #NMActiveConnection.
*
* Returns: success or failure
**/ **/
void gboolean
nm_client_deactivate_connection (NMClient *client, NMActiveConnection *active) nm_client_deactivate_connection (NMClient *client,
NMActiveConnection *active,
GCancellable *cancellable,
GError **error)
{ {
NMClientPrivate *priv; NMClientPrivate *priv;
const char *path; const char *path;
g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (active), FALSE);
priv = NM_CLIENT_GET_PRIVATE (client);
if (!nm_client_get_nm_running (client))
return TRUE;
path = nm_object_get_path (NM_OBJECT (active));
return nmdbus_manager_call_deactivate_connection_sync (priv->manager_proxy,
path,
cancellable, error);
}
static void
deactivated_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
GError *error = NULL; GError *error = NULL;
if (nmdbus_manager_call_deactivate_connection_finish (NMDBUS_MANAGER (object),
result, &error))
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
else
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete (simple);
g_object_unref (simple);
}
/**
* nm_client_deactivate_connection_async:
* @client: a #NMClient
* @active: the #NMActiveConnection to deactivate
* @cancellable: a #GCancellable, or %NULL
* @callback: callback to be called when the deactivation has completed
* @user_data: caller-specific data passed to @callback
*
* Asynchronously deactivates an active #NMActiveConnection.
**/
void
nm_client_deactivate_connection_async (NMClient *client,
NMActiveConnection *active,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
NMClientPrivate *priv;
const char *path;
GSimpleAsyncResult *simple;
g_return_if_fail (NM_IS_CLIENT (client)); g_return_if_fail (NM_IS_CLIENT (client));
g_return_if_fail (NM_IS_ACTIVE_CONNECTION (active)); g_return_if_fail (NM_IS_ACTIVE_CONNECTION (active));
simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
nm_client_deactivate_connection_async);
priv = NM_CLIENT_GET_PRIVATE (client); priv = NM_CLIENT_GET_PRIVATE (client);
if (!nm_client_get_nm_running (client)) if (!nm_client_get_nm_running (client)) {
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
g_simple_async_result_complete_in_idle (simple);
g_object_unref (simple);
return; return;
}
path = nm_object_get_path (NM_OBJECT (active)); path = nm_object_get_path (NM_OBJECT (active));
if (!nmdbus_manager_call_deactivate_connection_sync (priv->manager_proxy, nmdbus_manager_call_deactivate_connection (priv->manager_proxy,
path, path,
NULL, &error)) { cancellable,
g_warning ("Could not deactivate connection '%s': %s", path, error->message); deactivated_cb, simple);
g_error_free (error); }
}
/**
* nm_client_deactivate_connection_finish:
* @client: a #NMClient
* @result: the result passed to the #GAsyncReadyCallback
* @error: location for a #GError, or %NULL
*
* Gets the result of a call to nm_client_deactivate_connection_async().
*
* Returns: success or failure
**/
gboolean
nm_client_deactivate_connection_finish (NMClient *client,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), nm_client_deactivate_connection_async), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else
return g_simple_async_result_get_op_res_gboolean (simple);
} }
/** /**
@ -1765,8 +1932,10 @@ dispose (GObject *object)
g_clear_object (&priv->primary_connection); g_clear_object (&priv->primary_connection);
g_clear_object (&priv->activating_connection); g_clear_object (&priv->activating_connection);
g_slist_free_full (priv->pending_activations, (GDestroyNotify) activate_info_free); /* Each activation should hold a ref on @client, so if we're being disposed,
priv->pending_activations = NULL; * there shouldn't be any pending.
*/
g_warn_if_fail (priv->pending_activations == NULL);
g_hash_table_destroy (priv->permissions); g_hash_table_destroy (priv->permissions);
priv->permissions = NULL; priv->permissions = NULL;

View file

@ -176,32 +176,40 @@ const GPtrArray *nm_client_get_devices (NMClient *client);
NMDevice *nm_client_get_device_by_path (NMClient *client, const char *object_path); NMDevice *nm_client_get_device_by_path (NMClient *client, const char *object_path);
NMDevice *nm_client_get_device_by_iface (NMClient *client, const char *iface); NMDevice *nm_client_get_device_by_iface (NMClient *client, const char *iface);
typedef void (*NMClientActivateFn) (NMClient *client, void nm_client_activate_connection_async (NMClient *client,
NMActiveConnection *active_connection, NMConnection *connection,
GError *error, NMDevice *device,
gpointer user_data); const char *specific_object,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
NMActiveConnection *nm_client_activate_connection_finish (NMClient *client,
GAsyncResult *result,
GError **error);
void nm_client_activate_connection (NMClient *client, void nm_client_add_and_activate_connection_async (NMClient *client,
NMConnection *connection, NMConnection *partial,
NMDevice *device, NMDevice *device,
const char *specific_object, const char *specific_object,
NMClientActivateFn callback, GCancellable *cancellable,
gpointer user_data); GAsyncReadyCallback callback,
gpointer user_data);
NMActiveConnection *nm_client_add_and_activate_connection_finish (NMClient *client,
GAsyncResult *result,
GError **error);
typedef void (*NMClientAddActivateFn) (NMClient *client, gboolean nm_client_deactivate_connection (NMClient *client,
NMActiveConnection *connection, NMActiveConnection *active,
const char *new_connection_path, GCancellable *cancellable,
GError *error, GError **error);
gpointer user_data); void nm_client_deactivate_connection_async (NMClient *client,
NMActiveConnection *active,
void nm_client_add_and_activate_connection (NMClient *client, GCancellable *cancellable,
NMConnection *partial, GAsyncReadyCallback callback,
NMDevice *device, gpointer user_data);
const char *specific_object, gboolean nm_client_deactivate_connection_finish (NMClient *client,
NMClientAddActivateFn callback, GAsyncResult *result,
gpointer user_data); GError **error);
void nm_client_deactivate_connection (NMClient *client, NMActiveConnection *active);
gboolean nm_client_networking_get_enabled (NMClient *client); gboolean nm_client_networking_get_enabled (NMClient *client);
void nm_client_networking_set_enabled (NMClient *client, gboolean enabled); void nm_client_networking_set_enabled (NMClient *client, gboolean enabled);

View file

@ -47,9 +47,7 @@ static void state_changed_cb (NMDevice *device, GParamSpec *pspec, gpointer user
typedef struct { typedef struct {
NMDeviceWifi *device; NMDeviceWifi *device;
GCancellable *cancellable; GSimpleAsyncResult *simple;
NMDeviceWifiRequestScanFn callback;
gpointer user_data;
} RequestScanInfo; } RequestScanInfo;
typedef struct { typedef struct {
@ -287,65 +285,123 @@ nm_device_wifi_get_access_point_by_path (NMDeviceWifi *device,
return ap; return ap;
} }
/**
* nm_device_wifi_request_scan:
* @device: a #NMDeviceWifi
* @cancellable: a #GCancellable, or %NULL
* @error: location for a #GError, or %NULL
*
* Request NM to scan for access points on @device. Note that the function
* returns immediately after requesting the scan, and it may take some time
* after that for the scan to complete.
*
* Returns: %TRUE on success, %FALSE on error, in which case @error will be
* set.
**/
gboolean
nm_device_wifi_request_scan (NMDeviceWifi *device,
GCancellable *cancellable,
GError **error)
{
g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), FALSE);
return nmdbus_device_wifi_call_request_scan_sync (NM_DEVICE_WIFI_GET_PRIVATE (device)->proxy,
g_variant_new_array (G_VARIANT_TYPE_VARDICT,
NULL, 0),
cancellable, error);
}
static void static void
request_scan_cb (GObject *source, request_scan_cb (GObject *source,
GAsyncResult *result, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
RequestScanInfo *info = user_data; RequestScanInfo *info = user_data;
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (info->device);
GError *error = NULL;
if (info->callback) { priv->scan_info = NULL;
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (info->device);
GError *error = NULL;
nmdbus_device_wifi_call_request_scan_finish (NMDBUS_DEVICE_WIFI (source), if (nmdbus_device_wifi_call_request_scan_finish (NMDBUS_DEVICE_WIFI (source),
result, &error); result, &error))
g_simple_async_result_set_op_res_gboolean (info->simple, TRUE);
else
g_simple_async_result_take_error (info->simple, error);
info->callback (info->device, error, info->user_data); g_simple_async_result_complete (info->simple);
g_object_unref (info->simple);
g_clear_error (&error);
priv->scan_info = NULL;
}
g_clear_object (&info->cancellable);
g_slice_free (RequestScanInfo, info); g_slice_free (RequestScanInfo, info);
} }
/** /**
* nm_device_wifi_request_scan_simple: * nm_device_wifi_request_scan_async:
* @device: a #NMDeviceWifi * @device: a #NMDeviceWifi
* @callback: (scope async) (allow-none): the function to call when the call is done * @cancellable: a #GCancellable, or %NULL
* @user_data: (closure): user data to pass to the callback function * @callback: callback to be called when the scan has been requested
* @user_data: caller-specific data passed to @callback
* *
* Request NM to scan for access points on the #NMDeviceWifi. This function only * Request NM to scan for access points on @device. Note that @callback will be
* instructs NM to perform scanning. Use nm_device_wifi_get_access_points() * called immediately after requesting the scan, and it may take some time after
* to get available access points. * that for the scan to complete.
**/ **/
void void
nm_device_wifi_request_scan_simple (NMDeviceWifi *device, nm_device_wifi_request_scan_async (NMDeviceWifi *device,
NMDeviceWifiRequestScanFn callback, GCancellable *cancellable,
gpointer user_data) GAsyncReadyCallback callback,
gpointer user_data)
{ {
RequestScanInfo *info;
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device);
RequestScanInfo *info;
GSimpleAsyncResult *simple;
g_return_if_fail (NM_IS_DEVICE_WIFI (device)); g_return_if_fail (NM_IS_DEVICE_WIFI (device));
simple = g_simple_async_result_new (G_OBJECT (device), callback, user_data,
nm_device_wifi_request_scan_async);
/* If a scan is in progress, just return */ /* If a scan is in progress, just return */
if (priv->scan_info) if (priv->scan_info) {
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
g_simple_async_result_complete_in_idle (simple);
g_object_unref (simple);
return; return;
}
info = g_slice_new0 (RequestScanInfo); info = g_slice_new0 (RequestScanInfo);
info->device = device; info->device = device;
info->cancellable = g_cancellable_new (); info->simple = simple;
info->callback = callback;
info->user_data = user_data;
priv->scan_info = info; priv->scan_info = info;
nmdbus_device_wifi_call_request_scan (NM_DEVICE_WIFI_GET_PRIVATE (device)->proxy, nmdbus_device_wifi_call_request_scan (NM_DEVICE_WIFI_GET_PRIVATE (device)->proxy,
g_variant_new_array (G_VARIANT_TYPE_VARDICT, NULL, 0), g_variant_new_array (G_VARIANT_TYPE_VARDICT, NULL, 0),
info->cancellable, cancellable, request_scan_cb, info);
request_scan_cb, info); }
/**
* nm_device_wifi_request_scan_finish:
* @device: a #NMDeviceWifi
* @result: the result passed to the #GAsyncReadyCallback
* @error: location for a #GError, or %NULL
*
* Gets the result of a call to nm_device_wifi_request_scan_async().
*
* Returns: %TRUE on success, %FALSE on error, in which case @error will be
* set.
**/
gboolean
nm_device_wifi_request_scan_finish (NMDeviceWifi *device,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (device), nm_device_wifi_request_scan_async), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else
return g_simple_async_result_get_op_res_gboolean (simple);
} }
static void static void
@ -620,25 +676,6 @@ static void
dispose (GObject *object) dispose (GObject *object)
{ {
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (object); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (object);
GError *error = NULL;
if (priv->scan_info) {
RequestScanInfo *scan_info;
scan_info = priv->scan_info;
priv->scan_info = NULL;
if (scan_info->callback) {
g_set_error_literal (&error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_UNKNOWN,
"Wi-Fi device was destroyed");
scan_info->callback (NULL, error, scan_info->user_data);
scan_info->callback = NULL;
g_clear_error (&error);
}
g_cancellable_cancel (scan_info->cancellable);
/* request_scan_cb() will free scan_info */
}
if (priv->aps) if (priv->aps)
clean_up_aps (NM_DEVICE_WIFI (object), TRUE); clean_up_aps (NM_DEVICE_WIFI (object), TRUE);

View file

@ -100,12 +100,17 @@ NMAccessPoint * nm_device_wifi_get_access_point_by_path (NMDeviceWifi *
const GPtrArray * nm_device_wifi_get_access_points (NMDeviceWifi *device); const GPtrArray * nm_device_wifi_get_access_points (NMDeviceWifi *device);
typedef void (*NMDeviceWifiRequestScanFn) (NMDeviceWifi *device, gboolean nm_device_wifi_request_scan (NMDeviceWifi *device,
GError *error, GCancellable *cancellable,
gpointer user_data); GError **error);
void nm_device_wifi_request_scan_simple (NMDeviceWifi *device,
NMDeviceWifiRequestScanFn callback, void nm_device_wifi_request_scan_async (NMDeviceWifi *device,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data); gpointer user_data);
gboolean nm_device_wifi_request_scan_finish (NMDeviceWifi *device,
GAsyncResult *result,
GError **error);
G_END_DECLS G_END_DECLS

View file

@ -1892,63 +1892,122 @@ nm_device_is_software (NMDevice *device)
return !!(NM_DEVICE_GET_PRIVATE (device)->capabilities & NM_DEVICE_CAP_IS_SOFTWARE); return !!(NM_DEVICE_GET_PRIVATE (device)->capabilities & NM_DEVICE_CAP_IS_SOFTWARE);
} }
typedef struct { /**
NMDevice *device; * nm_device_disconnect:
NMDeviceCallbackFn fn; * @device: a #NMDevice
gpointer user_data; * @cancellable: a #GCancellable, or %NULL
} DeviceCallbackInfo; * @error: location for a #GError, or %NULL
*
* Disconnects the device if currently connected, and prevents the device from
* automatically connecting to networks until the next manual network connection
* request.
*
* Returns: %TRUE on success, %FALSE on error, in which case @error will be set.
**/
gboolean
nm_device_disconnect (NMDevice *device,
GCancellable *cancellable,
GError **error)
{
g_return_val_if_fail (NM_IS_DEVICE (device), FALSE);
return nmdbus_device_call_disconnect_sync (NM_DEVICE_GET_PRIVATE (device)->proxy,
cancellable, error);
}
static void static void
device_disconnect_cb (GObject *proxy, device_disconnect_cb (GObject *proxy,
GAsyncResult *result, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
DeviceCallbackInfo *info = user_data; GSimpleAsyncResult *simple = user_data;
GError *error = NULL; GError *error = NULL;
nmdbus_device_call_disconnect_finish (NMDBUS_DEVICE (proxy), result, &error); if (nmdbus_device_call_disconnect_finish (NMDBUS_DEVICE (proxy), result, &error))
if (info->fn) g_simple_async_result_set_op_res_gboolean (simple, TRUE);
info->fn (info->device, error, info->user_data); else
else if (error) { g_simple_async_result_take_error (simple, error);
g_warning ("%s: device %s disconnect failed: %s",
__func__,
nm_object_get_path (NM_OBJECT (info->device)),
error->message);
}
g_clear_error (&error);
g_object_unref (info->device); g_simple_async_result_complete (simple);
g_slice_free (DeviceCallbackInfo, info); g_object_unref (simple);
} }
/** /**
* nm_device_disconnect: * nm_device_disconnect_async:
* @device: a #NMDevice * @device: a #NMDevice
* @callback: (scope async) (allow-none): callback to be called when disconnect * @cancellable: a #GCancellable, or %NULL
* operation completes * @callback: callback to be called when the disconnect operation completes
* @user_data: (closure): caller-specific data passed to @callback * @user_data: caller-specific data passed to @callback
* *
* Disconnects the device if currently connected, and prevents the device from * Asynchronously begins disconnecting the device if currently connected, and
* automatically connecting to networks until the next manual network connection * prevents the device from automatically connecting to networks until the next
* request. * manual network connection request.
**/ **/
void void
nm_device_disconnect (NMDevice *device, nm_device_disconnect_async (NMDevice *device,
NMDeviceCallbackFn callback, GCancellable *cancellable,
gpointer user_data) GAsyncReadyCallback callback,
gpointer user_data)
{ {
DeviceCallbackInfo *info; GSimpleAsyncResult *simple;
g_return_if_fail (NM_IS_DEVICE (device)); g_return_if_fail (NM_IS_DEVICE (device));
info = g_slice_new (DeviceCallbackInfo); simple = g_simple_async_result_new (G_OBJECT (device), callback, user_data,
info->fn = callback; nm_device_disconnect_async);
info->user_data = user_data;
info->device = g_object_ref (device);
nmdbus_device_call_disconnect (NM_DEVICE_GET_PRIVATE (device)->proxy, nmdbus_device_call_disconnect (NM_DEVICE_GET_PRIVATE (device)->proxy,
NULL, cancellable,
device_disconnect_cb, info); device_disconnect_cb, simple);
}
/**
* nm_device_disconnect_finish:
* @device: a #NMDevice
* @result: the result passed to the #GAsyncReadyCallback
* @error: location for a #GError, or %NULL
*
* Gets the result of a call to nm_device_disconnect_async().
*
* Returns: %TRUE on success, %FALSE on error, in which case @error
* will be set.
**/
gboolean
nm_device_disconnect_finish (NMDevice *device,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (device), nm_device_disconnect_async), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else
return g_simple_async_result_get_op_res_gboolean (simple);
}
/**
* nm_device_delete:
* @device: a #NMDevice
* @cancellable: a #GCancellable, or %NULL
* @error: location for a #GError, or %NULL
*
* Deletes the software device. Hardware devices can't be deleted.
*
* Returns: %TRUE on success, %FALSE on error, in which case @error
* will be set.
**/
gboolean
nm_device_delete (NMDevice *device,
GCancellable *cancellable,
GError **error)
{
g_return_val_if_fail (NM_IS_DEVICE (device), FALSE);
return nmdbus_device_call_delete_sync (NM_DEVICE_GET_PRIVATE (device)->proxy,
cancellable, error);
} }
static void static void
@ -1956,50 +2015,71 @@ device_delete_cb (GObject *proxy,
GAsyncResult *result, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
DeviceCallbackInfo *info = user_data; GSimpleAsyncResult *simple = user_data;
GError *error = NULL; GError *error = NULL;
nmdbus_device_call_delete_finish (NMDBUS_DEVICE (proxy), result, &error); if (nmdbus_device_call_delete_finish (NMDBUS_DEVICE (proxy), result, &error))
if (info->fn) g_simple_async_result_set_op_res_gboolean (simple, TRUE);
info->fn (info->device, error, info->user_data); else
else if (error) { g_simple_async_result_take_error (simple, error);
g_warning ("%s: device %s delete failed: %s",
__func__,
nm_object_get_path (NM_OBJECT (info->device)),
error->message);
}
g_clear_error (&error);
g_object_unref (info->device); g_simple_async_result_complete (simple);
g_slice_free (DeviceCallbackInfo, info); g_object_unref (simple);
} }
/** /**
* nm_device_delete: * nm_device_delete_async:
* @device: a #NMDevice * @device: a #NMDevice
* @callback: (scope async) (allow-none): callback to be called when delete * @cancellable: a #GCancellable, or %NULL
* operation completes * @callback: callback to be called when delete operation completes
* @user_data: (closure): caller-specific data passed to @callback * @user_data: caller-specific data passed to @callback
* *
* Deletes the software device. Hardware devices can't be deleted. * Asynchronously begins deleteing the software device. Hardware devices can't
* be deleted.
**/ **/
void void
nm_device_delete (NMDevice *device, nm_device_delete_async (NMDevice *device,
NMDeviceCallbackFn callback, GCancellable *cancellable,
gpointer user_data) GAsyncReadyCallback callback,
gpointer user_data)
{ {
DeviceCallbackInfo *info; GSimpleAsyncResult *simple;
g_return_if_fail (NM_IS_DEVICE (device)); g_return_if_fail (NM_IS_DEVICE (device));
info = g_slice_new (DeviceCallbackInfo); simple = g_simple_async_result_new (G_OBJECT (device), callback, user_data,
info->fn = callback; nm_device_delete_async);
info->user_data = user_data;
info->device = g_object_ref (device);
nmdbus_device_call_delete (NM_DEVICE_GET_PRIVATE (device)->proxy, nmdbus_device_call_delete (NM_DEVICE_GET_PRIVATE (device)->proxy,
NULL, cancellable,
device_delete_cb, info); device_delete_cb, simple);
}
/**
* nm_device_delete_finish:
* @device: a #NMDevice
* @result: the result passed to the #GAsyncReadyCallback
* @error: location for a #GError, or %NULL
*
* Gets the result of a call to nm_device_delete_async().
*
* Returns: %TRUE on success, %FALSE on error, in which case @error
* will be set.
**/
gboolean
nm_device_delete_finish (NMDevice *device,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (device), nm_device_delete_async), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else
return g_simple_async_result_get_op_res_gboolean (simple);
} }
/** /**

View file

@ -145,15 +145,27 @@ const char * nm_device_get_description (NMDevice *device);
char ** nm_device_disambiguate_names (NMDevice **devices, char ** nm_device_disambiguate_names (NMDevice **devices,
int num_devices); int num_devices);
typedef void (*NMDeviceCallbackFn) (NMDevice *device, GError *error, gpointer user_data); gboolean nm_device_disconnect (NMDevice *device,
GCancellable *cancellable,
void nm_device_disconnect (NMDevice *device, GError **error);
NMDeviceCallbackFn callback, void nm_device_disconnect_async (NMDevice *device,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data); gpointer user_data);
gboolean nm_device_disconnect_finish (NMDevice *device,
GAsyncResult *result,
GError **error);
void nm_device_delete (NMDevice *device, gboolean nm_device_delete (NMDevice *device,
NMDeviceCallbackFn callback, GCancellable *cancellable,
GError **error);
void nm_device_delete_async (NMDevice *device,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data); gpointer user_data);
gboolean nm_device_delete_finish (NMDevice *device,
GAsyncResult *result,
GError **error);
GSList * nm_device_filter_connections (NMDevice *device, GSList * nm_device_filter_connections (NMDevice *device,
const GSList *connections); const GSList *connections);

View file

@ -54,17 +54,6 @@ enum {
LAST_PROP LAST_PROP
}; };
typedef struct RemoteCall RemoteCall;
typedef void (*RemoteCallFetchResultCb) (RemoteCall *call, GAsyncResult *result);
struct RemoteCall {
NMRemoteConnection *self;
RemoteCallFetchResultCb fetch_result_cb;
GFunc callback;
gpointer user_data;
};
typedef struct { typedef struct {
NMDBusSettingsConnection *proxy; NMDBusSettingsConnection *proxy;
@ -94,271 +83,431 @@ nm_remote_connection_error_quark (void)
/****************************************************************/ /****************************************************************/
static void
remote_call_dbus_cb (GObject *proxy, GAsyncResult *result, gpointer user_data)
{
RemoteCall *call = user_data;
call->fetch_result_cb (call, result);
g_object_unref (call->self);
g_free (call);
}
static RemoteCall *
remote_call_new (NMRemoteConnection *self,
RemoteCallFetchResultCb fetch_result_cb,
GFunc callback,
gpointer user_data)
{
RemoteCall *call;
g_assert (fetch_result_cb);
call = g_malloc0 (sizeof (RemoteCall));
call->self = g_object_ref (self);
call->fetch_result_cb = fetch_result_cb;
call->user_data = user_data;
call->callback = callback;
return call;
}
/****************************************************************/
static void
update_result_cb (RemoteCall *call, GAsyncResult *result)
{
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (call->self);
NMRemoteConnectionResultFunc func = (NMRemoteConnectionResultFunc) call->callback;
GError *error = NULL;
nmdbus_settings_connection_call_update_finish (priv->proxy, result, &error);
if (func)
(*func) (call->self, error, call->user_data);
g_clear_error (&error);
}
/** /**
* nm_remote_connection_commit_changes: * nm_remote_connection_commit_changes:
* @connection: the #NMRemoteConnection * @connection: the #NMRemoteConnection
* @callback: (scope async) (allow-none): a function to be called when the * @save_to_disk: whether to persist the changes to disk
* commit completes * @cancellable: a #GCancellable, or %NULL
* @user_data: (closure): caller-specific data to be passed to @callback * @error: location for a #GError, or %NULL
* *
* Send any local changes to the settings and properties of this connection to * Send any local changes to the settings and properties of @connection to
* NetworkManager, which will immediately save them to disk. * NetworkManager. If @save_to_disk is %TRUE, the updated connection will be saved to
* disk; if %FALSE, then only the in-memory representation will be changed.
*
* Returns: %TRUE on success, %FALSE on error, in which case @error will be set.
**/ **/
void gboolean
nm_remote_connection_commit_changes (NMRemoteConnection *self, nm_remote_connection_commit_changes (NMRemoteConnection *connection,
NMRemoteConnectionResultFunc callback, gboolean save_to_disk,
gpointer user_data) GCancellable *cancellable,
GError **error)
{ {
NMRemoteConnectionPrivate *priv; NMRemoteConnectionPrivate *priv;
RemoteCall *call;
GVariant *settings; GVariant *settings;
g_return_if_fail (NM_IS_REMOTE_CONNECTION (self)); g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), FALSE);
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self); priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection);
call = remote_call_new (self, update_result_cb, (GFunc) callback, user_data); settings = nm_connection_to_dbus (NM_CONNECTION (connection), NM_CONNECTION_SERIALIZE_ALL);
if (!call) if (save_to_disk) {
return; return nmdbus_settings_connection_call_update_sync (priv->proxy,
settings,
settings = nm_connection_to_dbus (NM_CONNECTION (self), NM_CONNECTION_SERIALIZE_ALL); cancellable, error);
nmdbus_settings_connection_call_update (priv->proxy, } else {
settings, return nmdbus_settings_connection_call_update_unsaved_sync (priv->proxy,
NULL, settings,
remote_call_dbus_cb, call); cancellable, error);
}
} }
static void static void
update_unsaved_result_cb (RemoteCall *call, GAsyncResult *result) update_cb (GObject *proxy, GAsyncResult *result, gpointer user_data)
{ {
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (call->self); GSimpleAsyncResult *simple = user_data;
NMRemoteConnectionResultFunc func = (NMRemoteConnectionResultFunc) call->callback; gboolean (*finish_func) (NMDBusSettingsConnection *, GAsyncResult *, GError **);
GError *error = NULL; GError *error = NULL;
nmdbus_settings_connection_call_update_unsaved_finish (priv->proxy, result, &error); finish_func = g_object_get_data (G_OBJECT (simple), "finish_func");
if (func) if (finish_func (NMDBUS_SETTINGS_CONNECTION (proxy), result, &error))
(*func) (call->self, error, call->user_data); g_simple_async_result_set_op_res_gboolean (simple, TRUE);
g_clear_error (&error); else
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete (simple);
g_object_unref (simple);
} }
/** /**
* nm_remote_connection_commit_changes_unsaved: * nm_remote_connection_commit_changes_async:
* @connection: the #NMRemoteConnection * @connection: the #NMRemoteConnection
* @callback: (scope async) (allow-none): a function to be called when the * @save_to_disk: whether to save the changes to persistent storage
* commit completes * @cancellable: a #GCancellable, or %NULL
* @user_data: (closure): caller-specific data to be passed to @callback * @callback: callback to be called when the commit operation completes
* @user_data: caller-specific data passed to @callback
* *
* Send any local changes to the settings and properties of this connection to * Asynchronously sends any local changes to the settings and properties of
* NetworkManager. The changes are not saved to disk until either * @connection to NetworkManager. If @save is %TRUE, the updated connection will
* nm_remote_connection_save() or nm_remote_connection_commit_changes() is * be saved to disk; if %FALSE, then only the in-memory representation will be
* called. * changed.
**/ **/
void void
nm_remote_connection_commit_changes_unsaved (NMRemoteConnection *connection, nm_remote_connection_commit_changes_async (NMRemoteConnection *connection,
NMRemoteConnectionResultFunc callback, gboolean save_to_disk,
gpointer user_data) GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{ {
NMRemoteConnectionPrivate *priv; NMRemoteConnectionPrivate *priv;
GSimpleAsyncResult *simple;
GVariant *settings; GVariant *settings;
RemoteCall *call;
g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection)); g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection));
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection); priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection);
call = remote_call_new (connection, update_unsaved_result_cb, (GFunc) callback, user_data); simple = g_simple_async_result_new (G_OBJECT (connection), callback, user_data,
if (!call) nm_remote_connection_commit_changes_async);
return;
settings = nm_connection_to_dbus (NM_CONNECTION (connection), NM_CONNECTION_SERIALIZE_ALL); settings = nm_connection_to_dbus (NM_CONNECTION (connection), NM_CONNECTION_SERIALIZE_ALL);
nmdbus_settings_connection_call_update_unsaved (priv->proxy, if (save_to_disk) {
settings, g_object_set_data (G_OBJECT (simple), "finish_func",
NULL, nmdbus_settings_connection_call_update_finish);
remote_call_dbus_cb, call); nmdbus_settings_connection_call_update (priv->proxy,
settings,
cancellable,
update_cb, simple);
} else {
g_object_set_data (G_OBJECT (simple), "finish_func",
nmdbus_settings_connection_call_update_unsaved_finish);
nmdbus_settings_connection_call_update_unsaved (priv->proxy,
settings,
cancellable,
update_cb, simple);
}
} }
static void /**
save_result_cb (RemoteCall *call, GAsyncResult *result) * nm_remote_connection_commit_changes_finish:
* @connection: the #NMRemoteConnection
* @result: the result passed to the #GAsyncReadyCallback
* @error: location for a #GError, or %NULL
*
* Gets the result of a call to nm_remote_connection_commit_changes_async().
*
* Returns: %TRUE on success, %FALSE on error, in which case @error will be set.
**/
gboolean
nm_remote_connection_commit_changes_finish (NMRemoteConnection *connection,
GAsyncResult *result,
GError **error)
{ {
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (call->self); GSimpleAsyncResult *simple;
NMRemoteConnectionResultFunc func = (NMRemoteConnectionResultFunc) call->callback;
GError *error = NULL;
nmdbus_settings_connection_call_save_finish (priv->proxy, result, &error); g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (connection), nm_remote_connection_commit_changes_async), FALSE);
if (func)
(*func) (call->self, error, call->user_data); simple = G_SIMPLE_ASYNC_RESULT (result);
g_clear_error (&error); if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else
return g_simple_async_result_get_op_res_gboolean (simple);
} }
/** /**
* nm_remote_connection_save: * nm_remote_connection_save:
* @connection: the #NMRemoteConnection * @connection: the #NMRemoteConnection
* @callback: (scope async) (allow-none): a function to be called when the * @cancellable: a #GCancellable, or %NULL
* save completes * @error: location for a #GError, or %NULL
* @user_data: (closure): caller-specific data to be passed to @callback *
* Saves the connection to disk if the connection has changes that have not yet
* been written to disk, or if the connection has never been saved.
*
* Returns: %TRUE on success, %FALSE on error, in which case @error will be set.
**/
gboolean
nm_remote_connection_save (NMRemoteConnection *connection,
GCancellable *cancellable,
GError **error)
{
NMRemoteConnectionPrivate *priv;
g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), FALSE);
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection);
return nmdbus_settings_connection_call_save_sync (priv->proxy, cancellable, error);
}
static void
save_cb (GObject *proxy, GAsyncResult *result, gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
GError *error = NULL;
if (nmdbus_settings_connection_call_save_finish (NMDBUS_SETTINGS_CONNECTION (proxy),
result, &error))
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
else
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete (simple);
g_object_unref (simple);
}
/**
* nm_remote_connection_save_async:
* @connection: the #NMRemoteConnection
* @cancellable: a #GCancellable, or %NULL
* @callback: callback to be called when the save operation completes
* @user_data: caller-specific data passed to @callback
* *
* Saves the connection to disk if the connection has changes that have not yet * Saves the connection to disk if the connection has changes that have not yet
* been written to disk, or if the connection has never been saved. * been written to disk, or if the connection has never been saved.
**/ **/
void void
nm_remote_connection_save (NMRemoteConnection *connection, nm_remote_connection_save_async (NMRemoteConnection *connection,
NMRemoteConnectionResultFunc callback, GCancellable *cancellable,
gpointer user_data) GAsyncReadyCallback callback,
gpointer user_data)
{ {
NMRemoteConnectionPrivate *priv; NMRemoteConnectionPrivate *priv;
RemoteCall *call; GSimpleAsyncResult *simple;
g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection)); g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection));
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection); priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection);
call = remote_call_new (connection, save_result_cb, (GFunc) callback, user_data); simple = g_simple_async_result_new (G_OBJECT (connection), callback, user_data,
if (!call) nm_remote_connection_save_async);
return; nmdbus_settings_connection_call_save (priv->proxy, cancellable, save_cb, simple);
nmdbus_settings_connection_call_save (priv->proxy,
NULL,
remote_call_dbus_cb, call);
} }
static void /**
delete_result_cb (RemoteCall *call, GAsyncResult *result) * nm_remote_connection_save_finish:
* @connection: the #NMRemoteConnection
* @result: the result passed to the #GAsyncReadyCallback
* @error: location for a #GError, or %NULL
*
* Gets the result of a call to nm_remote_connection_save_async().
*
* Returns: %TRUE on success, %FALSE on error, in which case @error will be set.
**/
gboolean
nm_remote_connection_save_finish (NMRemoteConnection *connection,
GAsyncResult *result,
GError **error)
{ {
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (call->self); GSimpleAsyncResult *simple;
NMRemoteConnectionResultFunc func = (NMRemoteConnectionResultFunc) call->callback;
GError *error = NULL;
nmdbus_settings_connection_call_delete_finish (priv->proxy, result, &error); g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (connection), nm_remote_connection_save_async), FALSE);
if (func)
(*func) (call->self, error, call->user_data); simple = G_SIMPLE_ASYNC_RESULT (result);
g_clear_error (&error); if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else
return g_simple_async_result_get_op_res_gboolean (simple);
} }
/** /**
* nm_remote_connection_delete: * nm_remote_connection_delete:
* @connection: the #NMRemoteConnection * @connection: the #NMRemoteConnection
* @callback: (scope async) (allow-none): a function to be called when the delete completes * @cancellable: a #GCancellable, or %NULL
* @user_data: (closure): caller-specific data to be passed to @callback * @error: location for a #GError, or %NULL
* *
* Delete the connection. * Deletes the connection.
*
* Returns: %TRUE on success, %FALSE on error, in which case @error will be set.
**/ **/
void gboolean
nm_remote_connection_delete (NMRemoteConnection *self, nm_remote_connection_delete (NMRemoteConnection *connection,
NMRemoteConnectionResultFunc callback, GCancellable *cancellable,
gpointer user_data) GError **error)
{ {
NMRemoteConnectionPrivate *priv; NMRemoteConnectionPrivate *priv;
RemoteCall *call;
g_return_if_fail (NM_IS_REMOTE_CONNECTION (self)); g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection));
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self); priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection);
call = remote_call_new (self, delete_result_cb, (GFunc) callback, user_data); return nmdbus_settings_connection_call_delete_sync (priv->proxy, cancellable, error);
if (!call)
return;
nmdbus_settings_connection_call_delete (priv->proxy,
NULL,
remote_call_dbus_cb, call);
} }
static void static void
get_secrets_cb (RemoteCall *call, GAsyncResult *result) delete_cb (GObject *proxy, GAsyncResult *result, gpointer user_data)
{ {
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (call->self); GSimpleAsyncResult *simple = user_data;
NMRemoteConnectionGetSecretsFunc func = (NMRemoteConnectionGetSecretsFunc) call->callback;
GVariant *secrets = NULL;
GError *error = NULL; GError *error = NULL;
if (!nmdbus_settings_connection_call_get_secrets_finish (priv->proxy, &secrets, if (nmdbus_settings_connection_call_delete_finish (NMDBUS_SETTINGS_CONNECTION (proxy),
result, &error)) result, &error))
secrets = NULL; g_simple_async_result_set_op_res_gboolean (simple, TRUE);
if (func) else
(*func) (call->self, error ? NULL : secrets, error, call->user_data); g_simple_async_result_take_error (simple, error);
g_clear_error (&error); g_simple_async_result_complete (simple);
if (secrets) g_object_unref (simple);
g_variant_unref (secrets);
} }
/**
* nm_remote_connection_delete_async:
* @connection: the #NMRemoteConnection
* @cancellable: a #GCancellable, or %NULL
* @callback: callback to be called when the delete operation completes
* @user_data: caller-specific data passed to @callback
*
* Asynchronously deletes the connection.
**/
void
nm_remote_connection_delete_async (NMRemoteConnection *connection,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
NMRemoteConnectionPrivate *priv;
GSimpleAsyncResult *simple;
g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection));
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection);
simple = g_simple_async_result_new (G_OBJECT (connection), callback, user_data,
nm_remote_connection_delete_async);
nmdbus_settings_connection_call_delete (priv->proxy, cancellable, delete_cb, simple);
}
/**
* nm_remote_connection_delete_finish:
* @connection: the #NMRemoteConnection
* @result: the result passed to the #GAsyncReadyCallback
* @error: location for a #GError, or %NULL
*
* Gets the result of a call to nm_remote_connection_delete_async().
*
* Returns: %TRUE on success, %FALSE on error, in which case @error will be set.
**/
gboolean
nm_remote_connection_delete_finish (NMRemoteConnection *connection,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (connection), nm_remote_connection_delete_async), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else
return g_simple_async_result_get_op_res_gboolean (simple);
}
/** /**
* nm_remote_connection_get_secrets: * nm_remote_connection_get_secrets:
* @connection: the #NMRemoteConnection * @connection: the #NMRemoteConnection
* @setting_name: the #NMSetting object name to get secrets for * @setting_name: the #NMSetting object name to get secrets for
* @callback: (scope async): a function to be called when the update completes; * @cancellable: a #GCancellable, or %NULL
* must not be %NULL * @error: location for a #GError, or %NULL
* @user_data: (closure): caller-specific data to be passed to @callback
* *
* Request the connection's secrets. * Request the connection's secrets. Note that this is a blocking D-Bus call,
* not a simple property accessor.
*
* Returns: a #GVariant of type %NM_VARIANT_TYPE_CONNECTION containing
* @connection's secrets, or %NULL on error.
**/ **/
void GVariant *
nm_remote_connection_get_secrets (NMRemoteConnection *self, nm_remote_connection_get_secrets (NMRemoteConnection *connection,
const char *setting_name, const char *setting_name,
NMRemoteConnectionGetSecretsFunc callback, GCancellable *cancellable,
gpointer user_data) GError **error)
{ {
NMRemoteConnectionPrivate *priv; NMRemoteConnectionPrivate *priv;
RemoteCall *call; GVariant *secrets;
g_return_if_fail (NM_IS_REMOTE_CONNECTION (self)); g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), NULL);
g_return_if_fail (callback != NULL);
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self); priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection);
call = remote_call_new (self, get_secrets_cb, (GFunc) callback, user_data); if (nmdbus_settings_connection_call_get_secrets_sync (priv->proxy,
if (!call) setting_name,
return; &secrets,
cancellable, error))
return secrets;
else
return NULL;
}
static void
get_secrets_cb (GObject *proxy, GAsyncResult *result, gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
GVariant *secrets = NULL;
GError *error = NULL;
if (nmdbus_settings_connection_call_get_secrets_finish (NMDBUS_SETTINGS_CONNECTION (proxy),
&secrets, result, &error))
g_simple_async_result_set_op_res_gpointer (simple, secrets, (GDestroyNotify) g_variant_unref);
else
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete (simple);
g_object_unref (simple);
}
/**
* nm_remote_connection_get_secrets_async:
* @connection: the #NMRemoteConnection
* @setting_name: the #NMSetting object name to get secrets for
* @cancellable: a #GCancellable, or %NULL
* @callback: callback to be called when the secret request completes
* @user_data: caller-specific data passed to @callback
*
* Asynchronously requests the connection's secrets.
**/
void
nm_remote_connection_get_secrets_async (NMRemoteConnection *connection,
const char *setting_name,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
NMRemoteConnectionPrivate *priv;
GSimpleAsyncResult *simple;
g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection));
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection);
simple = g_simple_async_result_new (G_OBJECT (connection), callback, user_data,
nm_remote_connection_get_secrets_async);
nmdbus_settings_connection_call_get_secrets (priv->proxy, nmdbus_settings_connection_call_get_secrets (priv->proxy,
setting_name, setting_name,
NULL, cancellable,
remote_call_dbus_cb, call); get_secrets_cb, simple);
}
/**
* nm_remote_connection_get_secrets_finish:
* @connection: the #NMRemoteConnection
* @result: the result passed to the #GAsyncReadyCallback
* @error: location for a #GError, or %NULL
*
* Gets the result of a call to nm_remote_connection_get_secrets_async().
*
* Returns: (transfer full): a #GVariant of type %NM_VARIANT_TYPE_CONNECTION
* containing @connection's secrets, or %NULL on error.
**/
GVariant *
nm_remote_connection_get_secrets_finish (NMRemoteConnection *connection,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (connection), nm_remote_connection_get_secrets_async), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return NULL;
else
return g_variant_ref (g_simple_async_result_get_op_res_gpointer (simple));
} }
/** /**

View file

@ -69,61 +69,55 @@ typedef struct {
gpointer padding[8]; gpointer padding[8];
} NMRemoteConnectionClass; } NMRemoteConnectionClass;
/**
* NMRemoteConnectionResultFunc:
* @connection: the connection for which an operation was performed
* @error: on failure, a descriptive error
* @user_data: user data passed to function which began the operation
*
* Called when NetworkManager has finished an asynchronous operation on a
* connection, like commit changes, deleting, saving, etc.
*/
typedef void (*NMRemoteConnectionResultFunc) (NMRemoteConnection *connection,
GError *error,
gpointer user_data);
/* Backwards compatibility */
typedef NMRemoteConnectionResultFunc NMRemoteConnectionCommitFunc;
typedef NMRemoteConnectionResultFunc NMRemoteConnectionDeleteFunc;
/**
* NMRemoteConnectionGetSecretsFunc:
* @connection: the connection for which secrets were requested
* @secrets: on success, a #GVariant of type %NM_VARIANT_TYPE_CONNECTION
* containing secrets.
* @error: on failure, a descriptive error
* @user_data: user data passed to nm_remote_connection_get_secrets()
*
* Called when NetworkManager returns secrets in response to a request for
* secrets via nm_remote_connection_get_secrets().
*/
typedef void (*NMRemoteConnectionGetSecretsFunc) (NMRemoteConnection *connection,
GVariant *secrets,
GError *error,
gpointer user_data);
GType nm_remote_connection_get_type (void); GType nm_remote_connection_get_type (void);
void nm_remote_connection_commit_changes (NMRemoteConnection *connection, gboolean nm_remote_connection_commit_changes (NMRemoteConnection *connection,
NMRemoteConnectionResultFunc callback, gboolean save_to_disk,
gpointer user_data); GCancellable *cancellable,
GError **error);
void nm_remote_connection_commit_changes_async (NMRemoteConnection *connection,
gboolean save_to_disk,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean nm_remote_connection_commit_changes_finish (NMRemoteConnection *connection,
GAsyncResult *result,
GError **error);
void nm_remote_connection_commit_changes_unsaved (NMRemoteConnection *connection, gboolean nm_remote_connection_save (NMRemoteConnection *connection,
NMRemoteConnectionResultFunc callback, GCancellable *cancellable,
gpointer user_data); GError **error);
void nm_remote_connection_save_async (NMRemoteConnection *connection,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean nm_remote_connection_save_finish (NMRemoteConnection *connection,
GAsyncResult *result,
GError **error);
void nm_remote_connection_save (NMRemoteConnection *connection, gboolean nm_remote_connection_delete (NMRemoteConnection *connection,
NMRemoteConnectionResultFunc callback, GCancellable *cancellable,
gpointer user_data); GError **error);
void nm_remote_connection_delete_async (NMRemoteConnection *connection,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean nm_remote_connection_delete_finish (NMRemoteConnection *connection,
GAsyncResult *result,
GError **error);
void nm_remote_connection_delete (NMRemoteConnection *connection, GVariant *nm_remote_connection_get_secrets (NMRemoteConnection *connection,
NMRemoteConnectionResultFunc callback, const char *setting_name,
gpointer user_data); GCancellable *cancellable,
GError **error);
void nm_remote_connection_get_secrets (NMRemoteConnection *connection, void nm_remote_connection_get_secrets_async (NMRemoteConnection *connection,
const char *setting_name, const char *setting_name,
NMRemoteConnectionGetSecretsFunc callback, GCancellable *cancellable,
gpointer user_data); GAsyncReadyCallback callback,
gpointer user_data);
GVariant *nm_remote_connection_get_secrets_finish (NMRemoteConnection *connection,
GAsyncResult *result,
GError **error);
gboolean nm_remote_connection_get_unsaved (NMRemoteConnection *connection); gboolean nm_remote_connection_get_unsaved (NMRemoteConnection *connection);

View file

@ -59,14 +59,19 @@
* *
* |[<!-- language="C" --> * |[<!-- language="C" -->
* static void * static void
* added_cb (NMRemoteSettings *settings, * added_cb (GObject *object,
* NMRemoteConnection *remote, * GAsyncResult *result,
* GError *error,
* gpointer user_data) * gpointer user_data)
* { * {
* if (error) * NMRemoteConnection *remote;
* GError *error = NULL;
*
* remote = nm_remote_settings_add_connection_finish (NM_REMOTE_SETTINGS (object),
* result, &error);
* if (error) {
* g_print ("Error adding connection: %s", error->message); * g_print ("Error adding connection: %s", error->message);
* else { * g_clear_error (&error);
* } else {
* g_print ("Added: %s\n", nm_connection_get_path (NM_CONNECTION (remote))); * g_print ("Added: %s\n", nm_connection_get_path (NM_CONNECTION (remote)));
* /&ast; Use 'remote' with nm_remote_connection_commit_changes() to save * /&ast; Use 'remote' with nm_remote_connection_commit_changes() to save
* * changes and nm_remote_connection_delete() to delete the connection &ast;/ * * changes and nm_remote_connection_delete() to delete the connection &ast;/
@ -106,7 +111,8 @@
* nm_connection_add_setting (connection, NM_SETTING (s_ip4)); * nm_connection_add_setting (connection, NM_SETTING (s_ip4));
* *
* /&ast; Ask NetworkManager to store the connection &ast;/ * /&ast; Ask NetworkManager to store the connection &ast;/
* success = nm_remote_settings_add_connection (settings, connection, added_cb, loop); * success = nm_remote_settings_add_connection_async (settings, connection,
* NULL, added_cb, NULL);
* *
* /&ast; Release the template connection; the actual stored connection will * /&ast; Release the template connection; the actual stored connection will
* * be returned in added_cb() &ast;/ * * be returned in added_cb() &ast;/
@ -178,9 +184,9 @@ nm_remote_settings_error_quark (void)
typedef struct { typedef struct {
NMRemoteSettings *self; NMRemoteSettings *self;
NMRemoteSettingsAddConnectionFunc callback; GSimpleAsyncResult *simple;
gpointer callback_data;
char *path; char *path;
gboolean saved;
} AddConnectionInfo; } AddConnectionInfo;
static AddConnectionInfo * static AddConnectionInfo *
@ -199,27 +205,29 @@ add_connection_info_find (NMRemoteSettings *self, const char *path)
return NULL; return NULL;
} }
static void
add_connection_info_dispose (NMRemoteSettings *self, AddConnectionInfo *info)
{
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
priv->add_list = g_slist_remove (priv->add_list, info);
g_free (info->path);
g_free (info);
}
static void static void
add_connection_info_complete (NMRemoteSettings *self, add_connection_info_complete (NMRemoteSettings *self,
AddConnectionInfo *info, AddConnectionInfo *info,
NMRemoteConnection *connection, NMRemoteConnection *connection,
GError *error) GError *error)
{ {
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
g_return_if_fail (info != NULL); g_return_if_fail (info != NULL);
info->callback (info->self, connection, error, info->callback_data); if (connection) {
add_connection_info_dispose (self, info); g_simple_async_result_set_op_res_gpointer (info->simple,
g_object_ref (connection),
g_object_unref);
} else
g_simple_async_result_set_from_error (info->simple, error);
g_simple_async_result_complete (info->simple);
g_object_unref (info->simple);
priv->add_list = g_slist_remove (priv->add_list, info);
g_free (info->path);
g_slice_free (AddConnectionInfo, info);
} }
typedef const char * (*ConnectionStringGetter) (NMConnection *); typedef const char * (*ConnectionStringGetter) (NMConnection *);
@ -424,125 +432,140 @@ nm_remote_settings_list_connections (NMRemoteSettings *settings)
return list; return list;
} }
static gboolean
settings_service_is_running (NMRemoteSettings *settings, GError **error)
{
if (!_nm_object_get_nm_running (NM_OBJECT (settings))) {
g_set_error_literal (error, NM_REMOTE_SETTINGS_ERROR,
NM_REMOTE_SETTINGS_ERROR_SERVICE_UNAVAILABLE,
"NetworkManager is not running.");
return FALSE;
} else
return TRUE;
}
static void static void
add_connection_done (GObject *proxy, GAsyncResult *result, gpointer user_data) add_connection_done (GObject *proxy, GAsyncResult *result, gpointer user_data)
{ {
AddConnectionInfo *info = user_data; AddConnectionInfo *info = user_data;
GError *error = NULL; GError *error = NULL;
if (nmdbus_settings_call_add_connection_finish (NMDBUS_SETTINGS (proxy), if (info->saved) {
&info->path, nmdbus_settings_call_add_connection_finish (NMDBUS_SETTINGS (proxy),
result, &error)) { &info->path,
/* Wait until this connection is fully initialized before calling the callback */ result, &error);
} else { } else {
nmdbus_settings_call_add_connection_unsaved_finish (NMDBUS_SETTINGS (proxy),
&info->path,
result, &error);
}
if (error) {
add_connection_info_complete (info->self, info, NULL, error); add_connection_info_complete (info->self, info, NULL, error);
g_clear_error (&error); g_clear_error (&error);
} }
/* On success, we still have to wait until the connection is fully
* initialized before calling the callback.
*/
} }
/** /**
* nm_remote_settings_add_connection: * nm_remote_settings_add_connection_async:
* @settings: the %NMRemoteSettings * @settings: the %NMRemoteSettings
* @connection: the connection to add. Note that this object's settings will be * @connection: the connection to add. Note that this object's settings will be
* added, not the object itself * added, not the object itself
* @save_to_disk: whether to immediately save the connection to disk
* @cancellable: a #GCancellable, or %NULL
* @callback: (scope async): callback to be called when the add operation completes * @callback: (scope async): callback to be called when the add operation completes
* @user_data: (closure): caller-specific data passed to @callback * @user_data: (closure): caller-specific data passed to @callback
* *
* Requests that the remote settings service add the given settings to a new * Requests that the remote settings service add the given settings to a new
* connection. The connection is immediately written to disk. @connection is * connection. If @save_to_disk is %TRUE, the connection is immediately written
* untouched by this function and only serves as a template of the settings to * to disk; otherwise it is initially only stored in memory, but may be saved
* add. The #NMRemoteConnection object that represents what NetworkManager * later by calling the connection's nm_remote_connection_commit_changes()
* actually added is returned to @callback when the addition operation is complete. * method.
*
* @connection is untouched by this function and only serves as a template of
* the settings to add. The #NMRemoteConnection object that represents what
* NetworkManager actually added is returned to @callback when the addition
* operation is complete.
* *
* Note that the #NMRemoteConnection returned in @callback may not contain * Note that the #NMRemoteConnection returned in @callback may not contain
* identical settings to @connection as NetworkManager may perform automatic * identical settings to @connection as NetworkManager may perform automatic
* completion and/or normalization of connection properties. * completion and/or normalization of connection properties.
*
* Returns: %TRUE if the request was successful, %FALSE if it failed
**/ **/
gboolean void
nm_remote_settings_add_connection (NMRemoteSettings *settings, nm_remote_settings_add_connection_async (NMRemoteSettings *settings,
NMConnection *connection, NMConnection *connection,
NMRemoteSettingsAddConnectionFunc callback, gboolean save_to_disk,
gpointer user_data) GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{ {
NMRemoteSettingsPrivate *priv; NMRemoteSettingsPrivate *priv;
AddConnectionInfo *info; AddConnectionInfo *info;
GVariant *new_settings; GVariant *new_settings;
GError *error = NULL;
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE); g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE);
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
g_return_val_if_fail (callback != NULL, FALSE);
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
if (!_nm_object_get_nm_running (NM_OBJECT (settings))) if (!settings_service_is_running (settings, &error)) {
return FALSE; g_simple_async_report_take_gerror_in_idle (G_OBJECT (settings), callback, user_data, error);
return;
}
info = g_malloc0 (sizeof (AddConnectionInfo)); info = g_slice_new0 (AddConnectionInfo);
info->self = settings; info->self = settings;
info->callback = callback; info->simple = g_simple_async_result_new (G_OBJECT (settings), callback, user_data,
info->callback_data = user_data; nm_remote_settings_add_connection_async);
info->saved = save_to_disk;
new_settings = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL); new_settings = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL);
nmdbus_settings_call_add_connection (priv->proxy,
new_settings, if (save_to_disk) {
NULL, nmdbus_settings_call_add_connection (priv->proxy,
add_connection_done, info); new_settings,
NULL,
add_connection_done, info);
} else {
nmdbus_settings_call_add_connection_unsaved (priv->proxy,
new_settings,
NULL,
add_connection_done, info);
}
priv->add_list = g_slist_append (priv->add_list, info); priv->add_list = g_slist_append (priv->add_list, info);
return TRUE;
} }
/** /**
* nm_remote_settings_add_connection_unsaved: * nm_remote_settings_add_connection_finish:
* @settings: the %NMRemoteSettings * @settings: an #NMRemoteSettings
* @connection: the connection to add. Note that this object's settings will be * @result: the result passed to the #GAsyncReadyCallback
* added, not the object itself * @error: location for a #GError, or %NULL
* @callback: (scope async): callback to be called when the add operation completes
* @user_data: (closure): caller-specific data passed to @callback
* *
* Requests that the remote settings service add the given settings to a new * Gets the result of a call to nm_remote_settings_add_connection_async().
* connection. The connection is not written to disk, which may be done at
* a later time by calling the connection's nm_remote_connection_commit_changes()
* method.
* *
* Returns: %TRUE if the request was successful, %FALSE if it failed * Returns: (transfer full): the new #NMRemoteConnection on success, %NULL on
* failure, in which case @error will be set.
**/ **/
gboolean NMRemoteConnection *
nm_remote_settings_add_connection_unsaved (NMRemoteSettings *settings, nm_remote_settings_add_connection_finish (NMRemoteSettings *settings,
NMConnection *connection, GAsyncResult *result,
NMRemoteSettingsAddConnectionFunc callback, GError **error)
gpointer user_data)
{ {
NMRemoteSettingsPrivate *priv; GSimpleAsyncResult *simple;
AddConnectionInfo *info;
GVariant *new_settings;
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE); g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (settings), nm_remote_settings_add_connection_async), NULL);
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
g_return_val_if_fail (callback != NULL, FALSE);
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
if (!_nm_object_get_nm_running (NM_OBJECT (settings))) return NULL;
return FALSE; else
return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
info = g_malloc0 (sizeof (AddConnectionInfo));
info->self = settings;
info->callback = callback;
info->callback_data = user_data;
new_settings = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL);
nmdbus_settings_call_add_connection_unsaved (priv->proxy,
new_settings,
NULL,
add_connection_done, info);
priv->add_list = g_slist_append (priv->add_list, info);
return TRUE;
} }
/** /**
@ -551,6 +574,7 @@ nm_remote_settings_add_connection_unsaved (NMRemoteSettings *settings,
* @filenames: %NULL-terminated array of filenames to load * @filenames: %NULL-terminated array of filenames to load
* @failures: (out) (transfer full): on return, a %NULL-terminated array of * @failures: (out) (transfer full): on return, a %NULL-terminated array of
* filenames that failed to load * filenames that failed to load
* @cancellable: a #GCancellable, or %NULL
* @error: return location for #GError * @error: return location for #GError
* *
* Requests that the remote settings service load or reload the given files, * Requests that the remote settings service load or reload the given files,
@ -564,7 +588,7 @@ nm_remote_settings_add_connection_unsaved (NMRemoteSettings *settings,
* NetworkManager tried to load the files, but some (or all) failed, * NetworkManager tried to load the files, but some (or all) failed,
* then @failures will be set to a %NULL-terminated array of the * then @failures will be set to a %NULL-terminated array of the
* filenames that failed to load. * filenames that failed to load.
*
* Returns: %TRUE if NetworkManager at least tried to load @filenames, * Returns: %TRUE if NetworkManager at least tried to load @filenames,
* %FALSE if an error occurred (eg, permission denied). * %FALSE if an error occurred (eg, permission denied).
**/ **/
@ -572,6 +596,7 @@ gboolean
nm_remote_settings_load_connections (NMRemoteSettings *settings, nm_remote_settings_load_connections (NMRemoteSettings *settings,
char **filenames, char **filenames,
char ***failures, char ***failures,
GCancellable *cancellable,
GError **error) GError **error)
{ {
NMRemoteSettingsPrivate *priv; NMRemoteSettingsPrivate *priv;
@ -582,26 +607,120 @@ nm_remote_settings_load_connections (NMRemoteSettings *settings,
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
if (!_nm_object_get_nm_running (NM_OBJECT (settings))) { if (!settings_service_is_running (settings, error))
g_set_error_literal (error, NM_REMOTE_SETTINGS_ERROR,
NM_REMOTE_SETTINGS_ERROR_SERVICE_UNAVAILABLE,
"NetworkManager is not running.");
return FALSE; return FALSE;
}
if (!nmdbus_settings_call_load_connections_sync (priv->proxy, if (!nmdbus_settings_call_load_connections_sync (priv->proxy,
(const char * const *) filenames, (const char * const *) filenames,
&success, &success,
failures, failures,
NULL, error)) cancellable, error))
success = FALSE; success = FALSE;
return success; return success;
} }
static void
load_connections_cb (GObject *proxy, GAsyncResult *result, gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
GError *error = NULL;
gboolean success;
char **failures = NULL;
if (nmdbus_settings_call_load_connections_finish (NMDBUS_SETTINGS (proxy),
&success, &failures,
result, &error))
g_simple_async_result_set_op_res_gpointer (simple, failures, (GDestroyNotify) g_strfreev);
else
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete (simple);
g_object_unref (simple);
}
/**
* nm_remote_settings_load_connections_async:
* @settings: the %NMRemoteSettings
* @filenames: %NULL-terminated array of filenames to load
* @cancellable: a #GCancellable, or %NULL
* @callback: (scope async): callback to be called when the operation completes
* @user_data: (closure): caller-specific data passed to @callback
*
* Requests that the remote settings service asynchronously load or reload the
* given files, adding or updating the connections described within.
*
* See nm_remote_settings_load_connections() for more details.
**/
void
nm_remote_settings_load_connections_async (NMRemoteSettings *settings,
char **filenames,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
NMRemoteSettingsPrivate *priv;
GSimpleAsyncResult *simple;
GError *error = NULL;
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE);
g_return_val_if_fail (filenames != NULL, FALSE);
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
simple = g_simple_async_result_new (G_OBJECT (settings), callback, user_data,
nm_remote_settings_load_connections_async);
if (!settings_service_is_running (settings, &error)) {
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete_in_idle (simple);
g_object_unref (simple);
return;
}
nmdbus_settings_call_load_connections (priv->proxy,
(const char * const *) filenames,
cancellable, load_connections_cb, simple);
}
/**
* nm_remote_settings_load_connections_finish:
* @settings: the %NMRemoteSettings
* @failures: (out) (transfer full): on return, a %NULL-terminated array of
* filenames that failed to load
* @result: the result passed to the #GAsyncReadyCallback
* @error: location for a #GError, or %NULL
*
* Gets the result of an nm_remote_settings_load_connections_async() call.
* See nm_remote_settings_load_connections() for more details.
*
* Returns: %TRUE if NetworkManager at least tried to load @filenames,
* %FALSE if an error occurred (eg, permission denied).
**/
gboolean
nm_remote_settings_load_connections_finish (NMRemoteSettings *settings,
char ***failures,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (settings), nm_remote_settings_load_connections_async), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else {
*failures = g_strdupv (g_simple_async_result_get_op_res_gpointer (simple));
return TRUE;
}
}
/** /**
* nm_remote_settings_reload_connections: * nm_remote_settings_reload_connections:
* @settings: the #NMRemoteSettings * @settings: the #NMRemoteSettings
* @cancellable: a #GCancellable, or %NULL
* @error: return location for #GError * @error: return location for #GError
* *
* Requests that the remote settings service reload all connection * Requests that the remote settings service reload all connection
@ -612,6 +731,7 @@ nm_remote_settings_load_connections (NMRemoteSettings *settings,
**/ **/
gboolean gboolean
nm_remote_settings_reload_connections (NMRemoteSettings *settings, nm_remote_settings_reload_connections (NMRemoteSettings *settings,
GCancellable *cancellable,
GError **error) GError **error)
{ {
NMRemoteSettingsPrivate *priv; NMRemoteSettingsPrivate *priv;
@ -621,48 +741,106 @@ nm_remote_settings_reload_connections (NMRemoteSettings *settings,
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
if (!_nm_object_get_nm_running (NM_OBJECT (settings))) { if (!settings_service_is_running (settings, error))
g_set_error_literal (error, NM_REMOTE_SETTINGS_ERROR,
NM_REMOTE_SETTINGS_ERROR_SERVICE_UNAVAILABLE,
"NetworkManager is not running.");
return FALSE; return FALSE;
}
if (!nmdbus_settings_call_reload_connections_sync (priv->proxy, &success, if (!nmdbus_settings_call_reload_connections_sync (priv->proxy, &success,
NULL, error)) cancellable, error))
success = FALSE; success = FALSE;
return success; return success;
} }
typedef struct {
NMRemoteSettings *settings;
NMRemoteSettingsSaveHostnameFunc callback;
gpointer callback_data;
} SaveHostnameInfo;
static void static void
save_hostname_cb (GObject *proxy, reload_connections_cb (GObject *proxy, GAsyncResult *result, gpointer user_data)
GAsyncResult *result,
gpointer user_data)
{ {
SaveHostnameInfo *info = user_data; GSimpleAsyncResult *simple = user_data;
gboolean success;
GError *error = NULL; GError *error = NULL;
nmdbus_settings_call_save_hostname_finish (NMDBUS_SETTINGS (proxy), result, &error); if (nmdbus_settings_call_reload_connections_finish (NMDBUS_SETTINGS (proxy),
if (info->callback != NULL) &success,
info->callback (info->settings, error, info->callback_data); result, &error))
g_clear_error (&error); g_simple_async_result_set_op_res_gboolean (simple, success);
else
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete (simple);
g_object_unref (simple);
}
/**
* nm_remote_settings_reload_connections_async:
* @settings: the #NMRemoteSettings
* @cancellable: a #GCancellable, or %NULL
* @callback: (scope async): callback to be called when the reload operation completes
* @user_data: (closure): caller-specific data passed to @callback
*
* Requests that the remote settings service begin reloading all connection
* files from disk, adding, updating, and removing connections until the
* in-memory state matches the on-disk state.
**/
void
nm_remote_settings_reload_connections_async (NMRemoteSettings *settings,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
NMRemoteSettingsPrivate *priv;
GSimpleAsyncResult *simple;
GError *error = NULL;
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE);
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
simple = g_simple_async_result_new (G_OBJECT (settings), callback, user_data,
nm_remote_settings_reload_connections_async);
if (!settings_service_is_running (settings, &error)) {
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete_in_idle (simple);
g_object_unref (simple);
return;
}
nmdbus_settings_call_reload_connections (priv->proxy, cancellable,
reload_connections_cb, simple);
}
/**
* nm_remote_settings_reload_connections_finish:
* @settings: the #NMRemoteSettings
* @result: the result passed to the #GAsyncReadyCallback
* @error: return location for #GError
*
* Gets the result of an nm_remote_settings_reload_connections_async() call.
*
* Return value: %TRUE on success, %FALSE on failure
**/
gboolean
nm_remote_settings_reload_connections_finish (NMRemoteSettings *settings,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (settings), nm_remote_settings_reload_connections_async), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else
return g_simple_async_result_get_op_res_gboolean (simple);
} }
/** /**
* nm_remote_settings_save_hostname: * nm_remote_settings_save_hostname:
* @settings: the %NMRemoteSettings * @settings: the %NMRemoteSettings
* @hostname: the new persistent hostname to set, or %NULL to clear any existing * @hostname: (allow-none): the new persistent hostname to set, or %NULL to
* persistent hostname * clear any existing persistent hostname
* @callback: (scope async) (allow-none): callback to be called when the * @cancellable: a #GCancellable, or %NULL
* hostname operation completes * @error: return location for #GError
* @user_data: (closure): caller-specific data passed to @callback
* *
* Requests that the machine's persistent hostname be set to the specified value * Requests that the machine's persistent hostname be set to the specified value
* or cleared. * or cleared.
@ -672,31 +850,105 @@ save_hostname_cb (GObject *proxy,
gboolean gboolean
nm_remote_settings_save_hostname (NMRemoteSettings *settings, nm_remote_settings_save_hostname (NMRemoteSettings *settings,
const char *hostname, const char *hostname,
NMRemoteSettingsSaveHostnameFunc callback, GCancellable *cancellable,
gpointer user_data) GError **error)
{ {
NMRemoteSettingsPrivate *priv; NMRemoteSettingsPrivate *priv;
SaveHostnameInfo *info;
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE); g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE);
g_return_val_if_fail (hostname != NULL, FALSE);
g_return_val_if_fail (callback != NULL, FALSE);
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
if (!_nm_object_get_nm_running (NM_OBJECT (settings))) if (!settings_service_is_running (settings, error))
return FALSE; return FALSE;
info = g_malloc0 (sizeof (SaveHostnameInfo)); return nmdbus_settings_call_save_hostname_sync (priv->proxy,
info->settings = settings; hostname ? hostname : "",
info->callback = callback; cancellable, error);
info->callback_data = user_data; }
static void
save_hostname_cb (GObject *proxy,
GAsyncResult *result,
gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
GError *error = NULL;
if (nmdbus_settings_call_save_hostname_finish (NMDBUS_SETTINGS (proxy), result, &error))
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
else
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete (simple);
g_object_unref (simple);
}
/**
* nm_remote_settings_save_hostname_async:
* @settings: the %NMRemoteSettings
* @hostname: (allow-none): the new persistent hostname to set, or %NULL to
* clear any existing persistent hostname
* @cancellable: a #GCancellable, or %NULL
* @callback: (scope async): callback to be called when the operation completes
* @user_data: (closure): caller-specific data passed to @callback
*
* Requests that the machine's persistent hostname be set to the specified value
* or cleared.
**/
void
nm_remote_settings_save_hostname_async (NMRemoteSettings *settings,
const char *hostname,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
NMRemoteSettingsPrivate *priv;
GSimpleAsyncResult *simple;
GError *error = NULL;
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE);
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
simple = g_simple_async_result_new (G_OBJECT (settings), callback, user_data,
nm_remote_settings_save_hostname_async);
if (!settings_service_is_running (settings, &error)) {
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete_in_idle (simple);
g_object_unref (simple);
return;
}
nmdbus_settings_call_save_hostname (priv->proxy, nmdbus_settings_call_save_hostname (priv->proxy,
hostname ? hostname : "", hostname ? hostname : "",
NULL, cancellable, save_hostname_cb, simple);
save_hostname_cb, info); }
return TRUE;
/**
* nm_remote_settings_save_hostname_finish:
* @settings: the %NMRemoteSettings
* @result: the result passed to the #GAsyncReadyCallback
* @error: return location for #GError
*
* Gets the result of an nm_remote_settings_save_hostname_async() call.
*
* Returns: %TRUE if the request was successful, %FALSE if it failed
**/
gboolean
nm_remote_settings_save_hostname_finish (NMRemoteSettings *settings,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (settings), nm_remote_settings_save_hostname_async), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else
return g_simple_async_result_get_op_res_gboolean (simple);
} }
static void static void
@ -889,9 +1141,6 @@ dispose (GObject *object)
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self); NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
int i; int i;
while (g_slist_length (priv->add_list))
add_connection_info_dispose (self, (AddConnectionInfo *) priv->add_list->data);
if (priv->all_connections) { if (priv->all_connections) {
for (i = 0; i < priv->all_connections->len; i++) for (i = 0; i < priv->all_connections->len; i++)
cleanup_connection (self, priv->all_connections->pdata[i]); cleanup_connection (self, priv->all_connections->pdata[i]);

View file

@ -74,22 +74,6 @@ GQuark nm_remote_settings_error_quark (void);
typedef struct _NMRemoteSettings NMRemoteSettings; typedef struct _NMRemoteSettings NMRemoteSettings;
typedef struct _NMRemoteSettingsClass NMRemoteSettingsClass; typedef struct _NMRemoteSettingsClass NMRemoteSettingsClass;
typedef void (*NMRemoteSettingsAddConnectionFunc) (NMRemoteSettings *settings,
NMRemoteConnection *connection,
GError *error,
gpointer user_data);
typedef void (*NMRemoteSettingsLoadConnectionsFunc) (NMRemoteSettings *settings,
char **failures,
GError *error,
gpointer user_data);
typedef void (*NMRemoteSettingsSaveHostnameFunc) (NMRemoteSettings *settings,
GError *error,
gpointer user_data);
struct _NMRemoteSettings { struct _NMRemoteSettings {
NMObject parent; NMObject parent;
}; };
@ -129,28 +113,54 @@ NMRemoteConnection * nm_remote_settings_get_connection_by_path (NMRemoteSettings
NMRemoteConnection *nm_remote_settings_get_connection_by_uuid (NMRemoteSettings *settings, NMRemoteConnection *nm_remote_settings_get_connection_by_uuid (NMRemoteSettings *settings,
const char *uuid); const char *uuid);
gboolean nm_remote_settings_add_connection (NMRemoteSettings *settings, void nm_remote_settings_add_connection_async (NMRemoteSettings *settings,
NMConnection *connection, NMConnection *connection,
NMRemoteSettingsAddConnectionFunc callback, gboolean save_to_disk,
gpointer user_data); GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
NMRemoteConnection *nm_remote_settings_add_connection_finish (NMRemoteSettings *settings,
GAsyncResult *result,
GError **error);
gboolean nm_remote_settings_add_connection_unsaved (NMRemoteSettings *settings, gboolean nm_remote_settings_load_connections (NMRemoteSettings *settings,
NMConnection *connection, char **filenames,
NMRemoteSettingsAddConnectionFunc callback, char ***failures,
gpointer user_data); GCancellable *cancellable,
GError **error);
void nm_remote_settings_load_connections_async (NMRemoteSettings *settings,
char **filenames,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean nm_remote_settings_load_connections_finish (NMRemoteSettings *settings,
char ***failures,
GAsyncResult *result,
GError **error);
gboolean nm_remote_settings_load_connections (NMRemoteSettings *settings, gboolean nm_remote_settings_reload_connections (NMRemoteSettings *settings,
char **filenames, GCancellable *cancellable,
char ***failures, GError **error);
GError **error); void nm_remote_settings_reload_connections_async (NMRemoteSettings *settings,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean nm_remote_settings_reload_connections_finish (NMRemoteSettings *settings,
GAsyncResult *result,
GError **error);
gboolean nm_remote_settings_reload_connections (NMRemoteSettings *settings, gboolean nm_remote_settings_save_hostname (NMRemoteSettings *settings,
GError **error); const char *hostname,
GCancellable *cancellable,
gboolean nm_remote_settings_save_hostname (NMRemoteSettings *settings, GError **error);
const char *hostname, void nm_remote_settings_save_hostname_async (NMRemoteSettings *settings,
NMRemoteSettingsSaveHostnameFunc callback, const char *hostname,
gpointer user_data); GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean nm_remote_settings_save_hostname_finish (NMRemoteSettings *settings,
GAsyncResult *result,
GError **error);
G_END_DECLS G_END_DECLS

View file

@ -37,16 +37,24 @@ NMRemoteConnection *remote = NULL;
/*******************************************************************/ /*******************************************************************/
static void static void
add_cb (NMRemoteSettings *s, add_cb (GObject *s,
NMRemoteConnection *connection, GAsyncResult *result,
GError *error,
gpointer user_data) gpointer user_data)
{ {
gboolean *done = user_data;
GError *error = NULL;
remote = nm_remote_settings_add_connection_finish (settings, result, &error);
g_assert_no_error (error); g_assert_no_error (error);
*((gboolean *) user_data) = TRUE; *done = TRUE;
remote = connection; g_object_add_weak_pointer (G_OBJECT (remote), (void **) &remote);
g_object_add_weak_pointer (G_OBJECT (connection), (void **) &remote);
/* nm_remote_settings_add_connection_finish() adds a ref to @remote, but we
* want the weak pointer to be cleared as soon as @settings drops its own ref.
* So drop ours.
*/
g_object_unref (remote);
} }
#define TEST_CON_ID "blahblahblah" #define TEST_CON_ID "blahblahblah"
@ -55,17 +63,17 @@ static void
test_add_connection (void) test_add_connection (void)
{ {
NMConnection *connection; NMConnection *connection;
gboolean success;
time_t start, now; time_t start, now;
gboolean done = FALSE; gboolean done = FALSE;
connection = nmtst_create_minimal_connection (TEST_CON_ID, NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); connection = nmtst_create_minimal_connection (TEST_CON_ID, NULL, NM_SETTING_WIRED_SETTING_NAME, NULL);
success = nm_remote_settings_add_connection (settings, nm_remote_settings_add_connection_async (settings,
connection, connection,
add_cb, TRUE,
&done); NULL,
g_assert (success == TRUE); add_cb,
&done);
start = time (NULL); start = time (NULL);
do { do {
@ -351,15 +359,19 @@ test_remove_connection (void)
#define TEST_ADD_REMOVE_ID "add-remove-test-connection" #define TEST_ADD_REMOVE_ID "add-remove-test-connection"
static void static void
add_remove_cb (NMRemoteSettings *s, add_remove_cb (GObject *s,
NMRemoteConnection *connection, GAsyncResult *result,
GError *error,
gpointer user_data) gpointer user_data)
{ {
NMRemoteConnection *connection;
gboolean *done = user_data;
GError *error = NULL;
connection = nm_remote_settings_add_connection_finish (settings, result, &error);
g_assert_error (error, NM_REMOTE_SETTINGS_ERROR, NM_REMOTE_SETTINGS_ERROR_CONNECTION_REMOVED); g_assert_error (error, NM_REMOTE_SETTINGS_ERROR, NM_REMOTE_SETTINGS_ERROR_CONNECTION_REMOVED);
g_assert (connection == NULL); g_assert (connection == NULL);
*((gboolean *) user_data) = TRUE; *done = TRUE;
} }
static void static void
@ -368,7 +380,6 @@ test_add_remove_connection (void)
GVariant *ret; GVariant *ret;
GError *error = NULL; GError *error = NULL;
NMConnection *connection; NMConnection *connection;
gboolean success;
time_t start, now; time_t start, now;
gboolean done = FALSE; gboolean done = FALSE;
@ -385,11 +396,12 @@ test_add_remove_connection (void)
g_variant_unref (ret); g_variant_unref (ret);
connection = nmtst_create_minimal_connection (TEST_ADD_REMOVE_ID, NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); connection = nmtst_create_minimal_connection (TEST_ADD_REMOVE_ID, NULL, NM_SETTING_WIRED_SETTING_NAME, NULL);
success = nm_remote_settings_add_connection (settings, nm_remote_settings_add_connection_async (settings,
connection, connection,
add_remove_cb, TRUE,
&done); NULL,
g_assert (success == TRUE); add_remove_cb,
&done);
start = time (NULL); start = time (NULL);
do { do {

View file

@ -219,12 +219,15 @@ device_added_cb (NMClient *c,
} }
static void static void
connection_added_cb (NMRemoteSettings *s, connection_added_cb (GObject *s,
NMRemoteConnection *connection, GAsyncResult *result,
GError *error,
gpointer user_data) gpointer user_data)
{ {
TestSecretAgentData *sadata = user_data; TestSecretAgentData *sadata = user_data;
NMRemoteConnection *connection;
GError *error = NULL;
connection = nm_remote_settings_add_connection_finish (sadata->settings, result, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert_cmpstr (nm_connection_get_id (NM_CONNECTION (connection)), ==, sadata->con_id); g_assert_cmpstr (nm_connection_get_id (NM_CONNECTION (connection)), ==, sadata->con_id);
@ -258,7 +261,6 @@ test_setup (TestSecretAgentData *sadata, gconstpointer test_data)
NMSettingWireless *s_wireless; NMSettingWireless *s_wireless;
GBytes *ssid; GBytes *ssid;
NMSetting *s_wsec; NMSetting *s_wsec;
gboolean success;
GError *error = NULL; GError *error = NULL;
GVariant *ret; GVariant *ret;
gulong handler; gulong handler;
@ -314,11 +316,12 @@ test_setup (TestSecretAgentData *sadata, gconstpointer test_data)
NULL); NULL);
nm_connection_add_setting (connection, s_wsec); nm_connection_add_setting (connection, s_wsec);
success = nm_remote_settings_add_connection (sadata->settings, nm_remote_settings_add_connection_async (sadata->settings,
connection, connection,
connection_added_cb, TRUE,
sadata); NULL,
g_assert (success == TRUE); connection_added_cb,
sadata);
g_object_unref (connection); g_object_unref (connection);
g_main_loop_run (sadata->loop); g_main_loop_run (sadata->loop);
@ -353,6 +356,7 @@ test_cleanup (TestSecretAgentData *sadata, gconstpointer test_data)
g_object_unref (sadata->agent); g_object_unref (sadata->agent);
} }
g_object_unref (sadata->connection);
g_object_unref (sadata->client); g_object_unref (sadata->client);
g_object_unref (sadata->settings); g_object_unref (sadata->settings);
@ -379,12 +383,15 @@ test_cleanup (TestSecretAgentData *sadata, gconstpointer test_data)
/*******************************************************************/ /*******************************************************************/
static void static void
connection_activated_none_cb (NMClient *c, connection_activated_none_cb (GObject *c,
NMActiveConnection *ac, GAsyncResult *result,
GError *error,
gpointer user_data) gpointer user_data)
{ {
TestSecretAgentData *sadata = user_data; TestSecretAgentData *sadata = user_data;
NMActiveConnection *ac;
GError *error = NULL;
ac = nm_client_activate_connection_finish (sadata->client, result, &error);
g_assert (error != NULL); g_assert (error != NULL);
g_dbus_error_strip_remote_error (error); g_dbus_error_strip_remote_error (error);
@ -396,12 +403,13 @@ connection_activated_none_cb (NMClient *c,
static void static void
test_secret_agent_none (TestSecretAgentData *sadata, gconstpointer test_data) test_secret_agent_none (TestSecretAgentData *sadata, gconstpointer test_data)
{ {
nm_client_activate_connection (sadata->client, nm_client_activate_connection_async (sadata->client,
sadata->connection, sadata->connection,
sadata->device, sadata->device,
NULL, NULL,
connection_activated_none_cb, NULL,
sadata); connection_activated_none_cb,
sadata);
g_main_loop_run (sadata->loop); g_main_loop_run (sadata->loop);
} }
@ -424,12 +432,15 @@ secrets_requested_no_secrets_cb (TestSecretAgent *agent,
} }
static void static void
connection_activated_no_secrets_cb (NMClient *c, connection_activated_no_secrets_cb (GObject *c,
NMActiveConnection *ac, GAsyncResult *result,
GError *error,
gpointer user_data) gpointer user_data)
{ {
TestSecretAgentData *sadata = user_data; TestSecretAgentData *sadata = user_data;
NMActiveConnection *ac;
GError *error = NULL;
ac = nm_client_activate_connection_finish (sadata->client, result, &error);
g_assert (error != NULL); g_assert (error != NULL);
g_dbus_error_strip_remote_error (error); g_dbus_error_strip_remote_error (error);
@ -445,12 +456,13 @@ test_secret_agent_no_secrets (TestSecretAgentData *sadata, gconstpointer test_da
G_CALLBACK (secrets_requested_no_secrets_cb), G_CALLBACK (secrets_requested_no_secrets_cb),
sadata); sadata);
nm_client_activate_connection (sadata->client, nm_client_activate_connection_async (sadata->client,
sadata->connection, sadata->connection,
sadata->device, sadata->device,
NULL, NULL,
connection_activated_no_secrets_cb, NULL,
sadata); connection_activated_no_secrets_cb,
sadata);
g_main_loop_run (sadata->loop); g_main_loop_run (sadata->loop);
g_assert_cmpint (sadata->secrets_requested, ==, 1); g_assert_cmpint (sadata->secrets_requested, ==, 1);
@ -459,12 +471,15 @@ test_secret_agent_no_secrets (TestSecretAgentData *sadata, gconstpointer test_da
/*******************************************************************/ /*******************************************************************/
static void static void
connection_activated_cancel_cb (NMClient *c, connection_activated_cancel_cb (GObject *c,
NMActiveConnection *ac, GAsyncResult *result,
GError *error,
gpointer user_data) gpointer user_data)
{ {
TestSecretAgentData *sadata = user_data; TestSecretAgentData *sadata = user_data;
NMActiveConnection *ac;
GError *error = NULL;
ac = nm_client_activate_connection_finish (sadata->client, result, &error);
g_assert (error != NULL); g_assert (error != NULL);
g_dbus_error_strip_remote_error (error); g_dbus_error_strip_remote_error (error);
@ -496,12 +511,13 @@ test_secret_agent_cancel (TestSecretAgentData *sadata, gconstpointer test_data)
G_CALLBACK (secrets_requested_cancel_cb), G_CALLBACK (secrets_requested_cancel_cb),
sadata); sadata);
nm_client_activate_connection (sadata->client, nm_client_activate_connection_async (sadata->client,
sadata->connection, sadata->connection,
sadata->device, sadata->device,
NULL, NULL,
connection_activated_cancel_cb, NULL,
sadata); connection_activated_cancel_cb,
sadata);
g_main_loop_run (sadata->loop); g_main_loop_run (sadata->loop);
g_assert_cmpint (sadata->secrets_requested, ==, 1); g_assert_cmpint (sadata->secrets_requested, ==, 1);
@ -510,12 +526,15 @@ test_secret_agent_cancel (TestSecretAgentData *sadata, gconstpointer test_data)
/*******************************************************************/ /*******************************************************************/
static void static void
connection_activated_good_cb (NMClient *c, connection_activated_good_cb (GObject *c,
NMActiveConnection *ac, GAsyncResult *result,
GError *error,
gpointer user_data) gpointer user_data)
{ {
TestSecretAgentData *sadata = user_data; TestSecretAgentData *sadata = user_data;
NMActiveConnection *ac;
GError *error = NULL;
ac = nm_client_activate_connection_finish (sadata->client, result, &error);
/* test-networkmanager-service.py doesn't implement activation, but /* test-networkmanager-service.py doesn't implement activation, but
* we should at least get as far as the error telling us that (which the * we should at least get as far as the error telling us that (which the
@ -551,12 +570,13 @@ test_secret_agent_good (TestSecretAgentData *sadata, gconstpointer test_data)
G_CALLBACK (secrets_requested_good_cb), G_CALLBACK (secrets_requested_good_cb),
sadata); sadata);
nm_client_activate_connection (sadata->client, nm_client_activate_connection_async (sadata->client,
sadata->connection, sadata->connection,
sadata->device, sadata->device,
NULL, NULL,
connection_activated_good_cb, NULL,
sadata); connection_activated_good_cb,
sadata);
g_main_loop_run (sadata->loop); g_main_loop_run (sadata->loop);
g_assert_cmpint (sadata->secrets_requested, ==, 1); g_assert_cmpint (sadata->secrets_requested, ==, 1);