2007-02-12 Tambet Ingo <tambet@ximian.com>

Totally break NetworkManager. Please use 0.6 branch until futher notice.

	* src/:
		- Remove old low-level dbus interface implementations and replace them
		  with dbus-glib one.

	* configure.in:
		- Require dbus-glib >= 0.72.
		- Plug in new sources to build.

	* libnm-glib/:
		- Implement GObject wrappers on top of DBUS glib auto-generated bindings
		  to make it more convenient to use from GObject based programs.

	* introspection/:
		- Implement DBUS XML introspection files, used by both NM and libnm-glib.



git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2309 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Tambet Ingo
2007-02-12 09:23:43 +00:00
committed by Tambet Ingo
parent 13af56e67d
commit 8a4c57f631
44 changed files with 1842 additions and 191 deletions

View File

@@ -1,3 +1,22 @@
2007-02-12 Tambet Ingo <tambet@ximian.com>
Totally break NetworkManager. Please use 0.6 branch until futher notice.
* src/:
- Remove old low-level dbus interface implementations and replace them
with dbus-glib one.
* configure.in:
- Require dbus-glib >= 0.72.
- Plug in new sources to build.
* libnm-glib/:
- Implement GObject wrappers on top of DBUS glib auto-generated bindings
to make it more convenient to use from GObject based programs.
* introspection/:
- Implement DBUS XML introspection files, used by both NM and libnm-glib.
2007-02-09 Tambet Ingo <tambet@ximian.com> 2007-02-09 Tambet Ingo <tambet@ximian.com>
* src/nm-device-802-11-wireless.c: * src/nm-device-802-11-wireless.c:

View File

@@ -1,6 +1,7 @@
SUBDIRS = \ SUBDIRS = \
utils \ utils \
libnm-util \ libnm-util \
libnm-glib \
src \ src \
dispatcher-daemon \ dispatcher-daemon \
gnome \ gnome \

View File

@@ -114,7 +114,7 @@ fi
IWLIB=-liw IWLIB=-liw
AC_SUBST(IWLIB) AC_SUBST(IWLIB)
PKG_CHECK_MODULES(DBUS, dbus-glib-1 >= 0.60) PKG_CHECK_MODULES(DBUS, dbus-glib-1 >= 0.72)
##### Find out the version of DBUS we're using ##### Find out the version of DBUS we're using
dbus_version=`pkg-config --modversion dbus-1` dbus_version=`pkg-config --modversion dbus-1`
@@ -353,6 +353,8 @@ src/supplicant-manager/Makefile
src/backends/Makefile src/backends/Makefile
libnm-util/libnm-util.pc libnm-util/libnm-util.pc
libnm-util/Makefile libnm-util/Makefile
libnm-glib/libnm-glib.pc
libnm-glib/Makefile
dispatcher-daemon/Makefile dispatcher-daemon/Makefile
gnome/Makefile gnome/Makefile
gnome/libnm_glib/libnm_glib.pc gnome/libnm_glib/libnm_glib.pc

View File

@@ -29,10 +29,12 @@
#define NM_DBUS_PATH "/org/freedesktop/NetworkManager" #define NM_DBUS_PATH "/org/freedesktop/NetworkManager"
#define NM_DBUS_INTERFACE "org.freedesktop.NetworkManager" #define NM_DBUS_INTERFACE "org.freedesktop.NetworkManager"
#define NM_DBUS_PATH_DEVICES "/org/freedesktop/NetworkManager/Devices" #define NM_DBUS_PATH_DEVICE "/org/freedesktop/NetworkManager/Device"
#define NM_DBUS_INTERFACE_DEVICES "org.freedesktop.NetworkManager.Devices" #define NM_DBUS_INTERFACE_DEVICE "org.freedesktop.NetworkManager.Device"
#define NM_DBUS_PATH_DHCP "/org/freedesktop/NetworkManager/DhcpOptions" #define NM_DBUS_INTERFACE_DEVICE_WIRED "org.freedesktop.NetworkManager.Device.Wired"
#define NM_DBUS_INTERFACE_DHCP "org.freedesktop.NetworkManager.DhcpOptions" #define NM_DBUS_INTERFACE_DEVICE_WIRELESS "org.freedesktop.NetworkManager.Device.Wireless"
#define NM_DBUS_PATH_ACCESS_POINT "/org/freedesktop/NetworkManager/AccessPoint"
#define NM_DBUS_INTERFACE_ACCESS_POINT "org.freedesktop.NetworkManager.AccessPoint"
#define NMI_DBUS_SERVICE "org.freedesktop.NetworkManagerInfo" #define NMI_DBUS_SERVICE "org.freedesktop.NetworkManagerInfo"
#define NMI_DBUS_PATH "/org/freedesktop/NetworkManagerInfo" #define NMI_DBUS_PATH "/org/freedesktop/NetworkManagerInfo"

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node name="/">
<interface name="org.freedesktop.NetworkManager.AccessPoint">
<property name="Address" type="s" access="read"/>
<property name="Broadcast" type="b" access="read"/>
<property name="Capabilities" type="i" access="read"/>
<property name="Encrypted" type="b" access="read"/>
<property name="Essid" type="s" access="read"/>
<property name="Frequency" type="d" access="read"/>
<property name="HWAddress" type="s" access="read"/>
<property name="Mode" type="i" access="read"/>
<property name="Rate" type="i" access="read"/>
<property name="Strength" type="i" access="read"/>
<signal name="StrengthChanged">
<arg name="strength" type="y"/>
</signal>
</interface>
</node>

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node name="/">
<interface name="org.freedesktop.NetworkManager.Device.Wireless">
<method name="Activate">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_activate"/>
<arg name="access_point" type="o" direction="in"/>
<arg name="user_requested" type="b" direction="in"/>
</method>
<method name="GetActiveNetworks">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_get_active_networks"/>
<arg name="networks" type="ao" direction="out"/>
</method>
<property name="Address" type="s" access="read"/>
<property name="Mode" type="i" access="read"/>
<property name="ActiveNetwork" type="o" access="read"/>
<signal name="NetworkAdded">
<arg name="network" type="o"/>
</signal>
<signal name="NetworkRemoved">
<arg name="network" type="o"/>
</signal>
</interface>
</node>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node name="/">
<interface name="org.freedesktop.NetworkManager.Device.Wired">
<method name="Activate">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_802_3_ethernet_activate"/>
<arg name="user_requested" type="b"/>
</method>
<property name="Address" type="s" access="read"/>
<property name="Speed" type="i" access="read"/>
</interface>
</node>

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node name="/">
<interface name="org.freedesktop.NetworkManager.Device">
<method name="Deactivate">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_deactivate"/>
</method>
<property name="Udi" type="s" access="read"/>
<property name="Interface" type="s" access="read"/>
<property name="Driver" type="s" access="read"/>
<property name="Capabilities" type="i" access="read"/>
<property name="Ip4Address" type="i" access="read"/>
<property name="UseDhcp" type="b" access="read"/>
<property name="State" type="u" access="read"/>
<!-- Ugh, but I see no other way of getting the type on the caller
based on dbus object path only -->
<property name="DeviceType" type="u" access="read"/>
<signal name="StateChanged">
<arg name="state" type="u"/>
</signal>
<signal name="CarrierChanged">
<arg name="carrier_on" type="b"/>
</signal>
</interface>
</node>

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node name="/">
<interface name="org.freedesktop.NetworkManager">
<method name="GetDevices">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_get_devices"/>
<arg name="devices" type="ao" direction="out"/>
</method>
<method name="Sleep">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_sleep"/>
<arg name="sleep" type="b" direction="in"/>
</method>
<property name="WirelessEnabled" type="b" access="readwrite"/>
<property name="State" type="u" access="read"/>
<signal name="StateChange">
<arg name="state" type="u"/>
</signal>
<signal name="DeviceAdded">
<arg name="state" type="o"/>
</signal>
<signal name="DeviceRemoved">
<arg name="state" type="o"/>
</signal>
</interface>
</node>

69
libnm-glib/Makefile.am Normal file
View File

@@ -0,0 +1,69 @@
INCLUDES = -I$(top_srcdir)/include
BUILT_SOURCES = \
nm-client-bindings.h \
nm-device-bindings.h \
nm-device-802-3-ethernet-bindings.h \
nm-device-802-11-wireless-bindings.h \
nm-access-point-bindings.h
lib_LTLIBRARIES = libnm-glib.la
libnm_glib_la_CPPFLAGS = \
$(GLIB_CFLAGS) \
$(DBUS_CFLAGS)
libnmincludedir = $(includedir)/libnm-glib
libnminclude_HEADERS = \
nm-client.h \
nm-device.h \
nm-device-802-3-ethernet.h \
nm-device-802-11-wireless.h \
nm-access-point.h
libnm_glib_la_SOURCES = \
nm-client.c \
nm-device.c \
nm-device-private.h \
nm-device-802-3-ethernet.c \
nm-device-802-11-wireless.c \
nm-access-point.c \
nm-utils.c \
nm-utils.h \
$(BUILT_SOURCES)
libnm_glib_la_LDFLAGS = $(GLIB_LIBS) $(DBUS_LIBS)
noinst_PROGRAMS = libnm-glib-test
AM_CPPFLAGS = $(GLIB_CFLAGS) $(DBUS_CFLAGS)
libnm_glib_test_SOURCES = libnm-glib-test.c
libnm_glib_test_LDADD = $(GLIB_LIBS) $(DBUS_LIBS) $(top_builddir)/libnm-glib/libnm-glib.la
nm-client-bindings.h: $(top_srcdir)/introspection/nm-manager.xml
dbus-binding-tool --prefix=nm_client --mode=glib-client --output=nm-client-bindings.h $(top_srcdir)/introspection/nm-manager.xml
nm-device-bindings.h: $(top_srcdir)/introspection/nm-device.xml
dbus-binding-tool --prefix=nm_device --mode=glib-client --output=nm-device-bindings.h $(top_srcdir)/introspection/nm-device.xml
nm-device-802-3-ethernet-bindings.h: $(top_srcdir)/introspection/nm-device-802-3-ethernet.xml
dbus-binding-tool --prefix=nm_device_802_3_ethernet --mode=glib-client --output=nm-device-802-3-ethernet-bindings.h $(top_srcdir)/introspection/nm-device-802-3-ethernet.xml
nm-device-802-11-wireless-bindings.h: $(top_srcdir)/introspection/nm-device-802-11-wireless.xml
dbus-binding-tool --prefix=nm_device_802_11_wireless --mode=glib-client --output=nm-device-802-11-wireless-bindings.h $(top_srcdir)/introspection/nm-device-802-11-wireless.xml
nm-access-point-bindings.h: $(top_srcdir)/introspection/nm-access-point.xml
dbus-binding-tool --prefix=nm_access_point --mode=glib-client --output=nm-access-point-bindings.h $(top_srcdir)/introspection/nm-access-point.xml
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libnm-glib.pc
DISTCLEANFILES = libnm-glib.pc
EXTRA_DIST = libnm-glib.pc.in
CLEANFILES = \
$(BUILT_SOURCES)

