[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
gEDA-dev: Simple DBUS binding to PCB actions
Hi,
The attached patch is something that I've been cooking for a few days
now. It implements a simple DBUS interface which Peter Brett designed
for calling PCB actions from another program.
Due to the need for a g_mainloop, this is implemented in the GTK+ HID.
After applying the patch, you need to run ./autogen.sh in the source
directory, as configure.ac and Makefile.am are changed.
A new option: ./configure --with-dbus is added, which works with the GTK
HID. For now, it is disabled per default, although in the future, I
would like to see it on by default if the GTK HID is selected.
Comments on my autoconf / automake bits are appreciated, as I'm not
super familiar with either. Also, it would be nice if someone WITHOUT
dbus installed could try and ensure that things work as expected when
configuring and building.
Can this go into CVS PCB for at some point? The changes made are very
local, so ought not to produce a big problem should they need to be
backed out.
It is quite simple really..
configure.ac | 32 ++++++++
src/hid/gtk/dbus.c | 158
+++++++++++++++++++++++++++++++++++++++++++
src/hid/gtk/dbus.h | 27 +++++++
src/hid/gtk/dbus.xml | 17 ++++
src/hid/gtk/gui-top-window.c | 8 ++
5 files changed, 240 insertions(+), 2 deletions(-)
It doesn't add return codes to any of the actions, and other than file
access error handling (which needs a return code mechanism), does all we
need for our project manager.
I tested that it works with and without dbus support (GTK hid), and
lesstif still compiles and runs fine. I haven't tried compiling either
on a computer without dbus.
Regards
Peter Clifton
Index: configure.ac
===================================================================
RCS file: /cvsroot/pcb/pcb/configure.ac,v
retrieving revision 1.62
diff -U3 -p -r1.62 configure.ac
--- configure.ac 2 Oct 2006 02:06:31 -0000 1.62
+++ configure.ac 4 Oct 2006 22:41:30 -0000
@@ -177,6 +177,17 @@ then
HIDLIST=
fi
+AC_MSG_CHECKING([for GLIB_DBUS])
+AC_ARG_WITH([dbus],
+[ --with-dbus Specify if DBUS IPC is to be included (only works with gtk GUI)],
+[],[])
+AC_MSG_RESULT([$with_dbus])
+AM_CONDITIONAL(WITH_DBUS, test x$with_dbus = xyes)
+
+if test "x$with_dbus" = "xyes" -a x"$with_gui" != x"gtk"; then
+ AC_MSG_ERROR([DBUS selected, but only works with the GTK gui])
+fi
+
AC_MSG_CHECKING([for which printer to use])
AC_ARG_WITH([printer],
[ --with-printer= Specify the printer: lpr [[default=lpr]]],
@@ -322,6 +333,23 @@ Please review the following errors:
$GLIB_PKG_ERRORS])]
)
GLIB_VERSION=`$PKG_CONFIG glib-2.0 --modversion`
+
+ if test "X$with_dbus" = "Xyes"; then
+ PKG_CHECK_MODULES(DBUS, dbus-1 >= 0.61, ,
+ [AC_MSG_ERROR([Cannot find dbus-1 >= 0.61, install it and rerun ./configure
+ Please review the following errors:
+ $DBUS_PKG_ERRORS])]
+ )
+ DBUS_GLIB_VERSION=`$PKG_CONFIG dbus-glib-1 --modversion`
+ PKG_CHECK_MODULES(DBUS_GLIB, dbus-glib-1 >= 0.20, ,
+ [AC_MSG_ERROR([Cannot find dbus-glib-1 >= 0.20, install it and rerun ./configure
+ Please review the following errors:
+ $DBUS_GLIB_PKG_ERRORS])]
+ )
+ DBUS_GLIB_VERSION=`$PKG_CONFIG dbus-glib-1 --modversion`
+ AC_DEFINE([HAVE_DBUS], 1,
+ [Define to 1 if DBUS IPC is to be compiled in])
+ fi
;;
png )
@@ -494,8 +522,8 @@ fi
AC_MSG_RESULT([no])
])
-CFLAGS="$CFLAGS $X_CFLAGS $GTK_CFLAGS"
-LIBS="$LIBS $XM_LIBS $X_LIBS $GTK_LIBS $DMALLOC_LIBS $GD_LIBS"
+CFLAGS="$CFLAGS $X_CFLAGS $DBUS_GLIB_CFLAGS $GTK_CFLAGS"
+LIBS="$LIBS $XM_LIBS $DBUS_GLIB_LIBS $X_LIBS $GTK_LIBS $DMALLOC_LIBS $GD_LIBS"
# if we have gcc then add -Wall
Index: src/hid/gtk/gui-top-window.c
===================================================================
RCS file: /cvsroot/pcb/pcb/src/hid/gtk/gui-top-window.c,v
retrieving revision 1.31
diff -U3 -p -r1.31 gui-top-window.c
--- src/hid/gtk/gui-top-window.c 24 Sep 2006 21:23:49 -0000 1.31
+++ src/hid/gtk/gui-top-window.c 4 Oct 2006 22:34:17 -0000
@@ -80,6 +80,10 @@
#include "gui-icons-mode-buttons.data"
#include "gui-icons-misc.data"
+#ifdef HAVE_DBUS
+#include "dbus.h"
+#endif
+
#ifdef HAVE_LIBDMALLOC
#include <dmalloc.h>
#endif
@@ -3839,6 +3843,10 @@ ghid_do_export (HID_Attr_Val * options)
if (stdin_listen)
ghid_create_listener ();
+#ifdef HAVE_DBUS
+ ghid_dbus_setup();
+#endif
+
gtk_main ();
ghid_config_files_write ();
}
Index: src/hid/gtk/dbus.c
===================================================================
diff -U3 -p -r -N /home/pcjc2/empty/dbus.c src/hid/gtk/dbus.c
--- /home/pcjc2/empty/dbus.c 1970-01-01 01:00:00.000000000 +0100
+++ src/hid/gtk/dbus.c 2006-10-04 19:59:11.000000000 +0100
@@ -0,0 +1,158 @@
+/*
+ * PCB, an interactive printed circuit board editor
+ * D-Bus IPC logic
+ * Copyright (C) 2006 University of Cambridge
+ *
+ * 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
+ */
+
+/*
+ * D-Bus code derrived from example-service.c in the dbus-glib bindings
+ */
+
+#include "dbus.h"
+#include "data.h"
+
+#include <dbus/dbus-glib.h>
+
+typedef struct GhidDbus GhidDbus;
+typedef struct GhidDbusClass GhidDbusClass;
+
+GType ghid_dbus_get_type (void);
+
+struct GhidDbus
+{
+ GObject parent;
+};
+
+struct GhidDbusClass
+{
+ GObjectClass parent;
+};
+
+#define GHID_TYPE_DBUS (ghid_dbus_get_type ())
+#define GHID_DBUS(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GHID_TYPE_DBUS, GhidDbus))
+#define GHID_DBUS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GHID_TYPE_DBUS, GhidDbusClass))
+#define GHID_IS_DBUS(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GHID_TYPE_DBUS))
+#define GHID_IS_DBUS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GHID_TYPE_DBUS))
+#define GHID_DBUS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GHID_TYPE_DBUS, GhidDbusClass))
+
+G_DEFINE_TYPE(GhidDbus, ghid_dbus, G_TYPE_OBJECT)
+
+gboolean ghid_dbus_get_filename (GhidDbus *obj, char **ret, GError **error);
+gboolean ghid_dbus_exec_action (GhidDbus *obj, char *action, char **args, guint32 *ret, GError **error);
+
+#include "dbus-glue.h"
+
+static void
+ghid_dbus_init (GhidDbus *obj)
+{
+}
+
+static void
+ghid_dbus_class_init (GhidDbusClass *klass)
+{
+}
+
+gboolean
+ghid_dbus_get_filename (GhidDbus *obj, char **ret, GError **error)
+{
+#ifdef DEBUGDBUS
+ printf ("ghid_dbus_get_filename()\n");
+#endif
+ (*ret) = g_strdup ( PCB->Filename );
+
+ return TRUE;
+}
+
+gboolean
+ghid_dbus_exec_action (GhidDbus *obj, char *action, char **args, guint32 *ret, GError **error)
+{
+ char *arg;
+ int i;
+
+#ifdef DEBUGDBUS
+ printf( "ghid_dbus_exec_action()\n Got action = '%s'\n", action);
+#endif
+
+ for (i=0; args[i] != NULL; i++) {
+ arg = args[i];
+#ifdef DEBUGDBUS
+ printf( " Got argument #%i = '%s'\n", i, arg );
+#endif
+ }
+
+#ifdef DEBUGDBUS
+ printf ( " Argument count, i=%i\n", i );
+#endif
+
+ hid_actionv( action, i, args );
+
+ // TODO: Dummy return code for now, in the future we want a code from the action
+ (*ret) = 0;
+
+ return TRUE;
+}
+
+void
+ghid_dbus_setup ( void )
+{
+ DBusGConnection *bus;
+ DBusGProxy *bus_proxy;
+ GError *error = NULL;
+ GhidDbus *obj;
+ guint request_name_result;
+
+ dbus_g_object_type_install_info (GHID_TYPE_DBUS, &dbus_glib_ghid_dbus_object_info);
+
+ bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+ if (!bus)
+ {
+ g_message ("Couldn't connect to session bus: %s", error->message );
+ g_error_free (error);
+ return;
+ }
+
+ bus_proxy = dbus_g_proxy_new_for_name (bus,
+ "org.freedesktop.DBus",
+ "/org/freedesktop/DBus",
+ "org.freedesktop.DBus");
+
+ if (!dbus_g_proxy_call (bus_proxy, "RequestName", &error,
+ G_TYPE_STRING, "org.seul.geda.pcb",
+ G_TYPE_UINT, 0,
+ G_TYPE_INVALID,
+ G_TYPE_UINT, &request_name_result,
+ G_TYPE_INVALID))
+ {
+ g_message ("Failed to acquire org.seul.geda.pcb: %s", error->message );
+ g_error_free (error);
+ g_object_unref( bus_proxy );
+ dbus_g_connection_unref( bus );
+ return;
+ }
+
+ g_object_unref( bus_proxy );
+
+ obj = g_object_new (GHID_TYPE_DBUS, NULL);
+
+ dbus_g_connection_register_g_object (bus, "/org/seul/geda/pcb", G_OBJECT (obj));
+
+ // TODO: Find out if this is needed
+ dbus_g_connection_unref( bus );
+
+ return;
+}
+
Index: src/hid/gtk/dbus.h
===================================================================
diff -U3 -p -r -N /home/pcjc2/empty/dbus.h src/hid/gtk/dbus.h
--- /home/pcjc2/empty/dbus.h 1970-01-01 01:00:00.000000000 +0100
+++ src/hid/gtk/dbus.h 2006-10-03 22:15:24.000000000 +0100
@@ -0,0 +1,27 @@
+/*
+ * PCB, an interactive printed circuit board editor
+ * D-Bus IPC logic
+ * Copyright (C) 2006 University of Cambridge
+ *
+ * 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 _DBUS_H_
+#define _DBUS_H_
+
+/* Carry out all actions to setup the D-Bus and register signal handlers */
+void ghid_dbus_setup();
+
+
+#endif /* !_DBUS_H */
Index: src/hid/gtk/dbus.xml
===================================================================
diff -U3 -p -r -N /home/pcjc2/empty/dbus.xml src/hid/gtk/dbus.xml
--- /home/pcjc2/empty/dbus.xml 1970-01-01 01:00:00.000000000 +0100
+++ src/hid/gtk/dbus.xml 2006-10-04 01:23:43.000000000 +0100
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!-- Should name="/org/geda/seul/pcb" ? -->
+<node name="/">
+ <interface name="org.seul.geda.pcb">
+ <method name="GetFilename">
+ <arg direction="out" type="s" />
+ </method>
+ </interface>
+ <interface name="org.seul.geda.pcb.actions">
+ <method name="ExecAction">
+ <arg direction="in" type="s" name="action" />
+ <arg direction="in" type="as" name="args" />
+ <arg direction="out" type="u" />
+ </method>
+ </interface>
+</node>
+
_______________________________________________
geda-dev mailing list
geda-dev@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-dev