[gnome-color-manager] Add the initial DBus interface, which doesn't actually do anything just yet



commit 5cfb0f5fc30085e0e4b6d42fb23e5bbb42e9d802
Author: Richard Hughes <richard hughsie com>
Date:   Fri Nov 6 10:41:05 2009 +0000

    Add the initial DBus interface, which doesn't actually do anything just yet

 src/.gitignore    |    1 +
 src/Makefile.am   |   22 +++++++-
 src/gcm-dbus.c    |  142 ++++++++++++++++++++++++++++++++++++++++++++
 src/gcm-dbus.h    |   72 ++++++++++++++++++++++
 src/gcm-session.c |  169 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 405 insertions(+), 1 deletions(-)
---
diff --git a/src/.gitignore b/src/.gitignore
index d33f1a6..ad9c47e 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -5,5 +5,6 @@ gcm-apply
 gcm-import
 gcm-prefs
 gcm-inspect
+gcm-session
 org.gnome.ColorManager.h
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 3e76d17..0657691 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -47,6 +47,7 @@ libgcmshared_a_CFLAGS =					\
 bin_PROGRAMS =						\
 	gcm-apply					\
 	gcm-prefs					\
+	gcm-session					\
 	gcm-import
 
 noinst_PROGRAMS =					\
@@ -119,9 +120,28 @@ gcm_prefs_LDADD =					\
 gcm_prefs_CFLAGS =					\
 	$(WARNINGFLAGS_C)
 
+gcm_session_SOURCES =					\
+	gcm-dbus.c					\
+	gcm-dbus.h					\
+	gcm-session.c
+
+gcm_session_LDADD =					\
+	libgcmshared.a					\
+	$(GLIB_LIBS)					\
+	$(GNOMEDESKTOP_LIBS)				\
+	$(UNIQUE_LIBS)					\
+	$(GCONF_LIBS)					\
+	$(GUDEV_LIBS)					\
+	$(DBUS_GLIB_LIBS)				\
+	$(XORG_LIBS)					\
+	$(GTK_LIBS)
+
+gcm_session_CFLAGS =					\
+	$(WARNINGFLAGS_C)
+
 org.gnome.ColorManager.h: org.gnome.ColorManager.xml
 	$(LIBTOOL) --mode=execute dbus-binding-tool	\
-		--prefix=gpk_dbus			\
+		--prefix=gcm_dbus			\
 		--mode=glib-server			\
 		--output=org.gnome.ColorManager.h	\
 		$(srcdir)/org.gnome.ColorManager.xml