View File

@@ -0,0 +1,203 @@
#include <stdlib.h>
#include "nm-client.h"
#include "nm-device.h"
#include "nm-device-802-3-ethernet.h"
#include "nm-device-802-11-wireless.h"
static gboolean
test_wireless_enabled (NMClient *client)
{
gboolean wireless;
wireless = nm_client_wireless_get_enabled (client);
g_print ("Wireless enabled? %s\n", wireless ? "yes" : "no");
nm_client_wireless_set_enabled (client, !wireless);
wireless = nm_client_wireless_get_enabled (client);
g_print ("Wireless enabled? %s\n", wireless ? "yes" : "no");
nm_client_wireless_set_enabled (client, !wireless);
return TRUE;
}
static gboolean
test_get_state (NMClient *client)
{
guint state;
state = nm_client_get_state (client);
g_print ("Current state: %d\n", state);
return TRUE;
}
static void
dump_device (NMDevice *device)
{
char *str;
gboolean b;
guint32 u;
NMDeviceState state;
str = nm_device_get_iface (device);
g_print ("Interface: %s\n", str);
g_free (str);
str = nm_device_get_udi (device);
g_print ("Udi: %s\n", str);
g_free (str);
str = nm_device_get_driver (device);
g_print ("Driver: %s\n", str);
g_free (str);
b = nm_device_get_use_dhcp (device);
g_print ("Use DHCP: %s\n", b ? "yes" : "no");
u = nm_device_get_ip4_address (device);
g_print ("IP address: %d\n", u);
state = nm_device_get_state (device);
g_print ("State: %d\n", state);
if (NM_IS_DEVICE_802_3_ETHERNET (device)) {
int speed = nm_device_802_3_ethernet_get_speed (NM_DEVICE_802_3_ETHERNET (device));
g_print ("Speed: %d\n", speed);
} else if (NM_IS_DEVICE_802_11_WIRELESS (device)) {
GSList *iter;
GSList *networks = nm_device_802_11_wireless_get_networks (NM_DEVICE_802_11_WIRELESS (device));
g_print ("Networks:\n");
for (iter = networks; iter; iter = iter->next) {
NMAccessPoint *ap = NM_ACCESS_POINT (iter->data);
str = nm_access_point_get_essid (ap);
g_print ("\tEssid: %s\n", str);
g_free (str);
}
g_slist_foreach (networks, (GFunc) g_object_unref, NULL);
g_slist_free (networks);
}
}
static gboolean
test_devices (NMClient *client)
{
GSList *list, *iter;
list = nm_client_get_devices (client);
g_print ("Got devices:\n");
for (iter = list; iter; iter = iter->next) {
NMDevice *device = NM_DEVICE (iter->data);
dump_device (device);
g_print ("\n");
}
g_slist_foreach (list, (GFunc) g_object_unref, NULL);
g_slist_free (list);
return TRUE;
}
static void
device_added_cb (NMClient *client, NMDevice *device, gpointer user_data)
{
g_print ("New device added\n");
dump_device (device);
}
static void
device_removed_cb (NMClient *client, NMDevice *device, gpointer user_data)
{
g_print ("Device removed\n");
dump_device (device);
}
static gboolean
device_deactivate (gpointer user_data)
{
NMDevice *device = NM_DEVICE (user_data);
nm_device_deactivate (device);
return FALSE;
}
static void
device_state_changed (NMDevice *device, NMDeviceState state, gpointer user_data)
{
char *str;
str = nm_device_get_iface (device);
g_print ("Device state changed: %s %d\n", str, state);
g_free (str);
if (state == NM_DEVICE_STATE_ACTIVATED) {
g_print ("Scheduling device deactivation\n");
g_timeout_add (5 * 1000,
device_deactivate,
device);
}
}
static gboolean
do_stuff (gpointer user_data)
{
NMClient *client = NM_CLIENT (user_data);
GSList *list, *iter;
list = nm_client_get_devices (client);
for (iter = list; iter; iter = iter->next) {
if (NM_IS_DEVICE_802_3_ETHERNET (iter->data)) {
NMDevice8023Ethernet *device = NM_DEVICE_802_3_ETHERNET (iter->data);
g_signal_connect (device, "state-changed",
G_CALLBACK (device_state_changed),
NULL);
/* FIXME: This ref is never released */
g_object_ref (device);
nm_device_802_3_ethernet_activate (device, TRUE);
break;
}
}
g_slist_foreach (list, (GFunc) g_object_unref, NULL);
g_slist_free (list);
return FALSE;
}
int
main (int argc, char *argv[])
{
NMClient *client;
g_type_init ();
client = nm_client_new ();
if (!client) {
exit (1);
}
test_wireless_enabled (client);
test_get_state (client);
test_devices (client);
g_signal_connect (client, "device-added",
G_CALLBACK (device_added_cb), NULL);
g_signal_connect (client, "device-removed",
G_CALLBACK (device_removed_cb), NULL);
/* g_idle_add (do_stuff, client); */
g_main_loop_run (g_main_loop_new (NULL, FALSE));
g_object_unref (client);
return 0;
}

View File

@@ -0,0 +1,13 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: libnm_glib
Description: Convenience library for clients of NetworkManager
Version: @VERSION@
Requires: glib-2.0
Cflags: -I${includedir}/libnm-glib
Libs: -L${libdir} -lnm-glib

View File

@@ -0,0 +1,185 @@
#include "nm-access-point.h"
#include "NetworkManager.h"
#include "nm-access-point-bindings.h"
G_DEFINE_TYPE (NMAccessPoint, nm_access_point, DBUS_TYPE_G_PROXY)
static void
nm_access_point_init (NMAccessPoint *ap)
{
}
static void
nm_access_point_class_init (NMAccessPointClass *ap_class)
{
}
NMAccessPoint *
nm_access_point_new (DBusGConnection *connection, const char *path)
{
return (NMAccessPoint *) g_object_new (NM_TYPE_ACCESS_POINT,
"name", NM_DBUS_SERVICE,
"path", path,
"interface", NM_DBUS_INTERFACE_ACCESS_POINT,
"connection", connection,
NULL);
}
char *
nm_access_point_get_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,
"Address",
&value))
address = g_strdup (g_value_get_string (&value));
return address;
}
gboolean
nm_access_point_is_broadcast (NMAccessPoint *ap)
{
GValue value = {0,};
int broadcast = 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,
"Broadcast",
&value))
broadcast = g_value_get_boolean (&value);
return broadcast;
}
int
nm_access_point_get_capabilities (NMAccessPoint *ap)
{
GValue value = {0,};
int 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_int (&value);
return caps;
}
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;
}
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;
}
double
nm_access_point_get_frequency (NMAccessPoint *ap)
{
}
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;
}
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;
}
int
nm_access_point_get_rate (NMAccessPoint *ap)
{
GValue value = {0,};
int 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_int (&value);
return rate;
}
int
nm_access_point_get_strength (NMAccessPoint *ap)
{
GValue value = {0,};
int strength = 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,
"Strength",
&value))
strength = g_value_get_int (&value);
return strength;
}

View File

@@ -0,0 +1,38 @@
#ifndef NM_ACCESS_POINT_H
#define NM_ACCESS_POINT_H
#define NM_TYPE_ACCESS_POINT (nm_access_point_get_type ())
#define NM_ACCESS_POINT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_ACCESS_POINT, NMAccessPoint))
#define NM_ACCESS_POINT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_ACCESS_POINT, NMAccessPointClass))
#define NM_IS_ACCESS_POINT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_ACCESS_POINT))
#define NM_IS_ACCESS_POINT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_ACCESS_POINT))
#define NM_ACCESS_POINT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_ACCESS_POINT, NMAccessPointClass))
#include <glib/gtypes.h>
#include <glib-object.h>
#include <dbus/dbus-glib.h>
typedef struct {
DBusGProxy parent;
} NMAccessPoint;
typedef struct {
DBusGProxyClass parent;
} NMAccessPointClass;
GType nm_access_point_get_type (void);
NMAccessPoint *nm_access_point_new (DBusGConnection *connection, const char *path);
char *nm_access_point_get_address (NMAccessPoint *ap);
gboolean nm_access_point_is_broadcast (NMAccessPoint *ap);
int nm_access_point_get_capabilities (NMAccessPoint *ap);
gboolean nm_access_point_is_encrypted (NMAccessPoint *ap);
char *nm_access_point_get_essid (NMAccessPoint *ap);
double nm_access_point_get_frequency (NMAccessPoint *ap);
char *nm_access_point_get_hw_address (NMAccessPoint *ap);
int nm_access_point_get_mode (NMAccessPoint *ap);
int nm_access_point_get_rate (NMAccessPoint *ap);
int nm_access_point_get_strength (NMAccessPoint *ap);
#endif /* NM_ACCESS_POINT_H */

242
libnm-glib/nm-client.c Normal file
View File

