Renamed to glibtop_backend_get(). (glibtop_backend_get_server): New

2000-11-26  Martin Baulig  <martin@home-of-linux.org>

	* include/glibtop/glibtop-backend.h (glibtop_backend_open):
	Renamed to glibtop_backend_get().
	(glibtop_backend_get_server): New function.
This commit is contained in:
Martin Baulig
2000-11-26 22:58:47 +00:00
committed by Martin Baulig
parent 455118131e
commit 622eb0ea5b
7 changed files with 85 additions and 41 deletions

View File

@@ -1,5 +1,9 @@
2000-11-26 Martin Baulig <martin@home-of-linux.org>
* include/glibtop/glibtop-backend.h (glibtop_backend_open):
Renamed to glibtop_backend_get().
(glibtop_backend_get_server): New function.
* include/glibtop/glibtop-backend.h
(glibtop_backend_get_call_vector): New function.

View File

@@ -65,12 +65,15 @@ GType
glibtop_backend_get_type (void);
glibtop_backend *
glibtop_backend_open (const char *backend_name, u_int64_t features,
glibtop_backend_get (const char *backend_name, u_int64_t features,
const char **backend_args, GError **error);
glibtop_call_vector *
glibtop_backend_get_call_vector (glibtop_backend *backend);
glibtop_server *
glibtop_backend_get_server (glibtop_backend *backend);
END_LIBGTOP_DECLS
#endif

View File

@@ -10,13 +10,11 @@ noinst_LTLIBRARIES = libgtop_server.la
libgtop_la_SOURCES = errors.c glibtop-backend-info.c \
glibtop-client.c glibtop-server.c \
glibtop-backend.c sysdeps-init.c \
glibtop-client-private.h
glibtop-backend.c glibtop-client-private.h \
$(BUILT_SOURCES)
libgtop_server_la_SOURCES = error.c xmalloc.c
libgtop_server_la_LDFLAGS = $(LT_VERSION_INFO)
libgtop_la_LDFLAGS = $(LT_VERSION_INFO)
libgtop_la_LIBADD = $(GLIB_LIBS) $(XML_LIBS)

View File

@@ -86,12 +86,14 @@ glibtop_backend_class_init (glibtop_backend_class *class)
}
static void
glibtop_backend_init (glibtop_backend *glibtop)
glibtop_backend_init (glibtop_backend *backend)
{
glibtop_backend_private *priv;
g_message (G_STRLOC ": %p", backend);
priv = g_new0 (glibtop_backend_private, 1);
glibtop->_priv = priv;
backend->_priv = priv;
}
static void
@@ -103,6 +105,8 @@ glibtop_backend_finalize (GObject *object)
glibtop = GLIBTOP_BACKEND (object);
priv = glibtop->_priv;
g_message (G_STRLOC);
g_free (priv);
if (G_OBJECT_CLASS (parent_class)->finalize)
@@ -145,7 +149,7 @@ load_extra_libs (glibtop_backend_entry *entry, GError **error)
}
glibtop_backend *
glibtop_backend_open (const char *backend_name, u_int64_t features,
glibtop_backend_get (const char *backend_name, u_int64_t features,
const char **backend_args, GError **error)
{
const glibtop_backend_info *info;
@@ -212,6 +216,8 @@ glibtop_backend_open (const char *backend_name, u_int64_t features,
backend->_priv->server = glibtop_server_new ();
g_message (G_STRLOC ": %p - %p - %p", backend, backend->_priv, info);
if (info->open) {
int retval;
@@ -236,7 +242,21 @@ glibtop_backend_get_call_vector (glibtop_backend *backend)
{
g_return_val_if_fail (GLIBTOP_IS_BACKEND (backend), NULL);
g_message (G_STRLOC ": %p - %p - %p", backend, backend->_priv,
backend->_priv->info);
g_assert (backend->_priv->info != NULL);
return backend->_priv->info->call_vector;
}
glibtop_server *
glibtop_backend_get_server (glibtop_backend *backend)
{
g_return_val_if_fail (GLIBTOP_IS_BACKEND (backend), NULL);
glibtop_server_ref (backend->_priv->server);
return backend->_priv->server;
}

View File

@@ -262,7 +262,7 @@ glibtop_client_open_backend (glibtop_client *client, const char *backend_name,
g_return_if_fail (GLIBTOP_IS_CLIENT (client));
backend = glibtop_backend_open (backend_name, features, backend_args,
backend = glibtop_backend_get (backend_name, features, backend_args,
&error);
if (!backend) {
glibtop_client_propagate_error (client, error);

View File

@@ -31,32 +31,38 @@ print '';
print '#include <glibtop/sysdeps.h>';
print '#include <glibtop/union.h>';
print '';
print '#include <glibtop/backend.h>';
print '#include <glibtop/glibtop-client.h>';
print '';
print '#include <glibtop/call-vector.h>';
print '#include <glibtop-client-private.h>';
print '';
print '/* Some required fields are missing. */';
print '';
print '#if 0';
print '';
print 'static void';
print '_glibtop_missing_feature (glibtop *server, const char *feature,';
print '_glibtop_missing_feature (glibtop_client *client, const char *feature,';
print "\t\t\t const u_int64_t present, u_int64_t *required)";
print '{';
print "\tu_int64_t old_required = *required;\n";
print "\t/* Return if we have all required fields. */";
print "\tif ((~present & old_required) == 0)";
print "\t\treturn;\n";
print "\tswitch (server->_param.error_method) {";
print "\tswitch (client->_param.error_method) {";
print "\tcase GLIBTOP_ERROR_METHOD_WARN_ONCE:";
print "\t\t*required &= present;";
print "\tcase GLIBTOP_ERROR_METHOD_WARN:";
print "\t\tglibtop_warn_r (server,";
print "\t\tglibtop_warn_r (client,";
print "\t\t\t\t\"glibtop_get_%s (): Client requested \"";
print "\t\t\t\t\"field mask %05lx, but only have %05lx.\",";
print "\t\t\t\t feature, (unsigned long) old_required,";
print "\t\t\t\t (unsigned long) present);";
print "\t\tbreak;";
print "\tcase GLIBTOP_ERROR_METHOD_ABORT:";
print "\t\tglibtop_error_r (server,";
print "\t\tglibtop_error_r (client,";
print "\t\t\t\t\"glibtop_get_%s (): Client requested \"";
print "\t\t\t\t\"field mask %05lx, but only have %05lx.\",";
print "\t\t\t\t feature, (unsigned long) old_required,";
@@ -65,6 +71,9 @@ print "\t\tbreak;";
print "\t}";
print '}';
print '';
print '#endif';
print '';
print '/* Library functions. */';
print '';
@@ -151,14 +160,14 @@ sub output {
}
}
$local_var_code = sprintf ("\tGSList *list;\n\tint done = 0;\n");
$local_var_code = "\tGSList *list;\n\tint done = 0;\n\tGError *error = NULL;\n\n";
if ($retval !~ /^void$/) {
$local_var_code .= sprintf ("\t%s retval = (%s) 0;\n",
$retval, $retval);
}
$sysdeps_code = sprintf
("\tif (!server->_priv) {\n\t\tserver->glibtop_errno = GLIBTOP_ERROR_NO_BACKEND_OPENED;\n");
("\tif (client->_priv->backend_list == NULL) {\n\t\tg_set_error (&error, GLIBTOP_ERROR, GLIBTOP_ERROR_NO_BACKEND_OPENED, G_STRLOC);\n");
if ($line_fields[1] eq 'retval') {
$sysdeps_code .= sprintf
("\t\treturn -GLIBTOP_ERROR_NO_BACKEND_OPENED;\n");
@@ -170,31 +179,31 @@ sub output {
("\t}\n\n");
$sysdeps_code .= sprintf
("\tfor (list = server->_priv->backend_list;\n\t list; list = list->next) {\n\t\tglibtop_backend *backend = list->data;\n\n\t\tif (!backend->info || !backend->info->call_vector)\n\t\t\tcontinue;\n\n\t\tif (backend->info->call_vector->%s) {\n", $feature);
("\tfor (list = client->_priv->backend_list; list; list = list->next) {\n\t\tglibtop_backend *backend = list->data;\n\t\tglibtop_call_vector *call_vector;\n\n\t\tcall_vector = glibtop_backend_get_call_vector (backend);\n\n\t\tif (call_vector && call_vector->%s) {\n\t\t\tglibtop_server *server = glibtop_backend_get_server (backend);\n\n", $feature);
if ($line_fields[3] eq '') {
$sysdeps_code .= sprintf
("\t\t\tretval = backend->info->call_vector->%s (server, backend%s);\n",
("\t\t\tretval = call_vector->%s (server, backend%s);\n",
$feature, $call_param);
} elsif ($line_fields[3] eq 'array') {
$sysdeps_code .= sprintf
("\t\t\tretval = backend->info->call_vector->%s (server, backend, array%s);\n",
("\t\t\tretval = call_vector->%s (server, backend, array%s);\n",
$feature, $call_param);
} elsif ($line_fields[3] =~ /^array/) {
$sysdeps_code .= sprintf
("\t\t\tretval = backend->info->call_vector->%s (server, backend, array, buf%s);\n",
("\t\t\tretval = call_vector->%s (server, backend, array, buf%s);\n",
$feature, $call_param);
} else {
$sysdeps_code .= sprintf
("\t\t\tretval = backend->info->call_vector->%s (server, backend, buf%s);\n",
("\t\t\tretval = call_vector->%s (server, backend, buf%s);\n",
$feature, $call_param);
}
$sysdeps_code .= sprintf
("\t\t\tdone = 1;\n\t\t\tbreak;\n\t\t}\n\t}\n");
("\t\t\tdone = 1;\n\t\t\tglibtop_server_unref (server);\n\t\t\t\tbreak;\n\t\t}\n\t}\n");
$sysdeps_code .= sprintf
("\n\tif (!done) {\n\t\tserver->glibtop_errno = GLIBTOP_ERROR_NOT_IMPLEMENTED;\n");
("\n\tif (!done) {\n\t\tg_set_error (&error, GLIBTOP_ERROR, GLIBTOP_ERROR_NOT_IMPLEMENTED, G_STRLOC);\n");
if ($line_fields[1] eq 'retval') {
$sysdeps_code .= sprintf
("\t\treturn -GLIBTOP_ERROR_NOT_IMPLEMENTED;\n");
@@ -207,24 +216,25 @@ sub output {
if ($line_fields[1] eq 'retval') {
$sysdeps_code .= "\tif (retval < 0) {\n";
$sysdeps_code .= "\t\tserver->glibtop_errno = -retval;\n";
$sysdeps_code .= "\t\tg_set_error (&error, GLIBTOP_ERROR, -retval, G_STRLOC);\n";
$sysdeps_code .= "\t\tgoto do_return;\n";
$sysdeps_code .= "\t} else {\n\t\tserver->glibtop_errno = 0;\n\t}\n\n";
$sysdeps_code .= "\t}\n\n";
}
$sysdeps_code .= "\tgoto check_missing;\n";
$init_code = sprintf ("\tglibtop_init_r (&server, (1 << %s), 0);\n\n",
"GLIBTOP_SYSDEPS_".&toupper($feature));
# $init_code = sprintf ("\tglibtop_init_r (&client, (1 << %s), 0);\n\n",
# "GLIBTOP_SYSDEPS_".&toupper($feature));
$init_code = '';
$total_code = sprintf ("%s%s\n", $init_code, $sysdeps_code);
$check_code = "check_missing:\n";
$check_code .= "\t/* Make sure that all required fields are present. */\n";
if (!(($line_fields[3] eq '') or ($line_fields[3] eq 'array'))) {
$check_code .= "\tif (buf->flags & server->info->required." . $feature . ")\n";
$check_code .= "\t\t_glibtop_missing_feature (server, \"" . $feature .
"\", buf->flags,\n\t\t\t\t\t &server->info->required." . $feature . ");\n";
# $check_code .= "\tif (buf->flags & client->info->required." . $feature . ")\n";
# $check_code .= "\t\t_glibtop_missing_feature (client, \"" . $feature .
"\", buf->flags,\n\t\t\t\t\t &client->info->required." . $feature . ");\n";
}
$total_code .= $check_code."\tgoto do_return;\n\n";
@@ -240,16 +250,16 @@ sub output {
$func_decl = $retval."\n";
if ($line_fields[3] eq '') {
$func_decl .= sprintf ("glibtop_get_%s_l (glibtop *server%s)\n",
$func_decl .= sprintf ("glibtop_get_%s_l (glibtop_client *client%s)\n",
$feature, $param_decl);
} elsif ($line_fields[3] eq 'array') {
$func_decl .= sprintf ("glibtop_get_%s_l (glibtop *server, glibtop_array *array%s)\n",
$func_decl .= sprintf ("glibtop_get_%s_l (glibtop_client *client, glibtop_array *array%s)\n",
$feature, $param_decl);
} elsif ($line_fields[3] =~ /^array/) {
$func_decl .= sprintf ("glibtop_get_%s_l (glibtop *server, glibtop_array *array, %s *buf%s)\n",
$func_decl .= sprintf ("glibtop_get_%s_l (glibtop_client *client, glibtop_array *array, %s *buf%s)\n",
$feature, 'glibtop_'.$feature, $param_decl);
} else {
$func_decl .= sprintf ("glibtop_get_%s_l (glibtop *server, %s *buf%s)\n",
$func_decl .= sprintf ("glibtop_get_%s_l (glibtop_client *client, %s *buf%s)\n",
$feature, 'glibtop_'.$feature, $param_decl);
}

View File

@@ -34,12 +34,13 @@ main (int argc, char *argv [])
glibtop_backend *backend_common;
glibtop_backend *backend_sysdeps;
GError *error = NULL;
glibtop_cpu cpu;
g_type_init ();
client = glibtop_client_new ();
backend_common = glibtop_backend_open ("glibtop-backend-common",
backend_common = glibtop_backend_get ("glibtop-backend-common",
0, NULL, &error);
if (error != NULL) {
@@ -50,7 +51,10 @@ main (int argc, char *argv [])
g_message (G_STRLOC ": backend = %p", backend_common);
backend_sysdeps = glibtop_backend_open ("glibtop-backend-sysdeps",
if (backend_common != NULL)
glibtop_client_add_backend (client, backend_common);
backend_sysdeps = glibtop_backend_get ("glibtop-backend-sysdeps",
0, NULL, &error);
if (error != NULL) {
@@ -61,5 +65,10 @@ main (int argc, char *argv [])
g_message (G_STRLOC ": backend = %p", backend_sysdeps);
if (backend_sysdeps != NULL)
glibtop_client_add_backend (client, backend_sysdeps);
glibtop_get_cpu_l (client, &cpu);
exit (0);
}