device: add a new D-Bus 'Delete' method for removing software devices
authorJiří Klimeš <jklimes@redhat.com>
Thu, 19 Jun 2014 10:37:49 +0000 (12:37 +0200)
committerJiří Klimeš <jklimes@redhat.com>
Tue, 22 Jul 2014 12:24:42 +0000 (14:24 +0200)
introspection/nm-device.xml
src/devices/nm-device.c
src/devices/nm-device.h

index f459bce..0dca23c 100644 (file)
       </tp:docstring>
     </method>
 
+    <method name="Delete">
+      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_delete"/>
+      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+      <tp:docstring>
+        Deletes a software device from NetworkManager and removes the interface from the system.
+        The method returns an error when called for a hardware device.
+      </tp:docstring>
+    </method>
+
     <signal name="StateChanged">
       <arg name="new_state" type="u" tp:type="NM_DEVICE_STATE">
         <tp:docstring>
index fcf94b3..4750d0b 100644 (file)
@@ -71,6 +71,7 @@
 #include "nm-dns-manager.h"
 
 static void impl_device_disconnect (NMDevice *device, DBusGMethodInvocation *context);
+static void impl_device_delete     (NMDevice *device, DBusGMethodInvocation *context);
 
 #include "nm-device-glue.h"
 
@@ -4942,6 +4943,46 @@ impl_device_disconnect (NMDevice *device, DBusGMethodInvocation *context)
                       NULL);
 }
 
+static void
+delete_cb (NMDevice *device,
+           DBusGMethodInvocation *context,
+           GError *error,
+           gpointer user_data)
+{
+       if (error) {
+               dbus_g_method_return_error (context, error);
+               return;
+       }
+
+       /* Authorized */
+       nm_platform_link_delete (nm_device_get_ifindex (device));
+       dbus_g_method_return (context);
+}
+
+static void
+impl_device_delete (NMDevice *device, DBusGMethodInvocation *context)
+{
+       GError *error = NULL;
+
+       if (!nm_device_is_software (device)) {
+               error = g_error_new_literal (NM_DEVICE_ERROR,
+                                            NM_DEVICE_ERROR_NOT_SOFTWARE,
+                                            "This device is not a software device");
+               dbus_g_method_return_error (context, error);
+               g_error_free (error);
+               return;
+       }
+
+       /* Ask the manager to authenticate this request for us */
+       g_signal_emit (device, signals[AUTH_REQUEST], 0,
+                      context,
+                      NULL,
+                      NM_AUTH_PERMISSION_NETWORK_CONTROL,
+                      TRUE,
+                      delete_cb,
+                      NULL);
+}
+
 static void
 _device_activate (NMDevice *self, NMActRequest *req)
 {
index d034c94..e0f5b89 100644 (file)
@@ -95,6 +95,7 @@ typedef enum {
        NM_DEVICE_ERROR_CONNECTION_INVALID,        /*< nick=ConnectionInvalid >*/
        NM_DEVICE_ERROR_NOT_ACTIVE,                /*< nick=NotActive >*/
        NM_DEVICE_ERROR_UNSUPPORTED_DEVICE_TYPE,   /*< nick=UnsupportedDeviceType >*/
+       NM_DEVICE_ERROR_NOT_SOFTWARE,              /*< nick=NotSoftware >*/
 } NMDeviceError;
 
 struct _NMDevice {