summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMartin Baulig <martin@home-of-linux.org>2000-11-22 20:58:15 +0000
committerMartin Baulig <martin@src.gnome.org>2000-11-22 20:58:15 +0000
commitcee38c53bc3f7b22078e9805e0406c21552576cc (patch)
treeba1f0cb19112d8d6350db360d6d288dac5cdf155 /lib
parent81b009733e78367672a515b297f6221cd23e21c4 (diff)
downloadlibgtop-cee38c53bc3f7b22078e9805e0406c21552576cc.tar.gz
New file.
2000-11-22 Martin Baulig <martin@home-of-linux.org> * 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.
Diffstat (limited to 'lib')
-rw-r--r--lib/.cvsignore2
-rw-r--r--lib/Makefile.am17
-rw-r--r--lib/glibtop-client.c148
-rw-r--r--lib/glibtop-server.c57
-rw-r--r--lib/init-backends.c18
-rw-r--r--lib/test-backends.c66
6 files changed, 296 insertions, 12 deletions
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 <glibtop.h>
+#include <gobject/gsignal.h>
+#include <gobject/gvaluetypes.h>
+
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)
{
@@ -64,13 +75,102 @@ glibtop_client_get_type (void)
}
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 <martin@home-of-linux.org>, 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.h>
+
+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 <gnome-xml/parser.h>
+#include <libxml/parser.h>
#include <dirent.h>
@@ -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 <martin@home-of-linux.org>, 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.h>
+#include <glibtop/backend.h>
+
+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);
+}