@@ -0,0 +1,242 @@
#include <dbus/dbus-glib.h>
#include "nm-client.h"
#include "nm-device-802-3-ethernet.h"
#include "nm-device-802-11-wireless.h"
#include "nm-utils.h"
#include "nm-client-bindings.h"
G_DEFINE_TYPE (NMClient, nm_client, DBUS_TYPE_G_PROXY)
enum {
DEVICE_ADDED,
DEVICE_REMOVED,
STATE_CHANGE,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
static void client_state_change_proxy (DBusGProxy *proxy, guint state, gpointer user_data);
static void client_device_added_proxy (DBusGProxy *proxy, char *path, gpointer user_data);
static void client_device_removed_proxy (DBusGProxy *proxy, char *path, gpointer user_data);
static void
nm_client_init (NMClient *client)
{
}
static void
nm_client_class_init (NMClientClass *client_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (client_class);
/* signals */
signals[DEVICE_ADDED] =
g_signal_new ("device-added",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMClientClass, device_added),
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
G_TYPE_OBJECT);
signals[DEVICE_REMOVED] =
g_signal_new ("device-removed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMClientClass, device_removed),
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
G_TYPE_OBJECT);
signals[STATE_CHANGE] =
g_signal_new ("state-change",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMClientClass, state_change),
NULL, NULL,
g_cclosure_marshal_VOID__UINT,
G_TYPE_NONE, 1,
G_TYPE_UINT);
}
NMClient *
nm_client_new (void)
{
DBusGConnection *connection;
DBusGProxy *proxy;
NMClient *client;
GError *err = NULL;
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err);
if (!connection) {
g_warning ("Couldn't connect to system bus: %d", err->message);
g_error_free (err);
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),
client,
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),
client,
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),
client,
NULL);
return client;
}
static void
client_state_change_proxy (DBusGProxy *proxy, guint state, gpointer user_data)
{
NMClient *client = NM_CLIENT (user_data);
g_signal_emit (client, signals[STATE_CHANGE], 0, state);
}
static void
client_device_added_proxy (DBusGProxy *proxy, char *path, gpointer user_data)
{
NMClient *client = NM_CLIENT (user_data);
NMDevice *device;
DBusGConnection *connection = NULL;
g_object_get (client, "connection", &connection, NULL);
device = nm_device_new (connection, path);
g_signal_emit (client, signals[DEVICE_ADDED], 0, device);
g_object_unref (device);
}
static void
client_device_removed_proxy (DBusGProxy *proxy, char *path, gpointer user_data)
{
NMClient *client = NM_CLIENT (user_data);
NMDevice *device;
DBusGConnection *connection = NULL;
g_object_get (client, "connection", &connection, NULL);
device = nm_device_new (connection, path);
g_signal_emit (client, signals[DEVICE_REMOVED], 0, device);
g_object_unref (device);
}
GSList *
nm_client_get_devices (NMClient *client)
{
GSList *list = NULL;
GPtrArray *array = NULL;
GError *err = NULL;
g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
if (!org_freedesktop_NetworkManager_get_devices (DBUS_G_PROXY (client), &array, &err)) {
g_warning ("Error in get_devices: %s", err->message);
g_error_free (err);
} else {
DBusGConnection *connection = NULL;
int i;
g_object_get (client, "connection", &connection, NULL);
for (i = 0; i < array->len; i++) {
NMDevice *device;
const char *path = g_ptr_array_index (array, i);
NMDeviceType type = nm_device_type_for_path (connection, path);
switch (type) {
case DEVICE_TYPE_802_3_ETHERNET:
device = NM_DEVICE (nm_device_802_3_ethernet_new (connection, path));
break;
case DEVICE_TYPE_802_11_WIRELESS:
device = NM_DEVICE (nm_device_802_11_wireless_new (connection, path));
break;
default:
device = nm_device_new (connection, path);
break;
}
list = g_slist_append (list, device);
}
g_ptr_array_free (array, TRUE);
}
return list;
}
gboolean
nm_client_wireless_get_enabled (NMClient *client)
{
GValue value = {0,};
gboolean enabled = 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;
}
void
nm_client_wireless_set_enabled (NMClient *client, gboolean enabled)
{
GValue value = {0,};
g_return_if_fail (NM_IS_CLIENT (client));
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);
}
NMState
nm_client_get_state (NMClient *client)
{
GValue value = {0,};
NMState state = NM_STATE_UNKNOWN;
g_return_val_if_fail (NM_IS_CLIENT (client), state);
if (nm_dbus_get_property (DBUS_G_PROXY (client),
NM_DBUS_INTERFACE,
"State",
&value))
state = g_value_get_uint (&value);
return state;
}

42
libnm-glib/nm-client.h Normal file
View File

@@ -0,0 +1,42 @@
#ifndef NM_CLIENT_H
#define NM_CLIENT_H 1
#include <glib/gtypes.h>
#include <glib-object.h>
#include <dbus/dbus-glib.h>
#include "NetworkManager.h"
#include "nm-device.h"
#define NM_TYPE_CLIENT (nm_client_get_type ())
#define NM_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CLIENT, NMClient))
#define NM_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_CLIENT, NMClientClass))
#define NM_IS_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_CLIENT))
#define NM_IS_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_CLIENT))
#define NM_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_CLIENT, NMClientClass))
typedef struct {
DBusGProxy parent;
} NMClient;
typedef struct {
DBusGProxyClass parent;
/* Signals */
void (*device_added) (NMClient *client, NMDevice *device);
void (*device_removed) (NMClient *client, NMDevice *device);
void (*state_change) (NMClient *client, NMState state);
} NMClientClass;
GType nm_client_get_type (void);
NMClient *nm_client_new (void);
GSList *nm_client_get_devices (NMClient *client);
gboolean nm_client_wireless_get_enabled (NMClient *client);
void nm_client_wireless_set_enabled (NMClient *client, gboolean enabled);
NMState nm_client_get_state (NMClient *client);
#endif /* NM_CLIENT_H */

View File

@@ -0,0 +1,133 @@
#include "nm-device-802-11-wireless.h"
#include "nm-device-private.h"
#include "nm-device-802-11-wireless-bindings.h"
G_DEFINE_TYPE (NMDevice80211Wireless, nm_device_802_11_wireless, NM_TYPE_DEVICE)
static void
nm_device_802_11_wireless_init (NMDevice80211Wireless *device)
{
}
static void
nm_device_802_11_wireless_class_init (NMDevice80211WirelessClass *device_class)
{
}
NMDevice80211Wireless *
nm_device_802_11_wireless_new (DBusGConnection *connection, const char *path)
{
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
return (NMDevice80211Wireless *) g_object_new (NM_TYPE_DEVICE_802_11_WIRELESS,
"name", NM_DBUS_SERVICE,
"path", path,
"interface", NM_DBUS_INTERFACE_DEVICE_WIRELESS,
"connection", connection,
NULL);
}
char *
nm_device_802_11_wireless_get_address (NMDevice80211Wireless *device)
{
GValue value = {0,};
char *address = NULL;
g_return_val_if_fail (NM_IS_DEVICE_802_11_WIRELESS (device), NULL);
if (nm_dbus_get_property (DBUS_G_PROXY (device),
NM_DBUS_INTERFACE_DEVICE_WIRELESS,
"Address",
&value))
address = g_strdup (g_value_get_string (&value));
return address;
}
int
nm_device_802_11_wireless_get_mode (NMDevice80211Wireless *device)
{
GValue value = {0,};
int mode = 0;
g_return_val_if_fail (NM_IS_DEVICE_802_11_WIRELESS (device), 0);
if (nm_dbus_get_property (DBUS_G_PROXY (device),
NM_DBUS_INTERFACE_DEVICE_WIRELESS,
"Node",
&value))
mode = g_value_get_int (&value);
return mode;
}
NMAccessPoint *
nm_device_802_11_wireless_get_active_network (NMDevice80211Wireless *device)
{
GValue value = {0,};
NMAccessPoint *ap = NULL;
g_return_val_if_fail (NM_IS_DEVICE_802_11_WIRELESS (device), NULL);
if (nm_dbus_get_property (DBUS_G_PROXY (device),
NM_DBUS_INTERFACE_DEVICE_WIRELESS,
"ActiveNetwork",
&value)) {
DBusGConnection *connection = NULL;
g_object_get (device, "connection", &connection, NULL);
ap = nm_access_point_new (connection, g_value_get_string (&value));
}
return ap;
}
GSList *
nm_device_802_11_wireless_get_networks (NMDevice80211Wireless *device)
{
GSList *list = NULL;
GPtrArray *array = NULL;
GError *err = NULL;
g_return_val_if_fail (NM_IS_DEVICE_802_11_WIRELESS (device), NULL);
if (!org_freedesktop_NetworkManager_Device_Wireless_get_active_networks (DBUS_G_PROXY (device), &array, &err)) {
g_warning ("Error in get_networks: %s", err->message);
g_error_free (err);
} else {
DBusGConnection *connection = NULL;
int i;
g_object_get (device, "connection", &connection, NULL);
for (i = 0; i < array->len; i++) {
NMAccessPoint *ap = nm_access_point_new (connection, g_ptr_array_index (array, i));
list = g_slist_prepend (list, ap);
}
list = g_slist_reverse (list);
g_ptr_array_free (array, TRUE);
}
return list;
}
void
nm_device_802_11_wireless_activate (NMDevice80211Wireless *device,
NMAccessPoint *ap,
gboolean user_requested)
{
GError *err = NULL;
g_return_if_fail (NM_IS_DEVICE_802_11_WIRELESS (device));
g_return_if_fail (NM_IS_ACCESS_POINT (ap));
if (!org_freedesktop_NetworkManager_Device_Wireless_activate (DBUS_G_PROXY (device),
dbus_g_proxy_get_path (DBUS_G_PROXY (ap)),
user_requested,
&err)) {
g_warning ("Error in wireless_activate: %s", err->message);
g_error_free (err);
}
}

View File

@@ -0,0 +1,37 @@
#ifndef NM_DEVICE_802_11_WIRELESS_H
#define NM_DEVICE_802_11_WIRELESS_H
#include "nm-device.h"
#include "nm-access-point.h"
#define NM_TYPE_DEVICE_802_11_WIRELESS (nm_device_802_11_wireless_get_type ())
#define NM_DEVICE_802_11_WIRELESS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_802_11_WIRELESS, NMDevice80211Wireless))
#define NM_DEVICE_802_11_WIRELESS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_802_11_WIRELESS, NMDevice80211WirelessClass))
#define NM_IS_DEVICE_802_11_WIRELESS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_802_11_WIRELESS))
#define NM_IS_DEVICE_802_11_WIRELESS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_DEVICE_802_11_WIRELESS))
#define NM_DEVICE_802_11_WIRELESS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_802_11_WIRELESS, NMDevice80211WirelessClass))
typedef struct {
NMDevice parent;
} NMDevice80211Wireless;
typedef struct {
NMDeviceClass parent;
} NMDevice80211WirelessClass;
GType nm_device_802_11_wireless_get_type (void);
NMDevice80211Wireless *nm_device_802_11_wireless_new (DBusGConnection *connection,
const char *path);
int nm_device_802_11_wireless_get_speed (NMDevice80211Wireless *device);
char *nm_device_802_11_wireless_get_address (NMDevice80211Wireless *device);
int nm_device_802_11_wireless_get_mode (NMDevice80211Wireless *device);
NMAccessPoint *nm_device_802_11_wireless_get_active_network (NMDevice80211Wireless *device);
GSList *nm_device_802_11_wireless_get_networks (NMDevice80211Wireless *device);
void nm_device_802_11_wireless_activate (NMDevice80211Wireless *device,
NMAccessPoint *ap,
gboolean user_requested);
#endif /* NM_DEVICE_802_11_WIRELESS_H */

