gnome-packagekit r80 - in trunk: libgbus libselftest tools



Author: rhughes
Date: Sun Jan 20 22:34:09 2008
New Revision: 80
URL: http://svn.gnome.org/viewvc/gnome-packagekit?rev=80&view=rev

Log:
from git

Added:
   trunk/libgbus/
   trunk/libgbus/.gitignore
   trunk/libgbus/Makefile.am
   trunk/libgbus/libgbus-marshal.list
   trunk/libgbus/libgbus.c
   trunk/libgbus/libgbus.h
   trunk/libselftest/
   trunk/libselftest/.gitignore
   trunk/libselftest/Makefile.am
   trunk/libselftest/libselftest.c
   trunk/libselftest/libselftest.h
   trunk/tools/
   trunk/tools/push-fdo.sh   (contents, props changed)

Added: trunk/libgbus/.gitignore
==============================================================================
--- (empty file)
+++ trunk/libgbus/.gitignore	Sun Jan 20 22:34:09 2008
@@ -0,0 +1,8 @@
+.deps
+.libs
+*.o
+*.la
+*.lo
+*-marshal.c
+*-marshal.h
+

Added: trunk/libgbus/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/libgbus/Makefile.am	Sun Jan 20 22:34:09 2008
@@ -0,0 +1,37 @@
+INCLUDES = \
+	$(GLIB_CFLAGS)						\
+	$(DBUS_CFLAGS)						\
+	-I$(top_srcdir)/libgbus-glib				\
+	-DPACKAGE_DATA_DIR=\""$(datadir)"\"			\
+	-DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\"
+
+noinst_LTLIBRARIES =						\
+	libgbus.la
+
+libgbus_la_SOURCES =						\
+	libgbus-marshal.h					\
+	libgbus-marshal.c					\
+	libgbus.c						\
+	libgbus.h
+libgbus_la_LIBADD = @DBUS_LIBS@ $(INTLLIBS) $(GLIB_LIBS)
+
+EXTRA_DIST =							\
+	libgbus-marshal.list
+
+BUILT_SOURCES = 						\
+	libgbus-marshal.c					\
+	libgbus-marshal.h
+
+libgbus-marshal.c: libgbus-marshal.list
+	echo "#include \"libgbus-marshal.h\"" > $@ && \
+	@GLIB_GENMARSHAL@ $< --prefix=libgbus_marshal --body >> $@
+
+libgbus-marshal.h: libgbus-marshal.list
+	@GLIB_GENMARSHAL@ $< --prefix=libgbus_marshal --header > $@
+
+clean-local:
+	rm -f *~
+	rm -f libgbus-marshal.c libgbus-marshal.h
+
+CLEANFILES = $(BUILT_SOURCES)
+

Added: trunk/libgbus/libgbus-marshal.list
==============================================================================
--- (empty file)
+++ trunk/libgbus/libgbus-marshal.list	Sun Jan 20 22:34:09 2008
@@ -0,0 +1,2 @@
+NONE:STRING,STRING,STRING
+

