diff --git a/ChangeLog b/ChangeLog index 8f78c6a6..aec76d7c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2000-11-26 Martin Baulig + + * include/glibtop/backend.h: Removed. Split into glibtop-backend.h + and glibtop-backend-info.h. + + * include/glibtop/glibtop-backend.h: New file. Switched + glibtop_backend to a GObject. + + * include/glibtop/glibtop-backend-info.h: New file. + + * lib/backend.c, lib/init-backends.c, lib/open-backend.c: Removed. + + * lib/glibtop-backend.c: New file. + * lib/glibtop-backend-info.c: New file. + 2000-11-26 Martin Baulig * include/glibtop/call-vector.h (glibtop_call_vector): Moved diff --git a/backends/common/backend-common.c b/backends/common/backend-common.c index 1c616d86..500eccf9 100644 --- a/backends/common/backend-common.c +++ b/backends/common/backend-common.c @@ -28,7 +28,6 @@ #include #include -#include #include static int diff --git a/backends/common/glibtop-backend-private.h b/backends/common/glibtop-backend-private.h index 81d485b6..37234393 100644 --- a/backends/common/glibtop-backend-private.h +++ b/backends/common/glibtop-backend-private.h @@ -26,6 +26,10 @@ #ifndef __GLIBTOP_BACKEND_PRIVATE_H__ #define __GLIBTOP_BACKEND_PRIVATE_H__ +#include +#include +#include + struct _glibtop_backend_private { u_int64_t flags; diff --git a/backends/common/marshal.pl b/backends/common/marshal.pl index f9623964..7fb21067 100644 --- a/backends/common/marshal.pl +++ b/backends/common/marshal.pl @@ -31,7 +31,6 @@ print ''; print '#include '; print '#include '; print ''; -print '#include '; print '#include '; print ''; print '#include '; diff --git a/backends/sysdeps/backend-sysdeps.c b/backends/sysdeps/backend-sysdeps.c index 271dbf8c..c3955e24 100644 --- a/backends/sysdeps/backend-sysdeps.c +++ b/backends/sysdeps/backend-sysdeps.c @@ -27,8 +27,6 @@ #include #include -#include -#include #include static int diff --git a/backends/sysdeps/glibtop-backend-private.h b/backends/sysdeps/glibtop-backend-private.h index 81d485b6..37234393 100644 --- a/backends/sysdeps/glibtop-backend-private.h +++ b/backends/sysdeps/glibtop-backend-private.h @@ -26,6 +26,10 @@ #ifndef __GLIBTOP_BACKEND_PRIVATE_H__ #define __GLIBTOP_BACKEND_PRIVATE_H__ +#include +#include +#include + struct _glibtop_backend_private { u_int64_t flags; diff --git a/backends/sysdeps/marshal.pl b/backends/sysdeps/marshal.pl index 73557fc0..6f92186e 100644 --- a/backends/sysdeps/marshal.pl +++ b/backends/sysdeps/marshal.pl @@ -31,7 +31,6 @@ print ''; print '#include '; print '#include '; print ''; -print '#include '; print '#include '; print ''; print '#include '; diff --git a/include/glibtop/Makefile.am b/include/glibtop/Makefile.am index 4d185c00..71419485 100644 --- a/include/glibtop/Makefile.am +++ b/include/glibtop/Makefile.am @@ -9,8 +9,9 @@ glibtop_HEADERS = close.h loadavg.h prockernel.h procstate.h \ mountlist.h fsusage.h procmap.h signal.h \ inodedb.h sysinfo.h ppp.h procargs.h netload.h \ netinfo.h interfaces.h limits.h array.h compat_10.h \ - glib-arrays.h backend.h call-vector.h \ - glibtop-client.h glibtop-server.h + glib-arrays.h call-vector.h \ + glibtop-client.h glibtop-server.h glibtop-backend.h \ + glibtop-backend-info.h BUILT_SOURCES = call-vector.h diff --git a/include/glibtop/backend.h b/include/glibtop/glibtop-backend-info.h similarity index 82% rename from include/glibtop/backend.h rename to include/glibtop/glibtop-backend-info.h index 6a0ad911..3c25fb1c 100644 --- a/include/glibtop/backend.h +++ b/include/glibtop/glibtop-backend-info.h @@ -23,8 +23,8 @@ Boston, MA 02111-1307, USA. */ -#ifndef __GLIBTOP_BACKEND_H__ -#define __GLIBTOP_BACKEND_H__ +#ifndef __GLIBTOP_BACKEND_INFO_H__ +#define __GLIBTOP_BACKEND_INFO_H__ #include #include @@ -36,12 +36,9 @@ BEGIN_LIBGTOP_DECLS typedef struct _glibtop_backend_info glibtop_backend_info; typedef struct _glibtop_backend_entry glibtop_backend_entry; typedef struct _glibtop_backend_module glibtop_backend_module; -typedef struct _glibtop_backend_private glibtop_backend_private; typedef struct _glibtop_call_vector glibtop_call_vector; -typedef struct _glibtop_backend glibtop_backend; - typedef int (*glibtop_backend_open_func_t) (glibtop_server *, glibtop_backend *, u_int64_t, const char **); typedef int (*glibtop_backend_close_func_t) (glibtop_server *, glibtop_backend *); @@ -66,8 +63,6 @@ struct _glibtop_backend_module GSList *extra_modules; }; -#endif /* _IN_LIBGTOP */ - struct _glibtop_backend_entry { char *name; @@ -84,16 +79,7 @@ struct _glibtop_backend_entry glibtop_backend_module *_priv; }; -struct _glibtop_backend -{ - const glibtop_backend_info *info; - - glibtop_server *server; - - /* private pointers */ - glibtop_backend_private *_priv; - glibtop_backend_module *_priv_module; -}; +#endif /* _IN_LIBGTOP */ long glibtop_register_backend (glibtop_backend_entry *entry); @@ -110,10 +96,6 @@ glibtop_backend_by_name (const char *backend_name); void glibtop_init_backends (void); -glibtop_backend * -glibtop_open_backend (const char *backend_name, u_int64_t features, - const char **backend_args, GError **error); - END_LIBGTOP_DECLS #endif diff --git a/include/glibtop/glibtop-backend.h b/include/glibtop/glibtop-backend.h new file mode 100644 index 00000000..13632d68 --- /dev/null +++ b/include/glibtop/glibtop-backend.h @@ -0,0 +1,71 @@ +/* -*- 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. +*/ + +#ifndef __GLIBTOP_BACKEND_H__ +#define __GLIBTOP_BACKEND_H__ + +#include +#include + +BEGIN_LIBGTOP_DECLS + +#define GLIBTOP_TYPE_BACKEND (glibtop_backend_get_type ()) +#define GLIBTOP_BACKEND(backend) (G_TYPE_CHECK_INSTANCE_CAST ((backend), GLIBTOP_TYPE_BACKEND, glibtop_backend)) +#define GLIBTOP_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLIBTOP_TYPE_BACKEND, glibtop_backend_class)) +#define GLIBTOP_IS_BACKEND(backend) (G_TYPE_CHECK_INSTANCE_TYPE ((backend), GLIBTOP_TYPE_BACKEND)) +#define GLIBTOP_IS_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLIBTOP_TYPE_BACKEND)) +#define GLIBTOP_BACKEND_GET_CLASS(backend)(G_TYPE_INSTANCE_GET_CLASS ((backend), GLIBTOP_TYPE_BACKEND, glibtop_backend_class)) + +#define GLIBTOP_BACKEND_TYPE(backend) (G_TYPE_FROM_INSTANCE (backend)) +#define GLIBTOP_BACKEND_TYPE_NAME(backend)(g_type_name (GLIBTOP_BACKEND_TYPE (backend))) + +/* --- typedefs & structures --- */ +typedef struct _glibtop_backend glibtop_backend; +typedef struct _glibtop_backend_class glibtop_backend_class; +typedef struct _glibtop_backend_private glibtop_backend_private; + +struct _glibtop_backend +{ + GObject object; + + /* */ + glibtop_backend_private *_priv; +}; + +struct _glibtop_backend_class +{ + GObjectClass parent_class;; +}; + +GType +glibtop_backend_get_type (void); + +glibtop_backend * +glibtop_backend_open (const char *backend_name, u_int64_t features, + const char **backend_args, GError **error); + +END_LIBGTOP_DECLS + +#endif diff --git a/include/glibtop/glibtop-client.h b/include/glibtop/glibtop-client.h index f07a46be..c3fc1e02 100644 --- a/include/glibtop/glibtop-client.h +++ b/include/glibtop/glibtop-client.h @@ -29,7 +29,7 @@ #include #include -#include +#include BEGIN_LIBGTOP_DECLS diff --git a/lib/Makefile.am b/lib/Makefile.am index 5202ce6b..32c99c2c 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -8,10 +8,9 @@ lib_LTLIBRARIES = libgtop.la noinst_LTLIBRARIES = libgtop_server.la -libgtop_la_SOURCES = errors.c backend.c \ - init-backends.c open-backend.c \ +libgtop_la_SOURCES = errors.c glibtop-backend-info.c \ glibtop-client.c glibtop-server.c \ - sysdeps-init.c + glibtop-backend.c sysdeps-init.c libgtop_server_la_SOURCES = error.c xmalloc.c diff --git a/lib/backend.c b/lib/backend.c deleted file mode 100644 index 8e000346..00000000 --- a/lib/backend.c +++ /dev/null @@ -1,93 +0,0 @@ -/* -*- 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 -#include - -#include - -static GHashTable *_glibtop_backend_list = NULL; -static long _glibtop_backend_nr = 0; - -long -glibtop_register_backend (glibtop_backend_entry *entry) -{ - long id; - - if (!_glibtop_backend_list) - _glibtop_backend_list = g_hash_table_new (NULL, NULL); - - id = ++_glibtop_backend_nr; - - g_hash_table_insert (_glibtop_backend_list, - GINT_TO_POINTER (id), - entry); - - return id; -} - -void -glibtop_unregister_backend (long id) -{ - g_hash_table_remove (_glibtop_backend_list, - GINT_TO_POINTER (id)); -} - -glibtop_backend_entry * -glibtop_backend_by_id (long id) -{ - return g_hash_table_lookup (_glibtop_backend_list, - GINT_TO_POINTER (id)); -} - -typedef struct { - const char *backend_name; - glibtop_backend_entry *entry; -} _find_by_name_param_t; - -static void -find_by_name (gpointer key, gpointer value, gpointer user_data) -{ - _find_by_name_param_t *param = (_find_by_name_param_t *) user_data; - glibtop_backend_entry *entry = (glibtop_backend_entry *) value; - - if (!entry || !entry->name || param->entry) - return; - - if (!strcmp (entry->name, param->backend_name)) - param->entry = entry; -} - -glibtop_backend_entry * -glibtop_backend_by_name (const char *backend_name) -{ - _find_by_name_param_t param = { backend_name, NULL }; - - g_hash_table_foreach (_glibtop_backend_list, - find_by_name, ¶m); - - return param.entry; -} diff --git a/lib/init-backends.c b/lib/glibtop-backend-info.c similarity index 78% rename from lib/init-backends.c rename to lib/glibtop-backend-info.c index 98dbf244..254d8ead 100644 --- a/lib/init-backends.c +++ b/lib/glibtop-backend-info.c @@ -25,9 +25,12 @@ #include #include -#include -#include +#include +#include + +static GHashTable *_glibtop_backend_list = NULL; +static long _glibtop_backend_nr = 0; #if HAVE_LIBXML @@ -225,3 +228,63 @@ _glibtop_init_gmodule_backends (const char *directory) } #endif /* HAVE_LIBXML */ + +long +glibtop_register_backend (glibtop_backend_entry *entry) +{ + long id; + + if (!_glibtop_backend_list) + _glibtop_backend_list = g_hash_table_new (NULL, NULL); + + id = ++_glibtop_backend_nr; + + g_hash_table_insert (_glibtop_backend_list, + GINT_TO_POINTER (id), + entry); + + return id; +} + +void +glibtop_unregister_backend (long id) +{ + g_hash_table_remove (_glibtop_backend_list, + GINT_TO_POINTER (id)); +} + +glibtop_backend_entry * +glibtop_backend_by_id (long id) +{ + return g_hash_table_lookup (_glibtop_backend_list, + GINT_TO_POINTER (id)); +} + +typedef struct { + const char *backend_name; + glibtop_backend_entry *entry; +} _find_by_name_param_t; + +static void +find_by_name (gpointer key, gpointer value, gpointer user_data) +{ + _find_by_name_param_t *param = (_find_by_name_param_t *) user_data; + glibtop_backend_entry *entry = (glibtop_backend_entry *) value; + + if (!entry || !entry->name || param->entry) + return; + + if (!strcmp (entry->name, param->backend_name)) + param->entry = entry; +} + +glibtop_backend_entry * +glibtop_backend_by_name (const char *backend_name) +{ + _find_by_name_param_t param = { backend_name, NULL }; + + g_hash_table_foreach (_glibtop_backend_list, + find_by_name, ¶m); + + return param.entry; +} diff --git a/lib/open-backend.c b/lib/glibtop-backend.c similarity index 59% rename from lib/open-backend.c rename to lib/glibtop-backend.c index a695f72a..d4564bd4 100644 --- a/lib/open-backend.c +++ b/lib/glibtop-backend.c @@ -3,7 +3,7 @@ /* $Id$ */ /* Copyright (C) 1998-99 Martin Baulig - This file is part of LibGTop 1.0. + This file is part of LibGTop 2.0. Contributed by Martin Baulig , April 1998. @@ -24,11 +24,90 @@ */ #include -#include -#include +#include +#include -#include +#include +#include + +static void glibtop_backend_class_init (glibtop_backend_class *klass); +static void glibtop_backend_init (glibtop_backend *backend); +static void glibtop_backend_finalize (GObject *object); + +static gpointer parent_class = NULL; + + +/* Internal data */ + +struct _glibtop_backend_private +{ + const glibtop_backend_info *info; + + glibtop_server *server; + glibtop_backend_module *module; +}; + +GType +glibtop_backend_get_type (void) +{ + static GType glibtop_backend_type = 0; + + if (!glibtop_backend_type) { + static const GTypeInfo glibtop_backend_info = { + sizeof (glibtop_backend_class), + NULL, /* base_class_init */ + NULL, /* base_class_finalize */ + (GClassInitFunc) glibtop_backend_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (glibtop_backend), + 16, /* n_preallocs */ + (GInstanceInitFunc) glibtop_backend_init, + }; + + glibtop_backend_type = g_type_register_static + (G_TYPE_OBJECT, "glibtop_backend", &glibtop_backend_info, 0); + } + + return glibtop_backend_type; +} + +static void +glibtop_backend_class_init (glibtop_backend_class *class) +{ + GObjectClass *gobject_class; + + gobject_class = (GObjectClass *) class; + + parent_class = g_type_class_ref (G_TYPE_OBJECT); + + gobject_class->finalize = glibtop_backend_finalize; +} + +static void +glibtop_backend_init (glibtop_backend *glibtop) +{ + glibtop_backend_private *priv; + + priv = g_new0 (glibtop_backend_private, 1); + glibtop->_priv = priv; +} + +static void +glibtop_backend_finalize (GObject *object) +{ + glibtop_backend *glibtop; + glibtop_backend_private *priv = NULL; + + glibtop = GLIBTOP_BACKEND (object); + priv = glibtop->_priv; + + g_free (priv); + + if (G_OBJECT_CLASS (parent_class)->finalize) + G_OBJECT_CLASS (parent_class)->finalize (object); +} static void unload_module (gpointer data, gpointer user_data) @@ -66,13 +145,15 @@ load_extra_libs (glibtop_backend_entry *entry, GError **error) } glibtop_backend * -glibtop_open_backend (const char *backend_name, u_int64_t features, +glibtop_backend_open (const char *backend_name, u_int64_t features, const char **backend_args, GError **error) { const glibtop_backend_info *info; glibtop_backend_entry *entry; glibtop_backend *backend; + glibtop_init_backends (); + entry = glibtop_backend_by_name (backend_name); if (!entry) { g_set_error (error, GLIBTOP_ERROR, GLIBTOP_ERROR_NO_SUCH_BACKEND, @@ -124,23 +205,23 @@ glibtop_open_backend (const char *backend_name, u_int64_t features, return NULL; } - backend = g_new0 (glibtop_backend, 1); - backend->_priv_module = entry->_priv; - backend->info = info; + backend = g_object_new (GLIBTOP_TYPE_BACKEND, NULL); - backend->server = glibtop_server_new (); + backend->_priv->module = entry->_priv; + backend->_priv->info = info; + + backend->_priv->server = glibtop_server_new (); if (info->open) { int retval; - retval = info->open (backend->server, backend, features, backend_args); + retval = info->open (backend->_priv->server, backend, features, + backend_args); if (retval) { g_set_error (error, GLIBTOP_ERROR, GLIBTOP_ERROR_NO_SUCH_BACKEND, "Backend open function return error condition"); - glibtop_server_unref (backend->server); - g_free (backend->_priv); - g_free (backend); + g_object_unref (G_OBJECT (backend)); return NULL; } } @@ -149,4 +230,3 @@ glibtop_open_backend (const char *backend_name, u_int64_t features, return backend; } - diff --git a/lib/glibtop-client.c b/lib/glibtop-client.c index 43f37d87..25d246a1 100644 --- a/lib/glibtop-client.c +++ b/lib/glibtop-client.c @@ -262,7 +262,7 @@ glibtop_client_open_backend (glibtop_client *client, const char *backend_name, g_return_val_if_fail (GLIBTOP_IS_CLIENT (client), NULL); - backend = glibtop_open_backend (backend_name, features, backend_args, + backend = glibtop_backend_open (backend_name, features, backend_args, &error); if (!backend) { glibtop_client_propagate_error (client, error); @@ -280,7 +280,7 @@ glibtop_client_add_backend (glibtop_client *client, glibtop_backend *backend) { g_return_if_fail (GLIBTOP_IS_CLIENT (client)); - g_return_if_fail (backend != NULL); + g_return_if_fail (GLIBTOP_IS_BACKEND (backend)); } @@ -289,6 +289,6 @@ glibtop_client_remove_backend (glibtop_client *client, glibtop_backend *backend) { g_return_if_fail (GLIBTOP_IS_CLIENT (client)); - g_return_if_fail (backend != NULL); + g_return_if_fail (GLIBTOP_IS_BACKEND (backend)); } diff --git a/lib/sysdeps-init-freebsd.c b/lib/sysdeps-init-freebsd.c index 0ff69857..633493ec 100644 --- a/lib/sysdeps-init-freebsd.c +++ b/lib/sysdeps-init-freebsd.c @@ -25,7 +25,7 @@ #include #include -#include +#include #include diff --git a/lib/sysdeps-init-kernel.c b/lib/sysdeps-init-kernel.c index 5d35638b..42eee110 100644 --- a/lib/sysdeps-init-kernel.c +++ b/lib/sysdeps-init-kernel.c @@ -25,7 +25,7 @@ #include #include -#include +#include #include diff --git a/lib/sysdeps-init-linux.c b/lib/sysdeps-init-linux.c index ea87d3ed..098092b1 100644 --- a/lib/sysdeps-init-linux.c +++ b/lib/sysdeps-init-linux.c @@ -25,7 +25,7 @@ #include #include -#include +#include #include diff --git a/lib/sysdeps-init-osf1.c b/lib/sysdeps-init-osf1.c index 07f10544..9ea0fd7c 100644 --- a/lib/sysdeps-init-osf1.c +++ b/lib/sysdeps-init-osf1.c @@ -25,7 +25,7 @@ #include #include -#include +#include #include diff --git a/lib/sysdeps-init-solaris.c b/lib/sysdeps-init-solaris.c index 07f10544..9ea0fd7c 100644 --- a/lib/sysdeps-init-solaris.c +++ b/lib/sysdeps-init-solaris.c @@ -25,7 +25,7 @@ #include #include -#include +#include #include diff --git a/lib/sysdeps-init-stub-suid.c b/lib/sysdeps-init-stub-suid.c index ac226f27..dc294d12 100644 --- a/lib/sysdeps-init-stub-suid.c +++ b/lib/sysdeps-init-stub-suid.c @@ -25,7 +25,7 @@ #include #include -#include +#include #include diff --git a/lib/sysdeps-init-stub.c b/lib/sysdeps-init-stub.c index 718d8642..dad20445 100644 --- a/lib/sysdeps-init-stub.c +++ b/lib/sysdeps-init-stub.c @@ -25,7 +25,7 @@ #include #include -#include +#include #include diff --git a/lib/test-backends.c b/lib/test-backends.c index 036c90cd..c43c0198 100644 --- a/lib/test-backends.c +++ b/lib/test-backends.c @@ -24,7 +24,7 @@ */ #include -#include +#include #include @@ -38,8 +38,6 @@ main (int argc, char *argv []) g_type_init (); - glibtop_init_backends (); - client = glibtop_client_new (); backend_common = glibtop_client_open_backend