View File

@@ -0,0 +1,78 @@
#include "nm-device-802-3-ethernet.h"
#include "nm-device-private.h"
#include "nm-device-802-3-ethernet-bindings.h"
G_DEFINE_TYPE (NMDevice8023Ethernet, nm_device_802_3_ethernet, NM_TYPE_DEVICE)
static void
nm_device_802_3_ethernet_init (NMDevice8023Ethernet *device)
{
}
static void
nm_device_802_3_ethernet_class_init (NMDevice8023EthernetClass *device_class)
{
}
NMDevice8023Ethernet *
nm_device_802_3_ethernet_new (DBusGConnection *connection, const char *path)
{
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
return (NMDevice8023Ethernet *) g_object_new (NM_TYPE_DEVICE_802_3_ETHERNET,
"name", NM_DBUS_SERVICE,
"path", path,
"interface", NM_DBUS_INTERFACE_DEVICE_WIRED,
"connection", connection,
NULL);
}
int
nm_device_802_3_ethernet_get_speed (NMDevice8023Ethernet *device)
{
int speed = 0;
GValue value = {0,};
g_return_val_if_fail (NM_IS_DEVICE_802_3_ETHERNET (device), 0);
if (nm_dbus_get_property (DBUS_G_PROXY (device),
NM_DBUS_INTERFACE_DEVICE_WIRED,
"Speed",
&value))
speed = g_value_get_int (&value);
return speed;
}
char *
nm_device_802_3_ethernet_get_address (NMDevice8023Ethernet *device)
{
char *address = NULL;
GValue value = {0,};
g_return_val_if_fail (NM_IS_DEVICE_802_3_ETHERNET (device), NULL);
if (nm_dbus_get_property (DBUS_G_PROXY (device),
NM_DBUS_INTERFACE_DEVICE_WIRED,
"Address",
&value))
address = g_strdup (g_value_get_string (&value));
return address;
}
void
nm_device_802_3_ethernet_activate (NMDevice8023Ethernet *device, gboolean user_requested)
{
GError *err = NULL;
g_return_if_fail (NM_IS_DEVICE_802_3_ETHERNET (device));
if (!org_freedesktop_NetworkManager_Device_Wired_activate (DBUS_G_PROXY (device),
user_requested, &err)) {
g_warning ("Activation failed: %s", err->message);
g_error_free (err);
}
}

View File

@@ -0,0 +1,30 @@
#ifndef NM_DEVICE_802_3_ETHERNET_H
#define NM_DEVICE_802_3_ETHERNET_H
#include "nm-device.h"
#define NM_TYPE_DEVICE_802_3_ETHERNET (nm_device_802_3_ethernet_get_type ())
#define NM_DEVICE_802_3_ETHERNET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_802_3_ETHERNET, NMDevice8023Ethernet))
#define NM_DEVICE_802_3_ETHERNET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_802_3_ETHERNET, NMDevice8023EthernetClass))
#define NM_IS_DEVICE_802_3_ETHERNET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_802_3_ETHERNET))
#define NM_IS_DEVICE_802_3_ETHERNET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_DEVICE_802_3_ETHERNET))
#define NM_DEVICE_802_3_ETHERNET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_802_3_ETHERNET, NMDevice8023EthernetClass))
typedef struct {
NMDevice parent;
} NMDevice8023Ethernet;
typedef struct {
NMDeviceClass parent;
} NMDevice8023EthernetClass;
GType nm_device_802_3_ethernet_get_type (void);
NMDevice8023Ethernet *nm_device_802_3_ethernet_new (DBusGConnection *connection,
const char *path);
int nm_device_802_3_ethernet_get_speed (NMDevice8023Ethernet *device);
char *nm_device_802_3_ethernet_get_address (NMDevice8023Ethernet *device);
void nm_device_802_3_ethernet_activate (NMDevice8023Ethernet *device,
gboolean user_requested);
#endif /* NM_DEVICE_802_3_ETHERNET_H */

View File

@@ -0,0 +1,8 @@
#ifndef NM_DEVICE_PRIVATE_H
#define NM_DEVICE_PRIVATE_H
/* static methods */
NMDeviceType nm_device_type_for_path (DBusGConnection *connection,
const char *path);
#endif /* NM_DEVICE_PRIVATE_H */

226
libnm-glib/nm-device.c Normal file
View File

