From 3f8f65386e2e88257eca0a0a91c6b3f42132c019 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 2 Nov 2011 15:18:20 -0400 Subject: [PATCH] Make some APIs that return struct introspectable In order to do this, we need to define some boxed types. So we need to add a new dependency, GObject, to GTop. https://bugzilla.gnome.org/show_bug.cgi?id=663265 --- configure.ac | 3 ++- glibtop.h | 3 +++ include/glibtop/mountlist.h | 34 ++++++++++++++++++++++++ include/glibtop/procmap.h | 38 ++++++++++++++++++++++++++ include/glibtop/procopenfiles.h | 39 +++++++++++++++++++++++++++ lib/Makefile.am | 2 +- lib/boxed.c | 47 +++++++++++++++++++++++++++++++++ lib/libgtop.sym | 7 +++++ 8 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 lib/boxed.c diff --git a/configure.ac b/configure.ac index bc6f88f2..3fe868ed 100644 --- a/configure.ac +++ b/configure.ac @@ -91,8 +91,9 @@ GNOME_LIBGTOP_SYSDEPS GNOME_LIBGTOP_TYPES GLIB_REQUIRED=2.6.0 +GOBJECT_REQUIRED=2.26.0 -PKG_CHECK_MODULES(GLIB, glib-2.0 >= $GLIB_REQUIRED) +PKG_CHECK_MODULES(GLIB, glib-2.0 >= $GLIB_REQUIRED gobject-2.0 >= $GOBJECT_REQUIRED) AC_SUBST(GLIB_CFLAGS) AC_SUBST(GLIB_LIBS) diff --git a/glibtop.h b/glibtop.h index 8b31d10d..0d3e7ddd 100644 --- a/glibtop.h +++ b/glibtop.h @@ -23,6 +23,7 @@ #define __GLIBTOP_H__ #include +#include G_BEGIN_DECLS @@ -138,6 +139,8 @@ glibtop_init_s (glibtop **server_ptr, unsigned long features, unsigned flags); +GType glibtop_get_type (void) G_GNUC_CONST; + G_END_DECLS #endif diff --git a/include/glibtop/mountlist.h b/include/glibtop/mountlist.h index ee074a62..25174947 100644 --- a/include/glibtop/mountlist.h +++ b/include/glibtop/mountlist.h @@ -53,6 +53,38 @@ struct _glibtop_mountlist guint64 size; /* GLIBTOP_MOUNTLIST_SIZE */ }; +/** + * glibtop_get_mountlist: + * @buf: (out): + * @all_fs: + * + * Returns: (transfer full): + */ + +/** + * glibtop_get_mountlist_r: + * @buf: (out): + * @all_fs: + * + * Returns: (transfer none): + */ + +/** + * glibtop_get_mountlist_s: + * @buf: (out): + * @all_fs: + * + * Returns: (transfer none): + */ + +/** + * glibtop_get_mountlist_l: + * @buf: (out): + * @all_fs: + * + * Returns: (transfer none): + */ + glibtop_mountentry * glibtop_get_mountlist(glibtop_mountlist *buf, int all_fs); @@ -64,6 +96,8 @@ glibtop_get_mountlist_l (glibtop *server, glibtop_mountlist *buf, int all_fs); glibtop_mountentry * glibtop_get_mountlist_s (glibtop *server, glibtop_mountlist *buf, int all_fs); +GType glibtop_mountlist_get_type (void) G_GNUC_CONST; +GType glibtop_mountentry_get_type (void) G_GNUC_CONST; G_END_DECLS diff --git a/include/glibtop/procmap.h b/include/glibtop/procmap.h index f7d3d4b1..4434cb59 100644 --- a/include/glibtop/procmap.h +++ b/include/glibtop/procmap.h @@ -92,6 +92,42 @@ glibtop_map_entry * glibtop_get_proc_map(glibtop_proc_map *buf, pid_t pid); +/** + * glibtop_get_proc_map: + * @server: + * @buf: (out): + * @pid: + * + * Returns: (transfer none): + */ + +/** + * glibtop_get_proc_map_l: + * @server: + * @buf: (out): + * @pid: + * + * Returns: (transfer none): + */ + +/** + * glibtop_get_proc_map_p: + * @server: + * @buf: (out): + * @pid: + * + * Returns: (transfer none): + */ + +/** + * glibtop_get_proc_map_s: + * @server: + * @buf: (out): + * @pid: + * + * Returns: (transfer none): + */ + #if GLIBTOP_SUID_PROC_MAP #define glibtop_get_proc_map_r glibtop_get_proc_map_p #else @@ -113,6 +149,8 @@ glibtop_map_entry * glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid); #endif +GType glibtop_map_entry_get_type (void) G_GNUC_CONST; +GType glibtop_proc_map_get_type (void) G_GNUC_CONST; G_END_DECLS diff --git a/include/glibtop/procopenfiles.h b/include/glibtop/procopenfiles.h index 98099234..3a40eb94 100644 --- a/include/glibtop/procopenfiles.h +++ b/include/glibtop/procopenfiles.h @@ -94,6 +94,42 @@ struct _glibtop_proc_open_files guint64 size; /* GLIBTOP_PROC_OPEN_FILES_SIZE */ }; +/** + * glibtop_get_proc_open_files: + * @server: + * @buf: (out): + * @all_fs: + * + * Returns: (transfer none): + */ + +/** + * glibtop_get_proc_open_files_l: + * @server: + * @buf: (out): + * @all_fs: + * + * Returns: (transfer none): + */ + +/** + * glibtop_get_proc_open_files_p: + * @server: + * @buf: (out): + * @all_fs: + * + * Returns: (transfer none): + */ + +/** + * glibtop_get_proc_open_files_l: + * @server: + * @buf: (out): + * @all_fs: + * + * Returns: (transfer none): + */ + glibtop_open_files_entry * glibtop_get_proc_open_files(glibtop_proc_open_files *buf, pid_t pid); @@ -118,6 +154,9 @@ glibtop_open_files_entry * glibtop_get_proc_open_files_s (glibtop *server, glibtop_proc_open_files *buf, pid_t pid); #endif +GType glibtop_open_files_entry_get_type (void) G_GNUC_CONST; +GType glibtop_proc_open_files_get_type (void) G_GNUC_CONST; + G_END_DECLS #endif diff --git a/lib/Makefile.am b/lib/Makefile.am index f35ed006..75ab02f6 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -5,7 +5,7 @@ lib_LTLIBRARIES = libgtop-2.0.la libgtop_2_0_la_SOURCES = init.c open.c close.c command.c read.c \ read_data.c write.c lib.c parameter.c \ - sysdeps.c + sysdeps.c boxed.c libgtop_2_0_la_LDFLAGS = $(LT_VERSION_INFO) -export-symbols $(srcdir)/libgtop.sym -no-undefined libgtop_2_0_la_LIBADD = $(GLIB_LIBS) $(top_builddir)/sysdeps/common/libgtop_common-2.0.la $(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps-2.0.la $(sysdeps_suid_lib) diff --git a/lib/boxed.c b/lib/boxed.c new file mode 100644 index 00000000..cfeff2bb --- /dev/null +++ b/lib/boxed.c @@ -0,0 +1,47 @@ +/* Copyright (C) 2011 Red Hat + This file is part of LibGTop 1.0. + + Contributed by Jasper St. Pierre , November 2011 + + 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 + +#define DEFINE_BOXED(type) \ + static type * \ + type##_copy (type *p) \ + { \ + type *n = g_new (type, 1); \ + memcpy (n, p, sizeof (type)); \ + return n; \ + } \ + \ + G_DEFINE_BOXED_TYPE (type, \ + type, \ + type##_copy, \ + g_free) + +DEFINE_BOXED (glibtop); +DEFINE_BOXED (glibtop_map_entry); +DEFINE_BOXED (glibtop_proc_map); +DEFINE_BOXED (glibtop_open_files_entry); +DEFINE_BOXED (glibtop_proc_open_files); +DEFINE_BOXED (glibtop_mountentry); +DEFINE_BOXED (glibtop_mountlist); diff --git a/lib/libgtop.sym b/lib/libgtop.sym index 67db450f..d15adcc6 100644 --- a/lib/libgtop.sym +++ b/lib/libgtop.sym @@ -68,3 +68,10 @@ glibtop_open_l glibtop_server_features glibtop_set_parameter_l glibtop_sys_siglist +glibtop_mountlist_get_type +glibtop_mountentry_get_type +glibtop_open_files_entry_get_type +glibtop_proc_open_files_get_type +glibtop_map_entry_get_type +glibtop_proc_map_get_type +glibtop_get_type