vino r1127 - in trunk: . server
- From: jwendell svn gnome org
- To: svn-commits-list gnome org
- Subject: vino r1127 - in trunk: . server
- Date: Thu, 26 Feb 2009 17:31:03 +0000 (UTC)
Author: jwendell
Date: Thu Feb 26 17:31:03 2009
New Revision: 1127
URL: http://svn.gnome.org/viewvc/vino?rev=1127&view=rev
Log:
2009-02-26 Jonh Wendell <jwendell gnome org>
* configure.in,
* server/Makefile.am,
* server/vino-upnp.c: Added dependency on NetworkManager. Monitor for
network state changes and redo the UPnP forward.
New configure flag: --enable-network-manager. If not set, enable it
anyway if NetworkManager libraries are found. Requires NM 0.7.
Modified:
trunk/ChangeLog
trunk/configure.in
trunk/server/Makefile.am
trunk/server/vino-upnp.c
Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in (original)
+++ trunk/configure.in Thu Feb 26 17:31:03 2009
@@ -47,6 +47,7 @@
GLIB_VERSION=2.17.0
DBUS_VERSION=1.2.3
SOUP_VERSION=2.24.0
+NETWORKMANAGER_VERSION=0.7
PKG_CHECK_MODULES(VINO_SERVER, glib-2.0 >= $GLIB_VERSION gtk+-x11-2.0 >= $GTK_VERSION gconf-2.0 libglade-2.0 dbus-1 >= $DBUS_VERSION dbus-glib-1 libgnomeui-2.0)
@@ -79,6 +80,37 @@
AC_DEFINE(VINO_ENABLE_LIBNOTIFY, [], [Set if we should use libnotify])
fi
+dnl -- check for NetworkManager -----------------------------------------------
+AC_ARG_ENABLE(network-manager,
+ AC_HELP_STRING([--enable-network-manager],
+ [use NetworkManager to be notified when network status changes [default=auto]]),
+ [if test "x$enableval" = "xno" ; then
+ enable_networkmanager=no
+ else
+ enable_networkmanager=yes
+ fi],
+ enable_networkmanager=auto)
+
+if test "x$enable_networkmanager" = "xno"; then
+ have_networkmanager=no
+else
+ if test "x$enable_networkmanager" = "xyes"; then
+ PKG_CHECK_MODULES(VINO_NETWORKMANAGER, NetworkManager >= $NETWORKMANAGER_VERSION)
+ have_networkmanager=yes
+ else
+ PKG_CHECK_MODULES(VINO_NETWORKMANAGER,
+ NetworkManager >= $NETWORKMANAGER_VERSION,
+ have_networkmanager=yes, have_networkmanager=no)
+ fi;
+fi
+
+if test "x$have_networkmanager" = "xyes" ; then
+ AC_DEFINE(VINO_ENABLE_NETWORKMANAGER, [], [Set if we should use NetworkManager])
+fi
+
+AC_SUBST(VINO_NETWORKMANAGER_CFLAGS)
+AC_SUBST(VINO_NETWORKMANAGER_LIBS)
+
dnl --enable-gnome-keyring=(yes|no)
AC_ARG_ENABLE(gnome-keyring,
AC_HELP_STRING([--enable-gnome-keyring],
@@ -377,6 +409,7 @@
Avahi support ..............: ${VINO_ENABLE_MDNS}
Notify support .............: ${have_libnotify}
+ Network Manager support ....: ${have_networkmanager}
GNOME Keyring support.......: ${enable_gnome_keyring}
HTTP server.................: ${enable_http_server}
Libunique support...........: ${have_libunique}
Modified: trunk/server/Makefile.am
==============================================================================
--- trunk/server/Makefile.am (original)
+++ trunk/server/Makefile.am Thu Feb 26 17:31:03 2009
@@ -10,6 +10,7 @@
$(VINO_LIBNOTIFY_CFLAGS) \
$(VINO_KEYRING_CFLAGS) \
$(VINO_HTTP_CFLAGS) \
+ $(VINO_NETWORKMANAGER_CFLAGS) \
$(AVAHI_CFLAGS) \
$(LIBGNUTLS_CFLAGS) \
$(LIBGCRYPT_CFLAGS) \
@@ -27,6 +28,7 @@
$(VINO_LIBNOTIFY_LIBS) \
$(VINO_KEYRING_LIBS) \
$(AVAHI_LIBS) \
+ $(VINO_NETWORKMANAGER_LIBS) \
$(LIBGNUTLS_LIBS) \
$(LIBGCRYPT_LIBS) \
$(X_LIBS) $(XTEST_LIBS) $(XSHM_LIBS) $(XDAMAGE_LIBS) \
Modified: trunk/server/vino-upnp.c
==============================================================================
--- trunk/server/vino-upnp.c (original)
+++ trunk/server/vino-upnp.c Thu Feb 26 17:31:03 2009
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008 Jonh Wendell
+ * Copyright (C) 2008,2009 Jonh Wendell
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -20,9 +20,18 @@
* Jonh Wendell <wendell bani com br>
*/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include <miniupnp/miniupnpc.h>
#include <miniupnp/upnpcommands.h>
+#ifdef VINO_ENABLE_NETWORKMANAGER
+#include <dbus/dbus-glib.h>
+#include <NetworkManager/NetworkManager.h>
+#endif
+
#include "vino-upnp.h"
#include "vino-util.h"
@@ -33,6 +42,11 @@
char lanaddr[16];
gboolean have_igd;
int port;
+ int internal_port;
+#ifdef VINO_ENABLE_NETWORKMANAGER
+ DBusGConnection *bus;
+ DBusGProxy *proxy;
+#endif
};
G_DEFINE_TYPE (VinoUpnp, vino_upnp, G_TYPE_OBJECT);
@@ -116,6 +130,20 @@
vino_upnp_remove_port (upnp);
+#ifdef VINO_ENABLE_NETWORKMANAGER
+ if (upnp->priv->proxy)
+ {
+ g_object_unref (upnp->priv->proxy);
+ upnp->priv->proxy = NULL;
+ }
+
+ if (upnp->priv->bus)
+ {
+ dbus_g_connection_unref (upnp->priv->bus);
+ upnp->priv->bus = NULL;
+ }
+#endif
+
G_OBJECT_CLASS (vino_upnp_parent_class)->dispose (object);
}
@@ -130,6 +158,10 @@
g_type_class_add_private (gobject_class, sizeof (VinoUpnpPrivate));
}
+#ifdef VINO_ENABLE_NETWORKMANAGER
+static void setup_network_monitor (VinoUpnp *upnp);
+#endif
+
static void
vino_upnp_init (VinoUpnp *upnp)
{
@@ -139,6 +171,13 @@
upnp->priv->data = NULL;
upnp->priv->have_igd = FALSE;
upnp->priv->port = -1;
+ upnp->priv->internal_port = -1;
+
+#ifdef VINO_ENABLE_NETWORKMANAGER
+ upnp->priv->bus = NULL;
+ upnp->priv->proxy = NULL;
+ setup_network_monitor (upnp);
+#endif
}
VinoUpnp *
@@ -229,6 +268,7 @@
if (err == 0)
{
upnp->priv->port = local_port;
+ upnp->priv->internal_port = port;
dprintf (UPNP, "UPnP: Successfuly forwarded port %d\n", local_port);
}
else
@@ -267,6 +307,7 @@
g_free (port);
upnp->priv->port = -1;
+ upnp->priv->internal_port = -1;
}
int
@@ -276,3 +317,53 @@
return upnp->priv->port;
}
+
+#ifdef VINO_ENABLE_NETWORKMANAGER
+static gboolean
+redo_forward (VinoUpnp *upnp)
+{
+ int port = upnp->priv->internal_port;
+
+ dprintf (UPNP, "UPnP: Doing the forward again\n");
+ upnp->priv->have_igd = FALSE;
+ vino_upnp_remove_port (upnp);
+ vino_upnp_add_port (upnp, port);
+
+ return FALSE;
+}
+
+static void
+state_changed_cb (DBusGProxy *proxy, guint state, VinoUpnp *upnp)
+{
+ dprintf (UPNP, "UPnP: Got the 'network state changed' signal. Status = %d\n", state);
+
+ if ((state == NM_STATE_CONNECTED) && (upnp->priv->internal_port != -1))
+ g_timeout_add_seconds (2, (GSourceFunc) redo_forward, upnp);
+}
+
+static void
+setup_network_monitor (VinoUpnp *upnp)
+{
+ GError *error = NULL;
+
+ upnp->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ if (upnp->priv->bus == NULL)
+ {
+ g_warning ("Couldn't connect to system bus: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ upnp->priv->proxy = dbus_g_proxy_new_for_name (upnp->priv->bus,
+ NM_DBUS_SERVICE,
+ NM_DBUS_PATH,
+ NM_DBUS_INTERFACE);
+
+ dbus_g_proxy_add_signal (upnp->priv->proxy, "StateChanged", G_TYPE_UINT, G_TYPE_INVALID);
+ dbus_g_proxy_connect_signal (upnp->priv->proxy,
+ "StateChanged",
+ G_CALLBACK (state_changed_cb),
+ upnp,
+ NULL);
+}
+#endif /* HAVE_NETWORKMANAGER */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]