@@ -0,0 +1,226 @@
#include "nm-device.h"
#include "nm-device-private.h"
#include "nm-device-bindings.h"
G_DEFINE_TYPE (NMDevice, nm_device, DBUS_TYPE_G_PROXY)
enum {
STATE_CHANGED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
static void device_state_change_proxy (DBusGProxy *proxy, guint state, gpointer user_data);
static void
nm_device_init (NMDevice *device)
{
}
static GObject*
constructor (GType type,
guint n_construct_params,
GObjectConstructParam *construct_params)
{
GObject *object;
object = G_OBJECT_CLASS (nm_device_parent_class)->constructor (type,
n_construct_params,
construct_params);
if (!object)
return NULL;
dbus_g_proxy_add_signal (DBUS_G_PROXY (object), "StateChanged", G_TYPE_UINT, G_TYPE_INVALID);
dbus_g_proxy_connect_signal (DBUS_G_PROXY (object),
"StateChanged",
G_CALLBACK (device_state_change_proxy),
object,
NULL);
return object;
}
static void
nm_device_class_init (NMDeviceClass *device_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (device_class);
/* virtual methods */
object_class->constructor = constructor;
/* signals */
signals[STATE_CHANGED] =
g_signal_new ("state-changed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMDeviceClass, state_changed),
NULL, NULL,
g_cclosure_marshal_VOID__UINT,
G_TYPE_NONE, 1,
G_TYPE_UINT);
}
static void
device_state_change_proxy (DBusGProxy *proxy, guint state, gpointer user_data)
{
NMDevice *device = NM_DEVICE (user_data);
g_signal_emit (device, signals[STATE_CHANGED], 0, state);
}
NMDevice *
nm_device_new (DBusGConnection *connection, const char *path)
{
return (NMDevice *) g_object_new (NM_TYPE_DEVICE,
"name", NM_DBUS_SERVICE,
"path", path,
"interface", NM_DBUS_INTERFACE_DEVICE,
"connection", connection,
NULL);
}
void
nm_device_deactivate (NMDevice *device)
{
GError *err = NULL;
g_return_if_fail (NM_IS_DEVICE (device));
if (!org_freedesktop_NetworkManager_Device_deactivate (DBUS_G_PROXY (device), &err)) {
g_warning ("Cannot deactivate device: %s", err->message);
g_error_free (err);
}
}
char *
nm_device_get_iface (NMDevice *device)
{
char *iface = NULL;
GValue value = {0,};
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
if (nm_dbus_get_property (DBUS_G_PROXY (device),
NM_DBUS_INTERFACE_DEVICE,
"Interface",
&value))
iface = g_strdup (g_value_get_string (&value));
return iface;
}
char *
nm_device_get_udi (NMDevice *device)
{
char *udi = NULL;
GValue value = {0,};
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
if (nm_dbus_get_property (DBUS_G_PROXY (device),
NM_DBUS_INTERFACE_DEVICE,
"Udi",
&value))
udi = g_strdup (g_value_get_string (&value));
return udi;
}
char *
nm_device_get_driver (NMDevice *device)
{
char *driver = NULL;
GValue value = {0,};
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
if (nm_dbus_get_property (DBUS_G_PROXY (device),
NM_DBUS_INTERFACE_DEVICE,
"Driver",
&value))
driver = g_strdup (g_value_get_string (&value));
return driver;
}
gboolean
nm_device_get_use_dhcp (NMDevice *device)
{
gboolean dhcp = FALSE;
GValue value = {0,};
g_return_val_if_fail (NM_IS_DEVICE (device), FALSE);
if (nm_dbus_get_property (DBUS_G_PROXY (device),
NM_DBUS_INTERFACE_DEVICE,
"UseDhcp",
&value))
dhcp = g_value_get_boolean (&value);
return dhcp;
}
guint32
nm_device_get_ip4_address (NMDevice *device)
{
guint32 address = 0;
GValue value = {0,};
g_return_val_if_fail (NM_IS_DEVICE (device), 0);
if (nm_dbus_get_property (DBUS_G_PROXY (device),
NM_DBUS_INTERFACE_DEVICE,
"Ip4Address",
&value))
address = g_value_get_uint (&value);
return address;
}
NMDeviceState
nm_device_get_state (NMDevice *device)
{
NMDeviceState state = NM_DEVICE_STATE_UNKNOWN;
GValue value = {0,};
g_return_val_if_fail (NM_IS_DEVICE (device), 0);
if (nm_dbus_get_property (DBUS_G_PROXY (device),
NM_DBUS_INTERFACE_DEVICE,
"State",
&value))
state = g_value_get_uint (&value);
return state;
}
NMDeviceType
nm_device_type_for_path (DBusGConnection *connection,
const char *path)
{
DBusGProxy *proxy;
GValue value = {0,};
NMDeviceType type = DEVICE_TYPE_UNKNOWN;
g_return_val_if_fail (connection != NULL, type);
g_return_val_if_fail (path != NULL, type);
proxy = dbus_g_proxy_new_for_name (connection,
NM_DBUS_SERVICE,
path,
NM_DBUS_INTERFACE_DEVICE);
if (nm_dbus_get_property (proxy,
NM_DBUS_INTERFACE_DEVICE,
"DeviceType",
&value))
type = (NMDeviceType) g_value_get_uint (&value);
g_object_unref (proxy);
return type;
}

40
libnm-glib/nm-device.h Normal file
View File

@@ -0,0 +1,40 @@
#ifndef NM_DEVICE_H
#define NM_DEVICE_H
#include <glib/gtypes.h>
#include <glib-object.h>
#include <dbus/dbus-glib.h>
#include "NetworkManager.h"
#define NM_TYPE_DEVICE (nm_device_get_type ())
#define NM_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE, NMDevice))
#define NM_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE, NMDeviceClass))
#define NM_IS_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE))
#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))
typedef struct {
DBusGProxy parent;
} NMDevice;
typedef struct {
DBusGProxyClass parent;
/* Signals */
void (*state_changed) (NMDevice *device, NMDeviceState state);
} NMDeviceClass;
GType nm_device_get_type (void);
NMDevice *nm_device_new (DBusGConnection *connection, const char *path);
void nm_device_deactivate (NMDevice *device);
char *nm_device_get_iface (NMDevice *device);
char *nm_device_get_udi (NMDevice *device);
char *nm_device_get_driver (NMDevice *device);
gboolean nm_device_get_use_dhcp (NMDevice *device);
guint32 nm_device_get_ip4_address (NMDevice *device);
NMDeviceState nm_device_get_state (NMDevice *device);
#endif /* NM_DEVICE_H */

89
libnm-glib/nm-utils.c Normal file
View File

@@ -0,0 +1,89 @@
#include "nm-utils.h"
gboolean
nm_dbus_get_property (DBusGProxy *proxy,
const char *interface,
const char *prop_name,
GValue *value)
{
DBusGProxy *properties_proxy;
GError *err = NULL;
gboolean ret = TRUE;
g_return_val_if_fail (proxy != NULL, FALSE);
g_return_val_if_fail (interface != NULL, FALSE);
g_return_val_if_fail (prop_name != NULL, FALSE);
properties_proxy = dbus_g_proxy_new_from_proxy (proxy,
"org.freedesktop.DBus.Properties",
dbus_g_proxy_get_path (proxy));
if (!dbus_g_proxy_call (properties_proxy, "Get", &err,
G_TYPE_STRING, interface,
G_TYPE_STRING, prop_name,
G_TYPE_INVALID,
G_TYPE_VALUE, value,
G_TYPE_INVALID)) {
g_warning ("Error in device_get_property: %s\n", err->message);
g_error_free (err);
ret = FALSE;
}
g_object_unref (properties_proxy);
return ret;
}
void
nm_dbus_set_property (DBusGProxy *proxy,
const char *interface,
const char *prop_name,
GValue *value)
{
DBusGProxy *properties_proxy;
g_return_if_fail (proxy != NULL);
g_return_if_fail (interface != NULL);
g_return_if_fail (prop_name != NULL);
properties_proxy = dbus_g_proxy_new_from_proxy (proxy,
"org.freedesktop.DBus.Properties",
dbus_g_proxy_get_path (proxy));
dbus_g_proxy_call_no_reply (properties_proxy, "Set",
G_TYPE_STRING, interface,
G_TYPE_STRING, prop_name,
G_TYPE_VALUE, value,
G_TYPE_INVALID);
g_object_unref (properties_proxy);
}
char *
nm_dbus_introspect (DBusGConnection *connection,
const char *interface,
const char *path)
{
DBusGProxy *remote_object_introspectable;
char *introspect_data = NULL;
GError *err = NULL;
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (interface != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
remote_object_introspectable = dbus_g_proxy_new_for_name (connection,
interface,
path,
"org.freedesktop.DBus.Introspectable");
if (!dbus_g_proxy_call (remote_object_introspectable, "Introspect", &err,
G_TYPE_INVALID,
G_TYPE_STRING, &introspect_data, G_TYPE_INVALID)) {
g_error ("Failed to complete Introspect %s", err->message);
g_error_free (err);
}
g_object_unref (G_OBJECT (remote_object_introspectable));
return introspect_data;
}

19
libnm-glib/nm-utils.h Normal file
View File

@@ -0,0 +1,19 @@
#ifndef NM_UTILS_H
#define NM_UTILS_H
#include <dbus/dbus-glib.h>
gboolean nm_dbus_get_property (DBusGProxy *proxy,
const char *interface,
const char *prop_name,
GValue *value);
void nm_dbus_set_property (DBusGProxy *proxy,
const char *interface,
const char *prop_name,
GValue *value);
char *nm_dbus_introspect (DBusGConnection *connection,
const char *interface,
const char *path);
#endif /* NM_UTILS_H */

View File

@@ -34,12 +34,6 @@ NetworkManager_SOURCES = \
NetworkManagerDbusUtils.h \ NetworkManagerDbusUtils.h \
nm-dbus-manager.h \ nm-dbus-manager.h \
nm-dbus-manager.c \ nm-dbus-manager.c \
nm-dbus-nm.c \
nm-dbus-nm.h \
nm-dbus-device.c \
nm-dbus-device.h \
nm-dbus-net.c \
nm-dbus-net.h \
nm-dbus-nmi.c \ nm-dbus-nmi.c \
nm-dbus-nmi.h \ nm-dbus-nmi.h \
nm-hal-manager.c \ nm-hal-manager.c \
@@ -94,9 +88,30 @@ nm-marshal.c: Makefile.am nm-marshal.list
nm-marshal-main.c: nm-marshal.c nm-marshal.h nm-marshal-main.c: nm-marshal.c nm-marshal.h
nm-access-point-glue.h: $(top_srcdir)/introspection/nm-access-point.xml
dbus-binding-tool --prefix=nm_access_point --mode=glib-server --output=nm-access-point-glue.h $(top_srcdir)/introspection/nm-access-point.xml
nm-manager-glue.h: $(top_srcdir)/introspection/nm-manager.xml
dbus-binding-tool --prefix=nm_manager --mode=glib-server --output=nm-manager-glue.h $(top_srcdir)/introspection/nm-manager.xml
nm-device-interface-glue.h: $(top_srcdir)/introspection/nm-device.xml
dbus-binding-tool --prefix=nm_device_interface --mode=glib-server --output=nm-device-interface-glue.h $(top_srcdir)/introspection/nm-device.xml
nm-device-802-3-ethernet-glue.h: $(top_srcdir)/introspection/nm-device-802-3-ethernet.xml
dbus-binding-tool --prefix=nm_device_802_3_ethernet --mode=glib-server --output=nm-device-802-3-ethernet-glue.h $(top_srcdir)/introspection/nm-device-802-3-ethernet.xml
nm-device-802-11-wireless-glue.h: $(top_srcdir)/introspection/nm-device-802-11-wireless.xml
dbus-binding-tool --prefix=nm_device_802_11_wireless --mode=glib-server --output=nm-device-802-11-wireless-glue.h $(top_srcdir)/introspection/nm-device-802-11-wireless.xml
built_sources = \ built_sources = \
nm-marshal.h \ nm-marshal.h \
nm-marshal.c \ nm-marshal.c \
nm-access-point-glue.h \
nm-manager-glue.h \
nm-device-interface-glue.h \
nm-device-802-3-ethernet-glue.h \
nm-device-802-11-wireless-glue.h \
$(NULL) $(NULL)
$(NetworkManager_OBJECTS): $(built_sources) $(NetworkManager_OBJECTS): $(built_sources)

View File

@@ -225,9 +225,6 @@ static void nm_data_free (NMData *data)
nm_ap_list_unref (data->allowed_ap_list); nm_ap_list_unref (data->allowed_ap_list);
nm_ap_list_unref (data->invalid_ap_list); nm_ap_list_unref (data->invalid_ap_list);
nm_dbus_method_list_unref (data->nm_methods);
nm_dbus_method_list_unref (data->device_methods);
nm_vpn_manager_dispose (data->vpn_manager); nm_vpn_manager_dispose (data->vpn_manager);
g_object_unref (data->named_manager); g_object_unref (data->named_manager);
@@ -423,13 +420,6 @@ main (int argc, char *argv[])
nm_data); nm_data);
nm_data->nmi_sig_handler_id = id; nm_data->nmi_sig_handler_id = id;
/* Register DBus method handlers for the main NM objects */
nm_data->nm_methods = nm_dbus_nm_methods_setup (nm_data);
nm_dbus_manager_register_method_list (dbus_mgr, nm_data->nm_methods);
nm_data->device_methods = nm_dbus_device_methods_setup (nm_data);
nm_dbus_manager_register_method_list (dbus_mgr, nm_data->device_methods);
nm_data->net_methods = nm_dbus_net_methods_setup (nm_data);
manager = nm_manager_new (); manager = nm_manager_new ();
policy = nm_policy_new (manager); policy = nm_policy_new (manager);

View File

