2007-06-21 Tambet Ingo <tambet@ximian.com>

* libnm-glib/Makefile.am: Add NMObject to build, remove nm-utils.[ch].

	* nm-utils.[ch]: Remove.

	* libnm-glib/nm-object.c: Implement a base class for all libnm-glib dbus-aware
	objects for easy property access and dbus connection handling.

	* libnm-glib/nm-client.c: Derive from NMObject.

	* libnm-glib/nm-device.c: Ditto.

	* libnm-glib/nm-device-802-3-ethernet.c: Changes for being based on NMObject.

	* libnm-glib/nm-device-802-11-wireless.c: Ditto.

	* libnm-glib/nm-ip4-config.c: Ditto.

	* libnm-glib/nm-access-point.c: Ditto.

	* libnm-util/nm-connection.c (nm_connection_compare): Add a stub for connection
	comparision. Currently used by the device activation code to determine if the new
	activation is the same as the old one.

	* src/nm-dbus-nmi.c (nm_dbus_get_user_key_for_network): Don't use the obsolete and
	wrong way of getting the dbus path for AP. Fixes the issue where the applet isn't
	able to ask password for the AP.

	* src/nm-device.c (nm_device_activate): Change the logic here - instead of giving
	up if the device is already connected, tear down it's connection (if it isn't the
	same as new one) and start the activation.

	* src/nm-manager.c: Add the beginnings of NMConnection storage and signals.

	* src/NetworkManagerAP.c (nm_ap_init): Set the default values to AP memebers, fixes
	the issue where all APs are always listed as encrypted.

	* src/NetworkManagerDbus.c (nm_dbus_get_object_path_for_network): Remove. APs have
	their own registered paths.

	* test/nm-tool.c (detail_device): Don't try to get active network from wireless
	device if it's not connected - dbus-glib will happily crash trying to marshal NULL.




git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2615 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Tambet Ingo 2007-06-22 15:09:02 +00:00 committed by Tambet Ingo
parent 1519dc6035
commit 636b1140c5
22 changed files with 422 additions and 521 deletions

View file

@ -1,3 +1,47 @@
2007-06-21 Tambet Ingo <tambet@ximian.com>
* libnm-glib/Makefile.am: Add NMObject to build, remove nm-utils.[ch].
* nm-utils.[ch]: Remove.
* libnm-glib/nm-object.c: Implement a base class for all libnm-glib dbus-aware
objects for easy property access and dbus connection handling.
* libnm-glib/nm-client.c: Derive from NMObject.
* libnm-glib/nm-device.c: Ditto.
* libnm-glib/nm-device-802-3-ethernet.c: Changes for being based on NMObject.
* libnm-glib/nm-device-802-11-wireless.c: Ditto.
* libnm-glib/nm-ip4-config.c: Ditto.
* libnm-glib/nm-access-point.c: Ditto.
* libnm-util/nm-connection.c (nm_connection_compare): Add a stub for connection
comparision. Currently used by the device activation code to determine if the new
activation is the same as the old one.
* src/nm-dbus-nmi.c (nm_dbus_get_user_key_for_network): Don't use the obsolete and
wrong way of getting the dbus path for AP. Fixes the issue where the applet isn't
able to ask password for the AP.
* src/nm-device.c (nm_device_activate): Change the logic here - instead of giving
up if the device is already connected, tear down it's connection (if it isn't the
same as new one) and start the activation.
* src/nm-manager.c: Add the beginnings of NMConnection storage and signals.
* src/NetworkManagerAP.c (nm_ap_init): Set the default values to AP memebers, fixes
the issue where all APs are always listed as encrypted.
* src/NetworkManagerDbus.c (nm_dbus_get_object_path_for_network): Remove. APs have
their own registered paths.
* test/nm-tool.c (detail_device): Don't try to get active network from wireless
device if it's not connected - dbus-glib will happily crash trying to marshal NULL.
2007-06-13 Tambet Ingo <tambet@ximian.com>
* src/NetworkManagerAP.c (foreach_property_cb): Set WEP capabilities too!

View file

@ -18,6 +18,7 @@ libnm_glib_la_CFLAGS = \
libnmincludedir = $(includedir)/libnm-glib
libnminclude_HEADERS = \
nm-object.h \
nm-client.h \
nm-device.h \
nm-device-802-3-ethernet.h \
@ -27,6 +28,7 @@ libnminclude_HEADERS = \
nm-vpn-connection.h
libnm_glib_la_SOURCES = \
nm-object.c \
nm-client.c \
nm-device.c \
nm-device-private.h \
@ -34,8 +36,6 @@ libnm_glib_la_SOURCES = \
nm-device-802-11-wireless.c \
nm-access-point.c \
nm-ip4-config.c \
nm-utils.c \
nm-utils.h \
nm-vpn-connection.c \
nm-marshal-main.c

View file

