NetworkManager r3388 - in trunk: introspection src src/ppp-manager



Author: tambeti
Date: Fri Mar  7 18:04:59 2008
New Revision: 3388
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3388&view=rev

Log:
Squashed commit of the following:

commit 736e888c683a2b630310c5fb3119fdb0466df223
Author: Tambet Ingo <tambet gmail com>
Date:   Fri Mar 7 10:44:36 2008 -0600

    Rework ppp-manager to set up dbus service instead of doing it in pppd plugin.


Added:
   trunk/introspection/nm-ppp-manager.xml
Modified:
   trunk/src/nm-serial-device.c
   trunk/src/ppp-manager/Makefile.am
   trunk/src/ppp-manager/nm-ppp-manager.c
   trunk/src/ppp-manager/nm-ppp-manager.h
   trunk/src/ppp-manager/nm-pppd-plugin.c

Added: trunk/introspection/nm-ppp-manager.xml
==============================================================================
--- (empty file)
+++ trunk/introspection/nm-ppp-manager.xml	Fri Mar  7 18:04:59 2008
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<node name="/">
+  <interface name="org.freedesktop.NetworkManager.PPP">
+    <method name="NeedSecrets">
+      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_ppp_manager_need_secrets"/>
+      <arg name="settings" type="a{sa{sv}}" direction="in"/>
+      <arg name="setting_name" type="s" direction="out"/>
+    </method>
+
+    <method name="SetIp4Config">
+      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_ppp_manager_set_ip4_config"/>
+      <arg name="config" type="a{sv}" direction="in"/>
+    </method>
+
+    <method name="SetState">
+      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_ppp_manager_set_state"/>
+      <arg name="state" type="u" direction="in"/>
+    </method>
+  </interface>
+</node>

