2012-02-03 19:42:56 +01:00
|
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
|
|
|
|
* GObject introspection: Dump introspection data
|
2008-11-13 21:13:39 +01:00
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2008 Colin Walters <walters@verbum.org>
|
|
|
|
|
*
|
2023-10-25 18:10:10 +02:00
|
|
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
|
*
|
2008-11-13 21:13:39 +01:00
|
|
|
|
* 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., 59 Temple Place - Suite 330,
|
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-09-30 16:44:12 +02:00
|
|
|
|
/* This file is both compiled into libgirepository.so, and installed
|
|
|
|
|
* on the filesystem. But for the dumper, we want to avoid linking
|
|
|
|
|
* to libgirepository; see
|
|
|
|
|
* https://bugzilla.gnome.org/show_bug.cgi?id=630342
|
|
|
|
|
*/
|
2023-10-25 19:30:38 +02:00
|
|
|
|
#ifdef GI_COMPILATION
|
2008-11-13 21:13:39 +01:00
|
|
|
|
#include "config.h"
|
2010-09-30 16:44:12 +02:00
|
|
|
|
#include "girepository.h"
|
|
|
|
|
#endif
|
2008-11-13 21:13:39 +01:00
|
|
|
|
|
2023-10-25 20:33:29 +02:00
|
|
|
|
#include <glib.h>
|
|
|
|
|
#include <glib-object.h>
|
2023-12-14 04:30:14 +01:00
|
|
|
|
#include <gmodule.h>
|
2023-10-25 20:33:29 +02:00
|
|
|
|
|
2023-10-25 20:16:58 +02:00
|
|
|
|
#include <stdlib.h>
|
2024-01-15 22:20:02 +01:00
|
|
|
|
#include <stdint.h>
|
2023-12-14 04:30:14 +01:00
|
|
|
|
#include <stdio.h>
|
2008-11-13 21:13:39 +01:00
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2023-12-14 04:30:14 +01:00
|
|
|
|
/* Analogue of g_output_stream_write_all(). */
|
|
|
|
|
static gboolean
|
|
|
|
|
write_all (FILE *out,
|
|
|
|
|
const void *buffer,
|
2024-01-16 00:35:23 +01:00
|
|
|
|
size_t count,
|
|
|
|
|
size_t *bytes_written,
|
2023-12-14 04:30:14 +01:00
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
size_t ret;
|
|
|
|
|
|
|
|
|
|
ret = fwrite (buffer, 1, count, out);
|
|
|
|
|
|
|
|
|
|
if (bytes_written != NULL)
|
|
|
|
|
*bytes_written = ret;
|
|
|
|
|
|
|
|
|
|
if (ret < count)
|
|
|
|
|
{
|
|
|
|
|
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
|
|
|
|
"Failed to write to file");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Analogue of g_data_input_stream_read_line(). */
|
|
|
|
|
static char *
|
|
|
|
|
read_line (FILE *input,
|
|
|
|
|
size_t *len_out)
|
|
|
|
|
{
|
|
|
|
|
GByteArray *buffer = g_byte_array_new ();
|
2024-01-15 22:20:02 +01:00
|
|
|
|
const uint8_t nul = '\0';
|
2023-12-14 04:30:14 +01:00
|
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
|
{
|
|
|
|
|
size_t ret;
|
2024-01-15 22:20:02 +01:00
|
|
|
|
uint8_t byte;
|
2023-12-14 04:30:14 +01:00
|
|
|
|
|
|
|
|
|
ret = fread (&byte, 1, 1, input);
|
|
|
|
|
if (ret == 0)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (byte == '\n')
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
g_byte_array_append (buffer, &byte, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_byte_array_append (buffer, &nul, 1);
|
|
|
|
|
|
|
|
|
|
if (len_out != NULL)
|
|
|
|
|
*len_out = buffer->len - 1; /* don’t include terminating nul */
|
|
|
|
|
|
|
|
|
|
return (char *) g_byte_array_free (buffer, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-21 18:56:19 +02:00
|
|
|
|
static void
|
2023-12-14 04:30:14 +01:00
|
|
|
|
escaped_printf (FILE *out, const char *fmt, ...) G_GNUC_PRINTF (2, 3);
|
2013-04-21 18:56:19 +02:00
|
|
|
|
|
2008-11-13 21:13:39 +01:00
|
|
|
|
static void
|
2023-12-14 04:30:14 +01:00
|
|
|
|
escaped_printf (FILE *out, const char *fmt, ...)
|
2008-11-13 21:13:39 +01:00
|
|
|
|
{
|
|
|
|
|
char *str;
|
|
|
|
|
va_list args;
|
2024-01-16 00:35:23 +01:00
|
|
|
|
size_t written;
|
2008-11-13 21:13:39 +01:00
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
|
|
va_start (args, fmt);
|
|
|
|
|
|
|
|
|
|
str = g_markup_vprintf_escaped (fmt, args);
|
2023-12-14 04:30:14 +01:00
|
|
|
|
if (!write_all (out, str, strlen (str), &written, &error))
|
2008-11-13 21:13:39 +01:00
|
|
|
|
{
|
|
|
|
|
g_critical ("failed to write to iochannel: %s", error->message);
|
|
|
|
|
g_clear_error (&error);
|
|
|
|
|
}
|
|
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
|
|
va_end (args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2023-12-14 04:30:14 +01:00
|
|
|
|
goutput_write (FILE *out, const char *str)
|
2008-11-13 21:13:39 +01:00
|
|
|
|
{
|
2024-01-16 00:35:23 +01:00
|
|
|
|
size_t written;
|
2008-11-13 21:13:39 +01:00
|
|
|
|
GError *error = NULL;
|
2023-12-14 04:30:14 +01:00
|
|
|
|
if (!write_all (out, str, strlen (str), &written, &error))
|
2008-11-13 21:13:39 +01:00
|
|
|
|
{
|
|
|
|
|
g_critical ("failed to write to iochannel: %s", error->message);
|
|
|
|
|
g_clear_error (&error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef GType (*GetTypeFunc)(void);
|
2011-05-19 22:21:13 +02:00
|
|
|
|
typedef GQuark (*ErrorQuarkFunc)(void);
|
2008-11-13 21:13:39 +01:00
|
|
|
|
|
|
|
|
|
static GType
|
|
|
|
|
invoke_get_type (GModule *self, const char *symbol, GError **error)
|
|
|
|
|
{
|
|
|
|
|
GetTypeFunc sym;
|
2010-07-31 12:22:52 +02:00
|
|
|
|
GType ret;
|
2008-11-13 21:13:39 +01:00
|
|
|
|
|
|
|
|
|
if (!g_module_symbol (self, symbol, (void**)&sym))
|
|
|
|
|
{
|
|
|
|
|
g_set_error (error,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
G_FILE_ERROR,
|
|
|
|
|
G_FILE_ERROR_FAILED,
|
|
|
|
|
"Failed to find symbol '%s'", symbol);
|
2008-11-13 21:13:39 +01:00
|
|
|
|
return G_TYPE_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 12:22:52 +02:00
|
|
|
|
ret = sym ();
|
|
|
|
|
if (ret == G_TYPE_INVALID)
|
|
|
|
|
{
|
|
|
|
|
g_set_error (error,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
G_FILE_ERROR,
|
|
|
|
|
G_FILE_ERROR_FAILED,
|
|
|
|
|
"Function '%s' returned G_TYPE_INVALID", symbol);
|
2010-07-31 12:22:52 +02:00
|
|
|
|
}
|
|
|
|
|
return ret;
|
2008-11-13 21:13:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-19 22:21:13 +02:00
|
|
|
|
static GQuark
|
|
|
|
|
invoke_error_quark (GModule *self, const char *symbol, GError **error)
|
|
|
|
|
{
|
|
|
|
|
ErrorQuarkFunc sym;
|
|
|
|
|
|
|
|
|
|
if (!g_module_symbol (self, symbol, (void**)&sym))
|
|
|
|
|
{
|
|
|
|
|
g_set_error (error,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
G_FILE_ERROR,
|
|
|
|
|
G_FILE_ERROR_FAILED,
|
|
|
|
|
"Failed to find symbol '%s'", symbol);
|
2011-05-19 22:21:13 +02:00
|
|
|
|
return G_TYPE_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sym ();
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-20 22:56:57 +01:00
|
|
|
|
static char *
|
|
|
|
|
value_transform_to_string (const GValue *value)
|
|
|
|
|
{
|
|
|
|
|
GValue tmp = G_VALUE_INIT;
|
|
|
|
|
char *s = NULL;
|
|
|
|
|
|
|
|
|
|
g_value_init (&tmp, G_TYPE_STRING);
|
|
|
|
|
|
|
|
|
|
if (g_value_transform (value, &tmp))
|
|
|
|
|
{
|
|
|
|
|
const char *str = g_value_get_string (&tmp);
|
|
|
|
|
|
|
|
|
|
if (str != NULL)
|
|
|
|
|
s = g_strescape (str, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_value_unset (&tmp);
|
|
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-31 00:43:51 +02:00
|
|
|
|
/* A simpler version of g_strdup_value_contents(), but with stable
|
|
|
|
|
* output and less complex semantics
|
|
|
|
|
*/
|
|
|
|
|
static char *
|
|
|
|
|
value_to_string (const GValue *value)
|
|
|
|
|
{
|
2023-03-20 19:49:40 +01:00
|
|
|
|
if (value == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2022-08-31 00:43:51 +02:00
|
|
|
|
if (G_VALUE_HOLDS_STRING (value))
|
|
|
|
|
{
|
|
|
|
|
const char *s = g_value_get_string (value);
|
|
|
|
|
|
|
|
|
|
if (s == NULL)
|
|
|
|
|
return g_strdup ("NULL");
|
|
|
|
|
|
|
|
|
|
return g_strescape (s, NULL);
|
|
|
|
|
}
|
2023-03-20 22:56:57 +01:00
|
|
|
|
else
|
2022-08-31 00:43:51 +02:00
|
|
|
|
{
|
2023-03-20 22:56:57 +01:00
|
|
|
|
GType value_type = G_VALUE_TYPE (value);
|
|
|
|
|
|
|
|
|
|
switch (G_TYPE_FUNDAMENTAL (value_type))
|
|
|
|
|
{
|
|
|
|
|
case G_TYPE_BOXED:
|
|
|
|
|
if (g_value_get_boxed (value) == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
else
|
|
|
|
|
return value_transform_to_string (value);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case G_TYPE_OBJECT:
|
|
|
|
|
if (g_value_get_object (value) == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
else
|
|
|
|
|
return value_transform_to_string (value);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case G_TYPE_POINTER:
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return value_transform_to_string (value);
|
|
|
|
|
}
|
2022-08-31 00:43:51 +02:00
|
|
|
|
}
|
2023-03-20 22:56:57 +01:00
|
|
|
|
|
|
|
|
|
return NULL;
|
2022-08-31 00:43:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-11-13 21:13:39 +01:00
|
|
|
|
static void
|
2023-12-14 04:30:14 +01:00
|
|
|
|
dump_properties (GType type, FILE *out)
|
2008-11-13 21:13:39 +01:00
|
|
|
|
{
|
2024-01-15 22:20:02 +01:00
|
|
|
|
unsigned int i;
|
|
|
|
|
unsigned int n_properties = 0;
|
2008-11-13 21:13:39 +01:00
|
|
|
|
GParamSpec **props;
|
|
|
|
|
|
|
|
|
|
if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_OBJECT)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *klass;
|
|
|
|
|
klass = g_type_class_ref (type);
|
|
|
|
|
props = g_object_class_list_properties (klass, &n_properties);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
void *klass;
|
|
|
|
|
klass = g_type_default_interface_ref (type);
|
|
|
|
|
props = g_object_interface_list_properties (klass, &n_properties);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < n_properties; i++)
|
|
|
|
|
{
|
|
|
|
|
GParamSpec *prop;
|
|
|
|
|
|
|
|
|
|
prop = props[i];
|
|
|
|
|
if (prop->owner_type != type)
|
2024-01-16 17:30:37 +01:00
|
|
|
|
continue;
|
2008-11-13 21:13:39 +01:00
|
|
|
|
|
2022-08-31 00:43:51 +02:00
|
|
|
|
const GValue *v = g_param_spec_get_default_value (prop);
|
|
|
|
|
char *default_value = value_to_string (v);
|
|
|
|
|
|
2023-03-20 19:49:40 +01:00
|
|
|
|
if (v != NULL && default_value != NULL)
|
2023-01-08 15:20:06 +01:00
|
|
|
|
{
|
|
|
|
|
escaped_printf (out, " <property name=\"%s\" type=\"%s\" flags=\"%d\" default-value=\"%s\"/>\n",
|
|
|
|
|
prop->name,
|
|
|
|
|
g_type_name (prop->value_type),
|
|
|
|
|
prop->flags,
|
|
|
|
|
default_value);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
escaped_printf (out, " <property name=\"%s\" type=\"%s\" flags=\"%d\"/>\n",
|
|
|
|
|
prop->name,
|
|
|
|
|
g_type_name (prop->value_type),
|
|
|
|
|
prop->flags);
|
|
|
|
|
}
|
2022-08-31 00:43:51 +02:00
|
|
|
|
|
|
|
|
|
g_free (default_value);
|
2008-11-13 21:13:39 +01:00
|
|
|
|
}
|
2022-08-31 00:43:51 +02:00
|
|
|
|
|
2008-11-13 21:13:39 +01:00
|
|
|
|
g_free (props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2023-12-14 04:30:14 +01:00
|
|
|
|
dump_signals (GType type, FILE *out)
|
2008-11-13 21:13:39 +01:00
|
|
|
|
{
|
2024-01-15 22:20:02 +01:00
|
|
|
|
unsigned int i;
|
|
|
|
|
unsigned int n_sigs;
|
|
|
|
|
unsigned int *sig_ids;
|
2008-11-13 21:13:39 +01:00
|
|
|
|
|
|
|
|
|
sig_ids = g_signal_list_ids (type, &n_sigs);
|
|
|
|
|
for (i = 0; i < n_sigs; i++)
|
|
|
|
|
{
|
2024-01-15 22:20:02 +01:00
|
|
|
|
unsigned int sigid;
|
2008-11-13 21:13:39 +01:00
|
|
|
|
GSignalQuery query;
|
2024-01-15 22:20:02 +01:00
|
|
|
|
unsigned int j;
|
2008-11-13 21:13:39 +01:00
|
|
|
|
|
|
|
|
|
sigid = sig_ids[i];
|
|
|
|
|
g_signal_query (sigid, &query);
|
|
|
|
|
|
2011-08-13 16:21:05 +02:00
|
|
|
|
escaped_printf (out, " <signal name=\"%s\" return=\"%s\"",
|
2024-01-16 17:30:37 +01:00
|
|
|
|
query.signal_name, g_type_name (query.return_type));
|
2008-11-13 21:13:39 +01:00
|
|
|
|
|
2011-08-13 16:21:05 +02:00
|
|
|
|
if (query.signal_flags & G_SIGNAL_RUN_FIRST)
|
|
|
|
|
escaped_printf (out, " when=\"first\"");
|
|
|
|
|
else if (query.signal_flags & G_SIGNAL_RUN_LAST)
|
|
|
|
|
escaped_printf (out, " when=\"last\"");
|
|
|
|
|
else if (query.signal_flags & G_SIGNAL_RUN_CLEANUP)
|
|
|
|
|
escaped_printf (out, " when=\"cleanup\"");
|
|
|
|
|
else if (query.signal_flags & G_SIGNAL_MUST_COLLECT)
|
|
|
|
|
escaped_printf (out, " when=\"must-collect\"");
|
|
|
|
|
if (query.signal_flags & G_SIGNAL_NO_RECURSE)
|
|
|
|
|
escaped_printf (out, " no-recurse=\"1\"");
|
|
|
|
|
|
|
|
|
|
if (query.signal_flags & G_SIGNAL_DETAILED)
|
|
|
|
|
escaped_printf (out, " detailed=\"1\"");
|
|
|
|
|
|
|
|
|
|
if (query.signal_flags & G_SIGNAL_ACTION)
|
|
|
|
|
escaped_printf (out, " action=\"1\"");
|
|
|
|
|
|
|
|
|
|
if (query.signal_flags & G_SIGNAL_NO_HOOKS)
|
|
|
|
|
escaped_printf (out, " no-hooks=\"1\"");
|
|
|
|
|
|
|
|
|
|
goutput_write (out, ">\n");
|
|
|
|
|
|
2008-11-13 21:13:39 +01:00
|
|
|
|
for (j = 0; j < query.n_params; j++)
|
2024-01-16 17:30:37 +01:00
|
|
|
|
{
|
|
|
|
|
escaped_printf (out, " <param type=\"%s\"/>\n",
|
|
|
|
|
g_type_name (query.param_types[j]));
|
|
|
|
|
}
|
2008-11-13 21:13:39 +01:00
|
|
|
|
goutput_write (out, " </signal>\n");
|
|
|
|
|
}
|
2016-02-25 00:53:08 +01:00
|
|
|
|
g_free (sig_ids);
|
2008-11-13 21:13:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2023-12-14 04:30:14 +01:00
|
|
|
|
dump_object_type (GType type, const char *symbol, FILE *out)
|
2008-11-13 21:13:39 +01:00
|
|
|
|
{
|
2024-01-15 22:20:02 +01:00
|
|
|
|
unsigned int n_interfaces;
|
|
|
|
|
unsigned int i;
|
2008-11-13 21:13:39 +01:00
|
|
|
|
GType *interfaces;
|
|
|
|
|
|
|
|
|
|
escaped_printf (out, " <class name=\"%s\" get-type=\"%s\"",
|
2024-01-16 17:30:37 +01:00
|
|
|
|
g_type_name (type), symbol);
|
2008-11-13 21:13:39 +01:00
|
|
|
|
if (type != G_TYPE_OBJECT)
|
2009-10-20 00:18:14 +02:00
|
|
|
|
{
|
|
|
|
|
GString *parent_str;
|
|
|
|
|
GType parent;
|
|
|
|
|
gboolean first = TRUE;
|
2010-03-24 19:00:06 +01:00
|
|
|
|
|
2010-08-25 19:14:57 +02:00
|
|
|
|
parent = g_type_parent (type);
|
2009-10-20 00:18:14 +02:00
|
|
|
|
parent_str = g_string_new ("");
|
2011-05-25 19:26:49 +02:00
|
|
|
|
while (parent != G_TYPE_INVALID)
|
2009-10-20 00:18:14 +02:00
|
|
|
|
{
|
|
|
|
|
if (first)
|
|
|
|
|
first = FALSE;
|
|
|
|
|
else
|
|
|
|
|
g_string_append_c (parent_str, ',');
|
|
|
|
|
g_string_append (parent_str, g_type_name (parent));
|
2010-08-25 19:14:57 +02:00
|
|
|
|
parent = g_type_parent (parent);
|
|
|
|
|
}
|
2010-03-24 19:00:06 +01:00
|
|
|
|
|
2009-10-20 00:18:14 +02:00
|
|
|
|
escaped_printf (out, " parents=\"%s\"", parent_str->str);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
|
2009-10-20 00:18:14 +02:00
|
|
|
|
g_string_free (parent_str, TRUE);
|
|
|
|
|
}
|
2008-11-13 21:13:39 +01:00
|
|
|
|
|
|
|
|
|
if (G_TYPE_IS_ABSTRACT (type))
|
|
|
|
|
escaped_printf (out, " abstract=\"1\"");
|
2021-02-09 12:38:27 +01:00
|
|
|
|
|
|
|
|
|
if (G_TYPE_IS_FINAL (type))
|
|
|
|
|
escaped_printf (out, " final=\"1\"");
|
|
|
|
|
|
2008-11-13 21:13:39 +01:00
|
|
|
|
goutput_write (out, ">\n");
|
|
|
|
|
|
|
|
|
|
interfaces = g_type_interfaces (type, &n_interfaces);
|
|
|
|
|
for (i = 0; i < n_interfaces; i++)
|
|
|
|
|
{
|
|
|
|
|
GType itype = interfaces[i];
|
|
|
|
|
escaped_printf (out, " <implements name=\"%s\"/>\n",
|
2024-01-16 17:30:37 +01:00
|
|
|
|
g_type_name (itype));
|
2008-11-13 21:13:39 +01:00
|
|
|
|
}
|
2016-02-25 00:53:08 +01:00
|
|
|
|
g_free (interfaces);
|
|
|
|
|
|
2008-11-13 21:13:39 +01:00
|
|
|
|
dump_properties (type, out);
|
|
|
|
|
dump_signals (type, out);
|
|
|
|
|
goutput_write (out, " </class>\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2023-12-14 04:30:14 +01:00
|
|
|
|
dump_interface_type (GType type, const char *symbol, FILE *out)
|
2008-11-13 21:13:39 +01:00
|
|
|
|
{
|
2024-01-15 22:20:02 +01:00
|
|
|
|
unsigned int n_interfaces;
|
|
|
|
|
unsigned int i;
|
2008-11-13 21:13:39 +01:00
|
|
|
|
GType *interfaces;
|
|
|
|
|
|
|
|
|
|
escaped_printf (out, " <interface name=\"%s\" get-type=\"%s\">\n",
|
2024-01-16 17:30:37 +01:00
|
|
|
|
g_type_name (type), symbol);
|
2008-11-13 21:13:39 +01:00
|
|
|
|
|
|
|
|
|
interfaces = g_type_interface_prerequisites (type, &n_interfaces);
|
|
|
|
|
for (i = 0; i < n_interfaces; i++)
|
|
|
|
|
{
|
|
|
|
|
GType itype = interfaces[i];
|
2008-11-17 01:27:37 +01:00
|
|
|
|
if (itype == G_TYPE_OBJECT)
|
2024-01-16 17:30:37 +01:00
|
|
|
|
{
|
|
|
|
|
/* Treat this as implicit for now; in theory GInterfaces are
|
|
|
|
|
* supported on things like GstMiniObject, but right now
|
|
|
|
|
* the introspection system only supports GObject.
|
|
|
|
|
* http://bugzilla.gnome.org/show_bug.cgi?id=559706
|
|
|
|
|
*/
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2008-11-17 01:27:37 +01:00
|
|
|
|
escaped_printf (out, " <prerequisite name=\"%s\"/>\n",
|
2024-01-16 17:30:37 +01:00
|
|
|
|
g_type_name (itype));
|
2008-11-13 21:13:39 +01:00
|
|
|
|
}
|
2016-02-25 00:53:08 +01:00
|
|
|
|
g_free (interfaces);
|
|
|
|
|
|
2008-11-13 21:13:39 +01:00
|
|
|
|
dump_properties (type, out);
|
|
|
|
|
dump_signals (type, out);
|
|
|
|
|
goutput_write (out, " </interface>\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2023-12-14 04:30:14 +01:00
|
|
|
|
dump_boxed_type (GType type, const char *symbol, FILE *out)
|
2008-11-13 21:13:39 +01:00
|
|
|
|
{
|
|
|
|
|
escaped_printf (out, " <boxed name=\"%s\" get-type=\"%s\"/>\n",
|
2024-01-16 17:30:37 +01:00
|
|
|
|
g_type_name (type), symbol);
|
2008-11-13 21:13:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2023-12-14 04:30:14 +01:00
|
|
|
|
dump_flags_type (GType type, const char *symbol, FILE *out)
|
2008-11-13 21:13:39 +01:00
|
|
|
|
{
|
2024-01-15 22:20:02 +01:00
|
|
|
|
unsigned int i;
|
2008-11-13 21:13:39 +01:00
|
|
|
|
GFlagsClass *klass;
|
|
|
|
|
|
|
|
|
|
klass = g_type_class_ref (type);
|
|
|
|
|
escaped_printf (out, " <flags name=\"%s\" get-type=\"%s\">\n",
|
2024-01-16 17:30:37 +01:00
|
|
|
|
g_type_name (type), symbol);
|
2008-11-13 21:13:39 +01:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < klass->n_values; i++)
|
|
|
|
|
{
|
|
|
|
|
GFlagsValue *value = &(klass->values[i]);
|
|
|
|
|
|
2018-07-04 16:54:31 +02:00
|
|
|
|
escaped_printf (out, " <member name=\"%s\" nick=\"%s\" value=\"%u\"/>\n",
|
2024-01-16 17:30:37 +01:00
|
|
|
|
value->value_name, value->value_nick, value->value);
|
2008-11-13 21:13:39 +01:00
|
|
|
|
}
|
|
|
|
|
goutput_write (out, " </flags>\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2023-12-14 04:30:14 +01:00
|
|
|
|
dump_enum_type (GType type, const char *symbol, FILE *out)
|
2008-11-13 21:13:39 +01:00
|
|
|
|
{
|
2024-01-15 22:20:02 +01:00
|
|
|
|
unsigned int i;
|
2008-11-13 21:13:39 +01:00
|
|
|
|
GEnumClass *klass;
|
|
|
|
|
|
|
|
|
|
klass = g_type_class_ref (type);
|
|
|
|
|
escaped_printf (out, " <enum name=\"%s\" get-type=\"%s\">\n",
|
2024-01-16 17:30:37 +01:00
|
|
|
|
g_type_name (type), symbol);
|
2008-11-13 21:13:39 +01:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < klass->n_values; i++)
|
|
|
|
|
{
|
|
|
|
|
GEnumValue *value = &(klass->values[i]);
|
|
|
|
|
|
|
|
|
|
escaped_printf (out, " <member name=\"%s\" nick=\"%s\" value=\"%d\"/>\n",
|
2024-01-16 17:30:37 +01:00
|
|
|
|
value->value_name, value->value_nick, value->value);
|
2008-11-13 21:13:39 +01:00
|
|
|
|
}
|
|
|
|
|
goutput_write (out, " </enum>");
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-12 23:08:56 +02:00
|
|
|
|
static void
|
2023-12-14 04:30:14 +01:00
|
|
|
|
dump_fundamental_type (GType type, const char *symbol, FILE *out)
|
2010-06-12 23:08:56 +02:00
|
|
|
|
{
|
2024-01-15 22:20:02 +01:00
|
|
|
|
unsigned int n_interfaces;
|
|
|
|
|
unsigned int i;
|
2010-06-12 23:08:56 +02:00
|
|
|
|
GType *interfaces;
|
|
|
|
|
GString *parent_str;
|
|
|
|
|
GType parent;
|
|
|
|
|
gboolean first = TRUE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
escaped_printf (out, " <fundamental name=\"%s\" get-type=\"%s\"",
|
2024-01-16 17:30:37 +01:00
|
|
|
|
g_type_name (type), symbol);
|
2010-06-12 23:08:56 +02:00
|
|
|
|
|
|
|
|
|
if (G_TYPE_IS_ABSTRACT (type))
|
|
|
|
|
escaped_printf (out, " abstract=\"1\"");
|
|
|
|
|
|
2021-02-09 12:38:27 +01:00
|
|
|
|
if (G_TYPE_IS_FINAL (type))
|
|
|
|
|
escaped_printf (out, " final=\"1\"");
|
|
|
|
|
|
2010-06-12 23:08:56 +02:00
|
|
|
|
if (G_TYPE_IS_INSTANTIATABLE (type))
|
|
|
|
|
escaped_printf (out, " instantiatable=\"1\"");
|
|
|
|
|
|
2010-08-25 19:14:57 +02:00
|
|
|
|
parent = g_type_parent (type);
|
2010-06-12 23:08:56 +02:00
|
|
|
|
parent_str = g_string_new ("");
|
2010-08-25 19:14:57 +02:00
|
|
|
|
while (parent != G_TYPE_INVALID)
|
2010-06-12 23:08:56 +02:00
|
|
|
|
{
|
|
|
|
|
if (first)
|
|
|
|
|
first = FALSE;
|
|
|
|
|
else
|
|
|
|
|
g_string_append_c (parent_str, ',');
|
|
|
|
|
if (!g_type_name (parent))
|
|
|
|
|
break;
|
|
|
|
|
g_string_append (parent_str, g_type_name (parent));
|
2010-08-25 19:14:57 +02:00
|
|
|
|
parent = g_type_parent (parent);
|
|
|
|
|
}
|
2010-06-12 23:08:56 +02:00
|
|
|
|
|
|
|
|
|
if (parent_str->len > 0)
|
|
|
|
|
escaped_printf (out, " parents=\"%s\"", parent_str->str);
|
|
|
|
|
g_string_free (parent_str, TRUE);
|
|
|
|
|
|
|
|
|
|
goutput_write (out, ">\n");
|
|
|
|
|
|
|
|
|
|
interfaces = g_type_interfaces (type, &n_interfaces);
|
|
|
|
|
for (i = 0; i < n_interfaces; i++)
|
|
|
|
|
{
|
|
|
|
|
GType itype = interfaces[i];
|
|
|
|
|
escaped_printf (out, " <implements name=\"%s\"/>\n",
|
2024-01-16 17:30:37 +01:00
|
|
|
|
g_type_name (itype));
|
2010-06-12 23:08:56 +02:00
|
|
|
|
}
|
2016-02-25 00:53:08 +01:00
|
|
|
|
g_free (interfaces);
|
2010-06-12 23:08:56 +02:00
|
|
|
|
goutput_write (out, " </fundamental>\n");
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-13 21:13:39 +01:00
|
|
|
|
static void
|
2023-12-14 04:30:14 +01:00
|
|
|
|
dump_type (GType type, const char *symbol, FILE *out)
|
2008-11-13 21:13:39 +01:00
|
|
|
|
{
|
|
|
|
|
switch (g_type_fundamental (type))
|
|
|
|
|
{
|
|
|
|
|
case G_TYPE_OBJECT:
|
|
|
|
|
dump_object_type (type, symbol, out);
|
|
|
|
|
break;
|
|
|
|
|
case G_TYPE_INTERFACE:
|
|
|
|
|
dump_interface_type (type, symbol, out);
|
|
|
|
|
break;
|
|
|
|
|
case G_TYPE_BOXED:
|
|
|
|
|
dump_boxed_type (type, symbol, out);
|
|
|
|
|
break;
|
|
|
|
|
case G_TYPE_FLAGS:
|
|
|
|
|
dump_flags_type (type, symbol, out);
|
|
|
|
|
break;
|
|
|
|
|
case G_TYPE_ENUM:
|
|
|
|
|
dump_enum_type (type, symbol, out);
|
|
|
|
|
break;
|
|
|
|
|
case G_TYPE_POINTER:
|
|
|
|
|
/* GValue, etc. Just skip them. */
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2010-06-12 23:08:56 +02:00
|
|
|
|
dump_fundamental_type (type, symbol, out);
|
2008-11-24 17:22:16 +01:00
|
|
|
|
break;
|
2008-11-13 21:13:39 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-19 22:21:13 +02:00
|
|
|
|
static void
|
2023-12-14 04:30:14 +01:00
|
|
|
|
dump_error_quark (GQuark quark, const char *symbol, FILE *out)
|
2011-05-19 22:21:13 +02:00
|
|
|
|
{
|
|
|
|
|
escaped_printf (out, " <error-quark function=\"%s\" domain=\"%s\"/>\n",
|
2024-01-16 17:30:37 +01:00
|
|
|
|
symbol, g_quark_to_string (quark));
|
2011-05-19 22:21:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-11-13 21:13:39 +01:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_repository_dump:
|
2023-12-12 23:43:11 +01:00
|
|
|
|
* @input_filename: (type filename): Input filename (for example `input.txt`)
|
|
|
|
|
* @output_filename: (type filename): Output filename (for example `output.xml`)
|
2008-11-13 21:13:39 +01:00
|
|
|
|
* @error: a %GError
|
|
|
|
|
*
|
2023-12-12 23:43:11 +01:00
|
|
|
|
* Dump the introspection data from the types specified in @input_filename to
|
|
|
|
|
* @output_filename.
|
|
|
|
|
*
|
|
|
|
|
* The input file should be a
|
2013-06-05 13:28:30 +02:00
|
|
|
|
* UTF-8 Unix-line-ending text file, with each line containing either
|
2023-12-12 23:43:11 +01:00
|
|
|
|
* `get-type:` followed by the name of a [type@GObject.Type] `_get_type`
|
|
|
|
|
* function, or `error-quark:` followed by the name of an error quark function.
|
|
|
|
|
* No extra whitespace is allowed.
|
2008-11-13 21:13:39 +01:00
|
|
|
|
*
|
2023-12-12 23:43:11 +01:00
|
|
|
|
* This function will overwrite the contents of the output file.
|
2008-11-13 21:13:39 +01:00
|
|
|
|
*
|
2023-12-12 23:43:11 +01:00
|
|
|
|
* Returns: true on success, false on error
|
|
|
|
|
* Since: 2.80
|
2008-11-13 21:13:39 +01:00
|
|
|
|
*/
|
2023-10-25 19:30:38 +02:00
|
|
|
|
#ifndef GI_COMPILATION
|
2011-01-11 14:26:29 +01:00
|
|
|
|
static gboolean
|
2023-12-12 23:43:11 +01:00
|
|
|
|
dump_irepository (const char *input_filename,
|
|
|
|
|
const char *output_filename,
|
|
|
|
|
GError **error) G_GNUC_UNUSED;
|
2011-09-03 18:34:29 +02:00
|
|
|
|
static gboolean
|
2023-12-12 23:43:11 +01:00
|
|
|
|
dump_irepository (const char *input_filename,
|
|
|
|
|
const char *output_filename,
|
|
|
|
|
GError **error)
|
2011-01-11 14:26:29 +01:00
|
|
|
|
#else
|
2008-11-13 21:13:39 +01:00
|
|
|
|
gboolean
|
2023-12-12 23:43:11 +01:00
|
|
|
|
gi_repository_dump (const char *input_filename,
|
|
|
|
|
const char *output_filename,
|
|
|
|
|
GError **error)
|
2011-01-11 14:26:29 +01:00
|
|
|
|
#endif
|
2008-11-13 21:13:39 +01:00
|
|
|
|
{
|
|
|
|
|
GHashTable *output_types;
|
2023-12-14 04:30:14 +01:00
|
|
|
|
FILE *input;
|
|
|
|
|
FILE *output;
|
2008-11-13 21:13:39 +01:00
|
|
|
|
GModule *self;
|
|
|
|
|
gboolean caught_error = FALSE;
|
|
|
|
|
|
|
|
|
|
self = g_module_open (NULL, 0);
|
|
|
|
|
if (!self)
|
|
|
|
|
{
|
|
|
|
|
g_set_error (error,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
G_FILE_ERROR,
|
|
|
|
|
G_FILE_ERROR_FAILED,
|
|
|
|
|
"failed to open self: %s",
|
|
|
|
|
g_module_error ());
|
2008-11-13 21:13:39 +01:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-14 04:30:14 +01:00
|
|
|
|
input = fopen (input_filename, "rb");
|
2008-11-13 21:13:39 +01:00
|
|
|
|
if (input == NULL)
|
2016-04-22 13:23:51 +02:00
|
|
|
|
{
|
2023-12-14 04:30:14 +01:00
|
|
|
|
int saved_errno = errno;
|
|
|
|
|
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (saved_errno),
|
|
|
|
|
"Failed to open ‘%s’: %s", input_filename, g_strerror (saved_errno));
|
|
|
|
|
|
|
|
|
|
g_module_close (self);
|
|
|
|
|
|
2016-04-22 13:23:51 +02:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2008-11-13 21:13:39 +01:00
|
|
|
|
|
2023-12-14 04:30:14 +01:00
|
|
|
|
output = fopen (output_filename, "wb");
|
2008-11-13 21:13:39 +01:00
|
|
|
|
if (output == NULL)
|
|
|
|
|
{
|
2023-12-14 04:30:14 +01:00
|
|
|
|
int saved_errno = errno;
|
|
|
|
|
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (saved_errno),
|
|
|
|
|
"Failed to open ‘%s’: %s", output_filename, g_strerror (saved_errno));
|
|
|
|
|
|
|
|
|
|
fclose (input);
|
|
|
|
|
g_module_close (self);
|
|
|
|
|
|
2008-11-13 21:13:39 +01:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-14 04:30:14 +01:00
|
|
|
|
goutput_write (output, "<?xml version=\"1.0\"?>\n");
|
|
|
|
|
goutput_write (output, "<dump>\n");
|
2008-11-13 21:13:39 +01:00
|
|
|
|
|
|
|
|
|
output_types = g_hash_table_new (NULL, NULL);
|
|
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
|
{
|
2024-01-16 00:35:23 +01:00
|
|
|
|
size_t len;
|
2023-12-14 04:30:14 +01:00
|
|
|
|
char *line = read_line (input, &len);
|
2011-05-19 22:21:13 +02:00
|
|
|
|
const char *function;
|
2008-11-13 21:13:39 +01:00
|
|
|
|
|
|
|
|
|
if (line == NULL || *line == '\0')
|
2011-05-19 22:21:13 +02:00
|
|
|
|
{
|
|
|
|
|
g_free (line);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2008-11-13 21:13:39 +01:00
|
|
|
|
|
|
|
|
|
g_strchomp (line);
|
|
|
|
|
|
2011-05-19 22:21:13 +02:00
|
|
|
|
if (strncmp (line, "get-type:", strlen ("get-type:")) == 0)
|
|
|
|
|
{
|
|
|
|
|
GType type;
|
2008-11-13 21:13:39 +01:00
|
|
|
|
|
2011-05-19 22:21:13 +02:00
|
|
|
|
function = line + strlen ("get-type:");
|
|
|
|
|
|
|
|
|
|
type = invoke_get_type (self, function, error);
|
|
|
|
|
|
|
|
|
|
if (type == G_TYPE_INVALID)
|
|
|
|
|
{
|
|
|
|
|
g_printerr ("Invalid GType function: '%s'\n", function);
|
|
|
|
|
caught_error = TRUE;
|
|
|
|
|
g_free (line);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (g_hash_table_lookup (output_types, (gpointer) type))
|
|
|
|
|
goto next;
|
|
|
|
|
g_hash_table_insert (output_types, (gpointer) type, (gpointer) type);
|
|
|
|
|
|
2023-12-14 04:30:14 +01:00
|
|
|
|
dump_type (type, function, output);
|
2011-05-19 22:21:13 +02:00
|
|
|
|
}
|
|
|
|
|
else if (strncmp (line, "error-quark:", strlen ("error-quark:")) == 0)
|
|
|
|
|
{
|
|
|
|
|
GQuark quark;
|
|
|
|
|
function = line + strlen ("error-quark:");
|
|
|
|
|
quark = invoke_error_quark (self, function, error);
|
|
|
|
|
|
|
|
|
|
if (quark == 0)
|
|
|
|
|
{
|
|
|
|
|
g_printerr ("Invalid error quark function: '%s'\n", function);
|
|
|
|
|
caught_error = TRUE;
|
|
|
|
|
g_free (line);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-14 04:30:14 +01:00
|
|
|
|
dump_error_quark (quark, function, output);
|
2011-05-19 22:21:13 +02:00
|
|
|
|
}
|
2008-11-13 21:13:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
next:
|
|
|
|
|
g_free (line);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_hash_table_destroy (output_types);
|
|
|
|
|
|
2023-12-14 04:30:14 +01:00
|
|
|
|
goutput_write (output, "</dump>\n");
|
2008-11-13 21:13:39 +01:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
/* Avoid overwriting an earlier set error */
|
2023-12-14 04:30:14 +01:00
|
|
|
|
if (fclose (input) != 0 && !caught_error)
|
|
|
|
|
{
|
|
|
|
|
int saved_errno = errno;
|
|
|
|
|
|
|
|
|
|
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (saved_errno),
|
|
|
|
|
"Error closing input file ‘%s’: %s", input_filename,
|
|
|
|
|
g_strerror (saved_errno));
|
|
|
|
|
caught_error = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fclose (output) != 0 && !caught_error)
|
|
|
|
|
{
|
|
|
|
|
int saved_errno = errno;
|
|
|
|
|
|
|
|
|
|
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (saved_errno),
|
|
|
|
|
"Error closing output file ‘%s’: %s", output_filename,
|
|
|
|
|
g_strerror (saved_errno));
|
|
|
|
|
caught_error = TRUE;
|
|
|
|
|
}
|
2008-11-13 21:13:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return !caught_error;
|
|
|
|
|
}
|