@ -1,14 +1,14 @@
#include "nm-access-point.h"
#include "NetworkManager.h"
#include "nm-utils.h"
#include "nm-access-point-bindings.h"
G_DEFINE_TYPE (NMAccessPoint, nm_access_point, DBUS_TYPE_G_PROXY)
G_DEFINE_TYPE (NMAccessPoint, nm_access_point, NM_TYPE_OBJECT)
#define NM_ACCESS_POINT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_ACCESS_POINT, NMAccessPointPrivate))
typedef struct {
DBusGProxy *ap_proxy;
int strength;
} NMAccessPointPrivate;
@ -27,6 +27,37 @@ nm_access_point_init (NMAccessPoint *ap)
{
}
static GObject*
constructor (GType type,
guint n_construct_params,
GObjectConstructParam *construct_params)
{
NMObject *object;
NMAccessPointPrivate *priv;
object = (NMObject *) G_OBJECT_CLASS (nm_access_point_parent_class)->constructor (type,
n_construct_params,
construct_params);
if (!object)
return NULL;
priv = NM_ACCESS_POINT_GET_PRIVATE (object);
priv->ap_proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (object),
NM_DBUS_SERVICE,
nm_object_get_path (object),
NM_DBUS_INTERFACE_DEVICE);
dbus_g_proxy_add_signal (priv->ap_proxy, "StrengthChanged", G_TYPE_UCHAR, G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->ap_proxy,
"StrengthChanged",
G_CALLBACK (strength_changed_proxy),
NULL,
NULL);
return G_OBJECT (object);
}
static void
nm_access_point_class_init (NMAccessPointClass *ap_class)
{
@ -34,6 +65,9 @@ nm_access_point_class_init (NMAccessPointClass *ap_class)
g_type_class_add_private (ap_class, sizeof (NMAccessPointPrivate));
/* virtual methods */
object_class->constructor = constructor;
/* signals */
signals[STRENGTH_CHANGED] =
g_signal_new ("strength-changed",
@ -50,23 +84,10 @@ nm_access_point_class_init (NMAccessPointClass *ap_class)
NMAccessPoint *
nm_access_point_new (DBusGConnection *connection, const char *path)
{
NMAccessPoint *ap;
ap = (NMAccessPoint *) g_object_new (NM_TYPE_ACCESS_POINT,
"name", NM_DBUS_SERVICE,
"path", path,
"interface", NM_DBUS_INTERFACE_ACCESS_POINT,
"connection", connection,
NULL);
dbus_g_proxy_add_signal (DBUS_G_PROXY (ap), "StrengthChanged", G_TYPE_UCHAR, G_TYPE_INVALID);
dbus_g_proxy_connect_signal (DBUS_G_PROXY (ap),
"StrengthChanged",
G_CALLBACK (strength_changed_proxy),
NULL,
NULL);
return ap;
return (NMAccessPoint *) g_object_new (NM_TYPE_ACCESS_POINT,
NM_OBJECT_CONNECTION, connection,
NM_OBJECT_PATH, path,
NULL);
}
static void
@ -83,121 +104,57 @@ strength_changed_proxy (NMAccessPoint *ap, guchar strength)
guint32
nm_access_point_get_capabilities (NMAccessPoint *ap)
{
GValue value = {0,};
guint32 caps = 0;
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), 0);
if (nm_dbus_get_property (DBUS_G_PROXY (ap),
NM_DBUS_INTERFACE_ACCESS_POINT,
"Capabilities",
&value))
caps = g_value_get_uint (&value);
return caps;
return nm_object_get_uint_property (NM_OBJECT (ap), NM_DBUS_INTERFACE_ACCESS_POINT, "Capabilities");
}
gboolean
nm_access_point_is_encrypted (NMAccessPoint *ap)
{
GValue value = {0,};
int encrypted = FALSE;
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), FALSE);
if (nm_dbus_get_property (DBUS_G_PROXY (ap),
NM_DBUS_INTERFACE_ACCESS_POINT,
"Encrypted",
&value))
encrypted = g_value_get_boolean (&value);
return encrypted;
return nm_object_get_boolean_property (NM_OBJECT (ap), NM_DBUS_INTERFACE_ACCESS_POINT, "Encrypted");
}
char *
nm_access_point_get_essid (NMAccessPoint *ap)
{
GValue value = {0,};
char *essid = NULL;
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NULL);
if (nm_dbus_get_property (DBUS_G_PROXY (ap),
NM_DBUS_INTERFACE_ACCESS_POINT,
"Essid",
&value))
essid = g_strdup (g_value_get_string (&value));
return essid;
return nm_object_get_string_property (NM_OBJECT (ap), NM_DBUS_INTERFACE_ACCESS_POINT, "Essid");
}
gdouble
nm_access_point_get_frequency (NMAccessPoint *ap)
{
GValue value = {0,};
double freq = 0.0;
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), freq);
if (nm_dbus_get_property (DBUS_G_PROXY (ap),
NM_DBUS_INTERFACE_ACCESS_POINT,
"Frequency",
&value))
freq = g_value_get_double (&value);
return freq;
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), 0);
return nm_object_get_double_property (NM_OBJECT (ap), NM_DBUS_INTERFACE_ACCESS_POINT, "Frequency");
}
char *
nm_access_point_get_hw_address (NMAccessPoint *ap)
{
GValue value = {0,};
char *address = NULL;
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NULL);
if (nm_dbus_get_property (DBUS_G_PROXY (ap),
NM_DBUS_INTERFACE_ACCESS_POINT,
"HwAddress",
&value))
address = g_strdup (g_value_get_string (&value));
return address;
return nm_object_get_string_property (NM_OBJECT (ap), NM_DBUS_INTERFACE_ACCESS_POINT, "HwAddress");
}
int
nm_access_point_get_mode (NMAccessPoint *ap)
{
GValue value = {0,};
int mode = 0;
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), 0);
if (nm_dbus_get_property (DBUS_G_PROXY (ap),
NM_DBUS_INTERFACE_ACCESS_POINT,
"Mode",
&value))
mode = g_value_get_int (&value);
return mode;
return nm_object_get_int_property (NM_OBJECT (ap), NM_DBUS_INTERFACE_ACCESS_POINT, "Mode");
}
guint32
nm_access_point_get_rate (NMAccessPoint *ap)
{
GValue value = {0,};
guint32 rate = 0;
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), 0);
if (nm_dbus_get_property (DBUS_G_PROXY (ap),
NM_DBUS_INTERFACE_ACCESS_POINT,
"Rate",
&value))
rate = g_value_get_uint (&value);
return rate;
return nm_object_get_uint_property (NM_OBJECT (ap), NM_DBUS_INTERFACE_ACCESS_POINT, "Rate");
}
int
@ -209,15 +166,8 @@ nm_access_point_get_strength (NMAccessPoint *ap)
priv = NM_ACCESS_POINT_GET_PRIVATE (ap);
if (priv->strength == 0) {
GValue value = {0,};
if (nm_dbus_get_property (DBUS_G_PROXY (ap),
NM_DBUS_INTERFACE_ACCESS_POINT,
"Strength",
&value))
priv->strength = g_value_get_int (&value);
}
if (priv->strength == 0)
priv->strength = nm_object_get_int_property (NM_OBJECT (ap), NM_DBUS_INTERFACE_ACCESS_POINT, "Strength");
return priv->strength;
}

View file

