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.
This commit is contained in:
Martin Baulig
2000-11-22 21:15:28 +00:00
committed by Martin Baulig
parent 9ab1889a3f
commit f704c4becf
4 changed files with 62 additions and 22 deletions

View File

@@ -1,3 +1,9 @@
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.
2000-11-22 Martin Baulig <martin@home-of-linux.org> 2000-11-22 Martin Baulig <martin@home-of-linux.org>
* include/glibtop/glibtop-client.h (glibtop_client_class): * include/glibtop/glibtop-client.h (glibtop_client_class):

View File

@@ -113,7 +113,7 @@ glibtop_init_backends (void);
glibtop_backend * glibtop_backend *
glibtop_open_backend_l (glibtop_client *client, const char *backend_name, glibtop_open_backend_l (glibtop_client *client, const char *backend_name,
u_int64_t features, const char **backend_args, u_int64_t features, const char **backend_args,
GError **error); GError **opt_error);
END_LIBGTOP_DECLS END_LIBGTOP_DECLS

View File

@@ -69,16 +69,29 @@ load_extra_libs (glibtop_client *client, glibtop_backend_entry *entry,
glibtop_backend * glibtop_backend *
glibtop_open_backend_l (glibtop_client *client, const char *backend_name, glibtop_open_backend_l (glibtop_client *client, const char *backend_name,
u_int64_t features, const char **backend_args, u_int64_t features, const char **backend_args,
GError **error) GError **opt_error)
{ {
const glibtop_backend_info *info; const glibtop_backend_info *info;
glibtop_backend_entry *entry; glibtop_backend_entry *entry;
glibtop_backend *backend; glibtop_backend *backend;
GError **error, *my_error = NULL;
g_return_val_if_fail (GLIBTOP_IS_CLIENT (client), 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); 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) { if (!entry->_priv) {
entry->_priv = g_new0 (glibtop_backend_module, 1); 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; int retval;
retval = load_extra_libs (client, entry, error); 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, 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' " "Cannot open shared library `%s' "
"for backend `%s' (%s)", entry->shlib_name, "for backend `%s' (%s)", entry->shlib_name,
entry->name, g_module_error ()); entry->name, g_module_error ());
if (my_error != NULL) {
glibtop_client_propagate_error (client, my_error);
g_error_free (my_error);
}
return NULL; return NULL;
} }
@@ -108,6 +131,11 @@ glibtop_open_backend_l (glibtop_client *client, const char *backend_name,
"LibGTop Backend library (start symbol not found)", "LibGTop Backend library (start symbol not found)",
entry->shlib_name); 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_module_close (entry->_priv->module);
g_free (entry->_priv); g_free (entry->_priv);
entry->_priv = NULL; entry->_priv = NULL;
@@ -119,7 +147,15 @@ glibtop_open_backend_l (glibtop_client *client, const char *backend_name,
entry->_priv->refcount++; entry->_priv->refcount++;
info = entry->info; 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 = g_new0 (glibtop_backend, 1);
backend->_priv_module = entry->_priv; 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); retval = info->open (backend->server, backend, features, backend_args);
if (retval) { 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); glibtop_server_unref (backend->server);
g_free (backend->_priv); g_free (backend->_priv);
g_free (backend); 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; return backend;
} }

View File

@@ -32,7 +32,6 @@ main (int argc, char *argv [])
glibtop_client *client; glibtop_client *client;
glibtop_backend *backend_common; glibtop_backend *backend_common;
glibtop_backend *backend_sysdeps; glibtop_backend *backend_sysdeps;
GError *error = NULL;
g_type_init (); g_type_init ();
@@ -41,26 +40,14 @@ main (int argc, char *argv [])
client = glibtop_client_new (); client = glibtop_client_new ();
backend_common = glibtop_open_backend_l (client, "glibtop-backend-common", 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); g_message (G_STRLOC ": backend = %p", backend_common);
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", backend_sysdeps = glibtop_open_backend_l (client, "glibtop-backend-sysdeps",
0, NULL, &error); 0, NULL, NULL);
g_message (G_STRLOC ": backend = %p (%p)", backend_sysdeps, error); g_message (G_STRLOC ": backend = %p", backend_sysdeps);
if (error != NULL) {
glibtop_client_propagate_error (client, error);
g_error_free (error);
error = NULL;
}
exit (0); exit (0);
} }