From 57d102425fcbc8127c927b9d8af2e7fd58398fd4 Mon Sep 17 00:00:00 2001 From: Martin Baulig Date: Sun, 2 Jan 2000 12:53:53 +0000 Subject: [PATCH] All functions in the `glibtop_call_vector' now take an additional 2000-01-02 Martin Baulig * include/glibtop/call-vector.pl: All functions in the `glibtop_call_vector' now take an additional `glibtop_backend *' argument. --- ChangeLog | 6 + backends/server/command.c | 24 +-- backends/server/glibtop-backend-private.h | 5 + backends/server/marshal.pl | 12 +- backends/sysdeps/ChangeLog | 5 + backends/sysdeps/Makefile.am | 13 +- backends/sysdeps/marshal.pl | 178 ++++++++++++++++++++++ include/glibtop/backend.h | 4 +- include/glibtop/call-vector.pl | 8 +- lib/lib.pl | 8 +- 10 files changed, 235 insertions(+), 28 deletions(-) create mode 100644 backends/sysdeps/marshal.pl diff --git a/ChangeLog b/ChangeLog index 78115fa5..e4b57644 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2000-01-02 Martin Baulig + + * include/glibtop/call-vector.pl: All functions in the + `glibtop_call_vector' now take an additional `glibtop_backend *' + argument. + 2000-01-01 Martin Baulig * backends/: New directory. diff --git a/backends/server/command.c b/backends/server/command.c index 5bbdc75f..5ef4afc5 100644 --- a/backends/server/command.c +++ b/backends/server/command.c @@ -23,17 +23,19 @@ Boston, MA 02111-1307, USA. */ -#include -#include -#include - #include #include +#include +#include +#include + +#include + void * -glibtop_call_l (glibtop *server, unsigned command, size_t send_size, - const void *send_buf, size_t recv_size, void *recv_buf, - int *retval_ptr) +glibtop_call_i (glibtop *server, glibtop_backend *backend, unsigned command, + size_t send_size, const void *send_buf, size_t recv_size, + void *recv_buf, int *retval_ptr) { glibtop_command cmnd; glibtop_response response; @@ -56,16 +58,16 @@ glibtop_call_l (glibtop *server, unsigned command, size_t send_size, cmnd.data_size = send_size; } - glibtop_write_l (server, sizeof (glibtop_command), &cmnd); + glibtop_write_i (server, backend, sizeof (glibtop_command), &cmnd); - glibtop_read_l (server, sizeof (glibtop_response), &response); + glibtop_read_i (server, backend, sizeof (glibtop_response), &response); #ifdef DEBUG fprintf (stderr, "RESPONSE: %lu - %d\n", response.offset, response.data_size); #endif - glibtop_read_l (server, sizeof (int), &retval); + glibtop_read_i (server, backend, sizeof (int), &retval); if (retval_ptr) *retval_ptr = retval; @@ -76,7 +78,7 @@ glibtop_call_l (glibtop *server, unsigned command, size_t send_size, if (response.data_size) { void *ptr = glibtop_malloc_r (server, response.data_size); - glibtop_read_l (server, response.data_size, ptr); + glibtop_read_i (server, backend, response.data_size, ptr); return ptr; } diff --git a/backends/server/glibtop-backend-private.h b/backends/server/glibtop-backend-private.h index 1861a456..055d107b 100644 --- a/backends/server/glibtop-backend-private.h +++ b/backends/server/glibtop-backend-private.h @@ -34,6 +34,11 @@ struct _glibtop_backend_private pid_t pid; /* PID of the server */ }; +void * +glibtop_call_i (glibtop *server, glibtop_backend *backend, unsigned command, + size_t send_size, const void *send_buf, size_t recv_size, + void *recv_buf, int *retval_ptr); + void glibtop_read_i (glibtop *server, glibtop_backend *backend, size_t size, void *buf); diff --git a/backends/server/marshal.pl b/backends/server/marshal.pl index ada7e320..dbacb386 100644 --- a/backends/server/marshal.pl +++ b/backends/server/marshal.pl @@ -34,6 +34,8 @@ print ''; print '#include '; print '#include '; print ''; +print '#include '; +print ''; $feature_count = 0; @@ -174,7 +176,7 @@ sub output { $send_buf_code .= ";\n"; $call_code = ''; - $call_code .= sprintf ("\t%sglibtop_call_l (server, GLIBTOP_CMND_%s,\n", + $call_code .= sprintf ("\t%sglibtop_call_i (server, backend, GLIBTOP_CMND_%s,\n", $call_prefix, &toupper($feature)); $call_code .= sprintf ("\t\t\t%s%s, %s,\n", $call_prefix_space, "_LIBGTOP_SEND_len", "_LIBGTOP_SEND_ptr"); @@ -210,16 +212,16 @@ sub output { $func_decl = 'static '.$retval."\n"; if ($line_fields[3] eq '') { - $func_decl .= sprintf ("_glibtop_get_%s_c (glibtop *server%s)\n", + $func_decl .= sprintf ("_glibtop_get_%s_c (glibtop *server, glibtop_backend *backend%s)\n", $feature, $param_decl); } elsif ($line_fields[3] eq 'array') { - $func_decl .= sprintf ("_glibtop_get_%s_c (glibtop *server, glibtop_array *array%s)\n", + $func_decl .= sprintf ("_glibtop_get_%s_c (glibtop *server, glibtop_backend *backend, glibtop_array *array%s)\n", $feature, $param_decl); } elsif ($line_fields[3] =~ /^array/) { - $func_decl .= sprintf ("_glibtop_get_%s_c (glibtop *server, glibtop_array *array, %s *buf%s)\n", + $func_decl .= sprintf ("_glibtop_get_%s_c (glibtop *server, glibtop_backend *backend, glibtop_array *array, %s *buf%s)\n", $feature, 'glibtop_'.$feature, $param_decl); } else { - $func_decl .= sprintf ("_glibtop_get_%s_c (glibtop *server, %s *buf%s)\n", + $func_decl .= sprintf ("_glibtop_get_%s_c (glibtop *server, glibtop_backend *backend, %s *buf%s)\n", $feature, 'glibtop_'.$feature, $param_decl); } diff --git a/backends/sysdeps/ChangeLog b/backends/sysdeps/ChangeLog index ebc7d1ee..f8e76308 100644 --- a/backends/sysdeps/ChangeLog +++ b/backends/sysdeps/ChangeLog @@ -1,3 +1,8 @@ +2000-01-02 Martin Baulig + + * marshal.pl: New file. Automatically creates `marshal.c'. + * call-vector.c: Removed. + 2000-01-01 Martin Baulig Initial version of the "glibtop-backend-sysdeps" backend. diff --git a/backends/sysdeps/Makefile.am b/backends/sysdeps/Makefile.am index 293e6eba..ed3e076f 100644 --- a/backends/sysdeps/Makefile.am +++ b/backends/sysdeps/Makefile.am @@ -9,9 +9,18 @@ lib_LTLIBRARIES = \ libgtop_backend_sysdeps.la libgtop_backend_sysdeps_la_SOURCES = \ - backend-sysdeps.c \ - call-vector.c + backend-sysdeps.c \ + marshal.c libgtop_backend_sysdeps_la_LDFLAGS = \ $(LT_VERSION_INFO) +BUILT_SOURCES = \ + marshal.c + +CLEANFILES = $(BUILT_SOURCES) + +marshal.c: marshal.pl $(top_builddir)/config.h $(top_srcdir)/features.def $(top_srcdir)/scripts/c_types.pl + $(PERL) -I $(top_srcdir)/scripts $(srcdir)/marshal.pl < $(top_srcdir)/features.def > tmp-t + mv tmp-t marshal.c + diff --git a/backends/sysdeps/marshal.pl b/backends/sysdeps/marshal.pl new file mode 100644 index 00000000..6633c86c --- /dev/null +++ b/backends/sysdeps/marshal.pl @@ -0,0 +1,178 @@ +#!/usr/bin/perl + +require 'c_types.pl'; + +$[ = 1; # set array base to 1 +$, = ' '; # set output field separator +$\ = "\n"; # set output record separator + +$always_use_temp_storage = 1; + +sub toupper { + local($_) = @_; + tr/a-z/A-Z/; + return $_; +} + +sub tolower { + local($_) = @_; + tr/A-Z/a-z/; + return $_; +} + +print '/* marshal.c */'; +print "/* This is a generated file. Please modify `marshal.pl' */"; +print ''; + +print '#include '; +print '#include '; +print '#include '; +print ''; +print '#include '; +print '#include '; +print ''; +print '#include '; +print '#include '; +print ''; +print '#include '; +print ''; + +$feature_count = 0; + +while (<>) { + chop; # strip record separator + + if (/^[^#]/) { + &output($_); + } +} + +sub output { + local($line) = @_; + @line_fields = split(/\|/, $line, 9999); + $retval = $line_fields[1]; + $feature = $line_fields[2]; + $param_def = $line_fields[4]; + + $orig = $feature; + $feature =~ s/^@//; + $space = $feature; + $space =~ s/./ /g; + + $features{++$feature_count} = $feature; + + if ($retval eq 'retval') { + $retval_param = '&retval'; + $call_prefix = ''; + $call_prefix_space = ''; + $prefix = 'retval = '; + $prefix_space = ' '; + $retval = 'int'; + } + elsif ($retval !~ /^void$/) { + $retval_param = 'NULL'; + $prefix = 'retval = '; + $prefix_space = ' '; + $call_prefix = 'retval = '; + $call_prefix_space = ' '; + } + else { + $retval_param = 'NULL'; + $call_prefix = ''; + $call_prefix_space = ''; + $prefix = ''; + $prefix_space = ''; + } + + if ($retval =~ /^(array|pointer)\((.*)\)$/) { + $retval = ($2 eq 'string') ? 'char **' : "$2 *"; + } + + $need_temp_storage = $always_use_temp_storage; + $first_param_name = ''; + + $call_param = ''; + $param_decl = ''; + $need_temp_len = 0; + $nr_params = (@params = split(/:/, $param_def, 9999)); + for ($param = 1; $param <= $nr_params; $param++) { + $list = $params[$param]; + $type = $params[$param]; + $type =~ s/\(.*//; + $list =~ s/^.*\(//; + $list =~ s/\)$//; + $count = (@fields = split(/,/, $list, 9999)); + for ($field = 1; $field <= $count; $field++) { + my $c_type = $typeinfo->{$type}->[1]; + + if ($first_param_name eq '') { + $first_param_name = $fields[$field]; + } + + if ($typeinfo->{$type}->[2]) { + $need_temp_storage = 1; + } + + if ($param_decl eq '') { + $param_decl = ",\n " . $space . ' '; + } + else { + $param_decl = $param_decl . ', '; + } + $param_decl = $param_decl . $c_type . ' ' . $fields[$field]; + $call_param = $call_param . ', ' . $fields[$field]; + } + } + + if ($line_fields[3] eq '') { + $total_code = sprintf + ("\treturn glibtop_get_%s_s (server%s);\n", $feature, $call_param); + } elsif ($line_fields[3] eq 'array') { + $total_code = sprintf + ("\treturn glibtop_get_%s_s (server, array%s);\n", $feature, $call_param); + } elsif ($line_fields[3] =~ /^array/) { + $total_code = sprintf + ("\treturn glibtop_get_%s_s (server, array, buf%s);\n", $feature, $call_param); + } else { + $total_code = sprintf + ("\treturn glibtop_get_%s_s (server, buf%s);\n", $feature, $call_param); + } + + $func_decl = 'static '.$retval."\n"; + if ($line_fields[3] eq '') { + $func_decl .= sprintf ("_glibtop_get_%s_c (glibtop *server, glibtop_backend *backend%s)\n", + $feature, $param_decl); + } elsif ($line_fields[3] eq 'array') { + $func_decl .= sprintf ("_glibtop_get_%s_c (glibtop *server, glibtop_backend *backend, glibtop_array *array%s)\n", + $feature, $param_decl); + } elsif ($line_fields[3] =~ /^array/) { + $func_decl .= sprintf ("_glibtop_get_%s_c (glibtop *server, glibtop_backend *backend, glibtop_array *array, %s *buf%s)\n", + $feature, 'glibtop_'.$feature, $param_decl); + } else { + $func_decl .= sprintf ("_glibtop_get_%s_c (glibtop *server, glibtop_backend *backend, %s *buf%s)\n", + $feature, 'glibtop_'.$feature, $param_decl); + } + + $total_code = sprintf ("%s{\n%s\n%s}\n", $func_decl, $total_code); + + $total_code = sprintf ("#if (!GLIBTOP_SUID_%s)\n\n%s\n#endif /* not GLIBTOP_SUID_%s */\n\n", + &toupper($feature), $total_code, + &toupper($feature)); + + print $total_code; +} + +$call_vector_code = ''; +for ($nr = 1; $nr <= $feature_count; $nr++) { + $feature = $features{$nr}; + + $call_vector_code .= sprintf + (qq[\#if GLIBTOP_SUID_%s\n\tNULL,\n\#else\n\t_glibtop_get_%s_c,\n\#endif\n], + &toupper($feature), $feature); +} + +print 'glibtop_call_vector glibtop_backend_sysdeps_call_vector = {'; +print $call_vector_code; +print '};'; +print ''; + diff --git a/include/glibtop/backend.h b/include/glibtop/backend.h index e0c93c49..add3336f 100644 --- a/include/glibtop/backend.h +++ b/include/glibtop/backend.h @@ -29,8 +29,6 @@ #include #include -#include - #include BEGIN_LIBGTOP_DECLS @@ -40,6 +38,8 @@ typedef struct _glibtop_backend_private glibtop_backend_private; typedef struct _glibtop_backend glibtop_backend; +#include + typedef int (*glibtop_backend_open_func_t) (glibtop *, glibtop_backend *, u_int64_t, const char **); typedef int (*glibtop_backend_close_func_t) (glibtop *, glibtop_backend *); diff --git a/include/glibtop/call-vector.pl b/include/glibtop/call-vector.pl index 79a95724..21208ce5 100644 --- a/include/glibtop/call-vector.pl +++ b/include/glibtop/call-vector.pl @@ -82,16 +82,16 @@ sub parse_features_def { if ($line_fields[3] eq '') { $func_decl_code .= sprintf - (qq[\t%s (*%s) (glibtop *%s);\n], $retval, $feature, $param_decl); + (qq[\t%s (*%s) (glibtop *, glibtop_backend *%s);\n], $retval, $feature, $param_decl); } elsif ($line_fields[3] eq 'array') { $func_decl_code .= sprintf - (qq[\t%s (*%s) (glibtop *, glibtop_array *%s);\n], $retval, $feature, $param_decl); + (qq[\t%s (*%s) (glibtop *, glibtop_backend *, glibtop_array *%s);\n], $retval, $feature, $param_decl); } elsif ($line_fields[3] =~ /^array/) { $func_decl_code .= sprintf - (qq[\t%s (*%s) (glibtop *, glibtop_array *, %s *%s);\n], $retval, $feature, 'glibtop_'.$feature, $param_decl); + (qq[\t%s (*%s) (glibtop *, glibtop_backend *, glibtop_array *, %s *%s);\n], $retval, $feature, 'glibtop_'.$feature, $param_decl); } else { $func_decl_code .= sprintf - (qq[\t%s (*%s) (glibtop *, %s *%s);\n], $retval, $feature, 'glibtop_'.$feature, $param_decl); + (qq[\t%s (*%s) (glibtop *, glibtop_backend *, %s *%s);\n], $retval, $feature, 'glibtop_'.$feature, $param_decl); } } diff --git a/lib/lib.pl b/lib/lib.pl index 0e2d14ab..65cc4ac2 100755 --- a/lib/lib.pl +++ b/lib/lib.pl @@ -166,19 +166,19 @@ sub output { if ($line_fields[3] eq '') { $sysdeps_code .= sprintf - ("\t\t\tretval = backend->info->call_vector->%s (server%s);\n", + ("\t\t\tretval = backend->info->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, array%s);\n", + ("\t\t\tretval = backend->info->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, array, buf%s);\n", + ("\t\t\tretval = backend->info->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, buf%s);\n", + ("\t\t\tretval = backend->info->call_vector->%s (server, backend, buf%s);\n", $feature, $call_param); }