@ -10,14 +10,14 @@
#include <glib/gtypes.h>
#include <glib-object.h>
#include <dbus/dbus-glib.h>
#include "nm-object.h"
typedef struct {
DBusGProxy parent;
NMObject parent;
} NMAccessPoint;
typedef struct {
DBusGProxyClass parent;
NMObjectClass parent;
/* Signals */
void (*strength_changed) (NMAccessPoint *ap, gint8 strength);

View file

@ -3,17 +3,17 @@
#include "nm-client.h"
#include "nm-device-802-3-ethernet.h"
#include "nm-device-802-11-wireless.h"
#include "nm-utils.h"
#include "nm-device-private.h"
#include "nm-marshal.h"
#include "nm-client-bindings.h"
G_DEFINE_TYPE (NMClient, nm_client, DBUS_TYPE_G_PROXY)
G_DEFINE_TYPE (NMClient, nm_client, NM_TYPE_OBJECT)
#define NM_CLIENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_CLIENT, NMClientPrivate))
typedef struct {
DBusGProxy *client_proxy;
DBusGProxy *bus_proxy;
gboolean manager_running;
NMState state;
@ -66,11 +66,86 @@ nm_client_init (NMClient *client)
priv->vpn_state = NM_VPN_ACT_STAGE_UNKNOWN;
}
static GObject*
constructor (GType type,
guint n_construct_params,
GObjectConstructParam *construct_params)
{
NMObject *object;
DBusGConnection *connection;
NMClientPrivate *priv;
GError *err = NULL;
object = (NMObject *) G_OBJECT_CLASS (nm_client_parent_class)->constructor (type,
n_construct_params,
construct_params);
if (!object)
return NULL;
priv = NM_CLIENT_GET_PRIVATE (object);
connection = nm_object_get_connection (object);
priv->client_proxy = dbus_g_proxy_new_for_name (connection,
NM_DBUS_SERVICE,
nm_object_get_path (object),
NM_DBUS_INTERFACE);
dbus_g_proxy_add_signal (priv->client_proxy, "StateChange", G_TYPE_UINT, G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->client_proxy,
"StateChange",
G_CALLBACK (client_state_change_proxy),
object,
NULL);
dbus_g_proxy_add_signal (priv->client_proxy, "DeviceAdded", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->client_proxy,
"DeviceAdded",
G_CALLBACK (client_device_added_proxy),
object,
NULL);
dbus_g_proxy_add_signal (priv->client_proxy, "DeviceRemoved", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->client_proxy,
"DeviceRemoved",
G_CALLBACK (client_device_removed_proxy),
object,
NULL);
setup_vpn_proxy (NM_CLIENT (object), connection);
priv->bus_proxy = dbus_g_proxy_new_for_name (connection,
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus");
dbus_g_proxy_add_signal (priv->bus_proxy, "NameOwnerChanged",
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->bus_proxy,
"NameOwnerChanged",
G_CALLBACK (proxy_name_owner_changed),
object, NULL);
if (!dbus_g_proxy_call (priv->bus_proxy,
"NameHasOwner", &err,
G_TYPE_STRING, NM_DBUS_SERVICE,
G_TYPE_INVALID,
G_TYPE_BOOLEAN, &priv->manager_running,
G_TYPE_INVALID)) {
g_warning ("Error on NameHasOwner DBUS call: %s", err->message);
g_error_free (err);
}
return G_OBJECT (object);
}
static void
finalize (GObject *object)
{
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (object);
g_object_unref (priv->vpn_proxy);
g_object_unref (priv->client_proxy);
g_object_unref (priv->bus_proxy);
g_hash_table_destroy (priv->devices);
}
@ -95,6 +170,7 @@ nm_client_class_init (NMClientClass *client_class)
g_type_class_add_private (client_class, sizeof (NMClientPrivate));
/* virtual methods */
object_class->constructor = constructor;
object_class->finalize = finalize;
client_class->manager_running = manager_running;
@ -170,42 +246,10 @@ nm_client_class_init (NMClientClass *client_class)
G_TYPE_UINT);
}
static void
setup_bus_listener (NMClient *client, DBusGConnection *connection)
{
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
GError *err = NULL;
priv->bus_proxy = dbus_g_proxy_new_for_name (connection,
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus");
dbus_g_proxy_add_signal (priv->bus_proxy, "NameOwnerChanged",
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->bus_proxy,
"NameOwnerChanged",
G_CALLBACK (proxy_name_owner_changed),
client, NULL);
if (!dbus_g_proxy_call (priv->bus_proxy,
"NameHasOwner", &err,
G_TYPE_STRING, NM_DBUS_SERVICE,
G_TYPE_INVALID,
G_TYPE_BOOLEAN, &priv->manager_running,
G_TYPE_INVALID)) {
g_warning ("Error on NameHasOwner DBUS call: %s", err->message);
g_error_free (err);
}
}
NMClient *
nm_client_new (void)
{
DBusGConnection *connection;
DBusGProxy *proxy;
NMClient *client;
GError *err = NULL;
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err);
@ -215,40 +259,10 @@ nm_client_new (void)
return NULL;
}
client = (NMClient *) g_object_new (NM_TYPE_CLIENT,
"name", NM_DBUS_SERVICE,
"path", NM_DBUS_PATH,
"interface", NM_DBUS_INTERFACE,
"connection", connection,
NULL);
proxy = DBUS_G_PROXY (client);
dbus_g_proxy_add_signal (proxy, "StateChange", G_TYPE_UINT, G_TYPE_INVALID);
dbus_g_proxy_connect_signal (proxy,
"StateChange",
G_CALLBACK (client_state_change_proxy),
NULL,
NULL);
dbus_g_proxy_add_signal (proxy, "DeviceAdded", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
dbus_g_proxy_connect_signal (proxy,
"DeviceAdded",
G_CALLBACK (client_device_added_proxy),
NULL,
NULL);
dbus_g_proxy_add_signal (proxy, "DeviceRemoved", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
dbus_g_proxy_connect_signal (proxy,
"DeviceRemoved",
G_CALLBACK (client_device_removed_proxy),
NULL,
NULL);
setup_vpn_proxy (client, connection);
setup_bus_listener (client, connection);
return client;
return (NMClient *) g_object_new (NM_TYPE_CLIENT,
NM_OBJECT_CONNECTION, connection,
NM_OBJECT_PATH, NM_DBUS_PATH,
NULL);
}
static void
@ -273,7 +287,7 @@ proxy_name_owner_changed (DBusGProxy *proxy,
static void
client_state_change_proxy (DBusGProxy *proxy, guint state, gpointer user_data)
{
NMClient *client = NM_CLIENT (proxy);
NMClient *client = NM_CLIENT (user_data);
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
if (priv->state != state) {
@ -290,10 +304,10 @@ get_device (NMClient *client, const char *path, gboolean create_if_not_found)
device = g_hash_table_lookup (priv->devices, path);
if (!device && create_if_not_found) {
DBusGConnection *connection = NULL;
DBusGConnection *connection;
NMDeviceType type;
g_object_get (client, "connection", &connection, NULL);
connection = nm_object_get_connection (NM_OBJECT (client));
type = nm_device_type_for_path (connection, path);
switch (type) {
@ -317,7 +331,7 @@ get_device (NMClient *client, const char *path, gboolean create_if_not_found)
static void
client_device_added_proxy (DBusGProxy *proxy, char *path, gpointer user_data)
{
NMClient *client = NM_CLIENT (proxy);
NMClient *client = NM_CLIENT (user_data);
NMDevice *device;
device = get_device (client, path, TRUE);
@ -328,7 +342,7 @@ client_device_added_proxy (DBusGProxy *proxy, char *path, gpointer user_data)
static void
client_device_removed_proxy (DBusGProxy *proxy, char *path, gpointer user_data)
{
NMClient *client = NM_CLIENT (proxy);
NMClient *client = NM_CLIENT (user_data);
NMDevice *device;
device = get_device (client, path, FALSE);
@ -371,7 +385,7 @@ nm_client_get_devices (NMClient *client)
return list;
}
if (!org_freedesktop_NetworkManager_get_devices (DBUS_G_PROXY (client), &array, &err)) {
if (!org_freedesktop_NetworkManager_get_devices (priv->client_proxy, &array, &err)) {
g_warning ("Error in get_devices: %s", err->message);
g_error_free (err);
} else {
@ -405,7 +419,7 @@ nm_client_get_device_by_path (NMClient *client, const char *object_path)
devices = nm_client_get_devices (client);
for (iter = devices; iter; iter = iter->next) {
if (!strcmp (nm_device_get_path (NM_DEVICE (iter->data)), object_path)) {
if (!strcmp (nm_object_get_path (NM_OBJECT (iter->data)), object_path)) {
device = NM_DEVICE (iter->data);
break;
}
@ -418,18 +432,9 @@ nm_client_get_device_by_path (NMClient *client, const char *object_path)
gboolean
nm_client_wireless_get_enabled (NMClient *client)
{
GValue value = {0,};
gboolean enabled = FALSE;
g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
g_return_val_if_fail (NM_IS_CLIENT (client), enabled);
if (nm_dbus_get_property (DBUS_G_PROXY (client),
NM_DBUS_INTERFACE,
"WirelessEnabled",
&value))
enabled = g_value_get_boolean (&value);
return enabled;
return nm_object_get_boolean_property (NM_OBJECT (client), NM_DBUS_INTERFACE, "WirelessEnabled");
}
void
@ -441,10 +446,11 @@ nm_client_wireless_set_enabled (NMClient *client, gboolean enabled)
g_value_init (&value, G_TYPE_BOOLEAN);
g_value_set_boolean (&value, enabled);
nm_dbus_set_property (DBUS_G_PROXY (client),
NM_DBUS_INTERFACE,
"WirelessEnabled",
&value);
nm_object_set_property (NM_OBJECT (client),
NM_DBUS_INTERFACE,
"WirelessEnabled",
&value);
}
NMState
@ -456,15 +462,8 @@ nm_client_get_state (NMClient *client)
priv = NM_CLIENT_GET_PRIVATE (client);
if (priv->state == NM_STATE_UNKNOWN) {
GValue value = {0,};
if (nm_dbus_get_property (DBUS_G_PROXY (client),
NM_DBUS_INTERFACE,
"State",
&value))
priv->state = g_value_get_uint (&value);
}
if (priv->state == NM_STATE_UNKNOWN)
priv->state = nm_object_get_uint_property (NM_OBJECT (client), NM_DBUS_INTERFACE, "State");
return priv->state;
}
@ -476,7 +475,7 @@ nm_client_sleep (NMClient *client, gboolean sleep)
g_return_if_fail (NM_IS_CLIENT (client));
if (!org_freedesktop_NetworkManager_sleep (DBUS_G_PROXY (client), sleep, &err)) {
if (!org_freedesktop_NetworkManager_sleep (NM_CLIENT_GET_PRIVATE (client)->client_proxy, sleep, &err)) {
g_warning ("Error in sleep: %s", err->message);
g_error_free (err);
}

View file

@ -7,6 +7,7 @@
#include <dbus/dbus-glib.h>
#include <NetworkManager.h>
#include <NetworkManagerVPN.h>
#include "nm-object.h"
#include "nm-device.h"
#include "nm-vpn-connection.h"
@ -18,11 +19,11 @@
#define NM_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_CLIENT, NMClientClass))
typedef struct {
DBusGProxy parent;
NMObject parent;
} NMClient;
typedef struct {
DBusGProxyClass parent;
NMObjectClass parent;
/* Signals */
void (*manager_running) (NMClient *client, gboolean running);

View file

@ -1,6 +1,5 @@
#include "nm-device-802-11-wireless.h"
#include "nm-device-private.h"
#include "nm-utils.h"
#include "nm-device-802-11-wireless-bindings.h"
@ -55,9 +54,9 @@ constructor (GType type,
priv = NM_DEVICE_802_11_WIRELESS_GET_PRIVATE (object);
priv->wireless_proxy = dbus_g_proxy_new_for_name (nm_device_get_connection (NM_DEVICE (object)),
priv->wireless_proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (NM_OBJECT (object)),
NM_DBUS_SERVICE,
nm_device_get_path (NM_DEVICE (object)),
nm_object_get_path (NM_OBJECT (object)),
NM_DBUS_INTERFACE_DEVICE_WIRELESS);
dbus_g_proxy_add_signal (priv->wireless_proxy, "NetworkAdded", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
@ -69,7 +68,7 @@ constructor (GType type,
dbus_g_proxy_connect_signal (priv->wireless_proxy, "NetworkRemoved",
G_CALLBACK (network_removed_proxy),
object, NULL);
return object;
}
@ -121,7 +120,7 @@ nm_device_802_11_wireless_class_init (NMDevice80211WirelessClass *device_class)
G_TYPE_NONE, 1,
G_TYPE_OBJECT);
signals[NETWORK_ADDED] =
signals[NETWORK_REMOVED] =
g_signal_new ("network-removed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
@ -139,8 +138,8 @@ nm_device_802_11_wireless_new (DBusGConnection *connection, const char *path)
g_return_val_if_fail (path != NULL, NULL);
return (NMDevice80211Wireless *) g_object_new (NM_TYPE_DEVICE_802_11_WIRELESS,
NM_DEVICE_CONNECTION, connection,
NM_DEVICE_PATH, path,
NM_OBJECT_CONNECTION, connection,
NM_OBJECT_PATH, path,
NULL);
}
@ -149,8 +148,7 @@ nm_device_802_11_wireless_get_hw_address (NMDevice80211Wireless *device)
{
g_return_val_if_fail (NM_IS_DEVICE_802_11_WIRELESS (device), NULL);
return nm_dbus_get_string_property (nm_device_get_properties_proxy (NM_DEVICE (device)),
NM_DBUS_INTERFACE_DEVICE_WIRELESS, "HwAddress");
return nm_object_get_string_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE_WIRELESS, "HwAddress");
}
int
@ -158,8 +156,7 @@ nm_device_802_11_wireless_get_mode (NMDevice80211Wireless *device)
{
g_return_val_if_fail (NM_IS_DEVICE_802_11_WIRELESS (device), 0);
return nm_dbus_get_int_property (nm_device_get_properties_proxy (NM_DEVICE (device)),
NM_DBUS_INTERFACE_DEVICE_WIRELESS, "Mode");
return nm_object_get_int_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE_WIRELESS, "Mode");
}
int
@ -167,8 +164,7 @@ nm_device_802_11_wireless_get_bitrate (NMDevice80211Wireless *device)
{
g_return_val_if_fail (NM_IS_DEVICE_802_11_WIRELESS (device), 0);
return nm_dbus_get_int_property (nm_device_get_properties_proxy (NM_DEVICE (device)),
NM_DBUS_INTERFACE_DEVICE_WIRELESS, "Bitrate");
return nm_object_get_int_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE_WIRELESS, "Bitrate");
}
guint32
@ -176,8 +172,7 @@ nm_device_802_11_wireless_get_capabilities (NMDevice80211Wireless *device)
{
g_return_val_if_fail (NM_IS_DEVICE_802_11_WIRELESS (device), 0);
return nm_dbus_get_uint_property (nm_device_get_properties_proxy (NM_DEVICE (device)),
NM_DBUS_INTERFACE_DEVICE_WIRELESS, "WirelessCapabilities");
return nm_object_get_uint_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE_WIRELESS, "WirelessCapabilities");
}
static NMAccessPoint *
@ -188,7 +183,7 @@ get_network (NMDevice80211Wireless *device, const char *path, gboolean create_if
ap = g_hash_table_lookup (priv->networks, path);
if (!ap && create_if_not_found) {
ap = nm_access_point_new (nm_device_get_connection (NM_DEVICE (device)), path);
ap = nm_access_point_new (nm_object_get_connection (NM_OBJECT (device)), path);
if (ap)
g_hash_table_insert (priv->networks, g_strdup (path), ap);
}
@ -204,9 +199,7 @@ nm_device_802_11_wireless_get_active_network (NMDevice80211Wireless *device)
g_return_val_if_fail (NM_IS_DEVICE_802_11_WIRELESS (device), NULL);
path = nm_dbus_get_object_path_property (nm_device_get_properties_proxy (NM_DEVICE (device)),
NM_DBUS_INTERFACE_DEVICE_WIRELESS,
"ActiveNetwork");
path = nm_object_get_object_path_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE_WIRELESS, "ActiveNetwork");
if (path) {
ap = get_network (device, path, TRUE);
g_free (path);

View file

@ -1,6 +1,5 @@
#include "nm-device-802-3-ethernet.h"
#include "nm-device-private.h"
#include "nm-utils.h"
#include "nm-device-802-3-ethernet-bindings.h"
@ -39,9 +38,9 @@ constructor (GType type,
priv = NM_DEVICE_802_3_ETHERNET_GET_PRIVATE (object);
priv->ethernet_proxy = dbus_g_proxy_new_for_name (nm_device_get_connection (NM_DEVICE (object)),
priv->ethernet_proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (NM_OBJECT (object)),
NM_DBUS_SERVICE,
nm_device_get_path (NM_DEVICE (object)),
nm_object_get_path (NM_OBJECT (object)),
NM_DBUS_INTERFACE_DEVICE_WIRED);
return object;
}
@ -80,8 +79,8 @@ nm_device_802_3_ethernet_new (DBusGConnection *connection, const char *path)
g_return_val_if_fail (path != NULL, NULL);
return (NMDevice8023Ethernet *) g_object_new (NM_TYPE_DEVICE_802_3_ETHERNET,
NM_DEVICE_CONNECTION, connection,
NM_DEVICE_PATH, path,
NM_OBJECT_CONNECTION, connection,
NM_OBJECT_PATH, path,
NULL);
}
@ -90,8 +89,7 @@ nm_device_802_3_ethernet_get_speed (NMDevice8023Ethernet *device)
{
g_return_val_if_fail (NM_IS_DEVICE_802_3_ETHERNET (device), 0);
return nm_dbus_get_int_property (nm_device_get_properties_proxy (NM_DEVICE (device)),
NM_DBUS_INTERFACE_DEVICE_WIRED, "Speed");
return nm_object_get_int_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE_WIRED, "Speed");
}
char *
@ -99,6 +97,5 @@ nm_device_802_3_ethernet_get_hw_address (NMDevice8023Ethernet *device)
{
g_return_val_if_fail (NM_IS_DEVICE_802_3_ETHERNET (device), NULL);
return nm_dbus_get_string_property (nm_device_get_properties_proxy (NM_DEVICE (device)),
NM_DBUS_INTERFACE_DEVICE_WIRED, "HwAddress");
return nm_object_get_string_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE_WIRED, "HwAddress");
}

View file

@ -1,18 +1,14 @@
#include "nm-device.h"
#include "nm-device-private.h"
#include "nm-utils.h"
#include "nm-device-bindings.h"
G_DEFINE_TYPE (NMDevice, nm_device, G_TYPE_OBJECT)
G_DEFINE_TYPE (NMDevice, nm_device, NM_TYPE_OBJECT)
#define NM_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE, NMDevicePrivate))
typedef struct {
DBusGConnection *connection;
char *path;
DBusGProxy *device_proxy;
DBusGProxy *properties_proxy;
NMDeviceState state;
gboolean disposed;
@ -52,39 +48,27 @@ constructor (GType type,
guint n_construct_params,
GObjectConstructParam *construct_params)
{
GObject *object;
NMObject *object;
NMDevicePrivate *priv;
object = G_OBJECT_CLASS (nm_device_parent_class)->constructor (type,
n_construct_params,
construct_params);
object = (NMObject *) G_OBJECT_CLASS (nm_device_parent_class)->constructor (type,
n_construct_params,
construct_params);
if (!object)
return NULL;
priv = NM_DEVICE_GET_PRIVATE (object);
if (priv->connection == NULL || priv->path == NULL) {
g_warning ("Connection or path not received.");
g_object_unref (object);
return NULL;
}
priv->device_proxy = dbus_g_proxy_new_for_name (priv->connection,
priv->device_proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (object),
NM_DBUS_SERVICE,
priv->path,
nm_object_get_path (object),
NM_DBUS_INTERFACE_DEVICE);
dbus_g_proxy_add_signal (priv->device_proxy, "StateChanged", G_TYPE_UINT, G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->device_proxy, "StateChanged",
G_CALLBACK (device_state_change_proxy),
object, NULL);
priv->properties_proxy = dbus_g_proxy_new_for_name (priv->connection,
NM_DBUS_SERVICE,
priv->path,
"org.freedesktop.DBus.Properties");
return object;
return G_OBJECT (object);
}
static void
@ -98,62 +82,10 @@ dispose (GObject *object)
priv->disposed = TRUE;
g_object_unref (priv->device_proxy);
g_object_unref (priv->properties_proxy);
dbus_g_connection_unref (priv->connection);
G_OBJECT_CLASS (nm_device_parent_class)->dispose (object);
}
static void
finalize (GObject *object)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object);
g_free (priv->path);
G_OBJECT_CLASS (nm_device_parent_class)->finalize (object);
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object);
switch (prop_id) {
case PROP_CONNECTION:
/* Construct only */
priv->connection = dbus_g_connection_ref ((DBusGConnection *) g_value_get_boxed (value));
break;
case PROP_PATH:
/* Construct only */
priv->path = g_strdup (g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object);
switch (prop_id) {
case PROP_CONNECTION:
g_value_set_boxed (value, priv->connection);
break;
case PROP_PATH:
g_value_set_string (value, priv->path);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_device_class_init (NMDeviceClass *device_class)
{
@ -163,27 +95,7 @@ nm_device_class_init (NMDeviceClass *device_class)
/* virtual methods */
object_class->constructor = constructor;
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->dispose = dispose;
object_class->finalize = finalize;
/* porperties */
g_object_class_install_property
(object_class, PROP_CONNECTION,
g_param_spec_boxed (NM_DEVICE_CONNECTION,
"Connection",
"Connection",
DBUS_TYPE_G_CONNECTION,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property
(object_class, PROP_PATH,
g_param_spec_string (NM_DEVICE_PATH,
"Object Path",
"DBus Object Path",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
/* signals */
signals[STATE_CHANGED] =
@ -213,8 +125,8 @@ NMDevice *
nm_device_new (DBusGConnection *connection, const char *path)
{
return (NMDevice *) g_object_new (NM_TYPE_DEVICE,
NM_DEVICE_CONNECTION, connection,
NM_DEVICE_PATH, path,
NM_OBJECT_CONNECTION, connection,
NM_OBJECT_PATH, path,
NULL);
}
@ -252,8 +164,7 @@ nm_device_get_iface (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
return nm_dbus_get_string_property (NM_DEVICE_GET_PRIVATE (device)->properties_proxy,
NM_DBUS_INTERFACE_DEVICE, "Interface");
return nm_object_get_string_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE, "Interface");
}
char *
@ -261,8 +172,7 @@ nm_device_get_udi (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
return nm_dbus_get_string_property (NM_DEVICE_GET_PRIVATE (device)->properties_proxy,
NM_DBUS_INTERFACE_DEVICE, "Udi");
return nm_object_get_string_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE, "Udi");
}
char *
@ -270,8 +180,7 @@ nm_device_get_driver (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
return nm_dbus_get_string_property (NM_DEVICE_GET_PRIVATE (device)->properties_proxy,
NM_DBUS_INTERFACE_DEVICE, "Driver");
return nm_object_get_string_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE, "Driver");
}
guint32
@ -279,8 +188,7 @@ nm_device_get_capabilities (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), 0);
return nm_dbus_get_uint_property (NM_DEVICE_GET_PRIVATE (device)->properties_proxy,
NM_DBUS_INTERFACE_DEVICE, "Capabilities");
return nm_object_get_uint_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE, "Capabilities");
}
guint32
@ -288,25 +196,21 @@ nm_device_get_ip4_address (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), 0);
return nm_dbus_get_uint_property (NM_DEVICE_GET_PRIVATE (device)->properties_proxy,
NM_DBUS_INTERFACE_DEVICE, "Ip4Address");
return nm_object_get_uint_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE, "Ip4Address");
}
NMIP4Config *
nm_device_get_ip4_config (NMDevice *device)
{
NMDevicePrivate *priv;
char *path;
NMIP4Config *config = NULL;
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
priv = NM_DEVICE_GET_PRIVATE (device);
path = nm_dbus_get_object_path_property (priv->properties_proxy,
NM_DBUS_INTERFACE_DEVICE,
"Ip4Config");
path = nm_object_get_object_path_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE, "Ip4Config");
if (path) {
config = nm_ip4_config_new (priv->connection, path);
config = nm_ip4_config_new (nm_object_get_connection (NM_OBJECT (device)), path);
g_free (path);
}
@ -323,7 +227,7 @@ nm_device_get_state (NMDevice *device)
priv = NM_DEVICE_GET_PRIVATE (device);
if (priv->state == NM_DEVICE_STATE_UNKNOWN)
priv->state = nm_dbus_get_uint_property (priv->properties_proxy, NM_DBUS_INTERFACE_DEVICE, "State");
priv->state = nm_object_get_uint_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE, "State");
return priv->state;
}
@ -344,7 +248,7 @@ nm_device_get_description (NMDevice *device)
/* First, get the physical device info */
udi = nm_device_get_udi (device);
proxy = dbus_g_proxy_new_for_name (nm_device_get_connection (device),
proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (NM_OBJECT (device)),
"org.freedesktop.Hal",
udi,
"org.freedesktop.Hal.Device");
@ -363,7 +267,7 @@ nm_device_get_description (NMDevice *device)
/* Now get the vendor and product info from the physical device */
proxy = dbus_g_proxy_new_for_name (nm_device_get_connection (device),
proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (NM_OBJECT (device)),
"org.freedesktop.Hal",
physical_device_udi,
"org.freedesktop.Hal.Device");
@ -399,36 +303,13 @@ nm_device_get_description (NMDevice *device)
return description;
}
DBusGConnection *
nm_device_get_connection (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
return NM_DEVICE_GET_PRIVATE (device)->connection;
}
const char *
nm_device_get_path (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
return NM_DEVICE_GET_PRIVATE (device)->path;
}
DBusGProxy *
nm_device_get_properties_proxy (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
return NM_DEVICE_GET_PRIVATE (device)->properties_proxy;
}
NMDeviceType
nm_device_type_for_path (DBusGConnection *connection,
const char *path)
{
DBusGProxy *proxy;
GError *err = NULL;
GValue value = {0,};
NMDeviceType type = DEVICE_TYPE_UNKNOWN;
@ -438,13 +319,20 @@ nm_device_type_for_path (DBusGConnection *connection,
proxy = dbus_g_proxy_new_for_name (connection,
NM_DBUS_SERVICE,
path,
NM_DBUS_INTERFACE_DEVICE);
"org.freedesktop.DBus.Properties");
if (nm_dbus_get_property (proxy,
NM_DBUS_INTERFACE_DEVICE,
"DeviceType",
&value))
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)) {
type = (NMDeviceType) g_value_get_uint (&value);
} else {
g_warning ("Error in get_property: %s\n", err->message);
g_error_free (err);
}
g_object_unref (proxy);