Modified: trunk/src/nm-serial-device.c
==============================================================================
--- trunk/src/nm-serial-device.c	(original)
+++ trunk/src/nm-serial-device.c	Fri Mar  7 18:04:59 2008
@@ -843,17 +843,21 @@
 real_act_stage2_config (NMDevice *device)
 {
 	NMSerialDevicePrivate *priv = NM_SERIAL_DEVICE_GET_PRIVATE (device);
-	NMSettingPPP *setting;
+	NMActRequest *req;
+	NMConnection *connection;
 	GError *err = NULL;
 	NMActStageReturn ret;
 
-	setting = NM_SETTING_PPP (serial_device_get_setting (NM_SERIAL_DEVICE (device), NM_TYPE_SETTING_PPP));
+	req = nm_device_get_act_request (device);
+	g_assert (req);
+	connection = nm_act_request_get_connection (req);
+	g_assert (connection);
 
 	priv->ppp_manager = nm_ppp_manager_new ();
 
 	if (nm_ppp_manager_start (priv->ppp_manager,
 						 nm_device_get_iface (device),
-						 setting,
+						 connection,
 						 &err)) {
 		g_signal_connect (priv->ppp_manager, "state-changed",
 					   G_CALLBACK (ppp_state_changed),

Modified: trunk/src/ppp-manager/Makefile.am
==============================================================================
--- trunk/src/ppp-manager/Makefile.am	(original)
+++ trunk/src/ppp-manager/Makefile.am	Fri Mar  7 18:04:59 2008
@@ -12,6 +12,13 @@
 	nm-ppp-manager.h \
 	nm-ppp-status.h
 
+nm-ppp-manager-glue.h: $(top_srcdir)/introspection/nm-ppp-manager.xml
+	dbus-binding-tool --prefix=nm_ppp_manager --mode=glib-server --output=nm-ppp-manager-glue.h $(top_srcdir)/introspection/nm-ppp-manager.xml
+
+built_sources = nm-ppp-manager-glue.h
+
+$(libppp_manager_la_OBJECTS): $(built_sources)
+
 libppp_manager_la_CPPFLAGS = \
 	$(DBUS_CFLAGS) \
 	$(HAL_CFLAGS) \

Modified: trunk/src/ppp-manager/nm-ppp-manager.c
==============================================================================
--- trunk/src/ppp-manager/nm-ppp-manager.c	(original)
+++ trunk/src/ppp-manager/nm-ppp-manager.c	Fri Mar  7 18:04:59 2008
@@ -7,21 +7,35 @@
 #include <unistd.h>
 
 #include "nm-ppp-manager.h"
+#include "nm-setting-ppp.h"
 #include "nm-dbus-manager.h"
 #include "nm-utils.h"
 #include "nm-marshal.h"
 
+static gboolean impl_ppp_manager_need_secrets (NMPPPManager *manager,
+									  GHashTable *connection,
+									  char **service_name,
+									  GError **err);
+
+static gboolean impl_ppp_manager_set_state (NMPPPManager *manager,
+								    guint32 state,
+								    GError **err);
+
+static gboolean impl_ppp_manager_set_ip4_config (NMPPPManager *manager,
+									    GHashTable *config,
+									    GError **err);
+
+#include "nm-ppp-manager-glue.h"
+
 #define NM_PPPD_PLUGIN PLUGINDIR "/nm-pppd-plugin.so"
 #define NM_PPP_WAIT_PPPD 10000 /* 10 seconds */
 
 typedef struct {
 	GPid pid;
 	NMDBusManager *dbus_manager;
-	DBusGProxy *proxy;
 
 	guint32 ppp_watch_id;
 	guint32 ppp_timeout_handler;
-	guint32 name_owner_changed_handler;
 } NMPPPManagerPrivate;
 
 #define NM_PPP_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_PPP_MANAGER, NMPPPManagerPrivate))
@@ -53,10 +67,53 @@
 {
 }
 
+static GObject *
+constructor (GType type,
+		   guint n_construct_params,
+		   GObjectConstructParam *construct_params)
+{
+	GObject *object;
+	NMPPPManagerPrivate *priv;
+	DBusGConnection *connection;
+	DBusGProxy *proxy;
+	guint request_name_result;
+	GError *err = NULL;
+
+	object = G_OBJECT_CLASS (nm_ppp_manager_parent_class)->constructor (type,
+														   n_construct_params,
+														   construct_params);
+	if (!object)
+		return NULL;
+
+	priv = NM_PPP_MANAGER_GET_PRIVATE (object);
+	priv->dbus_manager = nm_dbus_manager_get ();
+	connection = nm_dbus_manager_get_connection (priv->dbus_manager);
+
+	proxy = dbus_g_proxy_new_for_name (connection,
+								"org.freedesktop.DBus",
+								"/org/freedesktop/DBus",
+								"org.freedesktop.DBus");
+
+	if (dbus_g_proxy_call (proxy, "RequestName", &err,
+					   G_TYPE_STRING, NM_DBUS_SERVICE_PPP,
+					   G_TYPE_UINT, 0,
+					   G_TYPE_INVALID,
+					   G_TYPE_UINT, &request_name_result,
+					   G_TYPE_INVALID))
+		dbus_g_connection_register_g_object (connection, NM_DBUS_PATH_PPP, object);
+
+	g_object_unref (proxy);
+
+	return object;
+}
+
 static void
 finalize (GObject *object)
 {
+	//NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (object);
+
 	nm_ppp_manager_stop (NM_PPP_MANAGER (object));
+	//g_object_unref (priv->dbus_manager);
 
 	G_OBJECT_CLASS (nm_ppp_manager_parent_class)->finalize (object);
 }
@@ -68,6 +125,10 @@
 
 	g_type_class_add_private (manager_class, sizeof (NMPPPManagerPrivate));
 
+	dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (manager_class),
+							   &dbus_glib_nm_ppp_manager_object_info);
+
+	object_class->constructor = constructor;
 	object_class->finalize = finalize;
 
 	/* signals */
@@ -101,6 +162,106 @@
 
 /*******************************************/
 
+static void
+remove_timeout_handler (NMPPPManager *manager)
+{
+	NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager);
+	
+	if (priv->ppp_timeout_handler) {
+		g_source_remove (priv->ppp_timeout_handler);
+		priv->ppp_timeout_handler = 0;
+	}
+}
+
+static gboolean
+impl_ppp_manager_need_secrets (NMPPPManager *manager,
+						 GHashTable *connection,
+						 char **service_name,
+						 GError **err)
+{
+	remove_timeout_handler (manager);
+	
+	return TRUE;
+}
+
+static gboolean impl_ppp_manager_set_state (NMPPPManager *manager,
+								    guint32 state,
+								    GError **err)
+{
+	remove_timeout_handler (manager);
+	g_signal_emit (manager, signals[STATE_CHANGED], 0, state);
+
+	return TRUE;
+}
+
+static gboolean
+impl_ppp_manager_set_ip4_config (NMPPPManager *manager,
+						   GHashTable *config_hash,
+						   GError **err)
+{
+	NMIP4Config *config;
+	GValue *val;
+	const char *iface;
+	int i;
+
+	nm_info ("PPP manager(IP Config Get) reply received.");
+
+	remove_timeout_handler (manager);
+
+	/* FIXME */
+/* 	g_source_remove (priv->ipconfig_timeout); */
+/* 	priv->ipconfig_timeout = 0; */
+
+	config = nm_ip4_config_new ();
+
+	val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_GATEWAY);
+	if (val) {
+		nm_ip4_config_set_gateway (config, g_value_get_uint (val));
+		nm_ip4_config_set_ptp_address (config, g_value_get_uint (val));
+	}
+
+	val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_ADDRESS);
+	if (val)
+		nm_ip4_config_set_address (config, g_value_get_uint (val));
+
+	val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_NETMASK);
+	if (val)
+		nm_ip4_config_set_netmask (config, g_value_get_uint (val));
+	else
+		/* If no netmask, default to Class C address */
+		nm_ip4_config_set_netmask (config, 0x00FF);
+
+	val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_DNS);
+	if (val) {
+		GArray *dns = (GArray *) g_value_get_boxed (val);
+
+		for (i = 0; i < dns->len; i++)
+			nm_ip4_config_add_nameserver (config, g_array_index (dns, guint, i));
+	}
+
+	/* FIXME: The plugin helpfully sends WINS servers as well
+	   and we're insensitive clods and ignore them. */
+
+	val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_INTERFACE);
+	if (val)
+		iface = g_value_get_string (val);
+	else {
+		nm_warning ("No interface");
+		goto out;
+	}
+
+	g_signal_emit (manager, signals[IP4_CONFIG], 0, iface, config);
+
+ out:
+	g_object_unref (config);
+
+	return TRUE;
+}
+
+/*******************************************/
+
+
+
 typedef struct {
 	GPtrArray *array;
 	GStringChunk *chunk;
@@ -284,137 +445,6 @@
 	return FALSE;
 }
 