@@ -104,7 +104,7 @@ char * nm_dbus_get_object_path_for_device (NMDevice *dev)
g_return_val_if_fail (dev != NULL, NULL); g_return_val_if_fail (dev != NULL, NULL);
object_path = g_strdup_printf ("%s/%s", NM_DBUS_PATH_DEVICES, nm_device_get_iface (dev)); object_path = g_strdup_printf ("%s/%s", NM_DBUS_PATH_DEVICE, nm_device_get_iface (dev));
escaped_object_path = nm_dbus_escape_object_path (object_path); escaped_object_path = nm_dbus_escape_object_path (object_path);
g_free (object_path); g_free (object_path);
@@ -128,7 +128,7 @@ char * nm_dbus_get_object_path_for_network (NMDevice *dev, NMAccessPoint *ap)
if (!nm_ap_get_essid (ap)) if (!nm_ap_get_essid (ap))
return NULL; return NULL;
object_path = g_strdup_printf ("%s/%s/Networks/%s", NM_DBUS_PATH_DEVICES, nm_device_get_iface (dev), nm_ap_get_essid (ap)); 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); escaped_object_path = nm_dbus_escape_object_path (object_path);
g_free (object_path); g_free (object_path);
@@ -159,7 +159,7 @@ NMDevice *nm_dbus_get_device_from_escaped_object_path (NMData *data, const char
if (!(dev = NM_DEVICE (elt->data))) if (!(dev = NM_DEVICE (elt->data)))
continue; continue;
compare_path = g_strdup_printf ("%s/%s", NM_DBUS_PATH_DEVICES, nm_device_get_iface (dev)); compare_path = g_strdup_printf ("%s/%s", NM_DBUS_PATH_DEVICE, nm_device_get_iface (dev));
escaped_compare_path = nm_dbus_escape_object_path (compare_path); escaped_compare_path = nm_dbus_escape_object_path (compare_path);
g_free (compare_path); g_free (compare_path);
len = strlen (escaped_compare_path); len = strlen (escaped_compare_path);

View File

@@ -48,10 +48,6 @@ typedef struct NMData
NMVPNManager * vpn_manager; NMVPNManager * vpn_manager;
guint32 nmi_sig_handler_id; guint32 nmi_sig_handler_id;
NMDbusMethodList * nm_methods;
NMDbusMethodList * device_methods;
NMDbusMethodList * net_methods;
GMainLoop * main_loop; GMainLoop * main_loop;
gboolean enable_test_devices; gboolean enable_test_devices;

View File

@@ -654,7 +654,7 @@ nm_dbus_device_message_handler (DBusConnection *connection,
/* Test whether or not the _networks_ of a device were queried instead of the device itself */ /* Test whether or not the _networks_ of a device were queried instead of the device itself */
object_path = g_strdup_printf ("%s/%s/Networks/", object_path = g_strdup_printf ("%s/%s/Networks/",
NM_DBUS_PATH_DEVICES, NM_DBUS_PATH_DEVICE,
nm_device_get_iface (dev)); nm_device_get_iface (dev));
escaped_object_path = nm_dbus_escape_object_path (object_path); escaped_object_path = nm_dbus_escape_object_path (object_path);
g_free (object_path); g_free (object_path);
@@ -703,7 +703,7 @@ NMDbusMethodList *nm_dbus_device_methods_setup (NMData *data)
g_return_val_if_fail (data != NULL, NULL); g_return_val_if_fail (data != NULL, NULL);
list = nm_dbus_method_list_new (NM_DBUS_PATH_DEVICES, TRUE, data, NULL); list = nm_dbus_method_list_new (NM_DBUS_PATH_DEVICE, TRUE, data, NULL);
nm_dbus_method_list_set_custom_handler_func (list, nm_dbus_device_message_handler); nm_dbus_method_list_set_custom_handler_func (list, nm_dbus_device_message_handler);
nm_dbus_method_list_add_method (list, "getProperties", nm_dbus_device_get_properties); nm_dbus_method_list_add_method (list, "getProperties", nm_dbus_device_get_properties);

View File

@@ -72,8 +72,6 @@ typedef struct {
DBusGProxy * proxy; DBusGProxy * proxy;
gboolean started; gboolean started;
GSList * msg_handlers;
GSList * matches; GSList * matches;
GSList * signal_handlers; GSList * signal_handlers;
guint32 sig_handler_id_counter; guint32 sig_handler_id_counter;
@@ -155,9 +153,6 @@ nm_dbus_manager_finalize (GObject *object)
nm_dbus_manager_cleanup (self); nm_dbus_manager_cleanup (self);
g_slist_foreach (priv->msg_handlers, cleanup_handler_data, NULL);
g_slist_free (priv->msg_handlers);
G_OBJECT_CLASS (nm_dbus_manager_parent_class)->finalize (object); G_OBJECT_CLASS (nm_dbus_manager_parent_class)->finalize (object);
} }
@@ -695,49 +690,6 @@ out:
return success; return success;
} }
static gboolean
nm_dbus_manager_register_method_handlers (NMDBusManager *self)
{
NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE (self);
gboolean success = FALSE;
GSList * elt;
for (elt = priv->msg_handlers; elt; elt = g_slist_next (elt)) {
MethodHandlerData * data = (MethodHandlerData *) elt->data;
DBusObjectPathVTable vtable = {NULL, &nm_dbus_manager_message_handler,
NULL, NULL, NULL, NULL};
dbus_bool_t ret = FALSE;
const char * path;
if (!nm_dbus_method_list_get_path (data->list)) {
nm_warning ("DBus message handler had no path.");
continue;
}
/* If the method list object specifies a custom handler, use that
* instead of our default built-in one.
*/
path = nm_dbus_method_list_get_path (data->list);
if (nm_dbus_method_list_get_is_fallback (data->list)) {
ret = dbus_connection_register_fallback (priv->connection,
path, &vtable, data);
} else {
ret = dbus_connection_register_object_path (priv->connection,
path, &vtable, data);
}
if (ret == FALSE) {
nm_warning ("Could not register DBus message handler for path %s.",
path);
goto out;
}
}
success = TRUE;
out:
return success;
}
/* Register our service on the bus; shouldn't be called until /* Register our service on the bus; shouldn't be called until
* all necessary message handlers have been registered, because * all necessary message handlers have been registered, because
* when we register on the bus, clients may start to call. * when we register on the bus, clients may start to call.
@@ -760,10 +712,6 @@ nm_dbus_manager_start_service (NMDBusManager *self)
return FALSE; return FALSE;
} }
/* Register our method handlers */
if (!nm_dbus_manager_register_method_handlers (self))
goto out;
/* And our signal handlers */ /* And our signal handlers */
for (elt = priv->matches; elt; elt = g_slist_next (elt)) { for (elt = priv->matches; elt; elt = g_slist_next (elt)) {
signal_match_enable (self, (SignalMatch *) elt->data, NULL); signal_match_enable (self, (SignalMatch *) elt->data, NULL);
@@ -803,45 +751,6 @@ out:
return priv->started; return priv->started;
} }
void
nm_dbus_manager_register_method_list (NMDBusManager *self,
NMDbusMethodList *list)
{
NMDBusManagerPrivate *priv;
MethodHandlerData * data;
g_return_if_fail (NM_IS_DBUS_MANAGER (self));
g_return_if_fail (list != NULL);
priv = NM_DBUS_MANAGER_GET_PRIVATE (self);
if (priv->started) {
nm_warning ("DBus Manager object already started!");
return;
}
if (priv->connection == NULL) {
nm_warning ("DBus Manager object not yet initialized!");
return;
}
if (g_slist_find (priv->msg_handlers, list)) {
nm_warning ("Handler already registered.");
return;
}
data = g_slice_new0 (MethodHandlerData);
if (!data) {
nm_warning ("Not enough memory to register the handler.");
return;
}
nm_dbus_method_list_ref (list);
data->list = list;
data->self = self;
priv->msg_handlers = g_slist_append (priv->msg_handlers, data);
}
static void static void
free_signal_handler_data (SignalHandlerData * data, free_signal_handler_data (SignalHandlerData * data,
NMDBusManager * mgr) NMDBusManager * mgr)

View File

@@ -67,9 +67,6 @@ char * nm_dbus_manager_get_name_owner (NMDBusManager *self,
gboolean nm_dbus_manager_start_service (NMDBusManager *self); gboolean nm_dbus_manager_start_service (NMDBusManager *self);
void nm_dbus_manager_register_method_list (NMDBusManager *self,
NMDbusMethodList *list);
gboolean nm_dbus_manager_name_has_owner (NMDBusManager *self, gboolean nm_dbus_manager_name_has_owner (NMDBusManager *self,
const char *name); const char *name);

View File

@@ -59,7 +59,7 @@ nm_dbus_get_ap_from_object_path (const char *path,
while ((ap = nm_ap_list_iter_next (iter))) { while ((ap = nm_ap_list_iter_next (iter))) {
int len; int len;
snprintf (compare_path, 100, "%s/%s/Networks/%s", NM_DBUS_PATH_DEVICES, snprintf (compare_path, 100, "%s/%s/Networks/%s", NM_DBUS_PATH_DEVICE,
nm_device_get_iface (dev), nm_ap_get_essid (ap)); nm_device_get_iface (dev), nm_ap_get_essid (ap));
escaped_compare_path = nm_dbus_escape_object_path (compare_path); escaped_compare_path = nm_dbus_escape_object_path (compare_path);

View File

@@ -48,6 +48,18 @@
#include "cipher.h" #include "cipher.h"
#include "dbus-dict-helpers.h" #include "dbus-dict-helpers.h"
static gboolean impl_device_activate (NMDevice80211Wireless *device,
const char *ap_path,
gboolean user_requested,
GError **err);
static gboolean impl_device_get_active_networks (NMDevice80211Wireless *device,
GPtrArray **networks,
GError **err);
#include "nm-device-802-11-wireless-glue.h"
/* #define IW_QUAL_DEBUG */ /* #define IW_QUAL_DEBUG */
G_DEFINE_TYPE (NMDevice80211Wireless, nm_device_802_11_wireless, NM_TYPE_DEVICE) G_DEFINE_TYPE (NMDevice80211Wireless, nm_device_802_11_wireless, NM_TYPE_DEVICE)
@@ -642,6 +654,27 @@ nm_device_802_11_wireless_activate (NMDevice80211Wireless *self,
} }
static gboolean
impl_device_activate (NMDevice80211Wireless *device,
const char *ap_path,
gboolean user_requested,
GError **err)
{
NMAccessPoint *ap;
ap = nm_device_802_11_wireless_ap_list_get_ap_by_obj_path (device, ap_path);
if (!ap) {
g_set_error (err, 0, 0, /* FIXME */
"Invalid Access Point");
return FALSE;
}
nm_device_802_11_wireless_activate (device, ap, user_requested);
return TRUE;
}
/* /*
* nm_device_copy_allowed_to_dev_list * nm_device_copy_allowed_to_dev_list
* *
@@ -1120,6 +1153,36 @@ nm_device_802_11_wireless_ap_list_get (NMDevice80211Wireless *self)
} }
static gboolean
impl_device_get_active_networks (NMDevice80211Wireless *device,
GPtrArray **networks,
GError **err)
{
NMAccessPointList *ap_list;
*networks = g_ptr_array_new ();
ap_list = nm_device_802_11_wireless_ap_list_get (device);
if (ap_list) {
NMAPListIter *list_iter;
if ((list_iter = nm_ap_list_iter_new (ap_list))) {
NMAccessPoint *ap;
while ((ap = nm_ap_list_iter_next (list_iter))) {
if (nm_ap_get_essid (ap)) {
g_ptr_array_add (*networks,
nm_dbus_get_object_path_for_network (NM_DEVICE (device), ap));
}
}
nm_ap_list_iter_free (list_iter);
}
}
return TRUE;
}
/* Return TRUE if activation is possible, FALSE if not */ /* Return TRUE if activation is possible, FALSE if not */
gboolean gboolean
nm_device_802_11_wireless_can_activate (NMDevice80211Wireless * self) nm_device_802_11_wireless_can_activate (NMDevice80211Wireless * self)
@@ -3331,6 +3394,9 @@ nm_device_802_11_wireless_class_init (NMDevice80211WirelessClass *klass)
g_cclosure_marshal_VOID__POINTER, g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1, G_TYPE_NONE, 1,
G_TYPE_POINTER); G_TYPE_POINTER);
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (klass),
&dbus_glib_nm_device_802_11_wireless_object_info);
} }

View File