View file

@ -4,6 +4,7 @@
#include <glib/gtypes.h>
#include <glib-object.h>
#include <dbus/dbus-glib.h>
#include "nm-object.h"
#include "NetworkManager.h"
#include "nm-ip4-config.h"
#include "nm-connection.h"
@ -15,15 +16,12 @@
#define NM_IS_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_DEVICE))
#define NM_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE, NMDeviceClass))
#define NM_DEVICE_CONNECTION "connection"
#define NM_DEVICE_PATH "path"
typedef struct {
GObject parent;
NMObject parent;
} NMDevice;
typedef struct {
GObjectClass parent;
NMObjectClass parent;
/* Signals */
void (*state_changed) (NMDevice *device, NMDeviceState state);
@ -31,21 +29,24 @@ typedef struct {
GType nm_device_get_type (void);
NMDevice *nm_device_new (DBusGConnection *connection, const char *path);
NMDevice *nm_device_new (DBusGConnection *connection,
const char *path);
void nm_device_activate (NMDevice *device, NMConnection *connection);
void nm_device_deactivate (NMDevice *device);
void nm_device_activate (NMDevice *device,
NMConnection *connection);
char *nm_device_get_iface (NMDevice *device);
char *nm_device_get_udi (NMDevice *device);
char *nm_device_get_driver (NMDevice *device);
guint32 nm_device_get_capabilities (NMDevice *device);
guint32 nm_device_get_ip4_address (NMDevice *device);
NMIP4Config *nm_device_get_ip4_config (NMDevice *device);
NMDeviceState nm_device_get_state (NMDevice *device);
char *nm_device_get_description (NMDevice *device);
void nm_device_deactivate (NMDevice *device);
NMDeviceType nm_device_type_for_path (DBusGConnection *connection,
const char *path);
char *nm_device_get_iface (NMDevice *device);
char *nm_device_get_udi (NMDevice *device);
char *nm_device_get_driver (NMDevice *device);
guint32 nm_device_get_capabilities (NMDevice *device);
guint32 nm_device_get_ip4_address (NMDevice *device);
NMIP4Config *nm_device_get_ip4_config (NMDevice *device);
NMDeviceState nm_device_get_state (NMDevice *device);
char *nm_device_get_description (NMDevice *device);
NMDeviceType nm_device_type_for_path (DBusGConnection *connection,
const char *path);
#endif /* NM_DEVICE_H */

View file

@ -1,8 +1,9 @@
#include "nm-ip4-config.h"
#include "nm-utils.h"
#include "NetworkManager.h"
#define INTERFACE NM_DBUS_INTERFACE ".IP4Config"
G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, DBUS_TYPE_G_PROXY)
G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, NM_TYPE_OBJECT)
static void
nm_ip4_config_init (NMIP4Config *config)
@ -14,102 +15,53 @@ nm_ip4_config_class_init (NMIP4ConfigClass *config_class)
{
}
#define INTERFACE NM_DBUS_INTERFACE ".IP4Config"
NMIP4Config *
nm_ip4_config_new (DBusGConnection *connection, const char *object_path)
{
return (NMIP4Config *) g_object_new (NM_TYPE_IP4_CONFIG,
"name", NM_DBUS_SERVICE,
"path", object_path,
"interface", INTERFACE,
"connection", connection,
NM_OBJECT_CONNECTION, connection,
NM_OBJECT_PATH, object_path,
NULL);
}
guint32
nm_ip4_config_get_address (NMIP4Config *config)
{
guint32 address = 0;
GValue value = {0,};
g_return_val_if_fail (NM_IS_IP4_CONFIG (config), 0);
if (nm_dbus_get_property (DBUS_G_PROXY (config),
INTERFACE,
"Address",
&value))
address = g_value_get_uint (&value);
return address;
return nm_object_get_uint_property (NM_OBJECT (config), INTERFACE, "Address");
}
guint32
nm_ip4_config_get_gateway (NMIP4Config *config)
{
guint32 gateway = 0;
GValue value = {0,};
g_return_val_if_fail (NM_IS_IP4_CONFIG (config), 0);
if (nm_dbus_get_property (DBUS_G_PROXY (config),
INTERFACE,
"Gateway",
&value))
gateway = g_value_get_uint (&value);
return gateway;
return nm_object_get_uint_property (NM_OBJECT (config), INTERFACE, "Gateway");
}
guint32
nm_ip4_config_get_netmask (NMIP4Config *config)
{
guint32 netmask = 0;
GValue value = {0,};
g_return_val_if_fail (NM_IS_IP4_CONFIG (config), 0);
if (nm_dbus_get_property (DBUS_G_PROXY (config),
INTERFACE,
"Netmask",
&value))
netmask = g_value_get_uint (&value);
return netmask;
return nm_object_get_uint_property (NM_OBJECT (config), INTERFACE, "Netmask");
}
guint32
nm_ip4_config_get_broadcast (NMIP4Config *config)
{
guint32 broadcast = 0;
GValue value = {0,};
g_return_val_if_fail (NM_IS_IP4_CONFIG (config), 0);
if (nm_dbus_get_property (DBUS_G_PROXY (config),
INTERFACE,
"Broadcast",
&value))
broadcast = g_value_get_uint (&value);
return broadcast;
return nm_object_get_uint_property (NM_OBJECT (config), INTERFACE, "Broadcast");
}
char *
nm_ip4_config_get_hostname (NMIP4Config *config)
{
char *address = NULL;
GValue value = {0,};
g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
if (nm_dbus_get_property (DBUS_G_PROXY (config),
INTERFACE,
"Hostname",
&value))
address = g_strdup (g_value_get_string (&value));
return address;
return nm_object_get_string_property (NM_OBJECT (config), INTERFACE, "Hostname");
}
GArray *
@ -120,16 +72,15 @@ nm_ip4_config_get_nameservers (NMIP4Config *config)
g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
if (nm_dbus_get_property (DBUS_G_PROXY (config),
INTERFACE,
"Nameservers",
&value))
if (nm_object_get_property (NM_OBJECT (config),
INTERFACE,
"Nameservers",
&value))
array = (GArray *) g_value_get_boxed (&value);
return array;
}
char **
nm_ip4_config_get_domains (NMIP4Config *config)
{
@ -138,10 +89,10 @@ nm_ip4_config_get_domains (NMIP4Config *config)
g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
if (nm_dbus_get_property (DBUS_G_PROXY (config),
INTERFACE,
"Domains",
&value))
if (nm_object_get_property (NM_OBJECT (config),
INTERFACE,
"Domains",
&value))
array = (char **) g_value_get_boxed (&value);
return array;
@ -155,10 +106,10 @@ nm_ip4_config_get_nis_domain (NMIP4Config *config)
g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
if (nm_dbus_get_property (DBUS_G_PROXY (config),
INTERFACE,
"NisDomain",
&value))
if (nm_object_get_property (NM_OBJECT (config),
INTERFACE,
"NisDomain",
&value))
address = g_strdup (g_value_get_string (&value));
return address;
@ -172,10 +123,10 @@ nm_ip4_config_get_nis_servers (NMIP4Config *config)
g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
if (nm_dbus_get_property (DBUS_G_PROXY (config),
INTERFACE,
"NisServers",
&value))
if (nm_object_get_property (NM_OBJECT (config),
INTERFACE,
"NisServers",
&value))
array = (GArray *) g_value_get_boxed (&value);
return array;

View file

@ -4,7 +4,7 @@
#include <glib/gtypes.h>
#include <glib-object.h>
#include <dbus/dbus-glib.h>
#include "NetworkManager.h"
#include "nm-object.h"
#define NM_TYPE_IP4_CONFIG (nm_ip4_config_get_type ())
#define NM_IP4_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_IP4_CONFIG, NMIP4Config))
@ -14,11 +14,11 @@
#define NM_IP4_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_IP4_CONFIG, NMIP4ConfigClass))
typedef struct {
DBusGProxy parent;
NMObject parent;
} NMIP4Config;
typedef struct {
DBusGProxyClass parent;
NMObjectClass parent;
} NMIP4ConfigClass;
GType nm_ip4_config_get_type (void);
@ -26,14 +26,14 @@ GType nm_ip4_config_get_type (void);
NMIP4Config *nm_ip4_config_new (DBusGConnection *connection,
const char *object_path);
guint32 nm_ip4_config_get_address (NMIP4Config *config);
guint32 nm_ip4_config_get_gateway (NMIP4Config *config);
guint32 nm_ip4_config_get_netmask (NMIP4Config *config);
guint32 nm_ip4_config_get_broadcast (NMIP4Config *config);
char *nm_ip4_config_get_hostname (NMIP4Config *config);
guint32 nm_ip4_config_get_address (NMIP4Config *config);
guint32 nm_ip4_config_get_gateway (NMIP4Config *config);
guint32 nm_ip4_config_get_netmask (NMIP4Config *config);
guint32 nm_ip4_config_get_broadcast (NMIP4Config *config);
char *nm_ip4_config_get_hostname (NMIP4Config *config);
GArray *nm_ip4_config_get_nameservers (NMIP4Config *config);
char **nm_ip4_config_get_domains (NMIP4Config *config);
char *nm_ip4_config_get_nis_domain (NMIP4Config *config);
char **nm_ip4_config_get_domains (NMIP4Config *config);
char *nm_ip4_config_get_nis_domain (NMIP4Config *config);
GArray *nm_ip4_config_get_nis_servers (NMIP4Config *config);

View file

@ -122,6 +122,20 @@ nm_connection_get_setting (NMConnection *connection, const char *setting_name)
return (NMSetting *) g_hash_table_lookup (connection->settings, setting_name);
}
gboolean
nm_connection_compare (NMConnection *connection, NMConnection *other)
{
if (!connection && !other)
return TRUE;
if (!connection || !other)
return FALSE;
/* FIXME: Implement */
return FALSE;
}
static void
add_one_setting_to_hash (gpointer key, gpointer data, gpointer user_data)
{

View file

@ -16,6 +16,9 @@ void nm_connection_add_setting (NMConnection *connection,
NMSetting *nm_connection_get_setting (NMConnection *connection,
const char *setting_name);
gboolean nm_connection_compare (NMConnection *connection,
NMConnection *other);
GHashTable *nm_connection_to_hash (NMConnection *connection);
void nm_connection_dump (NMConnection *connection);
void nm_connection_destroy (NMConnection *connection);

View file

@ -110,6 +110,9 @@ nm_ap_init (NMAccessPoint *ap)
static guint32 counter = 0;
priv->dbus_path = g_strdup_printf (NM_DBUS_PATH_ACCESS_POINT "/%d", counter++);
priv->mode = IW_MODE_INFRA;
priv->capabilities = NM_802_11_CAP_PROTO_NONE;
priv->broadcast = TRUE;
}
static void

View file

@ -102,30 +102,6 @@ char * nm_dbus_get_object_path_for_device (NMDevice *dev)
}
/*
* nm_dbus_get_object_path_for_network
*
* Copies the object path for a network object. Caller must free returned string.
*
*/
char * nm_dbus_get_object_path_for_network (NMDevice *dev, NMAccessPoint *ap)
{
char *object_path, *escaped_object_path;
g_return_val_if_fail (dev != NULL, NULL);
g_return_val_if_fail (ap != NULL, NULL);
if (!nm_ap_get_essid (ap))
return NULL;
object_path = g_strdup_printf ("%s/%s/Networks/%s", NM_DBUS_PATH_DEVICE, nm_device_get_iface (dev), nm_ap_get_essid (ap));
escaped_object_path = nm_dbus_escape_object_path (object_path);
g_free (object_path);
return escaped_object_path;
}
/*-------------------------------------------------------------*/
/* Handler code */
/*-------------------------------------------------------------*/