Added: trunk/libgbus/libgbus.c
==============================================================================
--- (empty file)
+++ trunk/libgbus/libgbus.c	Sun Jan 20 22:34:09 2008
@@ -0,0 +1,240 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2006-2007 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 <glib.h>
+#include <glib/gi18n.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <dbus/dbus.h>
+
+#include <libgbus.h>
+
+static void     libgbus_class_init (LibGBusClass *klass);
+static void     libgbus_init       (LibGBus      *watch);
+static void     libgbus_finalize   (GObject      *object);
+
+#define LIBGBUS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LIBGBUS_TYPE, LibGBusPrivate))
+
+struct LibGBusPrivate
+{
+	LibGBusType		 bus_type;
+	gchar			*service;
+	DBusGProxy		*proxy;
+	DBusGConnection		*connection;
+	gboolean		 connected;
+};
+
+enum {
+	CONNECTION_CHANGED,
+	LAST_SIGNAL
+};
+
+static guint	     signals [LAST_SIGNAL] = { 0, };
+
+G_DEFINE_TYPE (LibGBus, libgbus, G_TYPE_OBJECT)
+
+/**
+ * name_owner_changed_cb:
+ **/
+static void
+name_owner_changed_cb (DBusGProxy     *proxy,
+		       const gchar    *name,
+		       const gchar    *prev,
+		       const gchar    *new,
+		       LibGBus	      *libgbus)
+{
+	g_return_if_fail (IS_LIBGBUS (libgbus));
+	if (libgbus->priv->proxy == NULL) {
+		return;
+	}
+
+	if (strcmp (name, libgbus->priv->service) == 0) {
+		/* ITS4: ignore, not used for allocation */
+		if (strlen (prev) != 0 && strlen (new) == 0 && libgbus->priv->connected == TRUE) {
+			g_signal_emit (libgbus, signals [CONNECTION_CHANGED], 0, FALSE);
+			libgbus->priv->connected = FALSE;
+		}
+		/* ITS4: ignore, not used for allocation */
+		if (strlen (prev) == 0 && strlen (new) != 0 && libgbus->priv->connected == FALSE) {
+			g_signal_emit (libgbus, signals [CONNECTION_CHANGED], 0, TRUE);
+			libgbus->priv->connected = TRUE;
+		}
+	}
+}
+
+/**
+ * libgbus_assign:
+ * @libgbus: This class instance
+ * @bus_type: The bus type, either LIBGBUS_SESSION or LIBGBUS_SYSTEM
+ * @service: The LIBGBUS 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
+libgbus_assign (LibGBus      *libgbus,
+		LibGBusType   bus_type,
+		const gchar  *service)
+{
+	GError *error = NULL;
+
+	g_return_val_if_fail (IS_LIBGBUS (libgbus), FALSE);
+	g_return_val_if_fail (service != NULL, FALSE);
+
+	if (libgbus->priv->proxy != NULL) {
+		g_warning ("already assigned!");
+		return FALSE;
+	}
+
+	libgbus->priv->service = g_strdup (service);
+	libgbus->priv->bus_type = bus_type;
+
+	/* connect to correct bus */
+	if (bus_type == LIBGBUS_SESSION) {
+		libgbus->priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+	} else {
+		libgbus->priv->connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+	}
+	if (error != NULL) {
+		g_warning ("Cannot connect to bus: %s", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	libgbus->priv->proxy = dbus_g_proxy_new_for_name_owner (libgbus->priv->connection,
+								DBUS_SERVICE_DBUS,
+								DBUS_PATH_DBUS,
+						 		DBUS_INTERFACE_DBUS,
+								&error);
+	if (error != NULL) {
+		g_warning ("Cannot connect to DBUS: %s", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	dbus_g_proxy_add_signal (libgbus->priv->proxy, "NameOwnerChanged",
+				 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal (libgbus->priv->proxy, "NameOwnerChanged",
+				     G_CALLBACK (name_owner_changed_cb),
+				     libgbus, NULL);
+
+	/* coldplug */
+	libgbus->priv->connected = libgbus_is_connected (libgbus);
+	if (libgbus->priv->connected == TRUE) {
+		g_signal_emit (libgbus, signals [CONNECTION_CHANGED], 0, TRUE);
+	}
+	return TRUE;
+}
+
+/**
+ * libgbus_is_connected:
+ * @libgbus: This class instance
+ * Return value: if we are connected to a valid watch
+ **/
+gboolean
+libgbus_is_connected (LibGBus *libgbus)
+{
+	DBusError error;
+	DBusConnection *conn;
+	gboolean ret;
+	g_return_val_if_fail (IS_LIBGBUS (libgbus), FALSE);
+
+	/* get raw connection */
+	conn = dbus_g_connection_get_connection (libgbus->priv->connection);
+	dbus_error_init (&error);
+	ret = dbus_bus_name_has_owner (conn, libgbus->priv->service, &error);
+	if (dbus_error_is_set (&error)) {
+		g_debug ("error: %s", error.message);
+		dbus_error_free (&error);
+	}
+
+	return ret;
+}
+
+/**
+ * libgbus_class_init:
+ * @libgbus: This class instance
+ **/
+static void
+libgbus_class_init (LibGBusClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	object_class->finalize = libgbus_finalize;
+	g_type_class_add_private (klass, sizeof (LibGBusPrivate));
+
+	signals [CONNECTION_CHANGED] =
+		g_signal_new ("connection-changed",
+			      G_TYPE_FROM_CLASS (object_class),
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (LibGBusClass, connection_changed),
+			      NULL,
+			      NULL,
+			      g_cclosure_marshal_VOID__BOOLEAN,
+			      G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+}
+
+/**
+ * libgbus_init:
+ * @libgbus: This class instance
+ **/
+static void
+libgbus_init (LibGBus *libgbus)
+{
+	libgbus->priv = LIBGBUS_GET_PRIVATE (libgbus);
+
+	libgbus->priv->service = NULL;
+	libgbus->priv->bus_type = LIBGBUS_SESSION;
+	libgbus->priv->proxy = NULL;
+}
+
+/**
+ * libgbus_finalize:
+ * @object: This class instance
+ **/
+static void
+libgbus_finalize (GObject *object)
+{
+	LibGBus *libgbus;
+	g_return_if_fail (object != NULL);
+	g_return_if_fail (IS_LIBGBUS (object));
+
+	libgbus = LIBGBUS_OBJECT (object);
+	libgbus->priv = LIBGBUS_GET_PRIVATE (libgbus);
+
+	if (libgbus->priv->proxy != NULL) {
+		g_object_unref (libgbus->priv->proxy);
+	}
+}
+
+/**
+ * libgbus_new:
+ * Return value: new class instance.
+ **/
+LibGBus *
+libgbus_new (void)
+{
+	LibGBus *libgbus;
+	libgbus = g_object_new (LIBGBUS_TYPE, NULL);
+	return LIBGBUS_OBJECT (libgbus);
+}
+

Added: trunk/libgbus/libgbus.h
==============================================================================
--- (empty file)
+++ trunk/libgbus/libgbus.h	Sun Jan 20 22:34:09 2008
@@ -0,0 +1,68 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2006-2007 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 __LIBGBUS_H
+#define __LIBGBUS_H
+
+#include <glib-object.h>
+#include <dbus/dbus-glib.h>
+
+G_BEGIN_DECLS
+
+#define LIBGBUS_TYPE		(libgbus_get_type ())
+#define LIBGBUS_OBJECT(o)	(G_TYPE_CHECK_INSTANCE_CAST ((o), LIBGBUS_TYPE, LibGBus))
+#define LIBGBUS_CLASS(k)	(G_TYPE_CHECK_CLASS_CAST((k), LIBGBUS_TYPE, LibGBusClass))
+#define IS_LIBGBUS(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), LIBGBUS_TYPE))
+#define IS_LIBGBUS_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), LIBGBUS_TYPE))
+#define LIBGBUS_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), LIBGBUS_TYPE, LibGBusClass))
+
+typedef struct LibGBusPrivate LibGBusPrivate;
+
+typedef struct
+{
+	GObject		parent;
+	LibGBusPrivate *priv;
+} LibGBus;
+
+typedef struct
+{
+	GObjectClass	parent_class;
+	void		(* connection_changed)	(LibGBus	*watch,
+						 gboolean	 connected);
+} LibGBusClass;
+
+typedef enum {
+        LIBGBUS_SESSION,
+        LIBGBUS_SYSTEM
+} LibGBusType;
+
+GType		 libgbus_get_type		(void);
+LibGBus		*libgbus_new			(void);
+
+gboolean	 libgbus_assign			(LibGBus	*libgbus,
+						 LibGBusType	 bus_type,
+						 const gchar	*service);
+gboolean	 libgbus_is_connected		(LibGBus	*libgbus);
+
+G_END_DECLS
+
+#endif	/* __LIBGBUS_H */
+

Added: trunk/libselftest/.gitignore
==============================================================================
--- (empty file)
+++ trunk/libselftest/.gitignore	Sun Jan 20 22:34:09 2008
@@ -0,0 +1,8 @@
+.deps
+.libs
+*.o
+*.la
+*.lo
+*-marshal.c
+*-marshal.h
+

Added: trunk/libselftest/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/libselftest/Makefile.am	Sun Jan 20 22:34:09 2008
@@ -0,0 +1,20 @@
+INCLUDES = \
+	$(GLIB_CFLAGS)						\
+	$(DBUS_CFLAGS)						\
+	-I$(top_srcdir)/libselftest-glib			\
+	-DPACKAGE_DATA_DIR=\""$(datadir)"\"			\
+	-DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\"
+
+noinst_LTLIBRARIES =						\
+	libselftest.la
+
+libselftest_la_SOURCES =					\
+	libselftest.c						\
+	libselftest.h
+libselftest_la_LIBADD = @DBUS_LIBS@ $(INTLLIBS) $(GLIB_LIBS)
+
+clean-local:
+	rm -f *~
+
+CLEANFILES = $(BUILT_SOURCES)
+

Added: trunk/libselftest/libselftest.c
==============================================================================
--- (empty file)
+++ trunk/libselftest/libselftest.c	Sun Jan 20 22:34:09 2008
@@ -0,0 +1,146 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 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 <stdlib.h>
+#include <glib.h>
+#include <string.h>
+#include <glib/gi18n.h>
+#include <glib-object.h>
+#include <glib/gprintf.h>
+
+#include "libselftest.h"
+
+void
+libst_init (LibSelfTest *test)
+{
+	test->total = 0;
+	test->succeeded = 0;
+	test->type = NULL;
+	test->started = FALSE;
+	test->class = CLASS_AUTO;
+	test->level = LEVEL_ALL;
+}
+
+gint
+libst_finish (LibSelfTest *test)
+{
+	gint retval;
+	g_print ("test passes (%u/%u) : ", test->succeeded, test->total);
+	if (test->succeeded == test->total) {
+		g_print ("ALL OKAY\n");
+		retval = 0;
+	} else {
+		g_print ("%u FAILURE(S)\n", test->total - test->succeeded);
+		retval = 1;
+	}
+	return retval;
+}
+
+gboolean
+libst_start (LibSelfTest *test, const gchar *name, LibSelfTestClass class)
+{
+	if (class == CLASS_AUTO && test->class == CLASS_MANUAL) {
+		return FALSE;
+	}
+	if (class == CLASS_MANUAL && test->class == CLASS_AUTO) {
+		return FALSE;
+	}
+	if (test->started == TRUE) {
+		g_print ("Not ended test! Cannot start!\n");
+		exit (1);
+	}
+	test->type = g_strdup (name);
+	test->started = TRUE;
+	if (test->level == LEVEL_NORMAL) {
+		g_print ("%s...", test->type);
+	}
+	return TRUE;
+}
+
+void
+libst_end (LibSelfTest *test)
+{
+	if (test->started == FALSE) {
+		g_print ("Not started test! Cannot finish!\n");
+		exit (1);
+	}
+	if (test->level == LEVEL_NORMAL) {
+		g_print ("OK\n");
+	}
+	test->started = FALSE;
+	g_free (test->type);
+}
+
+void
+libst_title (LibSelfTest *test, const gchar *format, ...)
+{
+	va_list args;
+	gchar *va_args_buffer = NULL;
+	if (test->level == LEVEL_ALL) {
+		va_start (args, format);
+		g_vasprintf (&va_args_buffer, format, args);
+		va_end (args);
+		g_print ("> check #%u\t%s: \t%s...", test->total+1, test->type, va_args_buffer);
+		g_free(va_args_buffer);
+	}
+	test->total++;
+}
+
+void
+libst_success (LibSelfTest *test, const gchar *format, ...)
+{
+	va_list args;
+	gchar *va_args_buffer = NULL;
+	if (test->level == LEVEL_ALL) {
+		if (format == NULL) {
+			g_print ("...OK\n");
+			goto finish;
+		}
+		va_start (args, format);
+		g_vasprintf (&va_args_buffer, format, args);
+		va_end (args);
+		g_print ("...OK [%s]\n", va_args_buffer);
+		g_free(va_args_buffer);
+	}
+finish:
+	test->succeeded++;
+}
+
+void
+libst_failed (LibSelfTest *test, const gchar *format, ...)
+{
+	va_list args;
+	gchar *va_args_buffer = NULL;
+	if (test->level == LEVEL_ALL || test->level == LEVEL_NORMAL) {
+		if (format == NULL) {
+			g_print ("FAILED\n");
+			goto failed;
+		}
+		va_start (args, format);
+		g_vasprintf (&va_args_buffer, format, args);
+		va_end (args);
+		g_print ("FAILED [%s]\n", va_args_buffer);
+		g_free(va_args_buffer);
+	}
+failed:
+	exit (1);
+}
+

Added: trunk/libselftest/libselftest.h
==============================================================================
--- (empty file)
+++ trunk/libselftest/libselftest.h	Sun Jan 20 22:34:09 2008
@@ -0,0 +1,63 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 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 __LIBSELFTEST_H
+#define __LIBSELFTEST_H
+
+#include <glib.h>
+#include <string.h>
+
+typedef enum
+{
+	CLASS_ALL,
+	CLASS_AUTO,
+	CLASS_MANUAL,
+	CLASS_LAST
+} LibSelfTestClass;
+
+typedef enum
+{
+	LEVEL_QUIET,
+	LEVEL_NORMAL,
+	LEVEL_ALL,
+	LEVEL_LAST
+} LibSelfTestLevel;
+
+typedef struct
+{
+	guint		 total;
+	guint		 succeeded;
+	gboolean	 started;
+	LibSelfTestClass class;
+	LibSelfTestLevel level;
+	gchar		*type;
+} LibSelfTest;
+
+gboolean	libst_start	(LibSelfTest *test, const gchar *name, LibSelfTestClass class);
+void		libst_end	(LibSelfTest *test);
+void		libst_title	(LibSelfTest *test, const gchar *format, ...);
+void		libst_success	(LibSelfTest *test, const gchar *format, ...);
+void		libst_failed	(LibSelfTest *test, const gchar *format, ...);
+void		libst_init	(LibSelfTest *test);
+gint		libst_finish	(LibSelfTest *test);
+
+#endif	/* __LIBSELFTEST_H */
+

Added: trunk/tools/push-fdo.sh
==============================================================================
--- (empty file)
+++ trunk/tools/push-fdo.sh	Sun Jan 20 22:34:09 2008
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+git push ssh://hughsient people freedesktop org/~hughsient/gnome-packagekit
+



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