libnm-glib: implement nm_device_delete() for D-Bus device' Delete() method

This commit is contained in:
Jiří Klimeš 2014-06-19 13:15:09 +02:00
parent 3ff1477349
commit 576c82049b
3 changed files with 58 additions and 14 deletions

View file

@ -104,6 +104,7 @@ global:
nm_device_bt_new;
nm_device_connection_compatible;
nm_device_connection_valid;
nm_device_delete;
nm_device_disambiguate_names;
nm_device_disconnect;
nm_device_error_get_type;

View file

@ -2086,16 +2086,17 @@ nm_device_is_software (NMDevice *device)
typedef struct {
NMDevice *device;
NMDeviceDeactivateFn fn;
NMDeviceCallbackFn fn;
gpointer user_data;
} DeactivateInfo;
const char *method;
} DeviceCallbackInfo;
static void
deactivate_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
gpointer user_data)
device_operation_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
gpointer user_data)
{
DeactivateInfo *info = user_data;
DeviceCallbackInfo *info = user_data;
GError *error = NULL;
dbus_g_proxy_end_call (proxy, call, &error,
@ -2103,16 +2104,17 @@ deactivate_cb (DBusGProxy *proxy,
if (info->fn)
info->fn (info->device, error, info->user_data);
else if (error) {
g_warning ("%s: device %s deactivation failed: (%d) %s",
g_warning ("%s: device %s %s failed: (%d) %s",
__func__,
nm_object_get_path (NM_OBJECT (info->device)),
info->method,
error ? error->code : -1,
error && error->message ? error->message : "(unknown)");
}
g_clear_error (&error);
g_object_unref (info->device);
g_slice_free (DeactivateInfo, info);
g_slice_free (DeviceCallbackInfo, info);
}
/**
@ -2128,20 +2130,52 @@ deactivate_cb (DBusGProxy *proxy,
**/
void
nm_device_disconnect (NMDevice *device,
NMDeviceDeactivateFn callback,
NMDeviceCallbackFn callback,
gpointer user_data)
{
DeactivateInfo *info;
DeviceCallbackInfo *info;
g_return_if_fail (NM_IS_DEVICE (device));
info = g_slice_new (DeactivateInfo);
info = g_slice_new (DeviceCallbackInfo);
info->fn = callback;
info->user_data = user_data;
info->method = "Disconnect";
info->device = g_object_ref (device);
dbus_g_proxy_begin_call (NM_DEVICE_GET_PRIVATE (device)->proxy, "Disconnect",
deactivate_cb, info, NULL,
device_operation_cb, info, NULL,
G_TYPE_INVALID);
}
/**
* nm_device_delete:
* @device: a #NMDevice
* @callback: (scope async) (allow-none): callback to be called when delete
* operation completes
* @user_data: (closure): caller-specific data passed to @callback
*
* Deletes the software device. Hardware devices can't be deleted.
*
* Since: 1.0
**/
void
nm_device_delete (NMDevice *device,
NMDeviceCallbackFn callback,
gpointer user_data)
{
DeviceCallbackInfo *info;
g_return_if_fail (NM_IS_DEVICE (device));
info = g_slice_new (DeviceCallbackInfo);
info->fn = callback;
info->user_data = user_data;
info->method = "Delete";
info->device = g_object_ref (device);
dbus_g_proxy_begin_call (NM_DEVICE_GET_PRIVATE (device)->proxy, "Delete",
device_operation_cb, info, NULL,
G_TYPE_INVALID);
}

View file

@ -153,10 +153,15 @@ NM_AVAILABLE_IN_0_9_10
char ** nm_device_disambiguate_names (NMDevice **devices,
int num_devices);
typedef void (*NMDeviceDeactivateFn) (NMDevice *device, GError *error, gpointer user_data);
typedef void (*NMDeviceCallbackFn) (NMDevice *device, GError *error, gpointer user_data);
void nm_device_disconnect (NMDevice *device,
NMDeviceDeactivateFn callback,
NMDeviceCallbackFn callback,
gpointer user_data);
NM_AVAILABLE_IN_1_0
void nm_device_delete (NMDevice *device,
NMDeviceCallbackFn callback,
gpointer user_data);
GSList * nm_device_filter_connections (NMDevice *device,
@ -172,6 +177,10 @@ gboolean nm_device_connection_compatible (NMDevice *device,
NM_AVAILABLE_IN_0_9_10
GType nm_device_get_setting_type (NMDevice *device);
/* Deprecated */
NM_DEPRECATED_IN_1_0
typedef void (*NMDeviceDeactivateFn) (NMDevice *device, GError *error, gpointer user_data);
G_END_DECLS
#endif /* NM_DEVICE_H */