@@ -38,6 +38,15 @@
#include "nm-utils.h" #include "nm-utils.h"
#include "kernel-types.h" #include "kernel-types.h"
static gboolean impl_device_802_3_ethernet_activate (NMDevice8023Ethernet *device,
gboolean user_requested,
GError **err);
#include "nm-device-802-3-ethernet-glue.h"
G_DEFINE_TYPE (NMDevice8023Ethernet, nm_device_802_3_ethernet, NM_TYPE_DEVICE)
#define NM_DEVICE_802_3_ETHERNET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_802_3_ETHERNET, NMDevice8023EthernetPrivate)) #define NM_DEVICE_802_3_ETHERNET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_802_3_ETHERNET, NMDevice8023EthernetPrivate))
struct _NMDevice8023EthernetPrivate struct _NMDevice8023EthernetPrivate
@@ -53,6 +62,14 @@ struct _NMDevice8023EthernetPrivate
NMSupplicantInterface * sup_iface; NMSupplicantInterface * sup_iface;
}; };
enum {
PROP_0,
PROP_HW_ADDRESS,
PROP_SPEED,
LAST_PROP
};
static gboolean supports_mii_carrier_detect (NMDevice8023Ethernet *dev); static gboolean supports_mii_carrier_detect (NMDevice8023Ethernet *dev);
static gboolean supports_ethtool_carrier_detect (NMDevice8023Ethernet *dev); static gboolean supports_ethtool_carrier_detect (NMDevice8023Ethernet *dev);
@@ -260,6 +277,17 @@ nm_device_802_3_ethernet_activate (NMDevice8023Ethernet *self,
} }
static gboolean
impl_device_802_3_ethernet_activate (NMDevice8023Ethernet *device,
gboolean user_requested,
GError **err)
{
nm_device_802_3_ethernet_activate (device, user_requested);
return TRUE;
}
/* /*
* nm_device_802_3_ethernet_get_address * nm_device_802_3_ethernet_get_address
* *
@@ -337,8 +365,6 @@ static void
nm_device_802_3_ethernet_dispose (GObject *object) nm_device_802_3_ethernet_dispose (GObject *object)
{ {
NMDevice8023Ethernet * self = NM_DEVICE_802_3_ETHERNET (object); NMDevice8023Ethernet * self = NM_DEVICE_802_3_ETHERNET (object);
NMDevice8023EthernetClass * klass = NM_DEVICE_802_3_ETHERNET_GET_CLASS (object);
NMDeviceClass * parent_class;
NMData * data = nm_device_get_app_data (NM_DEVICE (self)); NMData * data = nm_device_get_app_data (NM_DEVICE (self));
NMSupplicantManager * sup_mgr; NMSupplicantManager * sup_mgr;
@@ -370,23 +396,37 @@ nm_device_802_3_ethernet_dispose (GObject *object)
self->priv->link_source_id = 0; self->priv->link_source_id = 0;
} }
/* Chain up to the parent class */ G_OBJECT_CLASS (nm_device_802_3_ethernet_parent_class)->dispose (object);
parent_class = NM_DEVICE_CLASS (g_type_class_peek_parent (klass));
G_OBJECT_CLASS (parent_class)->dispose (object);
} }
static void static void
nm_device_802_3_ethernet_finalize (GObject *object) nm_device_802_3_ethernet_finalize (GObject *object)
{ {
NMDevice8023Ethernet * self = NM_DEVICE_802_3_ETHERNET (object); NMDevice8023EthernetPrivate *priv = NM_DEVICE_802_3_ETHERNET_GET_PRIVATE (object);
NMDevice8023EthernetClass * klass = NM_DEVICE_802_3_ETHERNET_GET_CLASS (object);
NMDeviceClass * parent_class;
g_free (self->priv->carrier_file_path); g_free (priv->carrier_file_path);
/* Chain up to the parent class */ G_OBJECT_CLASS (nm_device_802_3_ethernet_parent_class)->finalize (object);
parent_class = NM_DEVICE_CLASS (g_type_class_peek_parent (klass)); }
G_OBJECT_CLASS (parent_class)->finalize (object);
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
/* FIXME: */
/* NMDevice8023EthernetPrivate *priv = NM_DEVICE_802_3_ETHERNET_GET_PRIVATE (object); */
switch (prop_id) {
/* case PROP_HW_ADDRESS: */
/* g_value_set_int (value, ); */
/* break; */
case PROP_SPEED:
g_value_set_int (value, nm_device_802_3_ethernet_get_speed (NM_DEVICE_802_3_ETHERNET (object)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
} }
@@ -399,6 +439,7 @@ nm_device_802_3_ethernet_class_init (NMDevice8023EthernetClass *klass)
g_type_class_add_private (object_class, sizeof (NMDevice8023EthernetPrivate)); g_type_class_add_private (object_class, sizeof (NMDevice8023EthernetPrivate));
/* virtual methods */ /* virtual methods */
object_class->get_property = get_property;
object_class->dispose = nm_device_802_3_ethernet_dispose; object_class->dispose = nm_device_802_3_ethernet_dispose;
object_class->finalize = nm_device_802_3_ethernet_finalize; object_class->finalize = nm_device_802_3_ethernet_finalize;
@@ -408,32 +449,26 @@ nm_device_802_3_ethernet_class_init (NMDevice8023EthernetClass *klass)
parent_class->update_link = real_update_link; parent_class->update_link = real_update_link;
parent_class->can_interrupt_activation = real_can_interrupt_activation; parent_class->can_interrupt_activation = real_can_interrupt_activation;
parent_class->set_hw_address = real_set_hw_address; parent_class->set_hw_address = real_set_hw_address;
}
GType /* properties */
nm_device_802_3_ethernet_get_type (void) g_object_class_install_property
{ (object_class, PROP_HW_ADDRESS,
static GType type = 0; g_param_spec_int (NM_DEVICE_802_3_ETHERNET_HW_ADDRESS,
if (type == 0) "MAC Address",
{ "Hardware MAC address",
static const GTypeInfo info = 0, G_MAXINT32, 0,
{ G_PARAM_READABLE));
sizeof (NMDevice8023EthernetClass),
NULL, /* base_init */ g_object_class_install_property
NULL, /* base_finalize */ (object_class, PROP_SPEED,
(GClassInitFunc) nm_device_802_3_ethernet_class_init, g_param_spec_int (NM_DEVICE_802_3_ETHERNET_SPEED,
NULL, /* class_finalize */ "Speed",
NULL, /* class_data */ "Speed",
sizeof (NMDevice8023Ethernet), 0, G_MAXINT32, 0,
0, /* n_preallocs */ G_PARAM_READABLE));
(GInstanceInitFunc) nm_device_802_3_ethernet_init,
NULL /* value_table */ dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (klass),
}; &dbus_glib_nm_device_802_3_ethernet_object_info);
type = g_type_register_static (NM_TYPE_DEVICE,
"NMDevice8023Ethernet",
&info, 0);
}
return type;
} }

View File

@@ -42,6 +42,9 @@ typedef struct _NMDevice8023Ethernet NMDevice8023Ethernet;
typedef struct _NMDevice8023EthernetClass NMDevice8023EthernetClass; typedef struct _NMDevice8023EthernetClass NMDevice8023EthernetClass;
typedef struct _NMDevice8023EthernetPrivate NMDevice8023EthernetPrivate; typedef struct _NMDevice8023EthernetPrivate NMDevice8023EthernetPrivate;
#define NM_DEVICE_802_3_ETHERNET_HW_ADDRESS "hw_address"
#define NM_DEVICE_802_3_ETHERNET_SPEED "speed"
struct _NMDevice8023Ethernet struct _NMDevice8023Ethernet
{ {
NMDevice parent; NMDevice parent;

View File

@@ -1,6 +1,10 @@
#include "nm-device-interface.h" #include "nm-device-interface.h"
static gboolean impl_device_deactivate (NMDeviceInterface *device, GError **err);
#include "nm-device-interface-glue.h"
static void static void
nm_device_interface_init (gpointer g_iface) nm_device_interface_init (gpointer g_iface)
{ {
@@ -58,14 +62,6 @@ nm_device_interface_init (gpointer g_iface)
0, G_MAXUINT32, 0, /* FIXME */ 0, G_MAXUINT32, 0, /* FIXME */
G_PARAM_READWRITE)); G_PARAM_READWRITE));
g_object_interface_install_property
(g_iface,
g_param_spec_boolean (NM_DEVICE_INTERFACE_USE_DHCP,
"Use DHCP",
"Use DHCP",
TRUE,
G_PARAM_READWRITE));
g_object_interface_install_property g_object_interface_install_property
(g_iface, (g_iface,
g_param_spec_uint (NM_DEVICE_INTERFACE_STATE, g_param_spec_uint (NM_DEVICE_INTERFACE_STATE,
@@ -101,6 +97,9 @@ nm_device_interface_init (gpointer g_iface)
G_TYPE_NONE, 1, G_TYPE_NONE, 1,
G_TYPE_BOOLEAN); G_TYPE_BOOLEAN);
dbus_g_object_type_install_info (iface_type,
&dbus_glib_nm_device_interface_object_info);
initialized = TRUE; initialized = TRUE;
} }
@@ -140,3 +139,13 @@ nm_device_interface_deactivate (NMDeviceInterface *device)
NM_DEVICE_INTERFACE_GET_INTERFACE (device)->deactivate (device); NM_DEVICE_INTERFACE_GET_INTERFACE (device)->deactivate (device);
} }
static gboolean
impl_device_deactivate (NMDeviceInterface *device, GError **err)
{
g_return_val_if_fail (NM_IS_DEVICE_INTERFACE (device), FALSE);
nm_device_interface_deactivate (device);
return TRUE;
}

View File