-static void
-ppp_status_changed (DBusGProxy *proxy,
-				guint32 status,
-				gpointer user_data)
-{
-	NMPPPManager *manager = NM_PPP_MANAGER (user_data);
-
-	g_signal_emit (manager, signals[STATE_CHANGED], 0, status);
-}
-
-static void
-ip4_config_get (DBusGProxy *proxy,
-			 GHashTable *config_hash,
-			 gpointer user_data)
-{
-	NMPPPManager *manager = NM_PPP_MANAGER (user_data);
-	NMIP4Config *config;
-	GValue *val;
-	const char *iface;
-	int i;
-
-	nm_info ("PPP manager(IP Config Get) reply received.");
-
-	/* FIXME */
-/* 	g_source_remove (priv->ipconfig_timeout); */
-/* 	priv->ipconfig_timeout = 0; */
-
-	config = nm_ip4_config_new ();
-
-	val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_GATEWAY);
-	if (val) {
-		nm_ip4_config_set_gateway (config, g_value_get_uint (val));
-		nm_ip4_config_set_ptp_address (config, g_value_get_uint (val));
-	}
-
-	val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_ADDRESS);
-	if (val)
-		nm_ip4_config_set_address (config, g_value_get_uint (val));
-
-	val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_NETMASK);
-	if (val)
-		nm_ip4_config_set_netmask (config, g_value_get_uint (val));
-	else
-		/* If no netmask, default to Class C address */
-		nm_ip4_config_set_netmask (config, 0x00FF);
-
-	val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_DNS);
-	if (val) {
-		GArray *dns = (GArray *) g_value_get_boxed (val);
-
-		for (i = 0; i < dns->len; i++)
-			nm_ip4_config_add_nameserver (config, g_array_index (dns, guint, i));
-	}
-
-	/* FIXME: The plugin helpfully sends WINS servers as well
-	   and we're insensitive clods and ignore them. */
-
-	val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_INTERFACE);
-	if (val)
-		iface = g_value_get_string (val);
-	else {
-		nm_warning ("No interface");
-		goto out;
-	}
-
-	g_signal_emit (manager, signals[IP4_CONFIG], 0, iface, config);
-
- out:
-	g_object_unref (config);
-}
-
-static void
-name_owner_changed (NMDBusManager *dbus_manager,
-				const char *name,
-				const char *old,
-				const char *new,
-				gpointer user_data)
-{
-	NMPPPManager *manager = NM_PPP_MANAGER (user_data);
-	NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager);
-	gboolean old_owner_good = (old && (strlen (old) > 0));
-	gboolean new_owner_good = (new && (strlen (new) > 0));
-
-	if (strcmp (name, NM_DBUS_SERVICE_PPP))
-		return;
-
-	if (!old_owner_good && new_owner_good) {
-		if (priv->ppp_timeout_handler) {
-			g_source_remove (priv->ppp_timeout_handler);
-			priv->ppp_timeout_handler = 0;
-		}
-
-		/* Work around the bug in dbus-glib where name-owner-changed signal is always emitted twice */
-		if (!priv->proxy) {
-			priv->proxy = dbus_g_proxy_new_for_name (nm_dbus_manager_get_connection (priv->dbus_manager),
-											 NM_DBUS_SERVICE_PPP,
-											 NM_DBUS_PATH_PPP,
-											 NM_DBUS_INTERFACE_PPP);
-
-			dbus_g_proxy_add_signal (priv->proxy, "StateChanged", G_TYPE_UINT, G_TYPE_INVALID);
-			dbus_g_proxy_connect_signal (priv->proxy, "StateChanged",
-								    G_CALLBACK (ppp_status_changed),
-								    manager, NULL);
-
-			dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__BOXED,
-										G_TYPE_NONE, G_TYPE_VALUE, G_TYPE_INVALID);
-			dbus_g_proxy_add_signal (priv->proxy, "Ip4Config",
-								dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
-								G_TYPE_INVALID);
-			dbus_g_proxy_connect_signal (priv->proxy, "Ip4Config",
-								    G_CALLBACK (ip4_config_get),
-								    manager, NULL);
-		}
-	} else if (old_owner_good && !new_owner_good) {
-		nm_ppp_manager_stop (manager);
-	}
-}
-
-static void
-start_dbus_watcher (NMPPPManager *manager)
-{
-	NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager);
-
-	priv->ppp_timeout_handler = g_timeout_add (NM_PPP_WAIT_PPPD, pppd_timed_out, manager);
-
-	priv->dbus_manager = nm_dbus_manager_get ();
-	priv->name_owner_changed_handler = g_signal_connect (priv->dbus_manager, "name-owner-changed",
-											   G_CALLBACK (name_owner_changed),
-											   manager);
-}
-
 static NMCmdLine *
 create_pppd_cmd_line (NMSettingPPP *setting, const char *device, GError **err)
 {
@@ -501,19 +531,22 @@
 gboolean
 nm_ppp_manager_start (NMPPPManager *manager,
 				  const char *device,
-				  NMSettingPPP *setting,
+				  NMConnection *connection,
 				  GError **err)
 {
 	NMPPPManagerPrivate *priv;
+	NMSettingPPP *ppp_setting;
 	NMCmdLine *ppp_cmd;
 	char *cmd_str;
 	GSource *ppp_watch;
 
 	g_return_val_if_fail (NM_IS_PPP_MANAGER (manager), FALSE);
 	g_return_val_if_fail (device != NULL, FALSE);
-	g_return_val_if_fail (setting != NULL, FALSE);
+	g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
+
+	ppp_setting = NM_SETTING_PPP (nm_connection_get_setting (connection, NM_TYPE_SETTING_PPP));
 
-	ppp_cmd = create_pppd_cmd_line (setting, device, err);
+	ppp_cmd = create_pppd_cmd_line (ppp_setting, device, err);
 	if (!ppp_cmd)
 		return FALSE;
 
@@ -543,7 +576,7 @@
 	priv->ppp_watch_id = g_source_get_id (ppp_watch);
 	g_source_unref (ppp_watch);
 
-	start_dbus_watcher (manager);
+	priv->ppp_timeout_handler = g_timeout_add (NM_PPP_WAIT_PPPD, pppd_timed_out, manager);
 
  out:
 	if (ppp_cmd)
@@ -566,17 +599,6 @@
 		priv->ppp_timeout_handler = 0;
 	}
 
-	if (priv->proxy) {
-		g_object_unref (priv->proxy);
-		priv->proxy = NULL;
-	}
-
-	if (priv->dbus_manager) {
-		g_signal_handler_disconnect (priv->dbus_manager, priv->name_owner_changed_handler);
-		g_object_unref (priv->dbus_manager);
-		priv->dbus_manager = NULL;
-	}
-
 	if (priv->ppp_watch_id) {
 		g_source_remove (priv->ppp_watch_id);
 		priv->ppp_watch_id = 0;

Modified: trunk/src/ppp-manager/nm-ppp-manager.h
==============================================================================
--- trunk/src/ppp-manager/nm-ppp-manager.h	(original)
+++ trunk/src/ppp-manager/nm-ppp-manager.h	Fri Mar  7 18:04:59 2008
@@ -1,3 +1,5 @@
+/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
+
 #ifndef NM_PPP_MANAGER_H
 #define NM_PPP_MANAGER_H
 
@@ -5,7 +7,7 @@
 #include <glib-object.h>
 
 #include "nm-ppp-status.h"
-#include "nm-setting-ppp.h"
+#include "nm-connection.h"
 #include "nm-ip4-config.h"
 #include "nm-pppd-plugin.h"
 
@@ -33,9 +35,9 @@
 NMPPPManager *nm_ppp_manager_new (void);
 
 gboolean nm_ppp_manager_start (NMPPPManager *manager,
-							   const char *device,
-							   NMSettingPPP *setting,
-							   GError **err);
+						 const char *device,
+						 NMConnection *connection,
+						 GError **err);
 
 void     nm_ppp_manager_stop  (NMPPPManager *manager);
 

Modified: trunk/src/ppp-manager/nm-pppd-plugin.c
==============================================================================
--- trunk/src/ppp-manager/nm-pppd-plugin.c	(original)
+++ trunk/src/ppp-manager/nm-pppd-plugin.c	Fri Mar  7 18:04:59 2008
@@ -14,127 +14,15 @@
 #include "nm-ppp-status.h"
 #include "nm-pppd-plugin-glue.h"
 
-GType nm_pppd_plugin_get_type (void);
 int plugin_init (void);
 
 char pppd_version[] = VERSION;
 
-#define NM_TYPE_PPPD_PLUGIN            (nm_pppd_plugin_get_type ())
-#define NM_PPPD_PLUGIN(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_PPPD_PLUGIN, NMPppdPlugin))
-#define NM_PPPD_PLUGIN_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_PPPD_PLUGIN, NMPppdPluginClass))
-#define NM_IS_PPPD_PLUGIN(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_PPPD_PLUGIN))
-#define NM_IS_PPPD_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_PPPD_PLUGIN))
-#define NM_PPPD_PLUGIN_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_PPPD_PLUGIN, NMPppdPluginClass))
-
-typedef struct {
-	GObject parent;
-} NMPppdPlugin;
-
-typedef struct {
-	GObjectClass parent;
-
-	void (*state_changed)  (NMPppdPlugin *plugin,
-					    NMPPPStatus status);
-	void (*ip4_config)     (NMPppdPlugin *plugin,
-					    GHashTable  *ip4_config);
-} NMPppdPluginClass;
-
-G_DEFINE_TYPE (NMPppdPlugin, nm_pppd_plugin, G_TYPE_OBJECT)
-
-#define NM_PPPD_PLUGIN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_PPPD_PLUGIN, NMPppdPluginPrivate))
-
-typedef struct {
-	DBusGConnection *bus;
-} NMPppdPluginPrivate;
-
-enum {
-	STATE_CHANGED,
-	IP4_CONFIG,
-
-	LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = { 0 };
-
-static void
-nm_pppd_plugin_init (NMPppdPlugin *plugin)
-{
-}
-
-static void
-finalize (GObject *object)
-{
-	dbus_g_connection_unref (NM_PPPD_PLUGIN_GET_PRIVATE (object)->bus);
-
-	G_OBJECT_CLASS (nm_pppd_plugin_parent_class)->finalize (object);
-}
-
-static void
-nm_pppd_plugin_class_init (NMPppdPluginClass *plugin_class)
-{
-	GObjectClass *object_class = G_OBJECT_CLASS (plugin_class);
-
-	g_type_class_add_private (object_class, sizeof (NMPppdPluginPrivate));
-	dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (plugin_class),
-							   &dbus_glib_nm_pppd_plugin_object_info);
-
-	object_class->finalize = finalize;
-
-	/* signals */
-	signals[STATE_CHANGED] =
-		g_signal_new ("state-changed",
-				    G_OBJECT_CLASS_TYPE (object_class),
-				    G_SIGNAL_RUN_FIRST,
-				    G_STRUCT_OFFSET (NMPppdPluginClass, state_changed),
-				    NULL, NULL,
-				    g_cclosure_marshal_VOID__UINT,
-				    G_TYPE_NONE, 1,
-				    G_TYPE_UINT);
-
-	signals[IP4_CONFIG] =
-		g_signal_new ("ip4-config",
-				    G_OBJECT_CLASS_TYPE (object_class),
-				    G_SIGNAL_RUN_FIRST,
-				    G_STRUCT_OFFSET (NMPppdPluginClass, ip4_config),
-				    NULL, NULL,
-				    g_cclosure_marshal_VOID__BOXED,
-				    G_TYPE_NONE, 1,
-				    dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE));
-}
-
-static NMPppdPlugin *
-nm_pppd_plugin_new (DBusGConnection *bus)
-{
-	GObject *obj;
-
-	obj = g_object_new (NM_TYPE_PPPD_PLUGIN, NULL);
-	if (!obj)
-		return NULL;
-
-	NM_PPPD_PLUGIN_GET_PRIVATE (obj)->bus = dbus_g_connection_ref (bus);
-	dbus_g_connection_register_g_object (bus, NM_DBUS_PATH_PPP, obj);
-
-	return (NMPppdPlugin *) obj;
-}
-
-static void
-nm_pppd_plugin_state_changed (NMPppdPlugin *plugin, NMPPPStatus ppp_status)
-{
-	g_signal_emit (plugin, signals[STATE_CHANGED], 0, ppp_status);
-}
-
-static void
-nm_pppd_plugin_ip4_config (NMPppdPlugin *plugin, GHashTable *ip4_config)
-{
-	g_signal_emit (plugin, signals[IP4_CONFIG], 0, ip4_config);
-}
-
-/*****************************************************************************/
+static DBusGProxy *proxy = NULL;
 
 static void
 nm_phasechange (void *data, int arg)
 {
-	NMPppdPlugin *plugin = NM_PPPD_PLUGIN (data);
 	NMPPPStatus ppp_status = NM_PPP_STATUS_UNKNOWN;
 	char *ppp_phase;
 
@@ -197,8 +85,12 @@
 		break;
 	}
 
