summaryrefslogtreecommitdiff
path: root/libnm/nm-device.c
diff options
context:
space:
mode:
Diffstat (limited to 'libnm/nm-device.c')
-rw-r--r--libnm/nm-device.c197
1 files changed, 93 insertions, 104 deletions
diff --git a/libnm/nm-device.c b/libnm/nm-device.c
index 2084b3e74f..b0a5163a90 100644
--- a/libnm/nm-device.c
+++ b/libnm/nm-device.c
@@ -48,9 +48,9 @@
#include "nm-utils.h"
#include "nm-dbus-helpers-private.h"
-static GType _nm_device_type_for_path (DBusGConnection *connection,
+static GType _nm_device_type_for_path (GDBusConnection *connection,
const char *path);
-static void _nm_device_type_for_path_async (DBusGConnection *connection,
+static void _nm_device_type_for_path_async (GDBusConnection *connection,
const char *path,
NMObjectTypeCallbackFunc callback,
gpointer user_data);
@@ -66,7 +66,7 @@ G_DEFINE_TYPE_WITH_CODE (NMDevice, nm_device, NM_TYPE_OBJECT,
#define NM_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE, NMDevicePrivate))
typedef struct {
- DBusGProxy *proxy;
+ GDBusProxy *proxy;
char *iface;
char *ip_iface;
@@ -164,28 +164,21 @@ nm_device_init (NMDevice *device)
}
static gboolean
-demarshal_state_reason (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
+demarshal_state_reason (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object);
- if (!G_VALUE_HOLDS (value, DBUS_G_TYPE_UINT_STRUCT))
- return FALSE;
-
- dbus_g_type_struct_get (value,
- 0, &priv->state,
- 1, &priv->reason,
- G_MAXUINT);
-
+ g_variant_get (value, "(uu)", &priv->state, &priv->reason);
_nm_object_queue_notify (object, NM_DEVICE_STATE_REASON);
return TRUE;
}
static void
-device_state_changed (DBusGProxy *proxy,
- NMDeviceState new_state,
- NMDeviceState old_state,
- NMDeviceStateReason reason,
- gpointer user_data);
+device_proxy_signal (GDBusProxy *proxy,
+ const gchar *sender_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data);
static void
init_dbus_properties (NMObject *object)
@@ -227,21 +220,8 @@ init_dbus_properties (NMObject *object)
priv->proxy,
property_info);
- dbus_g_object_register_marshaller (g_cclosure_marshal_generic,
- G_TYPE_NONE,
- G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT,
- G_TYPE_INVALID);
-
- dbus_g_proxy_add_signal (priv->proxy,
- "StateChanged",
- G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT,
- G_TYPE_INVALID);
-
- dbus_g_proxy_connect_signal (priv->proxy, "StateChanged",
- G_CALLBACK (device_state_changed),
- NM_DEVICE (object),
- NULL);
-
+ g_signal_connect (priv->proxy, "g-signal",
+ G_CALLBACK (device_proxy_signal), object);
}
typedef struct {
@@ -284,14 +264,21 @@ device_state_change_reloaded (GObject *object,
}
static void
-device_state_changed (DBusGProxy *proxy,
- NMDeviceState new_state,
- NMDeviceState old_state,
- NMDeviceStateReason reason,
- gpointer user_data)
+device_proxy_signal (GDBusProxy *proxy,
+ const gchar *sender_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
{
NMDevice *self = NM_DEVICE (user_data);
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
+ NMDeviceState new_state, old_state;
+ NMDeviceStateReason reason;
+
+ if (strcmp (signal_name, "StateChanged") != 0)
+ return;
+
+ g_variant_get (parameters, "(uuu)", &new_state, &old_state, &reason);
if (old_state != new_state) {
StateChangeData *data;
@@ -417,7 +404,6 @@ get_property (GObject *object,
GParamSpec *pspec)
{
NMDevice *device = NM_DEVICE (object);
- NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device);
switch (prop_id) {
case PROP_DEVICE_TYPE:
@@ -469,12 +455,7 @@ get_property (GObject *object,
g_value_set_enum (value, nm_device_get_state (device));
break;
case PROP_STATE_REASON:
- g_value_set_boxed (value,
- dbus_g_type_specialized_construct (DBUS_G_TYPE_UINT_STRUCT));
- dbus_g_type_struct_set (value,
- 0, priv->state,
- 1, priv->reason,
- G_MAXUINT);
+ g_value_set_enum (value, nm_device_get_state_reason (device));
break;
case PROP_ACTIVE_CONNECTION:
g_value_set_object (value, nm_device_get_active_connection (device));
@@ -755,10 +736,11 @@ nm_device_class_init (NMDeviceClass *device_class)
**/
g_object_class_install_property
(object_class, PROP_STATE_REASON,
- g_param_spec_boxed (NM_DEVICE_STATE_REASON, "", "",
- DBUS_G_TYPE_UINT_STRUCT,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
+ g_param_spec_enum (NM_DEVICE_STATE_REASON, "", "",
+ NM_TYPE_DEVICE_STATE_REASON,
+ NM_DEVICE_STATE_REASON_UNKNOWN,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
/**
* NMDevice:active-connection:
@@ -878,12 +860,12 @@ _nm_device_set_device_type (NMDevice *device, NMDeviceType dtype)
}
static GType
-_nm_device_type_for_path (DBusGConnection *connection,
+_nm_device_type_for_path (GDBusConnection *connection,
const char *path)
{
- DBusGProxy *proxy;
+ GDBusProxy *proxy;
GError *err = NULL;
- GValue value = G_VALUE_INIT;
+ GVariant *ret, *val;
NMDeviceType nm_dtype;
proxy = _nm_dbus_new_proxy_for_connection (connection, path, "org.freedesktop.DBus.Properties");
@@ -892,44 +874,51 @@ _nm_device_type_for_path (DBusGConnection *connection,
return G_TYPE_INVALID;
}
- if (!dbus_g_proxy_call (proxy,
- "Get", &err,
- G_TYPE_STRING, NM_DBUS_INTERFACE_DEVICE,
- G_TYPE_STRING, "DeviceType",
- G_TYPE_INVALID,
- G_TYPE_VALUE, &value, G_TYPE_INVALID)) {
+ ret = g_dbus_proxy_call_sync (proxy,
+ "Get",
+ g_variant_new ("(ss)", NM_DBUS_INTERFACE_DEVICE, "DeviceType"),
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL, &err);
+ g_object_unref (proxy);
+
+ if (ret) {
+ g_variant_get (ret, "(v)", &val);
+ nm_dtype = g_variant_get_uint32 (val);
+ g_variant_unref (val);
+ g_variant_unref (ret);
+
+ return _nm_device_gtype_from_dtype (nm_dtype);
+ } else {
g_warning ("Error in get_property: %s\n", err->message);
g_error_free (err);
- g_object_unref (proxy);
return G_TYPE_INVALID;
}
- g_object_unref (proxy);
-
- nm_dtype = g_value_get_uint (&value);
- return _nm_device_gtype_from_dtype (nm_dtype);
}
typedef struct {
- DBusGConnection *connection;
+ GDBusConnection *connection;
NMObjectTypeCallbackFunc callback;
gpointer user_data;
} NMDeviceAsyncData;
static void
-async_got_type (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
+async_got_type (GObject *object, GAsyncResult *result, gpointer user_data)
{
NMDeviceAsyncData *async_data = user_data;
- GValue value = G_VALUE_INIT;
- const char *path = dbus_g_proxy_get_path (proxy);
+ GDBusProxy *proxy = G_DBUS_PROXY (object);
+ GVariant *ret, *val;
+ const char *path = g_dbus_proxy_get_object_path (proxy);
GError *error = NULL;
GType type;
- if (dbus_g_proxy_end_call (proxy, call, &error,
- G_TYPE_VALUE, &value,
- G_TYPE_INVALID)) {
+ ret = g_dbus_proxy_call_finish (proxy, result, &error);
+ if (ret) {
NMDeviceType dtype;
- dtype = g_value_get_uint (&value);
+ g_variant_get (ret, "(v)", &val);
+ dtype = g_variant_get_uint32 (val);
+ g_variant_unref (val);
+ g_variant_unref (ret);
type = _nm_device_gtype_from_dtype (dtype);
} else {
g_warning ("%s: could not read properties for %s: %s", __func__, path, error->message);
@@ -943,13 +932,13 @@ async_got_type (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
}
static void
-_nm_device_type_for_path_async (DBusGConnection *connection,
+_nm_device_type_for_path_async (GDBusConnection *connection,
const char *path,
NMObjectTypeCallbackFunc callback,
gpointer user_data)
{
NMDeviceAsyncData *async_data;
- DBusGProxy *proxy;
+ GDBusProxy *proxy;
async_data = g_slice_new (NMDeviceAsyncData);
async_data->connection = connection;
@@ -957,11 +946,12 @@ _nm_device_type_for_path_async (DBusGConnection *connection,
async_data->user_data = user_data;
proxy = _nm_dbus_new_proxy_for_connection (connection, path, "org.freedesktop.DBus.Properties");
- dbus_g_proxy_begin_call (proxy, "Get",
- async_got_type, async_data, NULL,
- G_TYPE_STRING, NM_DBUS_INTERFACE_DEVICE,
- G_TYPE_STRING, "DeviceType",
- G_TYPE_INVALID);
+ g_dbus_proxy_call (proxy,
+ "Get",
+ g_variant_new ("(ss)", NM_DBUS_INTERFACE_DEVICE, "DeviceType"),
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL,
+ async_got_type, async_data);
}
/**
@@ -1197,20 +1187,14 @@ nm_device_get_autoconnect (NMDevice *device)
void
nm_device_set_autoconnect (NMDevice *device, gboolean autoconnect)
{
- GValue value = G_VALUE_INIT;
-
g_return_if_fail (NM_IS_DEVICE (device));
- g_value_init (&value, G_TYPE_BOOLEAN);
- g_value_set_boolean (&value, autoconnect);
-
-
NM_DEVICE_GET_PRIVATE (device)->autoconnect = autoconnect;
_nm_object_set_property (NM_OBJECT (device),
NM_DBUS_INTERFACE_DEVICE,
"Autoconnect",
- &value);
+ "b", autoconnect);
}
/**
@@ -1332,21 +1316,17 @@ nm_device_get_state (NMDevice *device)
/**
* nm_device_get_state_reason:
* @device: a #NMDevice
- * @reason: (out) (allow-none): location to store reason (#NMDeviceStateReason), or %NULL
*
- * Gets the current #NMDevice state (return value) and the reason for entering
- * the state (@reason argument).
+ * Gets the reason associated with the current #NMDevice state.
*
- * Returns: the current device state
+ * Returns: the reason for the current device state
**/
-NMDeviceState
-nm_device_get_state_reason (NMDevice *device, NMDeviceStateReason *reason)
+NMDeviceStateReason
+nm_device_get_state_reason (NMDevice *device)
{
- g_return_val_if_fail (NM_IS_DEVICE (device), NM_DEVICE_STATE_UNKNOWN);
+ g_return_val_if_fail (NM_IS_DEVICE (device), NM_DEVICE_STATE_REASON_UNKNOWN);
- if (reason)
- *reason = NM_DEVICE_GET_PRIVATE (device)->reason;
- return NM_DEVICE_GET_PRIVATE (device)->state;
+ return NM_DEVICE_GET_PRIVATE (device)->reason;
}
/**
@@ -2026,15 +2006,15 @@ typedef struct {
} DeviceCallbackInfo;
static void
-device_operation_cb (DBusGProxy *proxy,
- DBusGProxyCall *call,
+device_operation_cb (GObject *proxy,
+ GAsyncResult *result,
gpointer user_data)
{
DeviceCallbackInfo *info = user_data;
+ GVariant *ret;
GError *error = NULL;
- dbus_g_proxy_end_call (proxy, call, &error,
- G_TYPE_INVALID);
+ ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error);
if (info->fn)
info->fn (info->device, error, info->user_data);
else if (error) {
@@ -2047,6 +2027,9 @@ device_operation_cb (DBusGProxy *proxy,
}
g_clear_error (&error);
+ if (ret)
+ g_variant_unref (ret);
+
g_object_unref (info->device);
g_slice_free (DeviceCallbackInfo, info);
}
@@ -2077,9 +2060,12 @@ nm_device_disconnect (NMDevice *device,
info->method = "Disconnect";
info->device = g_object_ref (device);
- dbus_g_proxy_begin_call (NM_DEVICE_GET_PRIVATE (device)->proxy, "Disconnect",
- device_operation_cb, info, NULL,
- G_TYPE_INVALID);
+ g_dbus_proxy_call (NM_DEVICE_GET_PRIVATE (device)->proxy,
+ "Disconnect",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL,
+ device_operation_cb, info);
}
/**
@@ -2106,9 +2092,12 @@ nm_device_delete (NMDevice *device,
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);
+ g_dbus_proxy_call (NM_DEVICE_GET_PRIVATE (device)->proxy,
+ "Delete",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL,
+ device_operation_cb, info);
}
/**