NetworkManager r3740 - in trunk: . include introspection libnm-glib src src/ppp-manager



Author: dcbw
Date: Tue Jun 10 14:59:22 2008
New Revision: 3740
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3740&view=rev

Log:
2008-06-10  Dan Williams  <dcbw redhat com>

	Patch from Tambet Ingo <tambet gmail com>

	* src/ppp-manager/nm-ppp-manager.c: Add ppp stats monitoring, signal the
		changes.

	* src/nm-serial-device.c: Monitor "ppp-stats" signals from NMPPPManager. Add
		a signal to emit these changes over dbus.

	* src/Makefile.am: Genereate nm-serial-device-glue.

	* libnm-glib/nm-serial-device.[ch]: Implement.

	* libnm-glib/nm-cdma-device.[ch]
	  libnm-glib/nm-gsm-device.[ch]: Inherit from NMSerialDevice.

	* libnm-glib/Makefile.am: Add nm-serial-device.[ch].

	* introspection/nm-device-serial.xml: Implement.

	* introspection/all.xml: Fix a couple of typos, add nm-device-serial.xml.

	* introspection/Makefile.am: Add nm-device-serial.xml.

	* include/NetworkManager.h: Add a DBus interface for serial device.



Modified:
   trunk/ChangeLog
   trunk/include/NetworkManager.h
   trunk/introspection/Makefile.am
   trunk/introspection/all.xml
   trunk/libnm-glib/Makefile.am
   trunk/libnm-glib/nm-cdma-device.c
   trunk/libnm-glib/nm-cdma-device.h
   trunk/libnm-glib/nm-gsm-device.c
   trunk/libnm-glib/nm-gsm-device.h
   trunk/src/Makefile.am
   trunk/src/nm-serial-device.c
   trunk/src/nm-serial-device.h
   trunk/src/ppp-manager/nm-ppp-manager.c
   trunk/src/ppp-manager/nm-ppp-manager.h

Modified: trunk/include/NetworkManager.h
==============================================================================
--- trunk/include/NetworkManager.h	(original)
+++ trunk/include/NetworkManager.h	Tue Jun 10 14:59:22 2008
@@ -34,6 +34,7 @@
 #define NM_DBUS_INTERFACE_DEVICE_WIRELESS   NM_DBUS_INTERFACE_DEVICE ".Wireless"
 #define NM_DBUS_PATH_ACCESS_POINT           NM_DBUS_PATH "/AccessPoint"
 #define NM_DBUS_INTERFACE_ACCESS_POINT      NM_DBUS_INTERFACE ".AccessPoint"
+#define NM_DBUS_INTERFACE_SERIAL_DEVICE     NM_DBUS_INTERFACE_DEVICE ".Serial"
 #define NM_DBUS_INTERFACE_GSM_DEVICE        NM_DBUS_INTERFACE_DEVICE ".Gsm"
 #define NM_DBUS_INTERFACE_CDMA_DEVICE       NM_DBUS_INTERFACE_DEVICE ".Cdma"
 #define NM_DBUS_INTERFACE_ACTIVE_CONNECTION NM_DBUS_INTERFACE ".Connection.Active"

Modified: trunk/introspection/Makefile.am
==============================================================================
--- trunk/introspection/Makefile.am	(original)
+++ trunk/introspection/Makefile.am	Tue Jun 10 14:59:22 2008
@@ -4,6 +4,7 @@
 	nm-device-802-3-ethernet.xml	\
 	nm-device-cdma.xml \
 	nm-device-gsm.xml \
+	nm-device-serial.xml \
 	nm-device.xml					\
 	nm-ip4-config.xml				\
 	nm-manager.xml					\

Modified: trunk/introspection/all.xml
==============================================================================
--- trunk/introspection/all.xml	(original)
+++ trunk/introspection/all.xml	Tue Jun 10 14:59:22 2008
@@ -30,8 +30,9 @@
 <xi:include href="nm-device.xml"/>
 <xi:include href="nm-device-802-3-ethernet.xml"/>
 <xi:include href="nm-device-802-11-wireless.xml"/>
-<xi:include href="nm-cdma-device.xml"/>
-<xi:include href="nm-gsm-device.xml"/>
+<xi:include href="nm-device-cdma.xml"/>
+<xi:include href="nm-device-gsm.xml"/>
+<xi:include href="nm-device-serial.xml"/>
 <xi:include href="nm-ip4-config.xml"/>
 <xi:include href="nm-settings.xml"/>
 <xi:include href="nm-exported-connection.xml"/>

