gnome-power-manager r2919 - in trunk: . applets/brightness applets/inhibit libdbus-glib src
- From: rhughes svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-power-manager r2919 - in trunk: . applets/brightness applets/inhibit libdbus-glib src
- Date: Thu, 4 Sep 2008 11:27:02 +0000 (UTC)
Author: rhughes
Date: Thu Sep 4 11:27:01 2008
New Revision: 2919
URL: http://svn.gnome.org/viewvc/gnome-power-manager?rev=2919&view=rev
Log:
2008-09-04 Richard Hughes <richard hughsie com>
* applets/brightness/Makefile.am:
* applets/brightness/brightness-applet.c: (gpm_applet_destroy_cb),
(monitor_connection_cb), (gpm_brightness_applet_init):
* applets/inhibit/Makefile.am:
* applets/inhibit/inhibit-applet.c: (gpm_applet_destroy_cb),
(monitor_connection_cb), (gpm_inhibit_applet_init):
* libdbus-glib/Makefile.am:
* libdbus-glib/libdbus-proxy.c: (dbus_proxy_assign),
(dbus_proxy_get_proxy), (dbus_proxy_is_connected),
(dbus_proxy_finalize):
* libdbus-glib/libdbus-watch.c:
* libdbus-glib/libdbus-watch.h:
* src/Makefile.am:
* src/egg-dbus-monitor.c: (egg_dbus_monitor_name_owner_changed_cb),
(egg_dbus_monitor_assign), (egg_dbus_monitor_is_connected),
(egg_dbus_monitor_class_init), (egg_dbus_monitor_init),
(egg_dbus_monitor_finalize), (egg_dbus_monitor_new):
* src/egg-dbus-monitor.h:
* src/gpm-phone.c: (monitor_connection_cb), (gpm_phone_init),
(gpm_phone_finalize):
Remove use of DbusWatch and use the standard EggDbusMonitor instead.
Added:
trunk/src/egg-dbus-monitor.c
trunk/src/egg-dbus-monitor.h
Removed:
trunk/libdbus-glib/libdbus-watch.c
trunk/libdbus-glib/libdbus-watch.h
Modified:
trunk/ChangeLog
trunk/applets/brightness/Makefile.am
trunk/applets/brightness/brightness-applet.c
trunk/applets/inhibit/Makefile.am
trunk/applets/inhibit/inhibit-applet.c
trunk/libdbus-glib/Makefile.am
trunk/libdbus-glib/libdbus-proxy.c
trunk/src/Makefile.am
trunk/src/gpm-phone.c
Modified: trunk/applets/brightness/Makefile.am
==============================================================================
--- trunk/applets/brightness/Makefile.am (original)
+++ trunk/applets/brightness/Makefile.am Thu Sep 4 11:27:01 2008
@@ -14,6 +14,7 @@
-DLIBDIR=\""$(libdir)"\" \
-DVERSION="\"$(VERSION)\"" \
-DGPM_DATA=\"$(pkgdatadir)\" \
+ -DEGG_LOG_FILE=\""$(PK_LOG_DIR)/gnome-power-manager"\" \
-I$(top_srcdir)/libdbus-glib \
$(NULL)
@@ -24,7 +25,7 @@
libexec_PROGRAMS=gnome-brightness-applet
-gnome_brightness_applet_SOURCES = brightness-applet.c
+gnome_brightness_applet_SOURCES = brightness-applet.c ../../src/egg-dbus-monitor.c ../../src/egg-debug.c
gnome_brightness_applet_LDADD = \
$(LOCAL_LIBDBUS_LIBS) \
$(DBUS_LIBS) \
Modified: trunk/applets/brightness/brightness-applet.c
==============================================================================
--- trunk/applets/brightness/brightness-applet.c (original)
+++ trunk/applets/brightness/brightness-applet.c Thu Sep 4 11:27:01 2008
@@ -32,10 +32,10 @@
#include <gtk/gtkbox.h>
#include <libgnomeui/gnome-help.h>
#include <gdk/gdkkeysyms.h>
-#include <libdbus-watch.h>
#include <glib-object.h>
#include <dbus/dbus-glib.h>
+#include "../src/egg-dbus-monitor.h"
#include "../src/gpm-common.h"
#define GPM_TYPE_BRIGHTNESS_APPLET (gpm_brightness_applet_get_type ())
@@ -58,7 +58,7 @@
/* connection to g-p-m */
DBusGProxy *proxy;
DBusGConnection *connection;
- DbusWatch *watch;
+ EggDbusMonitor *monitor;
guint level;
/* a cache for panel size */
gint size;
@@ -823,8 +823,8 @@
{
GpmBrightnessApplet *applet = GPM_BRIGHTNESS_APPLET(object);
- if (applet->watch != NULL) {
- g_object_unref (applet->watch);
+ if (applet->monitor != NULL) {
+ g_object_unref (applet->monitor);
}
if (applet->icon != NULL) {
gdk_pixbuf_unref (applet->icon);
@@ -909,13 +909,13 @@
}
/**
- * watch_connection_cb:
+ * monitor_connection_cb:
* @proxy: The dbus raw proxy
* @status: The status of the service, where TRUE is connected
* @screensaver: This class instance
**/
static void
-watch_connection_cb (DbusWatch *watch,
+monitor_connection_cb (EggDbusMonitor *monitor,
gboolean status,
GpmBrightnessApplet *applet)
{
@@ -951,10 +951,10 @@
GPM_DATA G_DIR_SEPARATOR_S "icons");
- applet->watch = dbus_watch_new ();
- g_signal_connect (applet->watch, "connection-changed",
- G_CALLBACK (watch_connection_cb), applet);
- dbus_watch_assign (applet->watch, DBUS_WATCH_SESSION, GPM_DBUS_SERVICE);
+ applet->monitor = egg_dbus_monitor_new ();
+ g_signal_connect (applet->monitor, "connection-changed",
+ G_CALLBACK (monitor_connection_cb), applet);
+ egg_dbus_monitor_assign (applet->monitor, EGG_DBUS_MONITOR_SESSION, GPM_DBUS_SERVICE);
gpm_brightness_applet_dbus_connect (applet);
/* coldplug */
Modified: trunk/applets/inhibit/Makefile.am
==============================================================================
--- trunk/applets/inhibit/Makefile.am (original)
+++ trunk/applets/inhibit/Makefile.am Thu Sep 4 11:27:01 2008
@@ -14,6 +14,7 @@
-DLIBDIR=\""$(libdir)"\" \
-DVERSION="\"$(VERSION)\"" \
-DGPM_DATA=\"$(pkgdatadir)\" \
+ -DEGG_LOG_FILE=\""$(PK_LOG_DIR)/gnome-power-manager"\" \
-I$(top_srcdir)/libdbus-glib \
$(NULL)
@@ -24,7 +25,7 @@
libexec_PROGRAMS=gnome-inhibit-applet
-gnome_inhibit_applet_SOURCES = inhibit-applet.c
+gnome_inhibit_applet_SOURCES = inhibit-applet.c ../../src/egg-dbus-monitor.c ../../src/egg-debug.c
gnome_inhibit_applet_LDADD = \
$(LOCAL_LIBDBUS_LIBS) \
$(DBUS_LIBS) \
Modified: trunk/applets/inhibit/inhibit-applet.c
==============================================================================
--- trunk/applets/inhibit/inhibit-applet.c (original)
+++ trunk/applets/inhibit/inhibit-applet.c Thu Sep 4 11:27:01 2008
@@ -31,10 +31,10 @@
#include <gtk/gtk.h>
#include <gtk/gtkbox.h>
#include <libgnomeui/gnome-help.h>
-#include <libdbus-watch.h>
#include <glib-object.h>
#include <dbus/dbus-glib.h>
+#include "../src/egg-dbus-monitor.h"
#include "../src/gpm-common.h"
#define GPM_TYPE_INHIBIT_APPLET (gpm_inhibit_applet_get_type ())
@@ -54,7 +54,7 @@
/* connection to g-p-m */
DBusGProxy *proxy;
DBusGConnection *connection;
- DbusWatch *watch;
+ EggDbusMonitor *monitor;
guint level;
/* a cache for panel size */
gint size;
@@ -493,8 +493,8 @@
{
GpmInhibitApplet *applet = GPM_INHIBIT_APPLET(object);
- if (applet->watch != NULL) {
- g_object_unref (applet->watch);
+ if (applet->monitor != NULL) {
+ g_object_unref (applet->monitor);
}
if (applet->icon != NULL) {
gdk_pixbuf_unref (applet->icon);
@@ -566,13 +566,13 @@
}
/**
- * watch_connection_cb:
+ * monitor_connection_cb:
* @proxy: The dbus raw proxy
* @status: The status of the service, where TRUE is connected
* @screensaver: This class instance
**/
static void
-watch_connection_cb (DbusWatch *watch,
+monitor_connection_cb (EggDbusMonitor *monitor,
gboolean status,
GpmInhibitApplet *applet)
{
@@ -607,10 +607,10 @@
gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
GPM_DATA G_DIR_SEPARATOR_S "icons");
- applet->watch = dbus_watch_new ();
- g_signal_connect (applet->watch, "connection-changed",
- G_CALLBACK (watch_connection_cb), applet);
- dbus_watch_assign (applet->watch, DBUS_WATCH_SESSION, GPM_DBUS_SERVICE);
+ applet->monitor = egg_dbus_monitor_new ();
+ g_signal_connect (applet->monitor, "connection-changed",
+ G_CALLBACK (monitor_connection_cb), applet);
+ egg_dbus_monitor_assign (applet->monitor, EGG_DBUS_MONITOR_SESSION, GPM_DBUS_SERVICE);
gpm_inhibit_applet_dbus_connect (applet);
/* prepare */
Modified: trunk/libdbus-glib/Makefile.am
==============================================================================
--- trunk/libdbus-glib/Makefile.am (original)
+++ trunk/libdbus-glib/Makefile.am Thu Sep 4 11:27:01 2008
@@ -7,20 +7,17 @@
noinst_LTLIBRARIES = \
libdbus-proxy.la \
- libdbus-watch.la \
libdbus-monitor-session.la \
libdbus-monitor-system.la
-libdbus_watch_la_SOURCES = \
+libegg_dbus_monitor_la_SOURCES = \
libdbus-marshal.h \
libdbus-marshal.c \
libdbus-monitor-session.c \
libdbus-monitor-session.h \
libdbus-monitor-system.c \
libdbus-monitor-system.h \
- libdbus-watch.c \
- libdbus-watch.h
-libdbus_watch_la_LIBADD = @DBUS_LIBS@ $(INTLLIBS) $(GLIB_LIBS)
+libegg_dbus_monitor_la_LIBADD = @DBUS_LIBS@ $(INTLLIBS) $(GLIB_LIBS)
libdbus_proxy_la_SOURCES = \
libdbus-marshal.h \
Modified: trunk/libdbus-glib/libdbus-proxy.c
==============================================================================
--- trunk/libdbus-glib/libdbus-proxy.c (original)
+++ trunk/libdbus-glib/libdbus-proxy.c Thu Sep 4 11:27:01 2008
@@ -230,11 +230,10 @@
}
/* get the DBUS connection */
- if (bus_type == DBUS_PROXY_SESSION) {
+ if (bus_type == DBUS_PROXY_SESSION)
dbus_proxy->priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
- } else {
+ else
dbus_proxy->priv->connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- }
if (error) {
g_warning ("Could not connect to DBUS daemon: %s", error->message);
@@ -285,9 +284,8 @@
dbus_proxy_get_proxy (DbusProxy *dbus_proxy)
{
g_return_val_if_fail (DBUS_IS_PROXY (dbus_proxy), NULL);
- if (dbus_proxy->priv->assigned == FALSE) {
+ if (dbus_proxy->priv->assigned == FALSE)
return NULL;
- }
return dbus_proxy->priv->proxy;
}
@@ -364,12 +362,10 @@
dbus_proxy_is_connected (DbusProxy *dbus_proxy)
{
g_return_val_if_fail (DBUS_IS_PROXY (dbus_proxy), FALSE);
- if (dbus_proxy->priv->assigned == FALSE) {
+ if (dbus_proxy->priv->assigned == FALSE)
return FALSE;
- }
- if (dbus_proxy->priv->proxy == NULL) {
+ if (dbus_proxy->priv->proxy == NULL)
return FALSE;
- }
return TRUE;
}
@@ -431,12 +427,10 @@
dbus_proxy = DBUS_PROXY (object);
dbus_proxy->priv = DBUS_PROXY_GET_PRIVATE (dbus_proxy);
- if (dbus_proxy->priv->ses_sig_id != 0) {
+ if (dbus_proxy->priv->ses_sig_id != 0)
g_signal_handler_disconnect (dbus_proxy->priv->monitor_session, dbus_proxy->priv->ses_sig_id);
- }
- if (dbus_proxy->priv->sys_sig_id != 0) {
+ if (dbus_proxy->priv->sys_sig_id != 0)
g_signal_handler_disconnect (dbus_proxy->priv->monitor_system, dbus_proxy->priv->sys_sig_id);
- }
dbus_proxy_disconnect (dbus_proxy);
@@ -449,15 +443,9 @@
if (dbus_proxy->priv->monitor_system != NULL) {
g_object_unref (dbus_proxy->priv->monitor_system);
}
- if (dbus_proxy->priv->service != NULL) {
- g_free (dbus_proxy->priv->service);
- }
- if (dbus_proxy->priv->interface != NULL) {
- g_free (dbus_proxy->priv->interface);
- }
- if (dbus_proxy->priv->path != NULL) {
- g_free (dbus_proxy->priv->path);
- }
+ g_free (dbus_proxy->priv->service);
+ g_free (dbus_proxy->priv->interface);
+ g_free (dbus_proxy->priv->path);
G_OBJECT_CLASS (dbus_proxy_parent_class)->finalize (object);
}
Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Thu Sep 4 11:27:01 2008
@@ -44,7 +44,6 @@
LOCAL_LIBDBUS_LIBS = \
$(top_builddir)/libdbus-glib/libdbus-monitor-session.la \
$(top_builddir)/libdbus-glib/libdbus-monitor-system.la \
- $(top_builddir)/libdbus-glib/libdbus-watch.la \
$(top_builddir)/libdbus-glib/libdbus-proxy.la
bin_PROGRAMS = \
@@ -138,6 +137,8 @@
egg-color.h \
egg-debug.h \
egg-debug.c \
+ egg-dbus-monitor.h \
+ egg-dbus-monitor.c \
gpm-dpms.h \
gpm-dpms.c \
gpm-notify.h \
@@ -244,6 +245,8 @@
egg-test.c \
egg-debug.h \
egg-debug.c \
+ egg-dbus-monitor.h \
+ egg-dbus-monitor.c \
gpm-ac-adapter.h \
gpm-ac-adapter.c \
gpm-prefs-server.h \
Added: trunk/src/egg-dbus-monitor.c
==============================================================================
--- (empty file)
+++ trunk/src/egg-dbus-monitor.c Thu Sep 4 11:27:01 2008
@@ -0,0 +1,264 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2006-2008 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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 of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <glib.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <dbus/dbus.h>
+
+#include "egg-debug.h"
+#include "egg-dbus-monitor.h"
+
+static void egg_dbus_monitor_class_init (EggDbusMonitorClass *klass);
+static void egg_dbus_monitor_init (EggDbusMonitor *dbus_monitor);
+static void egg_dbus_monitor_finalize (GObject *object);
+
+#define EGG_DBUS_MONITOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), EGG_TYPE_DBUS_MONITOR, EggDbusMonitorPrivate))
+
+struct EggDbusMonitorPrivate
+{
+ EggDbusMonitorType bus_type;
+ gchar *service;
+ DBusGProxy *proxy;
+ DBusGConnection *connection;
+ const gchar *unique_name;
+};
+
+enum {
+ EGG_DBUS_MONITOR_CONNECTION_CHANGED,
+ EGG_DBUS_MONITOR_CONNECTION_REPLACED,
+ EGG_DBUS_MONITOR_LAST_SIGNAL
+};
+
+static guint signals [EGG_DBUS_MONITOR_LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE (EggDbusMonitor, egg_dbus_monitor, G_TYPE_OBJECT)
+
+/**
+ * egg_dbus_monitor_name_owner_changed_cb:
+ **/
+static void
+egg_dbus_monitor_name_owner_changed_cb (DBusGProxy *proxy, const gchar *name,
+ const gchar *prev, const gchar *new,
+ EggDbusMonitor *monitor)
+{
+ guint new_len;
+ guint prev_len;
+
+ g_return_if_fail (EGG_IS_DBUS_MONITOR (monitor));
+ if (monitor->priv->proxy == NULL)
+ return;
+
+ /* not us */
+ if (strcmp (name, monitor->priv->service) != 0)
+ return;
+
+ /* ITS4: ignore, not used for allocation */
+ new_len = strlen (new);
+ /* ITS4: ignore, not used for allocation */
+ prev_len = strlen (prev);
+
+ /* something --> nothing */
+ if (prev_len != 0 && new_len == 0) {
+ g_signal_emit (monitor, signals [EGG_DBUS_MONITOR_CONNECTION_CHANGED], 0, FALSE);
+ return;
+ }
+
+ /* nothing --> something */
+ if (prev_len == 0 && new_len != 0) {
+ g_signal_emit (monitor, signals [EGG_DBUS_MONITOR_CONNECTION_CHANGED], 0, TRUE);
+ return;
+ }
+
+ /* something --> something (we've replaced the old process) */
+ if (prev_len != 0 && new_len != 0) {
+ /* only send this to the prev client */
+ if (strcmp (monitor->priv->unique_name, prev) == 0)
+ g_signal_emit (monitor, signals [EGG_DBUS_MONITOR_CONNECTION_REPLACED], 0);
+ return;
+ }
+}
+
+/**
+ * egg_dbus_monitor_assign:
+ * @monitor: This class instance
+ * @bus_type: The bus type, either EGG_DBUS_MONITOR_SESSION or EGG_DBUS_MONITOR_SYSTEM
+ * @service: The EGG_DBUS_MONITOR service name
+ * Return value: success
+ *
+ * Emits connection-changed(TRUE) if connection is alive - this means you
+ * have to connect up the callback before this function is called.
+ **/
+gboolean
+egg_dbus_monitor_assign (EggDbusMonitor *monitor, EggDbusMonitorType bus_type, const gchar *service)
+{
+ GError *error = NULL;
+ gboolean connected;
+ DBusConnection *conn;
+
+ g_return_val_if_fail (EGG_IS_DBUS_MONITOR (monitor), FALSE);
+ g_return_val_if_fail (service != NULL, FALSE);
+
+ if (monitor->priv->proxy != NULL) {
+ egg_warning ("already assigned!");
+ return FALSE;
+ }
+
+ monitor->priv->service = g_strdup (service);
+ monitor->priv->bus_type = bus_type;
+
+ /* connect to correct bus */
+ if (bus_type == EGG_DBUS_MONITOR_SESSION)
+ monitor->priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+ else
+ monitor->priv->connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ if (error != NULL) {
+ egg_warning ("Cannot connect to bus: %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+ monitor->priv->proxy = dbus_g_proxy_new_for_name_owner (monitor->priv->connection,
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS,
+ &error);
+ if (error != NULL) {
+ egg_warning ("Cannot connect to DBUS: %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+ dbus_g_proxy_add_signal (monitor->priv->proxy, "NameOwnerChanged",
+ G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+ dbus_g_proxy_connect_signal (monitor->priv->proxy, "NameOwnerChanged",
+ G_CALLBACK (egg_dbus_monitor_name_owner_changed_cb),
+ monitor, NULL);
+
+ /* coldplug */
+ connected = egg_dbus_monitor_is_connected (monitor);
+ if (connected)
+ g_signal_emit (monitor, signals [EGG_DBUS_MONITOR_CONNECTION_CHANGED], 0, TRUE);
+
+ /* save this for the replaced check */
+ conn = dbus_g_connection_get_connection (monitor->priv->connection);
+ monitor->priv->unique_name = dbus_bus_get_unique_name (conn);
+ return TRUE;
+}
+
+/**
+ * egg_dbus_monitor_is_connected:
+ * @monitor: This class instance
+ * Return value: if we are connected to a valid watch
+ **/
+gboolean
+egg_dbus_monitor_is_connected (EggDbusMonitor *monitor)
+{
+ DBusError error;
+ DBusConnection *conn;
+ gboolean ret;
+ g_return_val_if_fail (EGG_IS_DBUS_MONITOR (monitor), FALSE);
+
+ /* get raw connection */
+ conn = dbus_g_connection_get_connection (monitor->priv->connection);
+ dbus_error_init (&error);
+ ret = dbus_bus_name_has_owner (conn, monitor->priv->service, &error);
+ if (dbus_error_is_set (&error)) {
+ egg_debug ("error: %s", error.message);
+ dbus_error_free (&error);
+ }
+
+ return ret;
+}
+
+/**
+ * egg_dbus_monitor_class_init:
+ * @klass: The EggDbusMonitorClass
+ **/
+static void
+egg_dbus_monitor_class_init (EggDbusMonitorClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = egg_dbus_monitor_finalize;
+ g_type_class_add_private (klass, sizeof (EggDbusMonitorPrivate));
+ signals [EGG_DBUS_MONITOR_CONNECTION_CHANGED] =
+ g_signal_new ("connection-changed",
+ G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EggDbusMonitorClass, connection_changed),
+ NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+ signals [EGG_DBUS_MONITOR_CONNECTION_REPLACED] =
+ g_signal_new ("connection-replaced",
+ G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EggDbusMonitorClass, connection_replaced),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+}
+
+/**
+ * egg_dbus_monitor_init:
+ * @monitor: This class instance
+ **/
+static void
+egg_dbus_monitor_init (EggDbusMonitor *monitor)
+{
+ monitor->priv = EGG_DBUS_MONITOR_GET_PRIVATE (monitor);
+ monitor->priv->service = NULL;
+ monitor->priv->bus_type = EGG_DBUS_MONITOR_SESSION;
+ monitor->priv->proxy = NULL;
+}
+
+/**
+ * egg_dbus_monitor_finalize:
+ * @object: The object to finalize
+ **/
+static void
+egg_dbus_monitor_finalize (GObject *object)
+{
+ EggDbusMonitor *monitor;
+
+ g_return_if_fail (EGG_IS_DBUS_MONITOR (object));
+
+ monitor = EGG_DBUS_MONITOR (object);
+
+ g_return_if_fail (monitor->priv != NULL);
+ if (monitor->priv->proxy != NULL)
+ g_object_unref (monitor->priv->proxy);
+
+ G_OBJECT_CLASS (egg_dbus_monitor_parent_class)->finalize (object);
+}
+
+/**
+ * egg_dbus_monitor_new:
+ *
+ * Return value: a new EggDbusMonitor object.
+ **/
+EggDbusMonitor *
+egg_dbus_monitor_new (void)
+{
+ EggDbusMonitor *monitor;
+ monitor = g_object_new (EGG_TYPE_DBUS_MONITOR, NULL);
+ return EGG_DBUS_MONITOR (monitor);
+}
+
Added: trunk/src/egg-dbus-monitor.h
==============================================================================
--- (empty file)
+++ trunk/src/egg-dbus-monitor.h Thu Sep 4 11:27:01 2008
@@ -0,0 +1,69 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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 of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __EGG_DBUS_MONITOR_H
+#define __EGG_DBUS_MONITOR_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define EGG_TYPE_DBUS_MONITOR (egg_dbus_monitor_get_type ())
+#define EGG_DBUS_MONITOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EGG_TYPE_DBUS_MONITOR, EggDbusMonitor))
+#define EGG_DBUS_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EGG_TYPE_DBUS_MONITOR, EggDbusMonitorClass))
+#define EGG_IS_DBUS_MONITOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EGG_TYPE_DBUS_MONITOR))
+#define EGG_IS_DBUS_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EGG_TYPE_DBUS_MONITOR))
+#define EGG_DBUS_MONITOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EGG_TYPE_DBUS_MONITOR, EggDbusMonitorClass))
+#define EGG_DBUS_MONITOR_ERROR (egg_dbus_monitor_error_quark ())
+#define EGG_DBUS_MONITOR_TYPE_ERROR (egg_dbus_monitor_error_get_type ())
+
+typedef struct EggDbusMonitorPrivate EggDbusMonitorPrivate;
+
+typedef struct
+{
+ GObject parent;
+ EggDbusMonitorPrivate *priv;
+} EggDbusMonitor;
+
+typedef struct
+{
+ GObjectClass parent_class;
+ void (* connection_changed) (EggDbusMonitor *watch,
+ gboolean connected);
+ void (* connection_replaced) (EggDbusMonitor *watch);
+} EggDbusMonitorClass;
+
+typedef enum {
+ EGG_DBUS_MONITOR_SESSION,
+ EGG_DBUS_MONITOR_SYSTEM
+} EggDbusMonitorType;
+
+GType egg_dbus_monitor_get_type (void) G_GNUC_CONST;
+EggDbusMonitor *egg_dbus_monitor_new (void);
+gboolean egg_dbus_monitor_assign (EggDbusMonitor *monitor,
+ EggDbusMonitorType bus_type,
+ const gchar *service);
+gboolean egg_dbus_monitor_is_connected (EggDbusMonitor *monitor);
+
+G_END_DECLS
+
+#endif /* __EGG_DBUS_MONITOR_H */
+
Modified: trunk/src/gpm-phone.c
==============================================================================
--- trunk/src/gpm-phone.c (original)
+++ trunk/src/gpm-phone.c Thu Sep 4 11:27:01 2008
@@ -31,7 +31,7 @@
#include "egg-debug.h"
#include "gpm-marshal.h"
-#include <libdbus-watch.h>
+#include "egg-dbus-monitor.h"
static void gpm_phone_class_init (GpmPhoneClass *klass);
static void gpm_phone_init (GpmPhone *phone);
@@ -43,7 +43,7 @@
{
DBusGProxy *proxy;
DBusGConnection *connection;
- DbusWatch *watch;
+ EggDbusMonitor *monitor;
gboolean present;
guint percentage;
gboolean onac;
@@ -336,13 +336,13 @@
}
/**
- * watch_connection_cb:
+ * monitor_connection_cb:
* @proxy: The dbus raw proxy
* @status: The status of the service, where TRUE is connected
* @screensaver: This class instance
**/
static void
-watch_connection_cb (DbusWatch *watch,
+monitor_connection_cb (EggDbusMonitor *monitor,
gboolean status,
GpmPhone *phone)
{
@@ -368,10 +368,10 @@
phone->priv->percentage = 0;
phone->priv->onac = FALSE;
- phone->priv->watch = dbus_watch_new ();
- g_signal_connect (phone->priv->watch, "connection-changed",
- G_CALLBACK (watch_connection_cb), phone);
- dbus_watch_assign (phone->priv->watch, DBUS_WATCH_SESSION, GNOME_PHONE_MANAGER_DBUS_SERVICE);
+ phone->priv->monitor = egg_dbus_monitor_new ();
+ g_signal_connect (phone->priv->monitor, "connection-changed",
+ G_CALLBACK (monitor_connection_cb), phone);
+ egg_dbus_monitor_assign (phone->priv->monitor, EGG_DBUS_MONITOR_SESSION, GNOME_PHONE_MANAGER_DBUS_SERVICE);
gpm_phone_dbus_connect (phone);
}
@@ -390,9 +390,8 @@
phone->priv = GPM_PHONE_GET_PRIVATE (phone);
gpm_phone_dbus_disconnect (phone);
- if (phone->priv->watch != NULL) {
- g_object_unref (phone->priv->watch);
- }
+ if (phone->priv->monitor != NULL)
+ g_object_unref (phone->priv->monitor);
G_OBJECT_CLASS (gpm_phone_parent_class)->finalize (object);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]