-	if (ppp_status != NM_PPP_STATUS_UNKNOWN)
-		nm_pppd_plugin_state_changed (plugin, ppp_status);
+	if (ppp_status != NM_PPP_STATUS_UNKNOWN) {
+		dbus_g_proxy_call_no_reply (proxy, "SetState",
+							   G_TYPE_UINT, ppp_status,
+							   G_TYPE_INVALID,
+							   G_TYPE_INVALID);
+	}
 }
 
 static GValue *
@@ -237,7 +129,6 @@
 static void
 nm_ip_up (void *data, int arg)
 {
-	NMPppdPlugin *plugin = NM_PPPD_PLUGIN (data);
 	ipcp_options opts = ipcp_gotoptions[ifunit];
 	ipcp_options peer_opts = ipcp_hisoptions[ifunit];
 	GHashTable *hash;
@@ -299,25 +190,25 @@
 		g_hash_table_insert (hash, NM_PPP_IP4_CONFIG_WINS, val);
 	}
 
-	nm_pppd_plugin_ip4_config (plugin, hash);
+	dbus_g_proxy_call_no_reply (proxy, "SetIp4Config",
+						   dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
+						   hash,
+						   G_TYPE_INVALID,
+						   G_TYPE_INVALID);
+
 	g_hash_table_destroy (hash);
 }
 
 static void
 nm_exit_notify (void *data, int arg)
 {
-	NMPppdPlugin *plugin = NM_PPPD_PLUGIN (data);
-
-	g_object_unref (plugin);
+	g_object_unref (data);
 }
 
 int
 plugin_init (void)
 {
 	DBusGConnection *bus;
-	DBusGProxy *bus_proxy;
-	NMPppdPlugin *plugin;
-	guint request_name_result;
 	GError *err = NULL;
 
 	g_type_init ();
@@ -329,33 +220,16 @@
 		return -1;
 	}
 
