From cee38c53bc3f7b22078e9805e0406c21552576cc Mon Sep 17 00:00:00 2001 From: Martin Baulig Date: Wed, 22 Nov 2000 20:58:15 +0000 Subject: [PATCH] New file. 2000-11-22 Martin Baulig * lib/glibtop-server.c: New file. * lib/test-backends.c: New file. * lib/Makefile.am: Build test-backends test program. * lib/init-backends.c: Port this to libxml 2. * configure.in: Make this really work. * acinclude.m4: Removed the xml stuff. * Makefile.am (SUBDIRS): Put lib in front of sysdeps and backends. --- ChangeLog | 13 ++++ Makefile.am | 2 +- acinclude.m4 | 38 ----------- configure.in | 46 ++++---------- lib/.cvsignore | 2 + lib/Makefile.am | 17 +++-- lib/glibtop-client.c | 148 +++++++++++++++++++++++++++++++++++++++++++ lib/glibtop-server.c | 57 +++++++++++++++++ lib/init-backends.c | 18 +++--- lib/test-backends.c | 66 +++++++++++++++++++ 10 files changed, 323 insertions(+), 84 deletions(-) create mode 100644 lib/glibtop-server.c create mode 100644 lib/test-backends.c diff --git a/ChangeLog b/ChangeLog index 5614c61e..cecd578a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2000-11-22 Martin Baulig + + * lib/glibtop-server.c: New file. + + * lib/test-backends.c: New file. + * lib/Makefile.am: Build test-backends test program. + + * lib/init-backends.c: Port this to libxml 2. + + * configure.in: Make this really work. + * acinclude.m4: Removed the xml stuff. + * Makefile.am (SUBDIRS): Put lib in front of sysdeps and backends. + 2000-11-21 Martin Baulig * configure.in: Removed gnomesupport checks here and started diff --git a/Makefile.am b/Makefile.am index 497622c4..0ca00dc2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in. -SUBDIRS = po intl misc include sysdeps backends lib src doc dtd scripts +SUBDIRS = po intl misc include lib sysdeps backends src doc dtd scripts include_HEADERS = glibtop.h configincludedir = $(pkglibdir)/include diff --git a/acinclude.m4 b/acinclude.m4 index 59044b84..1c1d32a5 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -520,41 +520,3 @@ AC_DEFUN([GNOME_LIBGTOP_SYSDEPS],[ AM_CONDITIONAL(HAVE_SYSDEPS, test x$libgtop_have_sysdeps = xyes) AM_CONDITIONAL(LIBGTOP_USE_GMODULE, test x$libgtop_use_gmodule = xyes) ]) - -dnl -dnl LIBGTOP_XML_HOOK (script-if-xml-found, failflag) -dnl -dnl If failflag is "failure", script aborts due to lack of XML -dnl -dnl Check for availability of the libxml library -dnl the XML parser uses libz if available too -dnl - -AC_DEFUN([LIBGTOP_XML_HOOK],[ - LIBGTOP_XML_LIB= - AC_PATH_PROG(XML_CONFIG,xml-config,no) - if test "$XML_CONFIG" = no; then - if test x$2 = xfailure; then - AC_MSG_ERROR(Could not find xml-config) - else - AC_MSG_WARN(Could not find xml-config) - fi - else - AC_CHECK_LIB(xml, xmlDocGetRootElement, [ - $1 - LIBGTOP_XML_LIB=`$XML_CONFIG --libs` - AC_DEFINE(HAVE_LIBXML) - ], [ - if test x$2 = xfailure; then - AC_MSG_ERROR(Could not link sample xml program) - else - AC_MSG_WARN(Could not link sample xml program) - fi - ], `$XML_CONFIG --libs`) - fi - AC_SUBST(LIBGTOP_XML_LIB) -]) - -AC_DEFUN([LIBGTOP_XML_CHECK], [ - LIBGTOP_XML_HOOK([],failure) -]) diff --git a/configure.in b/configure.in index 509f03a2..c69f4e3c 100644 --- a/configure.in +++ b/configure.in @@ -50,10 +50,8 @@ AC_SUBST(LT_CURRENT) AC_SUBST(LT_REVISION) AC_SUBST(LT_AGE) -GNOME_INTERFACE_VERSION=2 -AC_SUBST(GNOME_INTERFACE_VERSION) - GNOME_COMMON_INIT +GNOME_PLATFORM_GNOME_2(yes, force) AC_ISC_POSIX AC_PROG_CC @@ -94,7 +92,7 @@ AM_PROG_LIBTOOL dnl Let the user enable compiler warnings GNOME_COMPILE_WARNINGS -PKG_CHECK_MODULES(GNOMESUPPORT, gnome-support-2.0:1.2.1) +GNOME_PKGCONFIG_CHECK_MODULES(GNOMESUPPORT, gnome-support-2.0:1.2.1) AC_SUBST(GNOMESUPPORT_CFLAGS) AC_SUBST(GNOMESUPPORT_LIBS) @@ -117,7 +115,10 @@ fi AC_SUBST(sysdeps_init_file) AC_MSG_RESULT($sysdeps_init_file) -LIBGTOP_XML_CHECK +GNOME_PKGCONFIG_CHECK_MODULES(XML, libxml-2.0:2.2.8) +AC_DEFINE(HAVE_LIBXML) +AC_SUBST(XML_CFLAGS) +AC_SUBST(XML_LIBS) AC_ARG_WITH(libgtop-inodedb, [ --with-libgtop-inodedb Build the inodedb stuff (default=no)], @@ -142,15 +143,12 @@ AM_CONDITIONAL(ENABLE_SHARED, test x$enable_static = xyes) AM_PROG_LIBTOOL if test x$libgtop_use_gmodule = xyes ; then - AM_PATH_GLIB_2_0(1.3.0,,AC_MSG_ERROR(GLIB >= 1.3.0 is required for LibGTop), - [gmodule]) + GNOME_PKGCONFIG_CHECK_MODULES(GLIB, glib-2.0:1.3.1 gmodule-2.0:1.3.1 gobject-2.0:1.3.1) else - AM_PATH_GLIB_2_0(1.3.0,,AC_MSG_ERROR(GLIB >= 1.3.0 is required for LibGTop)) + GNOME_PKGCONFIG_CHECK_MODULES(GLIB, glib-2.0:1.3.1 gobject-2.0:1.3.1) fi - -dnl You need to uncomment the following line if you want to use -dnl libGTop without Gnome. -dnl GNOME_SUPPORT_CHECKS +AC_SUBST(GLIB_CFLAGS) +AC_SUBST(GLIB_LIBS) dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST @@ -278,24 +276,6 @@ if test "x$libgtop_enable_debug" = xyes ; then AC_DEFINE(LIBGTOP_ENABLE_DEBUG) fi -if test "x$gnome_found" = xyes ; then - LIBSUPPORT="$GNOME_LIBDIR -lgnomesupport" - SUPPORTINCS="$GNOME_INCLUDEDIR" -else - LIBSUPPORT='$(top_builddir)/support/libgnomesupport.la' - SUPPORTINCS='-DNEED_GNOMESUPPORT_H -I$(top_builddir)/support -I$(top_srcdir)/support' -fi - -dnl Some ugly hack; if '-lgnomesupport' is part of $GNOME_LIBS, -dnl we include it here. -case "$GNOME_LIBS" in - '*-lgnomesupport*' ) - LIBSUPPORT="$GNOME_LIBDIR -lgnomesupport" - SUPPORTINCS="$GNOME_INCLUDEDIR" ;; -esac -AC_SUBST(LIBSUPPORT) -AC_SUBST(SUPPORTINCS) - dnl These definitions are expanded in make. LIBGTOP_LIBS='-L$(libdir)' LIBGTOP_INCS='-I$(includedir) -I$(pkglibdir)/include' @@ -316,12 +296,12 @@ if test x$libgtop_have_sysinfo = xyes ; then LIBGTOP_INCS="$LIBGTOP_INCS -DHAVE_LIBGTOP_SYSINFO" fi -LIBGTOP_INCS="$LIBGTOP_INCS $SUPPORTINCS $GLIB_CFLAGS" +LIBGTOP_INCS="$LIBGTOP_INCS $GNOMESUPPORT_CFLAGS $GLIB_CFLAGS $XML_CFLAGS" LIBGTOP_BINDIR='$(bindir)' LIBGTOP_SERVER='$(bindir)/libgtop_server' -LIBGTOP_EXTRA_LIBS="$LIBGTOP_EXTRA_LIBS $GLIB_LIBS $LIBGTOP_XML_LIB" +LIBGTOP_EXTRA_LIBS="$LIBGTOP_EXTRA_LIBS $GLIB_LIBS $XML_LIBS" if test x$libgtop_use_gmodule != xyes ; then LIBGTOP_LIBS="$LIBGTOP_LIBS -lgtop -lgtop_backend_common -lgtop_common" @@ -348,7 +328,7 @@ AC_SUBST(machine_incs) LIBGTOP_BACKEND_DIR="\$(datadir)/libgtop/backends" -INCLUDES="-D_IN_LIBGTOP -D_GNU_SOURCE -DGLIBTOP_NAMES -I\$(top_builddir) -I\$(top_srcdir) -I\$(top_srcdir)/sysdeps/$sysdeps_dir -I\$(top_srcdir)/include -I\$(top_builddir)/include -I\$(top_srcdir)/intl $SUPPORTINCS $GLIB_CFLAGS $CFLAGS $X_CFLAGS "'-DGTOPLOCALEDIR=\"$(datadir)/locale\" -DLIBGTOP_VERSION=\"'"$LIBGTOP_VERSION"'\" -DLIBGTOP_SERVER_VERSION=\"'"$LIBGTOP_SERVER_VERSION"'\" -DLIBGTOP_VERSION_CODE='$LIBGTOP_VERSION_CODE' -DLIBGTOP_SERVER=\"'"$LIBGTOP_SERVER"'\" -DLIBGTOP_BACKEND_DIR=\"'"$LIBGTOP_BACKEND_DIR"'\"' +INCLUDES="-D_IN_LIBGTOP -D_GNU_SOURCE -DGLIBTOP_NAMES -I\$(top_builddir) -I\$(top_srcdir) -I\$(top_srcdir)/sysdeps/$sysdeps_dir -I\$(top_srcdir)/include -I\$(top_builddir)/include -I\$(top_srcdir)/intl $GNOMESUPPORT_CFLAGS $GLIB_CFLAGS $XML_CFLAGS $CFLAGS $X_CFLAGS "'-DGTOPLOCALEDIR=\"$(datadir)/locale\" -DLIBGTOP_VERSION=\"'"$LIBGTOP_VERSION"'\" -DLIBGTOP_SERVER_VERSION=\"'"$LIBGTOP_SERVER_VERSION"'\" -DLIBGTOP_VERSION_CODE='$LIBGTOP_VERSION_CODE' -DLIBGTOP_SERVER=\"'"$LIBGTOP_SERVER"'\" -DLIBGTOP_BACKEND_DIR=\"'"$LIBGTOP_BACKEND_DIR"'\"' AC_SUBST(INCLUDES) diff --git a/lib/.cvsignore b/lib/.cvsignore index 201cc977..5bb073c7 100644 --- a/lib/.cvsignore +++ b/lib/.cvsignore @@ -7,3 +7,5 @@ libgtop.la lib.c structures.h sysdeps-init.c +libgtop_server.la +test-backends diff --git a/lib/Makefile.am b/lib/Makefile.am index 9f7a2318..767d7806 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -2,18 +2,27 @@ LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@ INCLUDES = @INCLUDES@ -lib_LTLIBRARIES = libgtop.la libgtop_server.la +noinst_PROGRAMS = test-backends -libgtop_la_SOURCES = errors.c glib-arrays.c backend.c \ +lib_LTLIBRARIES = libgtop.la + +noinst_LTLIBRARIES = libgtop_server.la + +libgtop_la_SOURCES = errors.c backend.c \ init-backends.c open-backend.c \ - glibtop-client.c + glibtop-client.c glibtop-server.c libgtop_server_la_SOURCES = error.c xmalloc.c libgtop_server_la_LDFLAGS = $(LT_VERSION_INFO) libgtop_la_LDFLAGS = $(LT_VERSION_INFO) -libgtop_la_LIBADD = $(LIBGTOP_XML_LIB) +libgtop_la_LIBADD = $(GLIB_LIBS) $(XML_LIBS) + +test_backends_SOURCES = \ + test-backends.c + +test_backends_LDADD = libgtop.la glibtopdir = $(includedir)/glibtop diff --git a/lib/glibtop-client.c b/lib/glibtop-client.c index f4f98024..4ebe6761 100644 --- a/lib/glibtop-client.c +++ b/lib/glibtop-client.c @@ -25,6 +25,9 @@ #include +#include +#include + static void glibtop_client_class_init (glibtop_client_class *klass); static void glibtop_client_init (glibtop_client *client); static void glibtop_client_finalize (GObject *object); @@ -38,6 +41,14 @@ struct _glibtop_client_private { }; +enum { + GLIBTOP_CLIENT_SIGNAL_ERROR, + GLIBTOP_CLIENT_SIGNAL_WARNING, + LAST_SIGNAL +}; + +static guint glibtop_client_signals [LAST_SIGNAL] = { 0 }; + GType glibtop_client_get_type (void) { @@ -63,14 +74,103 @@ glibtop_client_get_type (void) return glibtop_client_type; } +static void +glibtop_client_error_handler (glibtop_client *client, GError *error) +{ + g_return_if_fail (GLIBTOP_IS_CLIENT (client)); + + if (error == NULL) + return; + + g_error ("%s (%d): %s", g_quark_to_string (error->domain), + error->code, error->message); +} + +static void +glibtop_client_warning_handler (glibtop_client *client, GError *error) +{ + g_return_if_fail (GLIBTOP_IS_CLIENT (client)); + + if (error == NULL) + return; + + g_warning ("%s (%d): %s", g_quark_to_string (error->domain), + error->code, error->message); + +} + +void +glibtop_client_marshal_VOID__POINTER (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data) +{ + typedef void (*GSignalFunc_VOID__POINTER) (gpointer data1, + gpointer arg_1, + gpointer data2); + register GSignalFunc_VOID__POINTER callback; + register GCClosure *cc = (GCClosure*) closure; + register gpointer data1, data2; + + g_return_if_fail (n_param_values >= 2); + + if (G_CCLOSURE_SWAP_DATA (closure)) + { + data1 = closure->data; + data2 = g_value_get_as_pointer (param_values + 0); + } + else + { + data1 = g_value_get_as_pointer (param_values + 0); + data2 = closure->data; + } + callback = (GSignalFunc_VOID__POINTER) (marshal_data ? marshal_data : cc->callback); + + callback (data1, + g_value_get_as_pointer (param_values + 1), + data2); +} + static void glibtop_client_class_init (glibtop_client_class *class) { GObjectClass *gobject_class; + GType *param_types; + GClosure *closure; gobject_class = (GObjectClass *) class; parent_class = g_type_class_ref (G_TYPE_OBJECT); + + closure = g_signal_type_closure_new (G_TYPE_FROM_CLASS (class), + G_STRUCT_OFFSET (glibtop_client_class, + error)); + + param_types = g_new0 (GType, 1); + param_types [0] = G_TYPE_POINTER; + + glibtop_client_signals [GLIBTOP_CLIENT_SIGNAL_ERROR] = + g_signal_newv ("error", G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_LAST, closure, NULL, + glibtop_client_marshal_VOID__POINTER, + G_TYPE_NONE, 1, param_types); + + closure = g_signal_type_closure_new (G_TYPE_FROM_CLASS (class), + G_STRUCT_OFFSET (glibtop_client_class, + warning)); + + glibtop_client_signals [GLIBTOP_CLIENT_SIGNAL_WARNING] = + g_signal_newv ("warning", G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_LAST, closure, NULL, + glibtop_client_marshal_VOID__POINTER, + G_TYPE_NONE, 1, param_types); + + g_free (param_types); + + class->error = glibtop_client_error_handler; + class->warning = glibtop_client_warning_handler; gobject_class->finalize = glibtop_client_finalize; } @@ -104,3 +204,51 @@ glibtop_client_new (void) { return g_object_new (GLIBTOP_TYPE_CLIENT, NULL); } + +void +glibtop_client_propagate_error (glibtop_client *client, GError *error) +{ + GValue params [2] = { { 0, }, { 0, } }; + + g_return_if_fail (GLIBTOP_IS_CLIENT (client)); + + if (error == NULL) + return; + + g_value_init (params, GLIBTOP_CLIENT_TYPE (client)); + g_value_set_object (params, G_OBJECT (client)); + + g_value_init (params + 1, G_TYPE_POINTER); + g_value_set_pointer (params + 1, error); + + g_signal_emitv (params, + glibtop_client_signals [GLIBTOP_CLIENT_SIGNAL_ERROR], + 0, NULL); + + g_value_unset (params + 1); + g_value_unset (params + 0); +} + +void +glibtop_client_propagate_warning (glibtop_client *client, GError *error) +{ + GValue params [2] = { { 0, }, { 0, } }; + + g_return_if_fail (GLIBTOP_IS_CLIENT (client)); + + if (error == NULL) + return; + + g_value_init (params, GLIBTOP_CLIENT_TYPE (client)); + g_value_set_object (params, G_OBJECT (client)); + + g_value_init (params + 1, G_TYPE_POINTER); + g_value_set_pointer (params + 1, error); + + g_signal_emitv (params, + glibtop_client_signals [GLIBTOP_CLIENT_SIGNAL_WARNING], + 0, NULL); + + g_value_unset (params + 1); + g_value_unset (params + 0); +} diff --git a/lib/glibtop-server.c b/lib/glibtop-server.c new file mode 100644 index 00000000..66fbe471 --- /dev/null +++ b/lib/glibtop-server.c @@ -0,0 +1,57 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ + +/* $Id$ */ + +/* Copyright (C) 1998-99 Martin Baulig + This file is part of LibGTop 2.0. + + Contributed by Martin Baulig , April 1998. + + LibGTop 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. + + LibGTop 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 LibGTop; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include + +glibtop_server * +glibtop_server_new (void) +{ + glibtop_server *retval; + + retval = g_new0 (glibtop_server, 1); + retval->info = g_new0 (glibtop_server_info, 1); + retval->_priv = g_new0 (glibtop_server_private, 1); + retval->refcount = 1; + + return retval; +} + +void +glibtop_server_ref (glibtop_server *server) +{ + server->refcount++; +} + +void +glibtop_server_unref (glibtop_server *server) +{ + server->refcount--; + + if (server->refcount <= 0) { + g_free (server->_priv); + g_free (server->info); + g_free (server); + } +} diff --git a/lib/init-backends.c b/lib/init-backends.c index e0baa1da..98dbf244 100644 --- a/lib/init-backends.c +++ b/lib/init-backends.c @@ -33,7 +33,7 @@ #define LIBGTOP_XML_NAMESPACE "http://www.home-of-linux.org/libgtop/1.1" -#include +#include #include @@ -51,6 +51,8 @@ glibtop_init_backends (void) backends_initialized = 1; #if HAVE_LIBXML + LIBXML_TEST_VERSION; + _glibtop_init_gmodule_backends (LIBGTOP_BACKEND_DIR); #endif } @@ -60,7 +62,7 @@ glibtop_init_backends (void) static gchar * _get_library_filename (xmlDocPtr doc, xmlNodePtr cur, const char *directory) { - char *filename = xmlNodeListGetString (doc, cur->childs, 1); + char *filename = xmlNodeListGetString (doc, cur->xmlChildrenNode, 1); gchar *retval; if (!filename) @@ -81,10 +83,10 @@ _parse_extra_libs (xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, const char *dir) GSList *list = NULL; /* We don't care what the top level element name is */ - cur = cur->childs; + cur = cur->xmlChildrenNode; while (cur != NULL) { if ((!strcmp (cur->name, "ExtraLib")) && (cur->ns == ns)) { - xmlNodePtr sub = cur->childs; + xmlNodePtr sub = cur->xmlChildrenNode; while (sub != NULL) { if ((!strcmp (sub->name, "ShlibName")) && (sub->ns == ns)) @@ -112,14 +114,14 @@ _parseBackend (xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, const char *dir) ret = g_new0 (glibtop_backend_entry, 1); /* We don't care what the top level element name is */ - cur = cur->childs; + cur = cur->xmlChildrenNode; while (cur != NULL) { if ((!strcmp (cur->name, "Name")) && (cur->ns == ns)) ret->name = xmlNodeListGetString - (doc, cur->childs, 1); + (doc, cur->xmlChildrenNode, 1); if ((!strcmp (cur->name, "Location")) && (cur->ns == ns)) { - xmlNodePtr sub = cur->childs; + xmlNodePtr sub = cur->xmlChildrenNode; while (sub != NULL) { if ((!strcmp (sub->name, "LibtoolName")) && (sub->ns == ns)) @@ -198,7 +200,7 @@ _glibtop_init_gmodule_backends (const char *directory) continue; } - cur = cur->childs; + cur = cur->xmlChildrenNode; while (cur != NULL) { glibtop_backend_entry *backend; diff --git a/lib/test-backends.c b/lib/test-backends.c new file mode 100644 index 00000000..de50114f --- /dev/null +++ b/lib/test-backends.c @@ -0,0 +1,66 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ + +/* $Id$ */ + +/* Copyright (C) 1998-99 Martin Baulig + This file is part of LibGTop 1.0. + + Contributed by Martin Baulig , April 1998. + + LibGTop 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. + + LibGTop 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 LibGTop; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include +#include + +int +main (int argc, char *argv []) +{ + glibtop_client *client; + glibtop_backend *backend_common; + glibtop_backend *backend_sysdeps; + GError *error = NULL; + + g_type_init (); + + glibtop_init_backends (); + + client = glibtop_client_new (); + + backend_common = glibtop_open_backend_l (client, "glibtop-backend-common", + 0, NULL, &error); + + g_message (G_STRLOC ": backend = %p (%p)", backend_common, error); + + if (error != NULL) { + glibtop_client_propagate_error (client, error); + g_error_free (error); + error = NULL; + } + + backend_sysdeps = glibtop_open_backend_l (client, "glibtop-backend-sysdeps", + 0, NULL, &error); + + g_message (G_STRLOC ": backend = %p (%p)", backend_sysdeps, error); + + if (error != NULL) { + glibtop_client_propagate_error (client, error); + g_error_free (error); + error = NULL; + } + + exit (0); +}