Modified: trunk/libnm-glib/Makefile.am
==============================================================================
--- trunk/libnm-glib/Makefile.am	(original)
+++ trunk/libnm-glib/Makefile.am	Tue Jun 10 14:59:22 2008
@@ -41,6 +41,7 @@
 	nm-settings.h \
 	nm-gsm-device.h \
 	nm-cdma-device.h \
+	nm-serial-device.h \
 	nm-vpn-connection.h \
 	nm-vpn-plugin.h \
 	nm-types.h \
@@ -65,6 +66,7 @@
 	nm-settings.c		\
 	nm-gsm-device.c	\
 	nm-cdma-device.c	\
+	nm-serial-device.c \
 	nm-vpn-connection.c	\
 	nm-types.c \
 	nm-types-private.h \

Modified: trunk/libnm-glib/nm-cdma-device.c
==============================================================================
--- trunk/libnm-glib/nm-cdma-device.c	(original)
+++ trunk/libnm-glib/nm-cdma-device.c	Tue Jun 10 14:59:22 2008
@@ -4,7 +4,7 @@
 #include "nm-device-private.h"
 #include "nm-object-private.h"
 
-G_DEFINE_TYPE (NMCdmaDevice, nm_cdma_device, NM_TYPE_DEVICE)
+G_DEFINE_TYPE (NMCdmaDevice, nm_cdma_device, NM_TYPE_SERIAL_DEVICE)
 
 #define NM_CDMA_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_CDMA_DEVICE, NMCdmaDevicePrivate))
 

Modified: trunk/libnm-glib/nm-cdma-device.h
==============================================================================
--- trunk/libnm-glib/nm-cdma-device.h	(original)
+++ trunk/libnm-glib/nm-cdma-device.h	Tue Jun 10 14:59:22 2008
@@ -3,7 +3,7 @@
 #ifndef NM_CDMA_DEVICE_H
 #define NM_CDMA_DEVICE_H
 
-#include "nm-device.h"
+#include "nm-serial-device.h"
 
 G_BEGIN_DECLS
 
@@ -15,11 +15,11 @@
 #define NM_CDMA_DEVICE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_CDMA_DEVICE, NMCdmaDeviceClass))
 
 typedef struct {
-	NMDevice parent;
+	NMSerialDevice parent;
 } NMCdmaDevice;
 
 typedef struct {
-	NMDeviceClass parent;
+	NMSerialDeviceClass parent;
 } NMCdmaDeviceClass;
 
 GType        nm_cdma_device_get_type (void);

Modified: trunk/libnm-glib/nm-gsm-device.c
==============================================================================
--- trunk/libnm-glib/nm-gsm-device.c	(original)
+++ trunk/libnm-glib/nm-gsm-device.c	Tue Jun 10 14:59:22 2008
@@ -4,7 +4,7 @@
 #include "nm-device-private.h"
 #include "nm-object-private.h"
 
-G_DEFINE_TYPE (NMGsmDevice, nm_gsm_device, NM_TYPE_DEVICE)
+G_DEFINE_TYPE (NMGsmDevice, nm_gsm_device, NM_TYPE_SERIAL_DEVICE)
 
 #define NM_GSM_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_GSM_DEVICE, NMGsmDevicePrivate))
 

Modified: trunk/libnm-glib/nm-gsm-device.h
==============================================================================
--- trunk/libnm-glib/nm-gsm-device.h	(original)
+++ trunk/libnm-glib/nm-gsm-device.h	Tue Jun 10 14:59:22 2008
@@ -3,7 +3,7 @@
 #ifndef NM_GSM_DEVICE_H
 #define NM_GSM_DEVICE_H
 
-#include "nm-device.h"
+#include "nm-serial-device.h"
 
 G_BEGIN_DECLS
 
@@ -15,11 +15,11 @@
 #define NM_GSM_DEVICE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_GSM_DEVICE, NMGsmDeviceClass))
 
 typedef struct {
-	NMDevice parent;
+	NMSerialDevice parent;
 } NMGsmDevice;
 
 typedef struct {
-	NMDeviceClass parent;
+	NMSerialDeviceClass parent;
 } NMGsmDeviceClass;
 
 GType        nm_gsm_device_get_type (void);

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Tue Jun 10 14:59:22 2008
@@ -87,6 +87,9 @@
 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
 
+nm-serial-device-glue.h: $(top_srcdir)/introspection/nm-device-serial.xml
+	dbus-binding-tool --prefix=nm_serial_device --mode=glib-server --output=nm-serial-device-glue.h $(top_srcdir)/introspection/nm-device-serial.xml
+
 nm-cdma-device-glue.h: $(top_srcdir)/introspection/nm-device-cdma.xml
 	dbus-binding-tool --prefix=nm_cdma_device --mode=glib-server --output=nm-cdma-device-glue.h $(top_srcdir)/introspection/nm-device-cdma.xml
 