@@ -16,7 +16,6 @@
#define NM_DEVICE_INTERFACE_DRIVER "driver" #define NM_DEVICE_INTERFACE_DRIVER "driver"
#define NM_DEVICE_INTERFACE_CAPABILITIES "capabilities" #define NM_DEVICE_INTERFACE_CAPABILITIES "capabilities"
#define NM_DEVICE_INTERFACE_IP4_ADDRESS "ip4_address" #define NM_DEVICE_INTERFACE_IP4_ADDRESS "ip4_address"
#define NM_DEVICE_INTERFACE_USE_DHCP "use_dhcp"
#define NM_DEVICE_INTERFACE_STATE "state" #define NM_DEVICE_INTERFACE_STATE "state"
#define NM_DEVICE_INTERFACE_APP_DATA "app_data" /* Ugh */ #define NM_DEVICE_INTERFACE_APP_DATA "app_data" /* Ugh */
#define NM_DEVICE_INTERFACE_DEVICE_TYPE "device_type" /* ugh */ #define NM_DEVICE_INTERFACE_DEVICE_TYPE "device_type" /* ugh */
@@ -29,7 +28,6 @@ typedef enum {
NM_DEVICE_INTERFACE_PROP_DRIVER, NM_DEVICE_INTERFACE_PROP_DRIVER,
NM_DEVICE_INTERFACE_PROP_CAPABILITIES, NM_DEVICE_INTERFACE_PROP_CAPABILITIES,
NM_DEVICE_INTERFACE_PROP_IP4_ADDRESS, NM_DEVICE_INTERFACE_PROP_IP4_ADDRESS,
NM_DEVICE_INTERFACE_PROP_USE_DHCP,
NM_DEVICE_INTERFACE_PROP_STATE, NM_DEVICE_INTERFACE_PROP_STATE,
NM_DEVICE_INTERFACE_PROP_APP_DATA, NM_DEVICE_INTERFACE_PROP_APP_DATA,
NM_DEVICE_INTERFACE_PROP_DEVICE_TYPE NM_DEVICE_INTERFACE_PROP_DEVICE_TYPE

View File

@@ -36,6 +36,7 @@
#include "NetworkManagerSystem.h" #include "NetworkManagerSystem.h"
#include "nm-vpn-manager.h" #include "nm-vpn-manager.h"
#include "nm-dhcp-manager.h" #include "nm-dhcp-manager.h"
#include "nm-dbus-manager.h"
#include "nm-dbus-nmi.h" #include "nm-dbus-nmi.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "autoip.h" #include "autoip.h"
@@ -131,6 +132,8 @@ constructor (GType type,
{ {
GObject *object; GObject *object;
NMDevice *dev; NMDevice *dev;
NMDBusManager *manager;
char *path;
object = G_OBJECT_CLASS (nm_device_parent_class)->constructor (type, object = G_OBJECT_CLASS (nm_device_parent_class)->constructor (type,
n_construct_params, n_construct_params,
@@ -175,6 +178,13 @@ constructor (GType type,
NM_DEVICE_GET_CLASS (dev)->start (dev); NM_DEVICE_GET_CLASS (dev)->start (dev);
manager = nm_dbus_manager_get ();
path = nm_dbus_get_object_path_for_device (dev);
dbus_g_connection_register_g_object (nm_dbus_manager_get_connection (manager),
path, object);
g_free (path);
return object; return object;
} }
@@ -1662,9 +1672,6 @@ set_property (GObject *object, guint prop_id,
case NM_DEVICE_INTERFACE_PROP_IP4_ADDRESS: case NM_DEVICE_INTERFACE_PROP_IP4_ADDRESS:
priv->ip4_address = g_value_get_uint (value); priv->ip4_address = g_value_get_uint (value);
break; break;
case NM_DEVICE_INTERFACE_PROP_USE_DHCP:
nm_device_set_use_dhcp (NM_DEVICE (object), g_value_get_boolean (value));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@@ -1696,9 +1703,6 @@ get_property (GObject *object, guint prop_id,
case NM_DEVICE_INTERFACE_PROP_IP4_ADDRESS: case NM_DEVICE_INTERFACE_PROP_IP4_ADDRESS:
g_value_set_uint (value, priv->ip4_address); g_value_set_uint (value, priv->ip4_address);
break; break;
case NM_DEVICE_INTERFACE_PROP_USE_DHCP:
g_value_set_boolean (value, nm_device_get_use_dhcp (NM_DEVICE (object)));
break;
case NM_DEVICE_INTERFACE_PROP_STATE: case NM_DEVICE_INTERFACE_PROP_STATE:
g_value_set_uint (value, priv->state); g_value_set_uint (value, priv->state);
break; break;
@@ -1759,10 +1763,6 @@ nm_device_class_init (NMDeviceClass *klass)
NM_DEVICE_INTERFACE_PROP_IP4_ADDRESS, NM_DEVICE_INTERFACE_PROP_IP4_ADDRESS,
NM_DEVICE_INTERFACE_IP4_ADDRESS); NM_DEVICE_INTERFACE_IP4_ADDRESS);
g_object_class_override_property (object_class,
NM_DEVICE_INTERFACE_PROP_USE_DHCP,
NM_DEVICE_INTERFACE_USE_DHCP);
g_object_class_override_property (object_class, g_object_class_override_property (object_class,
NM_DEVICE_INTERFACE_PROP_STATE, NM_DEVICE_INTERFACE_PROP_STATE,
NM_DEVICE_INTERFACE_STATE); NM_DEVICE_INTERFACE_STATE);

View File

@@ -8,6 +8,11 @@
#include "NetworkManagerSystem.h" #include "NetworkManagerSystem.h"
// #include "NetworkManagerDbus.h" // #include "NetworkManagerDbus.h"
static gboolean impl_manager_get_devices (NMManager *manager, GPtrArray **devices, GError **err);
static gboolean impl_manager_sleep (NMManager *manager, gboolean sleep, GError **err);
#include "nm-manager-glue.h"
static void manager_state_changed (NMManager *manager); static void manager_state_changed (NMManager *manager);
static void manager_set_wireless_enabled (NMManager *manager, gboolean enabled); static void manager_set_wireless_enabled (NMManager *manager, gboolean enabled);
@@ -160,9 +165,12 @@ nm_manager_class_init (NMManagerClass *manager_class)
G_SIGNAL_RUN_FIRST, G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMManagerClass, state_change), G_STRUCT_OFFSET (NMManagerClass, state_change),
NULL, NULL, NULL, NULL,
g_cclosure_marshal_VOID__UCHAR, g_cclosure_marshal_VOID__UINT,
G_TYPE_NONE, 1, G_TYPE_NONE, 1,
G_TYPE_UCHAR); G_TYPE_UINT);
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (manager_class),
&dbus_glib_nm_manager_object_info);
} }
NMManager * NMManager *
@@ -290,6 +298,20 @@ nm_manager_get_devices (NMManager *manager)
return NM_MANAGER_GET_PRIVATE (manager)->devices; return NM_MANAGER_GET_PRIVATE (manager)->devices;
} }
static gboolean
impl_manager_get_devices (NMManager *manager, GPtrArray **devices, GError **err)
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
GSList *iter;
*devices = g_ptr_array_sized_new (g_slist_length (priv->devices));
for (iter = priv->devices; iter; iter = iter->next)
g_ptr_array_add (*devices, nm_dbus_get_object_path_for_device (NM_DEVICE (iter->data)));
return TRUE;
}
NMDevice * NMDevice *
nm_manager_get_device_by_iface (NMManager *manager, const char *iface) nm_manager_get_device_by_iface (NMManager *manager, const char *iface)
{ {
@@ -404,6 +426,14 @@ nm_manager_sleep (NMManager *manager, gboolean sleep)
manager_state_changed (manager); manager_state_changed (manager);
} }
static gboolean
impl_manager_sleep (NMManager *manager, gboolean sleep, GError **err)
{
nm_manager_sleep (manager, sleep);
return TRUE;
}
NMDevice * NMDevice *
nm_manager_get_active_device (NMManager *manager) nm_manager_get_active_device (NMManager *manager)
{ {

View File

@@ -75,7 +75,8 @@ NMVPNManager *nm_vpn_manager_new (NMManager *nm_manager, NMData *app_data)
manager->dbus_methods = nm_dbus_vpn_methods_setup (manager); manager->dbus_methods = nm_dbus_vpn_methods_setup (manager);
dbus_mgr = nm_dbus_manager_get (); dbus_mgr = nm_dbus_manager_get ();
nm_dbus_manager_register_method_list (dbus_mgr, manager->dbus_methods); /* FIXME */
/* nm_dbus_manager_register_method_list (dbus_mgr, manager->dbus_methods); */
g_object_unref (dbus_mgr); g_object_unref (dbus_mgr);
return manager; return manager;

View File

@@ -127,7 +127,7 @@ static void detail_network (DBusConnection *connection, const char *path, const
g_return_if_fail (connection != NULL); g_return_if_fail (connection != NULL);
g_return_if_fail (path != NULL); g_return_if_fail (path != NULL);
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE_DEVICES, "getProperties"))) if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE_DEVICE, "getProperties")))
{ {
fprintf (stderr, "detail_network(): couldn't create new dbus message.\n"); fprintf (stderr, "detail_network(): couldn't create new dbus message.\n");
return; return;
@@ -214,7 +214,7 @@ get_driver_name (DBusConnection *connection, const char *path)
g_return_val_if_fail (path != NULL, NULL); g_return_val_if_fail (path != NULL, NULL);
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE_DEVICES, "getDriver"))) if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE_DEVICE, "getDriver")))
{ {
nm_warning ("%s(): Couldn't allocate the dbus message", __func__); nm_warning ("%s(): Couldn't allocate the dbus message", __func__);
return NULL; return NULL;
@@ -266,7 +266,7 @@ static void detail_device (DBusConnection *connection, const char *path)
g_return_if_fail (connection != NULL); g_return_if_fail (connection != NULL);
g_return_if_fail (path != NULL); g_return_if_fail (path != NULL);
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE_DEVICES, "getProperties"))) if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE_DEVICE, "getProperties")))
{ {
fprintf (stderr, "detail_device(): couldn't create new dbus message.\n"); fprintf (stderr, "detail_device(): couldn't create new dbus message.\n");
return; return;

View File

@@ -203,8 +203,8 @@ static void get_networks_of_type (DBusConnection *connection, NMNetworkType type
static void get_user_key_for_network (DBusConnection *connection) static void get_user_key_for_network (DBusConnection *connection)
{ {
DBusMessage * message; DBusMessage * message;
const char * dev_path = NM_DBUS_PATH_DEVICES"/eth1"; const char * dev_path = NM_DBUS_PATH_DEVICE"/eth1";
const char * net_path = NM_DBUS_PATH_DEVICES"/Networks/wireless-ap"; const char * net_path = NM_DBUS_PATH_DEVICE"/Networks/wireless-ap";
const char * essid = "wireless-ap"; const char * essid = "wireless-ap";
const int attempts = 0; const int attempts = 0;
const gboolean new_key = FALSE; const gboolean new_key = FALSE;

View File

@@ -129,7 +129,7 @@ static void set_link_active (DBusConnection *connection, char *dev, gboolean act
g_return_if_fail (connection != NULL); g_return_if_fail (connection != NULL);
g_return_if_fail (dev != NULL); g_return_if_fail (dev != NULL);
message = dbus_message_new_method_call (NM_DBUS_SERVICE, dev, NM_DBUS_INTERFACE_DEVICES, "setLinkActive"); message = dbus_message_new_method_call (NM_DBUS_SERVICE, dev, NM_DBUS_INTERFACE_DEVICE, "setLinkActive");
if (message == NULL) if (message == NULL)
{ {
fprintf (stderr, "Couldn't allocate the dbus message\n"); fprintf (stderr, "Couldn't allocate the dbus message\n");