View file

@ -40,7 +40,6 @@ static inline gboolean message_is_error (DBusMessage *msg)
}
char * nm_dbus_get_object_path_for_device (NMDevice *dev);
char * nm_dbus_get_object_path_for_network (NMDevice *dev, NMAccessPoint *ap);
DBusMessage * nm_dbus_create_error_message (DBusMessage *message, const char *exception_namespace, const char *exception, const char *format, ...);

View file

@ -156,7 +156,7 @@ nm_dbus_get_user_key_for_network (NMDevice *dev,
NMAccessPoint * ap;
gint32 attempt = 1;
char * dev_path;
char * net_path;
const char * net_path;
const char * essid;
g_return_if_fail (NM_IS_DEVICE (dev));
@ -187,7 +187,7 @@ nm_dbus_get_user_key_for_network (NMDevice *dev,
}
dev_path = nm_dbus_get_object_path_for_device (dev);
net_path = nm_dbus_get_object_path_for_network (dev, ap);
net_path = nm_ap_get_dbus_path (ap);
if (dev_path && strlen (dev_path) && net_path && strlen (net_path)) {
dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &dev_path,
DBUS_TYPE_OBJECT_PATH, &net_path,
@ -211,7 +211,6 @@ nm_dbus_get_user_key_for_network (NMDevice *dev,
} else {
nm_warning ("bad object path data");
}
g_free (net_path);
g_free (dev_path);
/* FIXME: figure out how to deal with a failure here, otherwise

View file

@ -1024,14 +1024,22 @@ nm_device_activate (NMDeviceInterface *device,
NMDevice *self = NM_DEVICE (device);
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
if (priv->state != NM_DEVICE_STATE_DISCONNECTED)
/* Already activating or activated */
return;
if (!NM_DEVICE_GET_CLASS (self)->check_connection (self, connection))
/* connection is invalid */
return;
if (nm_device_get_state (self) == NM_DEVICE_STATE_ACTIVATED || nm_device_is_activating (self)) {
NMConnection *current_connection;
current_connection = nm_act_request_get_connection (nm_device_get_act_request (self));
if (nm_connection_compare (connection, current_connection))
/* Already activating or activated with the same connection */
return;
nm_device_deactivate (device);
}
nm_info ("Activating device %s", nm_device_get_iface (self));
priv->act_request = nm_act_request_new (connection, user_requested);
nm_device_activate_schedule_stage1_device_prepare (self);

View file

@ -13,11 +13,13 @@ static gboolean impl_manager_sleep (NMManager *manager, gboolean sleep, GError *
#include "nm-manager-glue.h"
static void nm_manager_connections_destroy (NMManager *manager);
static void manager_state_changed (NMManager *manager);
static void manager_set_wireless_enabled (NMManager *manager, gboolean enabled);
typedef struct {
GSList *devices;
GSList *connections;
gboolean wireless_enabled;
gboolean sleeping;
} NMManagerPrivate;
@ -30,6 +32,8 @@ enum {
DEVICE_ADDED,
DEVICE_REMOVED,
STATE_CHANGE,
CONNECTION_ADDED,
CONNECTION_REMOVED,
LAST_SIGNAL
};
@ -59,6 +63,8 @@ finalize (GObject *object)
NMManager *manager = NM_MANAGER (object);
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
nm_manager_connections_destroy (manager);
while (g_slist_length (priv->devices))
nm_manager_remove_device (manager, NM_DEVICE (priv->devices->data));
@ -158,6 +164,26 @@ nm_manager_class_init (NMManagerClass *manager_class)
G_TYPE_NONE, 1,
G_TYPE_UINT);
signals[CONNECTION_ADDED] =
g_signal_new ("connection-added",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMManagerClass, connection_added),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
signals[CONNECTION_REMOVED] =
g_signal_new ("connection-removed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMManagerClass, connection_removed),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (manager_class),
&dbus_glib_nm_manager_object_info);
}
@ -178,6 +204,16 @@ nm_manager_new (void)
return (NMManager *) object;
}
static void
nm_manager_connections_destroy (NMManager *manager)
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
g_slist_foreach (priv->connections, (GFunc) nm_connection_destroy, NULL);
g_slist_free (priv->connections);
priv->connections = NULL;
}
static void
manager_state_changed (NMManager *manager)
{
@ -436,3 +472,26 @@ nm_manager_get_active_device (NMManager *manager)
return NULL;
}
/* Connections */
GSList *
nm_manager_get_connections (NMManager *manager)
{
g_return_val_if_fail (NM_IS_MANAGER (manager), NULL);
return NM_MANAGER_GET_PRIVATE (manager)->connections;
}
void
nm_manager_update_connections (NMManager *manager,
GSList *connections,
gboolean reset)
{
g_return_if_fail (NM_IS_MANAGER (manager));
if (reset)
nm_manager_connections_destroy (manager);
}