@@ -105,6 +108,7 @@
 	nm-device-interface-glue.h			\
 	nm-device-802-3-ethernet-glue.h			\
 	nm-device-802-11-wireless-glue.h		\
+	nm-serial-device-glue.h \
 	nm-cdma-device-glue.h \
 	nm-gsm-device-glue.h \
 	nm-ip4-config-glue.h				\

Modified: trunk/src/nm-serial-device.c
==============================================================================
--- trunk/src/nm-serial-device.c	(original)
+++ trunk/src/nm-serial-device.c	Tue Jun 10 14:59:22 2008
@@ -17,7 +17,9 @@
 #include "nm-device-private.h"
 #include "ppp-manager/nm-ppp-manager.h"
 #include "nm-setting-ppp.h"
+#include "nm-marshal.h"
 #include "nm-utils.h"
+#include "nm-serial-device-glue.h"
 
 /* #define NM_DEBUG_SERIAL 1 */
 
@@ -33,8 +35,20 @@
 	NMPPPManager *ppp_manager;
 	NMIP4Config  *pending_ip4_config;
 	struct termios old_t;
+
+	/* PPP stats */
+	guint32 in_bytes;
+	guint32 out_bytes;
 } NMSerialDevicePrivate;
 
+enum {
+	PPP_STATS,
+
+	LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
 static int
 parse_baudrate (guint i)
 {
@@ -941,6 +955,23 @@
 	nm_device_activate_schedule_stage4_ip_config_get (device);
 }
 
+static void
+ppp_stats (NMPPPManager *ppp_manager,
+		 guint32 in_bytes,
+		 guint32 out_bytes,
+		 gpointer user_data)
+{
+	NMSerialDevice *device = NM_SERIAL_DEVICE (user_data);
+	NMSerialDevicePrivate *priv = NM_SERIAL_DEVICE_GET_PRIVATE (device);
+
+	if (priv->in_bytes != in_bytes || priv->out_bytes != out_bytes) {
+		priv->in_bytes = in_bytes;
+		priv->out_bytes = out_bytes;
+
+		g_signal_emit (device, signals[PPP_STATS], 0, in_bytes, out_bytes);
+	}
+}
+
 static NMActStageReturn
 real_act_stage2_config (NMDevice *device)
 {
@@ -964,6 +995,10 @@
 		g_signal_connect (priv->ppp_manager, "ip4-config",
 					   G_CALLBACK (ppp_ip4_config),
 					   device);
+		g_signal_connect (priv->ppp_manager, "stats",
+					   G_CALLBACK (ppp_stats),
+					   device);
+
 		ret = NM_ACT_STAGE_RETURN_POSTPONE;
 	} else {
 		nm_warning ("%s", err->message);
@@ -1002,6 +1037,8 @@
 		priv->pending_ip4_config = NULL;
 	}
 
+	priv->in_bytes = priv->out_bytes = 0;
+
 	if (priv->ppp_manager) {
 		g_object_unref (priv->ppp_manager);
 		priv->ppp_manager = NULL;
@@ -1048,4 +1085,18 @@
 	parent_class->act_stage2_config = real_act_stage2_config;
 	parent_class->act_stage4_get_ip4_config = real_act_stage4_get_ip4_config;
 	parent_class->deactivate_quickly = real_deactivate_quickly;
+
+	/* Signals */
+	signals[PPP_STATS] =
+		g_signal_new ("ppp-stats",
+				    G_OBJECT_CLASS_TYPE (object_class),
+				    G_SIGNAL_RUN_FIRST,
+				    G_STRUCT_OFFSET (NMSerialDeviceClass, ppp_stats),
+				    NULL, NULL,
+				    nm_marshal_VOID__UINT_UINT,
+				    G_TYPE_NONE, 2,
+				    G_TYPE_UINT, G_TYPE_UINT);
+
+	dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (klass),
+							   &dbus_glib_nm_serial_device_object_info);
 }

Modified: trunk/src/nm-serial-device.h
==============================================================================
--- trunk/src/nm-serial-device.h	(original)
+++ trunk/src/nm-serial-device.h	Tue Jun 10 14:59:22 2008
@@ -21,6 +21,9 @@
 
 typedef struct {
 	NMDeviceClass parent;
+
+	/* Signals */
+	void (*ppp_stats) (NMSerialDevice *device, guint32 in_bytes, guint32 out_bytes);
 } NMSerialDeviceClass;
 
 GType nm_serial_device_get_type (void);

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	Tue Jun 10 14:59:22 2008
@@ -7,6 +7,18 @@
 #include <unistd.h>
 #include <arpa/inet.h>
 
