# name of documentation module
my $MODULE;
my $OUTPUT_DIR;
+my $INSPECT_DIR;
my $PRINT_VERSION;
my $PRINT_HELP;
my $TYPE_INIT_FUNC="g_type_init ()";
nogtkinit => \$NO_GTK_INIT,
'type-init-func' => \$TYPE_INIT_FUNC,
'output-dir' => \$OUTPUT_DIR,
+ 'inspect-dir' => \$INSPECT_DIR,
'version' => \$PRINT_VERSION,
'help' => \$PRINT_HELP);
-
-GetOptions(\%optctl, "module=s", "source=s", "types:s", "output-dir:s", "nogtkinit", "type-init-func:s", "version", "help");
+
+GetOptions(\%optctl, "module=s", "source=s", "types:s", "output-dir:s", "inspect-dir:s", "nogtkinit", "type-init-func:s", "version", "help");
if ($NO_GTK_INIT) {
# Do nothing. This just avoids a warning.
print "\n--types=FILE The name of the file to store the types in";
print "\n--type-init-func=FUNC The init function to call instead of g_type_init ()";
print "\n--output-dir=DIRNAME The directory where the results are stored";
+ print "\n--inspect-dir=DIRNAME The directory where the plugin inspect data is stored";
print "\n--version Print the version of this program";
print "\n--help Print this help\n";
exit 0;
$OUTPUT_DIR = $OUTPUT_DIR ? $OUTPUT_DIR : ".";
-# THOMAS: dynamic types; only use types file for headers
- $TYPES_FILE = $TYPES_FILE ? $TYPES_FILE : "$OUTPUT_DIR/$MODULE.types";
+$TYPES_FILE = $TYPES_FILE ? $TYPES_FILE : "$OUTPUT_DIR/$MODULE.types";
open (TYPES, $TYPES_FILE) || die "Cannot open $TYPES_FILE: $!\n";
open (OUTPUT, ">$MODULE-scan.c") || die "Cannot open $MODULE-scan.c: $!\n";
# write a C program to scan the types
$includes = "";
-#@types = ();
+@types = ();
+@impl_types = ();
for (<TYPES>) {
if (/^#include/) {
$includes .= $_;
-# } elsif (/^%/) {
-# next;
-# } elsif (/^\s*$/) {
-# next;
-# } else {
-# chomp;
-# push @types, $_;
+ } elsif (/^%/) {
+ next;
+ } elsif (/^\s*$/) {
+ next;
+ } elsif (/^type:(.*)$/) {
+ $t = $1;
+ chomp $t;
+ push @impl_types, $t;
+ } else {
+ chomp;
+ push @types, $_;
}
}
-#$ntypes = @types + 1;
+$ntypes = @types + @impl_types;
print OUTPUT <<EOT;
#include <string.h>
#include <errno.h>
$includes
+
#ifdef GTK_IS_WIDGET_CLASS
#include <gtk/gtkversion.h>
#endif
-GType *object_types = NULL;
+
+static GType *object_types = NULL;
+
+static GString *xmlstr = NULL;
+
+static const gchar*
+xmlprint (gint indent, const gchar *tag, const gchar *data)
+{
+ const gchar indent_str[] = " ";
+
+ /* reset */
+ g_string_truncate (xmlstr, 0);
+ g_string_append_len (xmlstr, indent_str, MIN (indent, strlen (indent_str)));
+ g_string_append_printf (xmlstr, "<%s>", tag);
+
+ if (data) {
+ gchar *s;
+
+ s = g_markup_escape_text (data, -1);
+ g_string_append (xmlstr, s);
+ g_free (s);
+ }
+
+ g_string_append_printf (xmlstr, "</%s>\\n", tag);
+ return xmlstr->str;
+}
+
+static gint
+gst_feature_sort_compare (gconstpointer a, gconstpointer b)
+{
+ return strcmp (((GstPluginFeature *)a)->name, ((GstPluginFeature *)b)->name);
+}
+
+static gint
+static_pad_template_compare (gconstpointer a, gconstpointer b)
+{
+ GstStaticPadTemplate *spt_a = (GstStaticPadTemplate *) a;
+ GstStaticPadTemplate *spt_b = (GstStaticPadTemplate *) b;
+
+ /* we want SINK before SRC (enum is UNKNOWN, SRC, SINK) */
+ if (spt_a->direction != spt_b->direction)
+ return spt_b->direction - spt_a->direction;
+
+ /* we want ALWAYS first, SOMETIMES second, REQUEST last
+ * (enum is ALWAYS, SOMETIMES, REQUEST) */
+ if (spt_a->presence != spt_b->presence)
+ return spt_a->presence - spt_b->presence;
+
+ return strcmp (spt_a->name_template, spt_b->name_template);
+}
static GType *
get_object_types (void)
GList *factories = NULL;
GList *l;
GstElementFactory *factory = NULL;
-
+ GType type;
gint i = 0;
-
+ gboolean reinspect;
+
/* get a list of features from plugins in our source module */
plugins = gst_registry_get_plugin_list (gst_registry_get_default());
+ xmlstr = g_string_new ("");
+
+ reinspect = !g_file_test ("scanobj-build.stamp", G_FILE_TEST_EXISTS);
+
while (plugins) {
GList *features;
GstPlugin *plugin;
const gchar *source;
+ FILE *inspect = NULL;
+ gchar *inspect_name;
plugin = (GstPlugin *) (plugins->data);
plugins = g_list_next (plugins);
source = gst_plugin_get_source (plugin);
- g_print ("source: %s\\n", source);
- if (!source || strcmp (gst_plugin_get_source (plugin), "$SOURCE") != 0) {
+ /*g_print ("plugin: %s source: %s\\n", plugin->desc.name, source);*/
+ if (!source || strcmp (source, "$SOURCE") != 0) {
continue;
}
+ /* skip static coreelements plugin with pipeline and bin element factory */
+ if (gst_plugin_get_filename (plugin) == NULL)
+ continue;
+
+ g_print ("plugin: %s source: %s\\n", plugin->desc.name, source);
+
+ if (reinspect) {
+ inspect_name = g_strdup_printf ("$INSPECT_DIR" G_DIR_SEPARATOR_S "plugin-%s.xml",
+ plugin->desc.name);
+ inspect = fopen (inspect_name, "w");
+ if (inspect == NULL) {
+ g_error ("Could not open %s for writing: %s\\n", inspect_name,
+ g_strerror (errno));
+ }
+ g_free (inspect_name);
+
+ /* output plugin data */
+ fputs ("<plugin>\\n",inspect);
+ fputs (xmlprint(2, "name", plugin->desc.name),inspect);
+ fputs (xmlprint(2, "description", plugin->desc.description),inspect);
+ fputs (xmlprint(2, "filename", plugin->filename),inspect);
+ fputs (xmlprint(2, "basename", plugin->basename),inspect);
+ fputs (xmlprint(2, "version", plugin->desc.version),inspect);
+ fputs (xmlprint(2, "license", plugin->desc.license),inspect);
+ fputs (xmlprint(2, "source", plugin->desc.source),inspect);
+ fputs (xmlprint(2, "package", plugin->desc.package),inspect);
+ fputs (xmlprint(2, "origin", plugin->desc.origin),inspect);
+ fputs (" <elements>\\n", inspect);
+ }
+
features =
gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
plugin->desc.name);
+
+ /* sort factories by feature->name */
+ features = g_list_sort (features, gst_feature_sort_compare);
+
while (features) {
GstPluginFeature *feature;
feature = GST_PLUGIN_FEATURE (features->data);
}
if (GST_IS_ELEMENT_FACTORY (feature)) {
+ const gchar *pad_dir[] = { "unknown","source","sink" };
+ const gchar *pad_pres[] = { "always","sometimes","request" };
+ GList *pads, *pad;
+
+ /*g_print (" feature: %s\\n", feature->name);*/
+
factory = GST_ELEMENT_FACTORY (feature);
- factories = g_list_append (factories, factory);
+ factories = g_list_prepend (factories, factory);
+
+ if (reinspect) {
+ /* output element data */
+ fputs (" <element>\\n", inspect);
+ fputs (xmlprint(6, "name", feature->name),inspect);
+ fputs (xmlprint(6, "longname", factory->details.longname),inspect);
+ fputs (xmlprint(6, "class", factory->details.klass),inspect);
+ fputs (xmlprint(6, "description", factory->details.description),inspect);
+ fputs (xmlprint(6, "author", factory->details.author),inspect);
+ fputs (" <pads>\\n", inspect);
+
+ /* output pad-template data */
+ pads = g_list_copy ((GList *) gst_element_factory_get_static_pad_templates (factory));
+ pads = g_list_sort (pads, static_pad_template_compare);
+ for (pad = pads; pad != NULL; pad = pad->next) {
+ GstStaticPadTemplate *pt = pad->data;
+
+ fputs (" <caps>\\n", inspect);
+ fputs (xmlprint(10, "name", pt->name_template),inspect);
+ fputs (xmlprint(10, "direction", pad_dir[pt->direction]),inspect);
+ fputs (xmlprint(10, "presence", pad_pres[pt->presence]),inspect);
+ fputs (xmlprint(10, "details", pt->static_caps.string),inspect);
+ fputs (" </caps>\\n", inspect);
+ }
+ g_list_free (pads);
+ fputs (" </pads>\\n </element>\\n", inspect);
+ }
}
features = g_list_next (features);
}
+
+ if (reinspect) {
+ fputs (" </elements>\\n</plugin>", inspect);
+ fclose (inspect);
+ }
}
+
+ g_string_free (xmlstr, TRUE);
g_message ("number of element factories: %d", g_list_length (factories));
/* allocate the object_types array to hold them */
- object_types = g_new0 (GType, g_list_length (factories)+1);
+ object_types = g_new0 (GType, g_list_length (factories)+$ntypes+1);
l = factories;
i = 0;
/* fill it */
while (l) {
- GType type;
factory = GST_ELEMENT_FACTORY (l->data);
- g_message ("adding type for factory %s", gst_element_factory_get_longname (factory));
type = gst_element_factory_get_element_type (factory);
- g_message ("adding type %p", (void *) type);
- object_types[i] = type;
- i++;
+ if (type != 0) {
+ g_message ("adding type %p for factory %s", (void *) type, gst_element_factory_get_longname (factory));
+ object_types[i++] = type;
+ } else {
+ g_message ("type info for factory %s not found",
+ gst_element_factory_get_longname (factory));
+ }
l = g_list_next (l);
}
- object_types[i] = 0;
+
+EOT
+
+# get_type functions:
+for (@types) {
+print OUTPUT <<EOT;
+ type = $_ ();
+ if (type == 0) {
+ g_message ("$_ () didn't return a valid type");
+ }
+ else {
+ object_types[i++] = type;
+ }
+EOT
+}
+
+# Implicit types retrieved from GLib:
+for (@impl_types) {
+print OUTPUT <<EOT;
+ type = g_type_from_name ("$_");
+ if (type == 0) {
+ g_message ("Implicit type $_ not found");
+ }
+ else {
+ object_types[i++] = type;
+ }
EOT
+}
print OUTPUT <<EOT;
+ object_types[i] = 0;
+
/* Need to make sure all the types are loaded in and initialize
* their signals and properties.
*/
for (i=0; object_types[i]; i++) {
if (G_TYPE_IS_CLASSED (object_types[i]))
g_type_class_ref (object_types[i]);
+ else {
+ g_warning ("not reffing type: %s", g_type_name (object_types[i]));
+ }
}
return object_types;
if (g_type_is_a (type, G_TYPE_POINTER))
*is_pointer = TRUE;
+ /* But enums are not */
+ if (g_type_is_a (type, G_TYPE_ENUM) ||
+ g_type_is_a (type, G_TYPE_FLAGS))
+ *is_pointer = FALSE;
+
return type_name;
}
}
output_hierarchy (fp, G_TYPE_OBJECT, 0);
output_hierarchy (fp, G_TYPE_INTERFACE, 0);
-
+
for (i=0; object_types[i]; i++) {
if (!g_type_parent (object_types[i]) &&
+ (object_types[i] != G_TYPE_NONE) &&
(object_types[i] != G_TYPE_OBJECT) &&
(object_types[i] != G_TYPE_INTERFACE)
) {
+ g_warning ("printing hierarchy for root type: %s",
+ g_type_name (object_types[i]));
output_hierarchy (fp, object_types[i], 0);
}
}
+ /* for debugging
+ for (i=0; object_types[i]; i++) {
+ if(object_types[i] != G_TYPE_NONE) {
+ g_print ("type has not been added to hierarchy: %s\\n",
+ g_type_name (object_types[i]));
+ }
+ }
+ for debugging */
fclose (fp);
}
+static int
+type_cmp (const void * p1, const void * p2)
+{
+ return strcmp (g_type_name (*((GType *) p1)), g_type_name (*((GType *) p2)));
+}
+
/* This is called recursively to output the hierarchy of a widget. */
static void
output_hierarchy (FILE *fp,
if (!type)
return;
+ /* for debugging
+ for (i=0; object_types[i]; i++) {
+ if(object_types[i] == type) {
+ g_print ("added type to hierarchy (level %d): %s\\n",
+ level, g_type_name (type));
+ object_types[i] = G_TYPE_NONE;
+ break;
+ }
+ }
+ for debugging */
+
for (i = 0; i < level; i++)
fprintf (fp, " ");
- fprintf (fp, g_type_name (type));
+ fprintf (fp, "%s", g_type_name (type));
fprintf (fp, "\\n");
children = g_type_children (type, &n_children);
- for (i=0; i < n_children; i++)
+ qsort (&children[0], n_children, sizeof (GType), type_cmp);
+
+ for (i=0; i < n_children; i++) {
output_hierarchy (fp, children[i], level + 1);
+ }
g_free (children);
}
static void output_object_interfaces (void)
{
+ guint i;
FILE *fp;
fp = fopen (interfaces_filename, "w");
return;
}
output_interfaces (fp, G_TYPE_OBJECT);
+
+ for (i = 0; object_types[i]; i++)
+ {
+ if (!g_type_parent (object_types[i]) &&
+ (object_types[i] != G_TYPE_OBJECT) &&
+ G_TYPE_IS_INSTANTIATABLE (object_types[i]))
+ {
+ output_interfaces (fp, object_types[i]);
+ }
+ }
fclose (fp);
}
if (n_interfaces > 0)
{
- fprintf (fp, g_type_name (type));
+ fprintf (fp, "%s", g_type_name (type));
for (i=0; i < n_interfaces; i++)
fprintf (fp, " %s", g_type_name (interfaces[i]));
fprintf (fp, "\\n");
if (n_prerequisites > 0)
{
- fprintf (fp, g_type_name (type));
+ fprintf (fp, "%s", g_type_name (type));
for (i=0; i < n_prerequisites; i++)
fprintf (fp, " %s", g_type_name (prerequisites[i]));
fprintf (fp, "\\n");
desc = g_strdup ("G_MINFLOAT");
else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXFLOAT))
desc = g_strdup ("-G_MAXFLOAT");
- else
- desc = g_strdup_printf ("%lg", value);
+ else {
+ /* make sure floats are output with a decimal dot irrespective of
+ * current locale. Use formatd since we want human-readable numbers
+ * and do not need the exact same bit representation when deserialising */
+ desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
+ g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g", value);
+ }
return desc;
}
{
GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
- desc = g_strdup_printf ("%g", pspec->default_value);
+ /* make sure floats are output with a decimal dot irrespective of
+ * current locale. Use formatd since we want human-readable numbers
+ * and do not need the exact same bit representation when deserialising */
+ desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
+ g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
+ pspec->default_value);
}
else if (G_IS_PARAM_SPEC_DOUBLE (spec))
{
GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
- desc = g_strdup_printf ("%lg", pspec->default_value);
+ /* make sure floats are output with a decimal dot irrespective of
+ * current locale. Use formatd since we want human-readable numbers
+ * and do not need the exact same bit representation when deserialising */
+ desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
+ g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
+ pspec->default_value);
}
else if (G_IS_PARAM_SPEC_STRING (spec))
{
guint n_properties;
gboolean child_prop;
gboolean style_prop;
+ gboolean is_pointer;
+ const gchar *type_name;
gchar *type_desc;
gchar *default_value;
- if (G_TYPE_IS_CLASSED (object_type))
+ if (G_TYPE_IS_OBJECT (object_type))
{
class = g_type_class_peek (object_type);
if (!class)
type_desc = describe_type (spec);
default_value = describe_default (spec);
- fprintf (fp, "<ARG>\\n<NAME>%s::%s</NAME>\\n<TYPE>%s</TYPE>\\n<RANGE>%s</RANGE>\\n<FLAGS>%s</FLAGS>\\n<NICK>%s</NICK>\\n<BLURB>%s%s</BLURB>\\n<DEFAULT>%s</DEFAULT>\\n</ARG>\\n\\n",
- object_class_name, g_param_spec_get_name (spec), g_type_name (spec->value_type), type_desc, flags, nick ? nick : "(null)", blurb ? blurb : "(null)", dot, default_value);
+ type_name = get_type_name (spec->value_type, &is_pointer);
+ fprintf (fp, "<ARG>\\n<NAME>%s::%s</NAME>\\n<TYPE>%s%s</TYPE>\\n<RANGE>%s</RANGE>\\n<FLAGS>%s</FLAGS>\\n<NICK>%s</NICK>\\n<BLURB>%s%s</BLURB>\\n<DEFAULT>%s</DEFAULT>\\n</ARG>\\n\\n",
+ object_class_name, g_param_spec_get_name (spec), type_name, is_pointer ? "*" : "", type_desc, flags, nick ? nick : "(null)", blurb ? blurb : "(null)", dot, default_value);
g_free (type_desc);
g_free (default_value);
}
$CC = $ENV{CC} ? $ENV{CC} : "gcc";
$LD = $ENV{LD} ? $ENV{LD} : $CC;
-$CFLAGS = $ENV{CFLAGS} ? "$ENV{CFLAGS} -Wall -g" : "-Wall -g";
+$CFLAGS = $ENV{CFLAGS} ? "$ENV{CFLAGS}" : "";
$LDFLAGS = $ENV{LDFLAGS} ? $ENV{LDFLAGS} : "";
my $o_file;
print "gtk-doc: Running scanner $MODULE-scan\n";
system("sh -c ./$MODULE-scan") == 0 or die "Scan failed: $!\n";
-unlink "./$MODULE-scan.c", "./$MODULE-scan.o", "./$MODULE-scan.lo", "./$MODULE-scan";
+if (!defined($ENV{"GTK_DOC_KEEP_INTERMEDIATE"})) {
+ unlink "./$MODULE-scan.c", "./$MODULE-scan.o", "./$MODULE-scan.lo", "./$MODULE-scan";
+}
#&UpdateFileIfChanged ($old_signals_filename, $new_signals_filename, 0);
-#&UpdateFileIfChanged ($old_hierarchy_filename, $new_hierarchy_filename, 0);
-#&UpdateFileIfChanged ($old_interfaces_filename, $new_interfaces_filename, 0);
-#&UpdateFileIfChanged ($old_prerequisites_filename, $new_prerequisites_filename, 0);
+&UpdateFileIfChanged ($old_hierarchy_filename, $new_hierarchy_filename, 0);
+&UpdateFileIfChanged ($old_interfaces_filename, $new_interfaces_filename, 0);
+&UpdateFileIfChanged ($old_prerequisites_filename, $new_prerequisites_filename, 0);
#&UpdateFileIfChanged ($old_args_filename, $new_args_filename, 0);