diff --git a/src/gcm-dbus.c b/src/gcm-dbus.c
new file mode 100644
index 0000000..00aab06
--- /dev/null
+++ b/src/gcm-dbus.c
@@ -0,0 +1,142 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008-2009 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 <glib/gi18n.h>
+#include <dbus/dbus-glib.h>
+#include <gconf/gconf-client.h>
+
+#include "egg-debug.h"
+
+#include "gcm-dbus.h"
+#include "gcm-client.h"
+
+static void     gcm_dbus_finalize	(GObject	*object);
+
+#define GCM_DBUS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GCM_TYPE_DBUS, GcmDbusPrivate))
+
+struct GcmDbusPrivate
+{
+	GConfClient		*gconf_client;
+	GcmClient		*client;
+};
+
+G_DEFINE_TYPE (GcmDbus, gcm_dbus, G_TYPE_OBJECT)
+
+/**
+ * gcm_dbus_error_quark:
+ * Return value: Our personal error quark.
+ **/
+GQuark
+gcm_dbus_error_quark (void)
+{
+	static GQuark quark = 0;
+	if (!quark)
+		quark = g_quark_from_static_string ("gcm_dbus_error");
+	return quark;
+}
+
+/**
+ * gcm_dbus_error_get_type:
+ **/
+#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
+GType
+gcm_dbus_error_get_type (void)
+{
+	static GType etype = 0;
+
+	if (etype == 0) {
+		static const GEnumValue values[] =
+		{
+			ENUM_ENTRY (GCM_DBUS_ERROR_FAILED, "Failed"),
+			ENUM_ENTRY (GCM_DBUS_ERROR_INTERNAL_ERROR, "InternalError"),
+			{ 0, NULL, NULL }
+		};
+		etype = g_enum_register_static ("GcmDbusError", values);
+	}
+	return etype;
+}
+
+/**
+ * gcm_dbus_get_profiles_for_device:
+ **/
+void
+gcm_dbus_get_profiles_for_device (GcmDbus *dbus, const gchar *sysfs_path, const gchar *options, DBusGMethodInvocation *context)
+{
+	dbus_g_method_return (context, NULL);
+}
+
+/**
+ * gcm_dbus_class_init:
+ * @klass: The GcmDbusClass
+ **/
+static void
+gcm_dbus_class_init (GcmDbusClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	object_class->finalize = gcm_dbus_finalize;
+	g_type_class_add_private (klass, sizeof (GcmDbusPrivate));
+}
+
+/**
+ * gcm_dbus_init:
+ * @dbus: This class instance
+ **/
+static void
+gcm_dbus_init (GcmDbus *dbus)
+{
+	dbus->priv = GCM_DBUS_GET_PRIVATE (dbus);
+	dbus->priv->gconf_client = gconf_client_get_default ();
+	dbus->priv->client = gcm_client_new ();
+}
+
+/**
+ * gcm_dbus_finalize:
+ * @object: The object to finalize
+ **/
+static void
+gcm_dbus_finalize (GObject *object)
+{
+	GcmDbus *dbus;
+	g_return_if_fail (PK_IS_DBUS (object));
+
+	dbus = GCM_DBUS (object);
+	g_return_if_fail (dbus->priv != NULL);
+	g_object_unref (dbus->priv->client);
+	g_object_unref (dbus->priv->gconf_client);
+
+	G_OBJECT_CLASS (gcm_dbus_parent_class)->finalize (object);
+}
+
+/**
+ * gcm_dbus_new:
+ *
+ * Return value: a new GcmDbus object.
+ **/
+GcmDbus *
+gcm_dbus_new (void)
+{
+	GcmDbus *dbus;
+	dbus = g_object_new (GCM_TYPE_DBUS, NULL);
+	return GCM_DBUS (dbus);
+}
+
diff --git a/src/gcm-dbus.h b/src/gcm-dbus.h
new file mode 100644
index 0000000..4380cbc
--- /dev/null
+++ b/src/gcm-dbus.h
@@ -0,0 +1,72 @@
+/* -*- 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 __GCM_DBUS_H
+#define __GCM_DBUS_H
+
+#include <glib-object.h>
+#include <dbus/dbus-glib.h>
+
+G_BEGIN_DECLS
+
+#define GCM_TYPE_DBUS		(gcm_dbus_get_type ())
+#define GCM_DBUS(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), GCM_TYPE_DBUS, GcmDbus))
+#define GCM_DBUS_CLASS(k)	(G_TYPE_CHECK_CLASS_CAST((k), GCM_TYPE_DBUS, GcmDbusClass))
+#define PK_IS_DBUS(o)	 	(G_TYPE_CHECK_INSTANCE_TYPE ((o), GCM_TYPE_DBUS))
+#define PK_IS_DBUS_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), GCM_TYPE_DBUS))
+#define GCM_DBUS_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), GCM_TYPE_DBUS, GcmDbusClass))
+#define GCM_DBUS_ERROR		(gcm_dbus_error_quark ())
+#define GCM_DBUS_TYPE_ERROR	(gcm_dbus_error_get_type ())
+
+typedef struct GcmDbusPrivate GcmDbusPrivate;
+
+typedef struct
+{
+	 GObject		 parent;
+	 GcmDbusPrivate	*priv;
+} GcmDbus;
+
+typedef struct
+{
+	GObjectClass	parent_class;
+} GcmDbusClass;
+
+typedef enum
+{
+	GCM_DBUS_ERROR_FAILED,
+	GCM_DBUS_ERROR_INTERNAL_ERROR,
+	GCM_DBUS_ERROR_LAST
+} GcmDbusError;
+
+GQuark		 gcm_dbus_error_quark			(void);
+GType		 gcm_dbus_error_get_type		(void);
+GType		 gcm_dbus_get_type			(void);
+GcmDbus		*gcm_dbus_new				(void);
+
+/* org.gnome.ColorManager */
+void		 gcm_dbus_get_profiles_for_device	(GcmDbus	*dbus,
+							 const gchar	*sysfs_path,
+							 const gchar	*options,
+							 DBusGMethodInvocation *context);
+
+G_END_DECLS
+
+#endif /* __GCM_DBUS_H */
diff --git a/src/gcm-session.c b/src/gcm-session.c
new file mode 100644
index 0000000..2d562e3
--- /dev/null
+++ b/src/gcm-session.c
@@ -0,0 +1,169 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007-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 <errno.h>
+//#include <string.h>
+//#include <unistd.h>
+//#include <stdlib.h>
+//#include <glib.h>
+#include <glib/gi18n.h>
+#include <dbus/dbus-glib.h>
+#include <gtk/gtk.h>
+//#include <locale.h>
+//#include <libnotify/notify.h>
+//#include <packagekit-glib/packagekit.h>
+
+#include "egg-debug.h"
+//#include "egg-dbus-monitor.h"
+
+//#include "gcm-check-update.h"
+//#include "gcm-watch.h"
+//#include "gcm-firmware.h"
+//#include "gcm-hardware.h"
+#include "gcm-dbus.h"
+#include "org.gnome.ColorManager.h"
+//#include "gcm-common.h"
+
+#define GCM_DBUS_SERVICE	"org.gnome.ColorManager"
+#define GCM_DBUS_INTERFACE	"org.gnome.ColorManager"
+#define GCM_DBUS_PATH		"/org/gnome/ColorManager"
+
+/**
+ * gcm_session_object_register:
+ * @connection: What we want to register to
+ * @object: The GObject we want to register
+ *
+ * Return value: success
+ **/
+static gboolean
+gcm_session_object_register (DBusGConnection *connection, GObject *object)
+{
+	DBusGProxy *bus_proxy = NULL;
+	GError *error = NULL;
+	guint request_name_result;
+	gboolean ret;
+
+	/* connect to the bus */
+	bus_proxy = dbus_g_proxy_new_for_name (connection, DBUS_SERVICE_DBUS,
+					       DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
+
+	/* get our name */
+	ret = dbus_g_proxy_call (bus_proxy, "RequestName", &error,
+				 G_TYPE_STRING, GCM_DBUS_SERVICE,
+				 G_TYPE_UINT, DBUS_NAME_FLAG_ALLOW_REPLACEMENT |
+					      DBUS_NAME_FLAG_REPLACE_EXISTING |
+					      DBUS_NAME_FLAG_DO_NOT_QUEUE,
+				 G_TYPE_INVALID,
+				 G_TYPE_UINT, &request_name_result,
+				 G_TYPE_INVALID);
+	if (ret == FALSE) {
+		/* abort as the DBUS method failed */
+		egg_warning ("RequestName failed: %s", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+
+	/* free the bus_proxy */
+	g_object_unref (G_OBJECT (bus_proxy));
+
+	/* already running */
+	if (request_name_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
+		return FALSE;
+
+	dbus_g_object_type_install_info (GCM_TYPE_DBUS, &dbus_glib_gcm_dbus_object_info);
+	dbus_g_error_domain_register (GCM_DBUS_ERROR, NULL, GCM_DBUS_TYPE_ERROR);
+	dbus_g_connection_register_g_object (connection, GCM_DBUS_PATH, object);
+
+	return TRUE;
+}
+
+/**
+ * main:
+ **/
+int
+main (int argc, char *argv[])
+{
+	gboolean verbose = FALSE;
+	gboolean timed_exit = FALSE;
+	GcmDbus *dbus = NULL;
+	GOptionContext *context;
+	GError *error = NULL;
+	gboolean ret;
+	guint retval = 0;
+	DBusGConnection *connection;
+
+	const GOptionEntry options[] = {
+		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
+		  _("Show extra debugging information"), NULL },
+		{ "timed-exit", '\0', 0, G_OPTION_ARG_NONE, &timed_exit,
+		  _("Exit after a small delay"), NULL },
+		{ NULL}
+	};
+
+	if (! g_thread_supported ())
+		g_thread_init (NULL);
+	dbus_g_thread_init ();
+	g_type_init ();
+
+	/* TRANSLATORS: program name, a session wide daemon to watch for updates and changing system state */
+	g_set_application_name (_("Color Management"));
+	context = g_option_context_new (NULL);
+	g_option_context_set_summary (context, _("Color Management DBus Service"));
+	g_option_context_add_main_entries (context, options, NULL);
+	g_option_context_parse (context, &argc, &argv, NULL);
+	g_option_context_free (context);
+
+	egg_debug_init (verbose);
+	gtk_init (&argc, &argv);
+
+	/* create new objects */
+	dbus = gcm_dbus_new ();
+
+	/* get the bus */
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+	if (error) {
+		egg_warning ("%s", error->message);
+		g_error_free (error);
+		retval = 1;
+		goto out;
+	}
+
+	/* try to register */
+	ret = gcm_session_object_register (connection, G_OBJECT (dbus));
+	if (!ret) {
+		egg_warning ("failed to replace running instance.");
+		retval = 1;
+		goto out;
+	}
+
+	/* Only timeout if we have specified iton the command line */
+	if (timed_exit)
+		g_timeout_add_seconds (120, (GSourceFunc) gtk_main_quit, NULL);
+
+	/* wait */
+	gtk_main ();
+out:
+	g_object_unref (dbus);
+	return retval;
+}
+



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