summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiří Klimeš <jklimes@redhat.com>2014-06-19 13:15:09 +0200
committerJiří Klimeš <jklimes@redhat.com>2014-07-11 11:32:39 +0200
commit831c1ad1cb1d8393131d5d59eac696ba91a12d4c (patch)
treeeaa01b2c1b0b1ace51a0a2ab9e4c8fbbf2cc8087
parent3ed48b1e405903df73fe4c923afdf4408aab7a02 (diff)
downloadNetworkManager-831c1ad1cb1d8393131d5d59eac696ba91a12d4c.tar.gz
libnm-glib: implement nm_device_delete() for D-Bus device' Delete() method
-rw-r--r--libnm-glib/libnm-glib.ver1
-rw-r--r--libnm-glib/nm-device.c58
-rw-r--r--libnm-glib/nm-device.h13
3 files changed, 58 insertions, 14 deletions
diff --git a/libnm-glib/libnm-glib.ver b/libnm-glib/libnm-glib.ver
index 730af64ffd..c0f1bba0dc 100644
--- a/libnm-glib/libnm-glib.ver
+++ b/libnm-glib/libnm-glib.ver
@@ -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;
diff --git a/libnm-glib/nm-device.c b/libnm-glib/nm-device.c
index 623b2aba46..a781e150a5 100644
--- a/libnm-glib/nm-device.c
+++ b/libnm-glib/nm-device.c
@@ -2089,16 +2089,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,
@@ -2106,16 +2107,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);
}
/**
@@ -2131,20 +2133,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);
}
diff --git a/libnm-glib/nm-device.h b/libnm-glib/nm-device.h
index cdd7741f12..2957c92a48 100644
--- a/libnm-glib/nm-device.h
+++ b/libnm-glib/nm-device.h
@@ -156,10 +156,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,
@@ -175,6 +180,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 */