aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaudio Saavedra <csaavedra@igalia.com>2011-06-24 04:18:37 +0800
committerClaudio Saavedra <csaavedra@igalia.com>2011-06-24 05:00:18 +0800
commit3af15cdbcd31a7ac4eda748ae83180a228d30a80 (patch)
tree1454d2f428a9b6ef143efb54447ed4ebd49827a8
parentab913fa36787366d68e08a0831403872d3e62ffc (diff)
downloadgsoc2013-epiphany-3af15cdbcd31a7ac4eda748ae83180a228d30a80.tar
gsoc2013-epiphany-3af15cdbcd31a7ac4eda748ae83180a228d30a80.tar.gz
gsoc2013-epiphany-3af15cdbcd31a7ac4eda748ae83180a228d30a80.tar.bz2
gsoc2013-epiphany-3af15cdbcd31a7ac4eda748ae83180a228d30a80.tar.lz
gsoc2013-epiphany-3af15cdbcd31a7ac4eda748ae83180a228d30a80.tar.xz
gsoc2013-epiphany-3af15cdbcd31a7ac4eda748ae83180a228d30a80.tar.zst
gsoc2013-epiphany-3af15cdbcd31a7ac4eda748ae83180a228d30a80.zip
Use a gdbus-codegen generated GDBusProxy to monitor NM state
Get rid of the EphyNetMonitor code and instead generate a GDBusProxy subclass that monitors the StateChanged signal and State property in org.gnome.NetworkManager. This proxy exports these features as standard GObject signal and property, respectively, so we can use it directly through the relevant accessors. https://bugzilla.gnome.org/show_bug.cgi?id=622903
-rw-r--r--configure.ac1
-rw-r--r--data/Makefile.am1
-rw-r--r--data/ephy-network-manager.xml9
-rw-r--r--src/Makefile.am28
-rw-r--r--src/ephy-net-monitor.c374
-rw-r--r--src/ephy-net-monitor.h66
-rw-r--r--src/ephy-shell.c36
7 files changed, 52 insertions, 463 deletions
diff --git a/configure.ac b/configure.ac
index 0b16ea8e5..bace3970e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -323,6 +323,7 @@ if test "$enable_network_manager" != "no"; then
fi
if test "$enable_network_manager" = "yes"; then
+ AC_PATH_PROG([GDBUS_CODEGEN], [gdbus-codegen])
AC_DEFINE([ENABLE_NETWORK_MANAGER],[1],[Define for NetworkManager support])
fi
diff --git a/data/Makefile.am b/data/Makefile.am
index 6fcfa8144..4d9cf6a36 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -72,6 +72,7 @@ EXTRA_DIST = \
$(gsettings_files) \
$(convert_DATA) \
epiphany-service.xml \
+ ephy-network-manager.xml \
check-mime.py
DISTCLEANFILES = \
diff --git a/data/ephy-network-manager.xml b/data/ephy-network-manager.xml
new file mode 100644
index 000000000..90fcd7011
--- /dev/null
+++ b/data/ephy-network-manager.xml
@@ -0,0 +1,9 @@
+<node>
+ <interface name='org.freedesktop.NetworkManager'>
+ <signal name='StateChanged'>
+ <arg name='state' type='u' />
+ </signal>
+ <property name='State' type='u' access='read'/>
+ <property name='Version' type='s' access='read'/>
+ </interface>
+</node>
diff --git a/src/Makefile.am b/src/Makefile.am
index f3995050a..9c2e87eaf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -116,10 +116,26 @@ libephymain_la_CFLAGS = \
$(WEBKIT_CFLAGS) \
$(AM_CFLAGS)
+BUILT_SOURCES = \
+ $(TYPES_SOURCE) \
+ ephy-dbus-client-bindings.h \
+ ephy-dbus-server-bindings.h
+
if ENABLE_NETWORK_MANAGER
-libephymain_la_SOURCES += \
- ephy-net-monitor.c \
- ephy-net-monitor.h
+nodist_libephymain_la_SOURCES += \
+ ephy-network-manager.c \
+ ephy-network-manager.h
+
+BUILT_SOURCES += \
+ ephy-network-manager.h \
+ ephy-network-manager.c
+
+ephy-network-manager.c ephy-network-manager.h: $(top_srcdir)/data/ephy-network-manager.xml
+ $(AM_V_GEN) $(GDBUS_CODEGEN) \
+ --c-namespace Ephy \
+ --generate-c-code ephy-network-manager \
+ --interface-prefix org.freedesktop. \
+ $<
libephymain_la_CFLAGS += $(NETWORK_MANAGER_CFLAGS)
endif
@@ -184,12 +200,6 @@ epiphany_LDADD += \
$(NETWORK_MANAGER_LIBS)
endif
-BUILT_SOURCES = \
- $(TYPES_SOURCE) \
- ephy-dbus-client-bindings.h \
- ephy-dbus-server-bindings.h
-
-
TYPES_SOURCE = \
ephy-type-builtins.c \
ephy-type-builtins.h
diff --git a/src/ephy-net-monitor.c b/src/ephy-net-monitor.c
deleted file mode 100644
index 3c970c1bf..000000000
--- a/src/ephy-net-monitor.c
+++ /dev/null
@@ -1,374 +0,0 @@
-/*
- * Copyright © 2005, 2006 Jean-François Rameau
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "config.h"
-
-#include "ephy-net-monitor.h"
-
-#include "ephy-dbus.h"
-#include "ephy-debug.h"
-#include "ephy-settings.h"
-#include "ephy-prefs.h"
-
-#include <NetworkManager.h>
-
-#include <gmodule.h>
-
-typedef enum
-{
- NETWORK_UP,
- NETWORK_DOWN
-} NetworkStatus;
-
-#define EPHY_NET_MONITOR_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_NET_MONITOR, EphyNetMonitorPrivate))
-
-struct _EphyNetMonitorPrivate
-{
- DBusConnection *bus;
- guint active : 1;
- NetworkStatus status;
-};
-
-enum
-{
- PROP_0,
- PROP_NETWORK_STATUS
-};
-
-G_DEFINE_TYPE (EphyNetMonitor, ephy_net_monitor, G_TYPE_OBJECT)
-
-static void
-ephy_net_monitor_set_net_status (EphyNetMonitor *monitor,
- NetworkStatus status)
-{
- EphyNetMonitorPrivate *priv = monitor->priv;
-
- LOG ("EphyNetMonitor turning Epiphany to %s mode",
- status != NETWORK_DOWN ? "online" : "offline");
-
- priv->status = status;
-
- g_object_notify (G_OBJECT (monitor), "network-status");
-}
-
-static void
-ephy_net_monitor_dbus_notify (DBusPendingCall *pending,
- EphyNetMonitor *monitor)
-{
- DBusMessage* msg = dbus_pending_call_steal_reply (pending);
-
- LOG ("EphyNetMonitor getting response from dbus");
-
- if (!msg) return;
-
- if (dbus_message_get_type(msg) == DBUS_MESSAGE_TYPE_METHOD_RETURN)
- {
- dbus_uint32_t result;
-
- if (dbus_message_get_args (msg, NULL, DBUS_TYPE_UINT32, &result,
- DBUS_TYPE_INVALID))
- {
- NetworkStatus net_status;
-
- net_status = result == NM_STATE_CONNECTED ? NETWORK_UP : NETWORK_DOWN;
-
- LOG ("EphyNetMonitor guesses the network is %s",
- net_status != NETWORK_DOWN ? "up" : "down");
-
- ephy_net_monitor_set_net_status (monitor, net_status);
- }
- dbus_message_unref (msg);
- }
-}
-
-/* This is the heart of Net Monitor monitor */
-/* ATM, if there is an active device, we say that network is up: that's all ! */
-static void
-ephy_net_monitor_check_network (EphyNetMonitor *monitor)
-{
- EphyNetMonitorPrivate *priv = monitor->priv;
- DBusMessage *message;
- DBusPendingCall* reply;
-
- g_return_if_fail (priv != NULL && priv->bus != NULL);
-
- LOG ("EphyNetMonitor checking network");
-
- /* ask to Network Manager if there is at least one active device */
- message = dbus_message_new_method_call (NM_DBUS_SERVICE,
- NM_DBUS_PATH,
- NM_DBUS_INTERFACE,
- "state");
-
- if (message == NULL)
- {
- g_warning ("Couldn't allocate the dbus message");
- /* fallback: let's Epiphany roll */
- return;
- }
-
- if (dbus_connection_send_with_reply (priv->bus, message, &reply, -1))
- {
- dbus_pending_call_set_notify (reply,
- (DBusPendingCallNotifyFunction)ephy_net_monitor_dbus_notify,
- monitor, NULL);
- dbus_pending_call_unref (reply);
- }
-
- dbus_message_unref (message);
-}
-
-/* Filters all the messages from Network Manager */
-static DBusHandlerResult
-filter_func (DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
-{
- EphyNetMonitor *monitor;
-
- g_return_val_if_fail (user_data != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
-
- monitor = EPHY_NET_MONITOR (user_data);
-
- if (dbus_message_is_signal (message,
- NM_DBUS_INTERFACE,
- "StateChange"))
- {
- LOG ("EphyNetMonitor catches StateChange signal");
-
- ephy_net_monitor_check_network (monitor);
-
- return DBUS_HANDLER_RESULT_HANDLED;
- }
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
-static void
-ephy_net_monitor_attach_to_dbus (EphyNetMonitor *monitor)
-{
- EphyNetMonitorPrivate *priv = monitor->priv;
- DBusError error;
- EphyDbus *dbus;
- DBusGConnection *g_connection;
-
- LOG ("EphyNetMonitor is trying to attach to SYSTEM bus");
-
- dbus = ephy_dbus_get_default ();
-
- g_connection = ephy_dbus_get_bus (dbus, EPHY_DBUS_SYSTEM);
- if (g_connection == NULL) return;
-
- priv->bus = dbus_g_connection_get_connection (g_connection);
-
- if (priv->bus != NULL)
- {
- dbus_connection_add_filter (priv->bus,
- filter_func,
- monitor,
- NULL);
- dbus_error_init (&error);
- dbus_bus_add_match (priv->bus,
- "type='signal',interface='" NM_DBUS_INTERFACE "'",
- &error);
- if (dbus_error_is_set(&error))
- {
- g_warning("EphyNetMonitor cannot register signal handler: %s: %s",
- error.name, error.message);
- dbus_error_free(&error);
- }
- LOG ("EphyNetMonitor attached to SYSTEM bus");
- }
-}
-
-static void
-ephy_net_monitor_detach_from_dbus (EphyNetMonitor *monitor)
-{
- EphyNetMonitorPrivate *priv = monitor->priv;
-
- LOG ("EphyNetMonitor is trying to detach from SYSTEM bus");
-
- if (priv->bus != NULL)
- {
- dbus_connection_remove_filter (priv->bus,
- filter_func,
- monitor);
- priv->bus = NULL;
- }
-}
-
-
-static void
-connect_to_system_bus_cb (EphyDbus *dbus,
- EphyDbusBus kind,
- EphyNetMonitor *monitor)
-{
- if (kind == EPHY_DBUS_SYSTEM)
- {
- LOG ("EphyNetMonitor connecting to SYSTEM bus");
-
- ephy_net_monitor_attach_to_dbus (monitor);
- }
-}
-
-static void
-disconnect_from_system_bus_cb (EphyDbus *dbus,
- EphyDbusBus kind,
- EphyNetMonitor *monitor)
-{
- if (kind == EPHY_DBUS_SYSTEM)
- {
- LOG ("EphyNetMonitor disconnected from SYSTEM bus");
-
- /* no bus anymore */
- ephy_net_monitor_detach_from_dbus (monitor);
- }
-}
-
-static void
-ephy_net_monitor_startup (EphyNetMonitor *monitor)
-{
- EphyDbus *dbus;
-
- dbus = ephy_dbus_get_default ();
-
- LOG ("EphyNetMonitor starting up");
-
- ephy_net_monitor_attach_to_dbus (monitor);
-
- if (monitor->priv->bus != NULL)
- {
- /* DBUS may disconnect us at any time. So listen carefully to it */
- g_signal_connect (dbus, "connected",
- G_CALLBACK (connect_to_system_bus_cb), monitor);
- g_signal_connect (dbus, "disconnected",
- G_CALLBACK (disconnect_from_system_bus_cb), monitor);
-
- ephy_net_monitor_check_network (monitor);
- }
-}
-
-static void
-ephy_net_monitor_shutdown (EphyNetMonitor *monitor)
-{
- EphyNetMonitorPrivate *priv = monitor->priv;
- EphyDbus *dbus;
-
- dbus = ephy_dbus_get_default ();
-
- ephy_net_monitor_detach_from_dbus (monitor);
- g_signal_handlers_disconnect_by_func
- (dbus, G_CALLBACK (connect_to_system_bus_cb), monitor);
- g_signal_handlers_disconnect_by_func
- (dbus,G_CALLBACK (disconnect_from_system_bus_cb), monitor);
-
- priv->bus = NULL;
-
- LOG ("EphyNetMonitor shutdown");
-}
-
-static void
-ephy_net_monitor_init (EphyNetMonitor *monitor)
-{
- EphyNetMonitorPrivate *priv;
-
- priv = monitor->priv = EPHY_NET_MONITOR_GET_PRIVATE (monitor);
-
- LOG ("EphyNetMonitor initialising");
-
- priv->status = NETWORK_UP;
-
- ephy_net_monitor_startup (monitor);
-}
-
-static void
-ephy_net_monitor_dispose (GObject *object)
-{
- EphyNetMonitor *monitor = EPHY_NET_MONITOR (object);
-
- LOG ("EphyNetMonitor finalising");
-
- ephy_net_monitor_shutdown (monitor);
-
- G_OBJECT_CLASS (ephy_net_monitor_parent_class)->dispose (object);
-}
-
-static void
-ephy_net_monitor_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- EphyNetMonitor *monitor = EPHY_NET_MONITOR (object);
-
- switch (prop_id)
- {
- case PROP_NETWORK_STATUS:
- g_value_set_boolean (value, ephy_net_monitor_get_net_status (monitor));
- break;
- }
-}
-
-static void
-ephy_net_monitor_class_init (EphyNetMonitorClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->dispose = ephy_net_monitor_dispose;
- object_class->get_property = ephy_net_monitor_get_property;
-
-/**
- * EphyNetMonitor::network-status:
- *
- * Whether the network is on-line.
- */
- g_object_class_install_property
- (object_class,
- PROP_NETWORK_STATUS,
- g_param_spec_boolean ("network-status",
- "network-status",
- "network-status",
- FALSE,
- G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
-
- g_type_class_add_private (object_class, sizeof (EphyNetMonitorPrivate));
-}
-
-/* public API */
-
-EphyNetMonitor *
-ephy_net_monitor_new (void)
-{
- return g_object_new (EPHY_TYPE_NET_MONITOR, NULL);
-}
-
-gboolean
-ephy_net_monitor_get_net_status (EphyNetMonitor *monitor)
-{
- EphyNetMonitorPrivate *priv;
- gboolean managed;
-
- g_return_val_if_fail (EPHY_IS_NET_MONITOR (monitor), FALSE);
-
- priv = monitor->priv;
- managed = g_settings_get_boolean (EPHY_SETTINGS_MAIN,
- EPHY_PREFS_MANAGED_NETWORK);
-
- return !managed || priv->status != NETWORK_DOWN;
-}
diff --git a/src/ephy-net-monitor.h b/src/ephy-net-monitor.h
deleted file mode 100644
index 9255e8fda..000000000
--- a/src/ephy-net-monitor.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright © 2003 Marco Pesenti Gritti
- * Copyright © 2003 Christian Persch
- * Copyright © 2005, 2006 Jean-François Rameau
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#if !defined (__EPHY_EPIPHANY_H_INSIDE__) && !defined (EPIPHANY_COMPILATION)
-#error "Only <epiphany/epiphany.h> can be included directly."
-#endif
-
-#ifndef EPHY_NET_MONITOR_H
-#define EPHY_NET_MONITOR_H
-
-#include <glib.h>
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-#define EPHY_TYPE_NET_MONITOR (ephy_net_monitor_get_type ())
-#define EPHY_NET_MONITOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EPHY_TYPE_NET_MONITOR, EphyNetMonitor))
-#define EPHY_NET_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EPHY_TYPE_NET_MONITOR, EphyNetMonitorClass))
-#define EPHY_IS_NET_MONITOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EPHY_TYPE_NET_MONITOR))
-#define EPHY_IS_NET_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_NET_MONITOR))
-#define EPHY_NET_MONITOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_NET_MONITOR, EphyNetMonitorClass))
-
-typedef struct _EphyNetMonitor EphyNetMonitor;
-typedef struct _EphyNetMonitorClass EphyNetMonitorClass;
-typedef struct _EphyNetMonitorPrivate EphyNetMonitorPrivate;
-
-struct _EphyNetMonitorClass
-{
- GObjectClass parent_class;
-};
-
-struct _EphyNetMonitor
-{
- GObject parent_instance;
-
- /*< private >*/
- EphyNetMonitorPrivate *priv;
-};
-
-GType ephy_net_monitor_get_type (void);
-
-EphyNetMonitor *ephy_net_monitor_new (void);
-
-gboolean ephy_net_monitor_get_net_status (EphyNetMonitor *monitor);
-
-G_END_DECLS
-
-#endif
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index ef45fb493..6a246ee76 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -58,7 +58,8 @@
#include "ephy-web-view.h"
#ifdef ENABLE_NETWORK_MANAGER
-#include "ephy-net-monitor.h"
+#include <NetworkManager.h>
+#include "ephy-network-manager.h"
#endif
#define EPHY_SHELL_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_SHELL, EphyShellPrivate))
@@ -72,7 +73,7 @@ struct _EphyShellPrivate
EggToolbarsModel *fs_toolbars_model;
EphyExtensionsManager *extensions_manager;
#ifdef ENABLE_NETWORK_MANAGER
- EphyNetMonitor *net_monitor;
+ EphyNetworkManager *nm_proxy;
#endif
GtkWidget *bme;
GtkWidget *history_window;
@@ -151,8 +152,8 @@ ephy_shell_new_window_cb (EphyEmbedSingle *single,
#ifdef ENABLE_NETWORK_MANAGER
static void
-ephy_shell_sync_network_status (EphyNetMonitor *net_monitor,
- GParamSpec *pspec,
+ephy_shell_sync_network_status (EphyNetworkManager *nm_proxy,
+ NMState state,
EphyShell *shell)
{
EphyShellPrivate *priv = shell->priv;
@@ -163,7 +164,7 @@ ephy_shell_sync_network_status (EphyNetMonitor *net_monitor,
single = EPHY_EMBED_SINGLE (ephy_embed_shell_get_embed_single (EPHY_EMBED_SHELL (shell)));
- net_status = ephy_net_monitor_get_net_status (net_monitor);
+ net_status = state == NM_STATE_CONNECTED;
ephy_embed_single_set_network_status (single, net_status);
}
@@ -190,7 +191,9 @@ impl_get_embed_single (EphyEmbedShell *embed_shell)
#ifdef ENABLE_NETWORK_MANAGER
/* Now we need the net monitor */
ephy_shell_get_net_monitor (shell);
- ephy_shell_sync_network_status (priv->net_monitor, NULL, shell);
+ ephy_shell_sync_network_status (priv->nm_proxy,
+ ephy_network_manager_get_state (priv->nm_proxy),
+ shell);
#endif
}
@@ -291,13 +294,13 @@ ephy_shell_dispose (GObject *object)
}
#ifdef ENABLE_NETWORK_MANAGER
- if (priv->net_monitor != NULL)
+ if (priv->nm_proxy != NULL)
{
LOG ("Unref net monitor");
g_signal_handlers_disconnect_by_func
- (priv->net_monitor, G_CALLBACK (ephy_shell_sync_network_status), shell);
- g_object_unref (priv->net_monitor);
- priv->net_monitor = NULL;
+ (priv->nm_proxy, G_CALLBACK (ephy_shell_sync_network_status), shell);
+ g_object_unref (priv->nm_proxy);
+ priv->nm_proxy = NULL;
}
#endif /* ENABLE_NETWORK_MANAGER */
@@ -669,14 +672,19 @@ ephy_shell_get_net_monitor (EphyShell *shell)
#ifdef ENABLE_NETWORK_MANAGER
EphyShellPrivate *priv = shell->priv;
- if (priv->net_monitor == NULL)
+ if (priv->nm_proxy == NULL)
{
- priv->net_monitor = ephy_net_monitor_new ();
- g_signal_connect (priv->net_monitor, "notify::network-status",
+ priv->nm_proxy = ephy_network_manager_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NM_DBUS_SERVICE,
+ NM_DBUS_PATH,
+ NULL,
+ NULL);
+ g_signal_connect (priv->nm_proxy, "state-changed",
G_CALLBACK (ephy_shell_sync_network_status), shell);
}
- return G_OBJECT (priv->net_monitor);
+ return G_OBJECT (priv->nm_proxy);
#else
return NULL;
#endif /* ENABLE_NETWORK_MANAGER */