Commit 3ff14773 authored by Jiří Klimeš's avatar Jiří Klimeš

device: add a new D-Bus 'Delete' method for removing software devices

parent a0b3e4ff
......@@ -147,6 +147,15 @@
</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>
......
......@@ -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)
{
......
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment