From 8b8e1de19a5a81732c6e847cec5e1d1992add208 Mon Sep 17 00:00:00 2001 From: Martin Baulig Date: Wed, 12 Jan 2000 12:53:26 +0000 Subject: [PATCH] Initial version of the "glibtop-backend-common" backend. 2000-01-12 Martin Baulig Initial version of the "glibtop-backend-common" backend. * backend-common.c: New file. * glibtop-backend-private.h: New file. * marshal.pl: New file. Automatically creates `marshal.c'. --- backends/common/.cvsignore | 7 + backends/common/ChangeLog | 8 + backends/common/Makefile.am | 29 ++++ backends/common/backend-common.c | 62 ++++++++ backends/common/glibtop-backend-private.h | 34 ++++ backends/common/marshal.pl | 179 ++++++++++++++++++++++ 6 files changed, 319 insertions(+) create mode 100644 backends/common/.cvsignore create mode 100644 backends/common/ChangeLog create mode 100644 backends/common/Makefile.am create mode 100644 backends/common/backend-common.c create mode 100644 backends/common/glibtop-backend-private.h create mode 100644 backends/common/marshal.pl diff --git a/backends/common/.cvsignore b/backends/common/.cvsignore new file mode 100644 index 00000000..a081b16a --- /dev/null +++ b/backends/common/.cvsignore @@ -0,0 +1,7 @@ +.deps +.libs +Makefile +Makefile.in +*.lo +*.la +marshal.c diff --git a/backends/common/ChangeLog b/backends/common/ChangeLog new file mode 100644 index 00000000..0f43e9f8 --- /dev/null +++ b/backends/common/ChangeLog @@ -0,0 +1,8 @@ +2000-01-12 Martin Baulig + + Initial version of the "glibtop-backend-common" backend. + + * backend-common.c: New file. + * glibtop-backend-private.h: New file. + * marshal.pl: New file. Automatically creates `marshal.c'. + diff --git a/backends/common/Makefile.am b/backends/common/Makefile.am new file mode 100644 index 00000000..ae9d5443 --- /dev/null +++ b/backends/common/Makefile.am @@ -0,0 +1,29 @@ +LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@ + +INCLUDES = @INCLUDES@ + +noinst_HEADERS = \ + glibtop-backend-private.h + +lib_LTLIBRARIES = \ + libgtop_backend_common.la + +libgtop_backend_common_la_SOURCES = \ + backend-common.c \ + marshal.c + +libgtop_backend_common_la_LDFLAGS = \ + $(LT_VERSION_INFO) + +BUILT_SOURCES = \ + marshal.c + +EXTRA_DIST = \ + marshal.pl + +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/common/backend-common.c b/backends/common/backend-common.c new file mode 100644 index 00000000..ed09b97a --- /dev/null +++ b/backends/common/backend-common.c @@ -0,0 +1,62 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ + +/* $Id$ */ + +/* Copyright (C) 1998-99 Martin Baulig + This file is part of LibGTop 1.0. + + Contributed by Martin Baulig , April 1998. + + LibGTop is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + LibGTop is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with LibGTop; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include +#include +#include + +#include +#include +#include + +static int +_open_common (glibtop *, glibtop_backend *, u_int64_t, const char **); + +static int +_close_common (glibtop *, glibtop_backend *); + +extern glibtop_call_vector glibtop_backend_common_call_vector; + +glibtop_backend_info glibtop_backend_common = { + "glibtop-backend-common", _open_common, _close_common, + &glibtop_backend_common_call_vector +}; + +static int +_open_common (glibtop *server, glibtop_backend *backend, + u_int64_t features, const char **backend_args) +{ + backend->_priv = glibtop_calloc_r + (server, 1, sizeof (glibtop_backend_private)); + + return 0; +} + +static int +_close_common (glibtop *server, glibtop_backend *backend) +{ + return -1; +} + diff --git a/backends/common/glibtop-backend-private.h b/backends/common/glibtop-backend-private.h new file mode 100644 index 00000000..81d485b6 --- /dev/null +++ b/backends/common/glibtop-backend-private.h @@ -0,0 +1,34 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ + +/* $Id$ */ + +/* Copyright (C) 1998-99 Martin Baulig + This file is part of LibGTop 1.0. + + Contributed by Martin Baulig , April 1998. + + LibGTop is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + LibGTop is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with LibGTop; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef __GLIBTOP_BACKEND_PRIVATE_H__ +#define __GLIBTOP_BACKEND_PRIVATE_H__ + +struct _glibtop_backend_private +{ + u_int64_t flags; +}; + +#endif diff --git a/backends/common/marshal.pl b/backends/common/marshal.pl new file mode 100644 index 00000000..50a570d7 --- /dev/null +++ b/backends/common/marshal.pl @@ -0,0 +1,179 @@ +#!/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 ''; +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} = $orig; + + return unless $orig =~ /^@/; + + 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); + + print $total_code; +} + +$call_vector_code = ''; +for ($nr = 1; $nr <= $feature_count; $nr++) { + $feature = $features{$nr}; + + if ($feature =~ /^@/) { + $feature =~ s/^@//; + + $call_vector_code .= sprintf (qq[\t_glibtop_get_%s_c,\n], $feature); + } else { + $call_vector_code .= sprintf (qq[\tNULL,\n]); + } +} + +print 'glibtop_call_vector glibtop_backend_common_call_vector = {'; +print $call_vector_code; +print '};'; +print ''; +