diff options
author | Martin Baulig <martin@home-of-linux.org> | 2000-11-22 21:15:28 +0000 |
---|---|---|
committer | Martin Baulig <martin@src.gnome.org> | 2000-11-22 21:15:28 +0000 |
commit | f704c4becf992767dcdd819e07e48b5657d1d4ec (patch) | |
tree | 1d682029c582cd228bac92b1b8ac2d7e47231784 /lib | |
parent | 9ab1889a3f3a210e80ea4da29ac3e17485003f37 (diff) | |
download | libgtop-f704c4becf992767dcdd819e07e48b5657d1d4ec.tar.gz |
Allow the `error' argument to be NULL; propagate the error to the
2000-11-22 Martin Baulig <martin@home-of-linux.org>
* include/glibtop/backends.h (glibtop_open_backend_l): Allow
the `error' argument to be NULL; propagate the error to the
glibtop_client in this case.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/open-backend.c | 55 | ||||
-rw-r--r-- | lib/test-backends.c | 21 |
2 files changed, 55 insertions, 21 deletions
diff --git a/lib/open-backend.c b/lib/open-backend.c index 9caae1cc..aeb6cffb 100644 --- a/lib/open-backend.c +++ b/lib/open-backend.c @@ -69,16 +69,29 @@ load_extra_libs (glibtop_client *client, glibtop_backend_entry *entry, glibtop_backend * glibtop_open_backend_l (glibtop_client *client, const char *backend_name, u_int64_t features, const char **backend_args, - GError **error) + GError **opt_error) { const glibtop_backend_info *info; glibtop_backend_entry *entry; glibtop_backend *backend; + GError **error, *my_error = NULL; g_return_val_if_fail (GLIBTOP_IS_CLIENT (client), NULL); + if (opt_error == NULL) + error = &my_error; + else + error = opt_error; + entry = glibtop_backend_by_name (backend_name); - if (!entry) return NULL; + if (!entry) { + g_set_error (error, GLIBTOP_ERROR, GLIBTOP_ERROR_NO_SUCH_BACKEND, + "No backend with this name"); + if (my_error != NULL) { + glibtop_client_propagate_error (client, my_error); + g_error_free (my_error); + } + } if (!entry->_priv) { entry->_priv = g_new0 (glibtop_backend_module, 1); @@ -87,7 +100,13 @@ glibtop_open_backend_l (glibtop_client *client, const char *backend_name, int retval; retval = load_extra_libs (client, entry, error); - if (retval < 0) return NULL; + if (retval < 0) { + if (my_error != NULL) { + glibtop_client_propagate_error (client, my_error); + g_error_free (my_error); + } + return NULL; + } } entry->_priv->module = g_module_open (entry->shlib_name, @@ -97,6 +116,10 @@ glibtop_open_backend_l (glibtop_client *client, const char *backend_name, "Cannot open shared library `%s' " "for backend `%s' (%s)", entry->shlib_name, entry->name, g_module_error ()); + if (my_error != NULL) { + glibtop_client_propagate_error (client, my_error); + g_error_free (my_error); + } return NULL; } @@ -108,6 +131,11 @@ glibtop_open_backend_l (glibtop_client *client, const char *backend_name, "LibGTop Backend library (start symbol not found)", entry->shlib_name); + if (my_error != NULL) { + glibtop_client_propagate_error (client, my_error); + g_error_free (my_error); + } + g_module_close (entry->_priv->module); g_free (entry->_priv); entry->_priv = NULL; @@ -119,7 +147,15 @@ glibtop_open_backend_l (glibtop_client *client, const char *backend_name, entry->_priv->refcount++; info = entry->info; - if (!info) return NULL; + if (!info) { + g_set_error (error, GLIBTOP_ERROR, GLIBTOP_ERROR_NO_SUCH_BACKEND, + "Can't get backend info"); + if (my_error != NULL) { + glibtop_client_propagate_error (client, my_error); + g_error_free (my_error); + } + return NULL; + } backend = g_new0 (glibtop_backend, 1); backend->_priv_module = entry->_priv; @@ -132,6 +168,13 @@ glibtop_open_backend_l (glibtop_client *client, const char *backend_name, retval = info->open (backend->server, backend, features, backend_args); if (retval) { + g_set_error (error, GLIBTOP_ERROR, GLIBTOP_ERROR_NO_SUCH_BACKEND, + "Backend open function return error condition"); + if (my_error != NULL) { + glibtop_client_propagate_error (client, my_error); + g_error_free (my_error); + } + glibtop_server_unref (backend->server); g_free (backend->_priv); g_free (backend); @@ -139,5 +182,9 @@ glibtop_open_backend_l (glibtop_client *client, const char *backend_name, } } + if (my_error != NULL) + g_error_free (my_error); + return backend; } + diff --git a/lib/test-backends.c b/lib/test-backends.c index de50114f..b98accc2 100644 --- a/lib/test-backends.c +++ b/lib/test-backends.c @@ -32,7 +32,6 @@ main (int argc, char *argv []) glibtop_client *client; glibtop_backend *backend_common; glibtop_backend *backend_sysdeps; - GError *error = NULL; g_type_init (); @@ -41,26 +40,14 @@ main (int argc, char *argv []) client = glibtop_client_new (); backend_common = glibtop_open_backend_l (client, "glibtop-backend-common", - 0, NULL, &error); + 0, NULL, NULL); - 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; - } + g_message (G_STRLOC ": backend = %p", backend_common); backend_sysdeps = glibtop_open_backend_l (client, "glibtop-backend-sysdeps", - 0, NULL, &error); - - g_message (G_STRLOC ": backend = %p (%p)", backend_sysdeps, error); + 0, NULL, NULL); - if (error != NULL) { - glibtop_client_propagate_error (client, error); - g_error_free (error); - error = NULL; - } + g_message (G_STRLOC ": backend = %p", backend_sysdeps); exit (0); } |