-	bus_proxy = dbus_g_proxy_new_for_name (bus,
-								    "org.freedesktop.DBus",
-								    "/org/freedesktop/DBus",
-								    "org.freedesktop.DBus");
-
-	if (!dbus_g_proxy_call (bus_proxy, "RequestName", &err,
-					    G_TYPE_STRING, NM_DBUS_SERVICE_PPP,
-					    G_TYPE_UINT, 0,
-					    G_TYPE_INVALID,
-					    G_TYPE_UINT, &request_name_result,
-					    G_TYPE_INVALID)) {
-		g_warning ("Failed to acquire '" NM_DBUS_SERVICE_PPP "'");
-		g_error_free (err);
-		dbus_g_connection_unref (bus);
-		g_object_unref (bus_proxy);
-
-		return -1;
-	}
-
-	g_object_unref (bus_proxy);
+	proxy = dbus_g_proxy_new_for_name (bus,
+								NM_DBUS_SERVICE_PPP,
+								NM_DBUS_PATH_PPP,
+								NM_DBUS_INTERFACE_PPP);
 
-	plugin = nm_pppd_plugin_new (bus);
 	dbus_g_connection_unref (bus);
 
-	add_notifier (&phasechange, nm_phasechange, plugin);
-	add_notifier (&ip_up_notifier, nm_ip_up, plugin);
-	add_notifier (&exitnotify, nm_exit_notify, plugin);
+	add_notifier (&phasechange, nm_phasechange, NULL);
+	add_notifier (&ip_up_notifier, nm_ip_up, NULL);
+	add_notifier (&exitnotify, nm_exit_notify, proxy);
 
 	return 0;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]