+#include <errno.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <asm/types.h>
+#include <net/if.h>
+
+#include <linux/ppp_defs.h>
+#ifndef aligned_u64
+#define aligned_u64 unsigned long long __attribute__((aligned(8)))
+#endif
+#include <linux/if_ppp.h>
+
 #include "nm-ppp-manager.h"
 #include "nm-setting-connection.h"
 #include "nm-setting-ppp.h"
@@ -41,6 +53,11 @@
 
 	guint32 ppp_watch_id;
 	guint32 ppp_timeout_handler;
+
+	/* Monitoring */
+	char *iface;
+	int monitor_fd;
+	guint monitor_id;
 } NMPPPManagerPrivate;
 
 #define NM_PPP_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_PPP_MANAGER, NMPPPManagerPrivate))
@@ -50,6 +67,7 @@
 enum {
 	STATE_CHANGED,
 	IP4_CONFIG,
+	STATS,
 
 	LAST_SIGNAL
 };
@@ -163,6 +181,16 @@
 				    G_TYPE_NONE, 2,
 				    G_TYPE_STRING,
 				    G_TYPE_OBJECT);
+
+	signals[STATS] =
+		g_signal_new ("stats",
+				    G_OBJECT_CLASS_TYPE (object_class),
+				    G_SIGNAL_RUN_FIRST,
+				    G_STRUCT_OFFSET (NMPPPManagerClass, stats),
+				    NULL, NULL,
+				    nm_marshal_VOID__UINT_UINT,
+				    G_TYPE_NONE, 2,
+				    G_TYPE_UINT, G_TYPE_UINT);
 }
 
 NMPPPManager *
@@ -173,6 +201,42 @@
 
 /*******************************************/
 
+static gboolean
+monitor_cb (gpointer user_data)
+{
+	NMPPPManager *manager = NM_PPP_MANAGER (user_data);
+	NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager);
+	struct ifpppstatsreq req;
+
+	memset (&req, 0, sizeof (req));
+	req.stats_ptr = (caddr_t) &req.stats;
+
+	strncpy (req.ifr__name, priv->iface, sizeof (req.ifr__name));
+	if (!ioctl (priv->monitor_fd, SIOCGPPPSTATS, &req) < 0)
+		nm_warning ("Could not read ppp stats: %s", strerror (errno));
+	else
+		g_signal_emit (manager, signals[STATS], 0, 
+					req.stats.p.ppp_ibytes,
+					req.stats.p.ppp_obytes);
+
+	return TRUE;
+}
+
+static void
+monitor_stats (NMPPPManager *manager, const char *iface)
+{
+	NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager);
+
+	priv->monitor_fd = socket (AF_INET, SOCK_DGRAM, 0);
+	if (priv->monitor_fd > 0) {
+		priv->iface = g_strdup (iface);
+		priv->monitor_id = g_timeout_add (5000, monitor_cb, manager);
+	} else
+		nm_warning ("Could not open pppd monitor: %s", strerror (errno));
+}
+
+/*******************************************/
+
 static void
 remove_timeout_handler (NMPPPManager *manager)
 {
@@ -292,6 +356,8 @@
 
 	g_signal_emit (manager, signals[IP4_CONFIG], 0, iface, config);
 
+	monitor_stats (manager, iface);
+
  out:
 	g_object_unref (config);
 
@@ -753,6 +819,20 @@
 
 	priv = NM_PPP_MANAGER_GET_PRIVATE (manager);
 
+	if (priv->monitor_id) {
+		g_source_remove (priv->monitor_id);
+		priv->monitor_id = 0;
+	}
+
+	if (priv->monitor_fd) {
+		/* Get the stats one last time */
+		monitor_cb (manager);
+		close (priv->monitor_fd);
+		priv->monitor_fd = 0;
+	}
+
+	g_free (priv->iface);
+
 	if (priv->ppp_timeout_handler) {
 		g_source_remove (priv->ppp_timeout_handler);
 		priv->ppp_timeout_handler = 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	Tue Jun 10 14:59:22 2008
@@ -29,6 +29,7 @@
 	/* Signals */
 	void (*state_changed) (NMPPPManager *manager, NMPPPStatus status);
 	void (*ip4_config) (NMPPPManager *manager, const char *iface, NMIP4Config *config);
+	void (*stats) (NMPPPManager *manager, guint32 in_bytes, guint32 out_bytes);
 } NMPPPManagerClass;
 
 GType nm_ppp_manager_get_type (void);



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