diff --git a/ChangeLog b/ChangeLog index aec76d7c..483c6eba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2000-11-26 Martin Baulig + * include/glibtop/glibtop-client.h (glibtop_client_open_backend): + Changed return value to void. + + * lib/glibtop-client.c: Implement glibtop_client_add_backend() and + glibtop_client_remove_backend(). + * include/glibtop/backend.h: Removed. Split into glibtop-backend.h and glibtop-backend-info.h. diff --git a/include/glibtop/glibtop-client.h b/include/glibtop/glibtop-client.h index c3fc1e02..6a3c6c2b 100644 --- a/include/glibtop/glibtop-client.h +++ b/include/glibtop/glibtop-client.h @@ -79,7 +79,7 @@ glibtop_client_propagate_error (glibtop_client *client, GError *error); void glibtop_client_propagate_warning (glibtop_client *client, GError *error); -glibtop_backend * +void glibtop_client_open_backend (glibtop_client *client, const char *backend_name, u_int64_t features, const char **backend_args); diff --git a/lib/glibtop-client.c b/lib/glibtop-client.c index 25d246a1..5aadb44d 100644 --- a/lib/glibtop-client.c +++ b/lib/glibtop-client.c @@ -39,6 +39,7 @@ static gpointer parent_class = NULL; struct _glibtop_client_private { + GSList *backend_list; }; enum { @@ -189,9 +190,14 @@ glibtop_client_finalize (GObject *object) { glibtop_client *glibtop; glibtop_client_private *priv = NULL; + GSList *c; glibtop = GLIBTOP_CLIENT (object); priv = glibtop->_priv; + + for (c = priv->backend_list; c; c = c->next) + g_object_unref (G_OBJECT (c->data)); + g_slist_free (priv->backend_list); g_free (priv); @@ -253,26 +259,24 @@ glibtop_client_propagate_warning (glibtop_client *client, GError *error) g_value_unset (params + 0); } -glibtop_backend * +void glibtop_client_open_backend (glibtop_client *client, const char *backend_name, u_int64_t features, const char **backend_args) { glibtop_backend *backend; GError *error = NULL; - g_return_val_if_fail (GLIBTOP_IS_CLIENT (client), NULL); + g_return_if_fail (GLIBTOP_IS_CLIENT (client)); backend = glibtop_backend_open (backend_name, features, backend_args, &error); if (!backend) { glibtop_client_propagate_error (client, error); g_error_free (error); - return NULL; + return; } glibtop_client_add_backend (client, backend); - - return backend; } void @@ -282,13 +286,22 @@ glibtop_client_add_backend (glibtop_client *client, g_return_if_fail (GLIBTOP_IS_CLIENT (client)); g_return_if_fail (GLIBTOP_IS_BACKEND (backend)); + client->_priv->backend_list = g_slist_append + (client->_priv->backend_list, backend); } void glibtop_client_remove_backend (glibtop_client *client, glibtop_backend *backend) { + GSList *c; + g_return_if_fail (GLIBTOP_IS_CLIENT (client)); g_return_if_fail (GLIBTOP_IS_BACKEND (backend)); + c = g_slist_find (client->_priv->backend_list, backend); + if (!c) return; + + g_slist_remove_link (client->_priv->backend_list, c); + g_object_unref (G_OBJECT (backend)); } diff --git a/lib/test-backends.c b/lib/test-backends.c index c43c0198..a5e17757 100644 --- a/lib/test-backends.c +++ b/lib/test-backends.c @@ -24,7 +24,6 @@ */ #include -#include #include @@ -34,23 +33,33 @@ main (int argc, char *argv []) glibtop_client *client; glibtop_backend *backend_common; glibtop_backend *backend_sysdeps; - /* glibtop_cpu cpu; */ + GError *error = NULL; g_type_init (); client = glibtop_client_new (); - backend_common = glibtop_client_open_backend - (client, "glibtop-backend-common", 0, NULL); + backend_common = glibtop_backend_open ("glibtop-backend-common", + 0, NULL, &error); + + if (error != NULL) { + glibtop_client_propagate_warning (client, error); + g_error_free (error); + error = NULL; + } g_message (G_STRLOC ": backend = %p", backend_common); - backend_sysdeps = glibtop_client_open_backend - (client, "glibtop-backend-sysdeps", 0, NULL); + backend_sysdeps = glibtop_backend_open ("glibtop-backend-sysdeps", + 0, NULL, &error); + + if (error != NULL) { + glibtop_client_propagate_warning (client, error); + g_error_free (error); + error = NULL; + } g_message (G_STRLOC ": backend = %p", backend_sysdeps); - /* glibtop_get_cpu_l (client, &cpu); */ - exit (0); }