Commit d2c1a633 authored by Havoc Pennington's avatar Havoc Pennington

2005-01-30 Havoc Pennington <hp@redhat.com>

	* tools/dbus-names-model.c: dynamically watch NameOwnerChanged

	* autogen.sh: change to autotools 1.9

	* glib/dbus-gproxy.c: completely change how signals work
	(dbus_g_proxy_add_signal): new function to specify signature of a
	signal
	(dbus_g_proxy_emit_received): marshal the dbus message to GValues,
	and g_warning if the incoming message has the wrong signature.
parent d5b7d7a7
2005-01-30 Havoc Pennington <hp@redhat.com>
* tools/dbus-names-model.c: dynamically watch NameOwnerChanged
* autogen.sh: change to autotools 1.9
* glib/dbus-gproxy.c: completely change how signals work
(dbus_g_proxy_add_signal): new function to specify signature of a
signal
(dbus_g_proxy_emit_received): marshal the dbus message to GValues,
and g_warning if the incoming message has the wrong signature.
2005-01-30 Havoc Pennington <hp@redhat.com>
* tools/dbus-names-model.c (have_names_notify): fix this
......
......@@ -21,8 +21,8 @@ DIE=0
DIE=1
}
AUTOMAKE=automake-1.7
ACLOCAL=aclocal-1.7
AUTOMAKE=automake-1.9
ACLOCAL=aclocal-1.9
($AUTOMAKE --version) < /dev/null > /dev/null 2>&1 || {
AUTOMAKE=automake
......
......@@ -819,6 +819,13 @@ fi
AM_CONDITIONAL(HAVE_GLIB, test x$have_glib = xyes)
AM_CONDITIONAL(HAVE_GLIB_THREADS, test x$have_glib_threads = xyes)
if test x$have_glib = xyes; then
GLIB_GENMARSHAL=`$PKG_CONFIG --variable=glib_genmarshal glib-2.0`
else
GLIB_GENMARSHAL=glib-not-enabled-so-there-is-no-genmarshal
fi
AC_SUBST(GLIB_GENMARSHAL)
dnl GLib flags
AC_SUBST(DBUS_GLIB_CFLAGS)
AC_SUBST(DBUS_GLIB_LIBS)
......
......@@ -149,6 +149,9 @@ DBusGProxy* dbus_g_proxy_new_for_name_owner (DBusGConnection *connect
DBusGProxy* dbus_g_proxy_new_for_peer (DBusGConnection *connection,
const char *path_name,
const char *interface_name);
void dbus_g_proxy_add_signal (DBusGProxy *proxy,
const char *signal_name,
const char *signature);
void dbus_g_proxy_connect_signal (DBusGProxy *proxy,
const char *signal_name,
GCallback handler,
......
......@@ -55,9 +55,9 @@ Important for 1.0 GLib Bindings
dbus_malloc() memory, only g_malloc().
dbus_g_proxy_end_call() is the major offender.
- dbus_gproxy_connect_signal() has to take a signature for the signal
so it can figure out how to invoke the callback, or we have to rely
on having introspection data.
- DBusGProxy signals feature is a complete fiasco;
right now the problem is that it dynamically creates
signals on the global DBusGProxy class and never frees them
- DBusGProxy doesn't emit "destroy" when it should
......
......@@ -5,6 +5,8 @@ lib_LTLIBRARIES=libdbus-glib-1.la
libdbus_glib_1_la_SOURCES = \
dbus-glib.c \
dbus-gmain.c \
dbus-gmarshal.c \
dbus-gmarshal.h \
dbus-gobject.c \
dbus-gproxy.c \
dbus-gtest.c \
......@@ -41,6 +43,15 @@ dbus_binding_tool_SOURCES = \
dbus_binding_tool_LDADD= -lexpat libdbus-gtool.la
## we just rebuilt these manually and check them into cvs; easier than
## convincing automake/make to do this properly
regenerate-built-sources:
@GLIB_GENMARSHAL@ --prefix=_dbus_g_marshal dbus-gmarshal.list --header > dbus-gmarshal.h && \
echo '#include "dbus-gmarshal.h"' > dbus-gmarshal.c && \
@GLIB_GENMARSHAL@ --prefix=_dbus_g_marshal dbus-gmarshal.list --body >> dbus-gmarshal.c
EXTRA_DIST=dbus-gmarshal.list
if DBUS_BUILD_TESTS
## we use noinst_PROGRAMS not check_PROGRAMS for TESTS so that we
......
#include "dbus-gmarshal.h"
#include <glib-object.h>
#ifdef G_ENABLE_DEBUG
#define g_marshal_value_peek_boolean(v) g_value_get_boolean (v)
#define g_marshal_value_peek_char(v) g_value_get_char (v)
#define g_marshal_value_peek_uchar(v) g_value_get_uchar (v)
#define g_marshal_value_peek_int(v) g_value_get_int (v)
#define g_marshal_value_peek_uint(v) g_value_get_uint (v)
#define g_marshal_value_peek_long(v) g_value_get_long (v)
#define g_marshal_value_peek_ulong(v) g_value_get_ulong (v)
#define g_marshal_value_peek_int64(v) g_value_get_int64 (v)
#define g_marshal_value_peek_uint64(v) g_value_get_uint64 (v)
#define g_marshal_value_peek_enum(v) g_value_get_enum (v)
#define g_marshal_value_peek_flags(v) g_value_get_flags (v)
#define g_marshal_value_peek_float(v) g_value_get_float (v)
#define g_marshal_value_peek_double(v) g_value_get_double (v)
#define g_marshal_value_peek_string(v) (char*) g_value_get_string (v)
#define g_marshal_value_peek_param(v) g_value_get_param (v)
#define g_marshal_value_peek_boxed(v) g_value_get_boxed (v)
#define g_marshal_value_peek_pointer(v) g_value_get_pointer (v)
#define g_marshal_value_peek_object(v) g_value_get_object (v)
#else /* !G_ENABLE_DEBUG */
/* WARNING: This code accesses GValues directly, which is UNSUPPORTED API.
* Do not access GValues directly in your code. Instead, use the
* g_value_get_*() functions
*/
#define g_marshal_value_peek_boolean(v) (v)->data[0].v_int
#define g_marshal_value_peek_char(v) (v)->data[0].v_int
#define g_marshal_value_peek_uchar(v) (v)->data[0].v_uint
#define g_marshal_value_peek_int(v) (v)->data[0].v_int
#define g_marshal_value_peek_uint(v) (v)->data[0].v_uint
#define g_marshal_value_peek_long(v) (v)->data[0].v_long
#define g_marshal_value_peek_ulong(v) (v)->data[0].v_ulong
#define g_marshal_value_peek_int64(v) (v)->data[0].v_int64
#define g_marshal_value_peek_uint64(v) (v)->data[0].v_uint64
#define g_marshal_value_peek_enum(v) (v)->data[0].v_long
#define g_marshal_value_peek_flags(v) (v)->data[0].v_ulong
#define g_marshal_value_peek_float(v) (v)->data[0].v_float
#define g_marshal_value_peek_double(v) (v)->data[0].v_double
#define g_marshal_value_peek_string(v) (v)->data[0].v_pointer
#define g_marshal_value_peek_param(v) (v)->data[0].v_pointer
#define g_marshal_value_peek_boxed(v) (v)->data[0].v_pointer
#define g_marshal_value_peek_pointer(v) (v)->data[0].v_pointer
#define g_marshal_value_peek_object(v) (v)->data[0].v_pointer
#endif /* !G_ENABLE_DEBUG */
/* NONE:STRING,STRING,STRING (dbus-gmarshal.list:1) */
void
_dbus_g_marshal_VOID__STRING_STRING_STRING (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data)
{
typedef void (*GMarshalFunc_VOID__STRING_STRING_STRING) (gpointer data1,
gpointer arg_1,
gpointer arg_2,
gpointer arg_3,
gpointer data2);
register GMarshalFunc_VOID__STRING_STRING_STRING callback;
register GCClosure *cc = (GCClosure*) closure;
register gpointer data1, data2;
g_return_if_fail (n_param_values == 4);
if (G_CCLOSURE_SWAP_DATA (closure))
{
data1 = closure->data;
data2 = g_value_peek_pointer (param_values + 0);
}
else
{
data1 = g_value_peek_pointer (param_values + 0);
data2 = closure->data;
}
callback = (GMarshalFunc_VOID__STRING_STRING_STRING) (marshal_data ? marshal_data : cc->callback);
callback (data1,
g_marshal_value_peek_string (param_values + 1),
g_marshal_value_peek_string (param_values + 2),
g_marshal_value_peek_string (param_values + 3),
data2);
}
#ifndef ___dbus_g_marshal_MARSHAL_H__
#define ___dbus_g_marshal_MARSHAL_H__
#include <glib-object.h>
G_BEGIN_DECLS
/* NONE:STRING,STRING,STRING (dbus-gmarshal.list:1) */
extern void _dbus_g_marshal_VOID__STRING_STRING_STRING (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data);
#define _dbus_g_marshal_NONE__STRING_STRING_STRING _dbus_g_marshal_VOID__STRING_STRING_STRING
G_END_DECLS
#endif /* ___dbus_g_marshal_MARSHAL_H__ */
NONE:STRING,STRING,STRING
This diff is collapsed.
......@@ -22,6 +22,7 @@
*/
#include "dbus-names-model.h"
#include <glib/gi18n.h>
#include <string.h>
enum
{
......@@ -112,6 +113,81 @@ have_names_notify (DBusGPendingCall *call,
g_strfreev (names);
}
static gboolean
names_model_find_name (NamesModel *names_model,
const char *name,
GtkTreeIter *iter_p)
{
GtkTreeIter iter;
if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (names_model),
&iter))
return FALSE;
do
{
char *s;
gtk_tree_model_get (GTK_TREE_MODEL (names_model),
&iter,
MODEL_COLUMN_NAME, &s,
-1);
if (s && strcmp (s, name) == 0)
{
*iter_p = iter;
g_free (s);
return TRUE;
}
g_free (s);
}
while (gtk_tree_model_iter_next (GTK_TREE_MODEL (names_model),
&iter));
return FALSE;
}
static void
name_owner_changed (DBusGProxy *driver_proxy,
const char *name,
const char *old_owner,
const char *new_owner,
void *data)
{
NamesModel *names_model = NAMES_MODEL (data);
#if 0
g_printerr ("Name '%s' changed owner '%s' -> '%s'\n",
name, old_owner, new_owner);
#endif
if (*new_owner == '\0')
{
/* this name has vanished */
GtkTreeIter iter;
if (names_model_find_name (names_model, name, &iter))
gtk_tree_store_remove (GTK_TREE_STORE (names_model),
&iter);
}
else if (*old_owner == '\0')
{
/* this name has been added */
GtkTreeIter iter;
if (!names_model_find_name (names_model, name, &iter))
{
gtk_tree_store_append (GTK_TREE_STORE (names_model),
&iter, NULL);
gtk_tree_store_set (GTK_TREE_STORE (names_model),
&iter,
MODEL_COLUMN_NAME, name,
-1);
}
}
}
static void
names_model_reload (NamesModel *names_model)
{
......@@ -144,8 +220,6 @@ static void
names_model_set_connection (NamesModel *names_model,
DBusGConnection *connection)
{
const char *match_rule = "type='signal',member='NameOwnerChanged'";
g_return_if_fail (IS_NAMES_MODEL (names_model));
if (connection == names_model->connection)
......@@ -153,10 +227,11 @@ names_model_set_connection (NamesModel *names_model,
if (names_model->connection)
{
dbus_g_proxy_call_no_reply (names_model->driver_proxy,
"RemoveMatch",
DBUS_TYPE_STRING, &match_rule,
DBUS_TYPE_INVALID);
dbus_g_proxy_disconnect_signal (names_model->driver_proxy,
"NameOwnerChanged",
G_CALLBACK (name_owner_changed),
names_model);
g_object_unref (names_model->driver_proxy);
names_model->driver_proxy = NULL;
dbus_g_connection_unref (names_model->connection);
......@@ -174,6 +249,18 @@ names_model_set_connection (NamesModel *names_model,
DBUS_PATH_ORG_FREEDESKTOP_DBUS,
DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS);
g_assert (names_model->driver_proxy);
dbus_g_proxy_add_signal (names_model->driver_proxy,
"NameOwnerChanged",
DBUS_TYPE_STRING_AS_STRING
DBUS_TYPE_STRING_AS_STRING
DBUS_TYPE_STRING_AS_STRING);
dbus_g_proxy_connect_signal (names_model->driver_proxy,
"NameOwnerChanged",
G_CALLBACK (name_owner_changed),
names_model,
NULL);
}
names_model_reload (names_model);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment