From f75dd6fd1975146623052b843b182dc32c3fbe46 Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Fri, 8 Apr 2011 07:30:59 +0200 Subject: Imported Upstream version 0.8.998 --- docs/api/generate-settings-spec.c | 227 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 docs/api/generate-settings-spec.c (limited to 'docs/api/generate-settings-spec.c') diff --git a/docs/api/generate-settings-spec.c b/docs/api/generate-settings-spec.c new file mode 100644 index 00000000..9c15314f --- /dev/null +++ b/docs/api/generate-settings-spec.c @@ -0,0 +1,227 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* + * Dan Williams + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + * (C) Copyright 2009 - 2010 Red Hat, Inc. + */ + +#include +#include +#include +#include + +#include +#include +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +typedef NMSetting* (*SettingNewFunc) (void); + +static SettingNewFunc funcs[] = { + nm_setting_802_1x_new, + nm_setting_bluetooth_new, + nm_setting_cdma_new, + nm_setting_connection_new, + nm_setting_gsm_new, + nm_setting_ip4_config_new, + nm_setting_ip6_config_new, + nm_setting_olpc_mesh_new, + nm_setting_ppp_new, + nm_setting_pppoe_new, + nm_setting_serial_new, + nm_setting_vpn_new, + nm_setting_wimax_new, + nm_setting_wired_new, + nm_setting_wireless_new, + nm_setting_wireless_security_new, + NULL +}; + +typedef struct { + const char *gvalue_name; + const char *new_name; +} TypeNameElement; + +static TypeNameElement name_map[] = { + { "gchararray", "string" }, + { "GSList_gchararray_", "array of string" }, + { "GArray_guchar_", "byte array" }, + { "gboolean", "boolean" }, + { "guint64", "uint64" }, + { "gint", "int32" }, + { "guint", "uint32" }, + { "GArray_guint_", "array of uint32" }, + { "GPtrArray_GArray_guint__", "array of array of uint32" }, + { "GPtrArray_GArray_guchar__", "array of byte array" }, + { "GHashTable_gchararray+gchararray_", "dict of (string::string)" }, + { "GPtrArray_GValueArray_GArray_guchar_+guint+GArray_guchar___", "array of (byte array, uint32, byte array)" }, + { "GPtrArray_GValueArray_GArray_guchar_+guint+GArray_guchar_+guint__", "array of (byte array, uint32, byte array, uint32)" }, + { NULL, NULL } +}; + +static void +write_one_setting (FILE *f, SettingNewFunc func) +{ + NMSetting *s; + GParamSpec **props, **iter; + guint num; + + s = func (); + + /* write out section header */ + (void) fprintf (f, + "\n" + " %s setting\n" + " \n" + " \n" + " \n" + " Key Name\n" + " Value Type\n" + " Default Value\n" + " Value Description\n" + " \n" + " \n" + " \n", + nm_setting_get_name (s)); + + props = g_object_class_list_properties (G_OBJECT_GET_CLASS (G_OBJECT (s)), &num); + for (iter = props; iter && *iter; iter++) { + const char *key_name, *value_type, *value_desc; + char *default_value; + TypeNameElement *name_iter; + GValue value = { 0, }; + char *flags_str = NULL; + + value_type = g_type_name (G_PARAM_SPEC_VALUE_TYPE (*iter)); + for (name_iter = &name_map[0]; name_iter && name_iter->gvalue_name; name_iter++) { + if (!strcmp (value_type, name_iter->gvalue_name)) { + value_type = name_iter->new_name; + break; + } + } + + key_name = g_param_spec_get_name (*iter); + value_desc = g_param_spec_get_blurb (*iter); + + g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (*iter)); + g_param_value_set_default (*iter, &value); + default_value = g_strdup_value_contents (&value); + if (default_value && !strcmp (default_value, "NULL")) { + g_free (default_value); + default_value = NULL; + } + + if (!strcmp (key_name, NM_SETTING_NAME)) { + g_free (default_value); + default_value = NULL; + g_object_get (G_OBJECT (s), NM_SETTING_NAME, &default_value, NULL); + } + + if (g_str_has_suffix (key_name, "-flags")) + flags_str = g_strdup_printf (" (see for flag values)"); + + (void) fprintf (f, + " \n" + " %s\n" + " %s\n" + " %s\n" + " %s%s\n" + " \n", + key_name, + value_type, + default_value ? default_value : "", + value_desc, + flags_str ? flags_str : ""); + + g_free (flags_str); + g_free (default_value); + } + + (void) fprintf (f, + " \n" + " \n" + "
\n"); + + g_object_unref (s); +} + +int +main (int argc, char *argv[]) +{ + GError *error = NULL; + FILE *f; + SettingNewFunc *fptr; + + if (argc != 2) { + fprintf (stderr, "Usage: %s \n", argv[0]); + _exit (1); + } + + g_type_init (); + + if (!nm_utils_init (&error)) { + fprintf (stderr, "ERR: failed to initialize libnm-util: %s", error->message); + _exit (2); + } + + f = fopen (argv[1], "w"); + if (!f) { + fprintf (stderr, "ERR: could not create %s: %d\n", argv[1], errno); + _exit (3); + } + + (void) fprintf (f, + "\n" + "" + "]>" + "
\n" + " Configuration Settings\n" + " \n"); + + for (fptr = funcs; fptr && *fptr; fptr++) + write_one_setting (f, *fptr); + + (void) fprintf (f, + " \n" + "
\n"); + + fclose (f); + _exit (0); +} + -- cgit 1.3.0-6-gf8a5