View file

@ -28,21 +28,35 @@ typedef struct {
void (*device_removed) (NMManager *manager, NMDevice *device);
void (*state_change) (NMManager *manager, guint state);
void (*connection_added) (NMManager *manager, NMConnection *connection);
void (*connection_removed) (NMManager *manager, NMConnection *connection);
} NMManagerClass;
GType nm_manager_get_type (void);
NMManager *nm_manager_new (void);
/* Device handling */
void nm_manager_add_device (NMManager *manager, NMDevice *device);
void nm_manager_remove_device (NMManager *manager, NMDevice *device);
GSList *nm_manager_get_devices (NMManager *manager);
NMDevice *nm_manager_get_device_by_iface (NMManager *manager, const char *iface);
NMDevice *nm_manager_get_device_by_udi (NMManager *manager, const char *udi);
NMDevice *nm_manager_get_active_device (NMManager *manager);
/* State handling */
NMState nm_manager_get_state (NMManager *manager);
gboolean nm_manager_wireless_enabled (NMManager *manager);
void nm_manager_sleep (NMManager *manager, gboolean sleep);
NMDevice *nm_manager_get_active_device (NMManager *manager);
/* Connections */
GSList *nm_manager_get_connections (NMManager *manager);
void nm_manager_update_connections (NMManager *manager,
GSList *connections,
gboolean reset);
#endif /* NM_MANAGER_H */

View file

@ -236,8 +236,8 @@ detail_device (gpointer data, gpointer user_data)
/* Wireless specific information */
if ((NM_IS_DEVICE_802_11_WIRELESS (device))) {
guint32 wireless_caps;
NMAccessPoint *active_ap;
char *active_bssid;
NMAccessPoint *active_ap = NULL;
char *active_bssid = NULL;
GSList *networks;
printf ("\n Wireless Settings\n");
@ -254,8 +254,10 @@ detail_device (gpointer data, gpointer user_data)
if (wireless_caps & NM_802_11_CAP_PROTO_WPA2)
print_string (" WPA2 Encryption", "yes");
active_ap = nm_device_802_11_wireless_get_active_network (NM_DEVICE_802_11_WIRELESS (device));
active_bssid = active_ap ? nm_access_point_get_hw_address (active_ap) : NULL;
if (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED) {
active_ap = nm_device_802_11_wireless_get_active_network (NM_DEVICE_802_11_WIRELESS (device));
active_bssid = active_ap ? nm_access_point_get_hw_address (active_ap) : NULL;
}
printf ("\n Wireless Networks%s\n", active_ap ? "(* = Current Network)" : "");