Commit 8a4c57f6 authored by Tambet Ingo's avatar Tambet Ingo Committed by Tambet Ingo

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
parent 13af56e6
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>
* src/nm-device-802-11-wireless.c:
......
SUBDIRS = \
utils \
libnm-util \
libnm-glib \
src \
dispatcher-daemon \
gnome \
......
......@@ -114,7 +114,7 @@ fi
IWLIB=-liw
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
dbus_version=`pkg-config --modversion dbus-1`
......@@ -353,6 +353,8 @@ src/supplicant-manager/Makefile
src/backends/Makefile
libnm-util/libnm-util.pc
libnm-util/Makefile
libnm-glib/libnm-glib.pc
libnm-glib/Makefile
dispatcher-daemon/Makefile
gnome/Makefile
gnome/libnm_glib/libnm_glib.pc
......
......@@ -29,10 +29,12 @@
#define NM_DBUS_PATH "/org/freedesktop/NetworkManager"
#define NM_DBUS_INTERFACE "org.freedesktop.NetworkManager"
#define NM_DBUS_PATH_DEVICES "/org/freedesktop/NetworkManager/Devices"
#define NM_DBUS_INTERFACE_DEVICES "org.freedesktop.NetworkManager.Devices"
#define NM_DBUS_PATH_DHCP "/org/freedesktop/NetworkManager/DhcpOptions"
#define NM_DBUS_INTERFACE_DHCP "org.freedesktop.NetworkManager.DhcpOptions"
#define NM_DBUS_PATH_DEVICE "/org/freedesktop/NetworkManager/Device"
#define NM_DBUS_INTERFACE_DEVICE "org.freedesktop.NetworkManager.Device"
#define NM_DBUS_INTERFACE_DEVICE_WIRED "org.freedesktop.NetworkManager.Device.Wired"
#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_PATH "/org/freedesktop/NetworkManagerInfo"
......
<?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>
<?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>
<?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>
<?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>
<?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>
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)
#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;
}
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
#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;
}
#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 */
#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,