[anjuta] libanjuta: Change autogen API to support introspection
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] libanjuta: Change autogen API to support introspection
- Date: Mon, 30 Apr 2012 19:09:39 +0000 (UTC)
commit da50c0e662a160627f65deeb2fd2f628ae5de00a
Author: SÃbastien Granjoux <seb sfo free fr>
Date: Sun Apr 29 18:22:00 2012 +0200
libanjuta: Change autogen API to support introspection
libanjuta/anjuta-autogen.c | 132 +++++++++++++++++++++++++-------------
libanjuta/anjuta-autogen.h | 13 +++-
plugins/class-gen/generator.c | 2 +-
plugins/project-wizard/druid.c | 4 +-
plugins/project-wizard/install.c | 6 +-
5 files changed, 105 insertions(+), 52 deletions(-)
---
diff --git a/libanjuta/anjuta-autogen.c b/libanjuta/anjuta-autogen.c
index 816a4c0..0740bd0 100644
--- a/libanjuta/anjuta-autogen.c
+++ b/libanjuta/anjuta-autogen.c
@@ -90,6 +90,8 @@
struct _AnjutaAutogen
{
+ GObject parent;
+
gchar* deffilename; /* name of generated definition file */
const gchar* tplfilename; /* name of template (input) file */
gchar* temptplfilename; /* name of generated template if the
@@ -107,6 +109,8 @@ struct _AnjutaAutogen
* when autogen output something */
AnjutaAutogenOutputFunc outfunc;
gpointer outdata;
+ GDestroyNotify destroy;
+
/* Call back function and data used
* when autogen terminate */
AnjutaAutogenFunc endfunc;
@@ -116,6 +120,12 @@ struct _AnjutaAutogen
gboolean busy; /* For debugging */
};
+struct _AnjutaAutogenClass
+{
+ GObjectClass parent;
+};
+
+
/*---------------------------------------------------------------------------*/
/* Helper functions
@@ -207,7 +217,7 @@ cb_autogen_write_key (const gchar* name, const gchar *value, gpointer user_data)
/**
* anjuta_autogen_write_definition_file
* @this: A #AnjutaAutogen object
- * @values: A hash table containing all definitions
+ * @values: (element-type utf8 utf8): A hash table containing all definitions
* @error: Error propagation and reporting
*
* Write the autogen definition file. The definition file defined variables
@@ -322,8 +332,8 @@ anjuta_autogen_get_library_paths (AnjutaAutogen* this)
* anjuta_autogen_set_input_file
* @this: A #AnjutaAutogen object
* @filename: name of the input template file
- * @start_marker: (allow none): start marker string
- * @end_marker: (allow none): end marker string
+ * @start_marker: (allow-none): start marker string
+ * @end_marker: (allow-none): end marker string
*
* Read an autogen template file, optionally adding autogen markers.
*
@@ -361,14 +371,14 @@ anjuta_autogen_set_input_file (AnjutaAutogen* this, const gchar* filename, const
if (this->temptplfilename != NULL)
{
remove (this->temptplfilename);
- g_free (this->temptplfilename);
this->temptplfilename = NULL;
}
+ g_free (this->tplfilename);
if ((start_marker == NULL) && (end_marker == NULL))
{
/* input file is really an autogen file, nothig do to */
- this->tplfilename = filename;
+ this->tplfilename = g_strdup (filename);
return TRUE;
}
@@ -435,7 +445,8 @@ anjuta_autogen_set_output_file (AnjutaAutogen* this, const gchar* filename)
/* Autogen should not be running */
g_return_val_if_fail (this->busy == FALSE, FALSE);
- this->outfilename = filename;
+ g_free (this->outfilename);
+ this->outfilename = g_strdup (filename);
this->outfunc = NULL;
return TRUE;
@@ -444,8 +455,9 @@ anjuta_autogen_set_output_file (AnjutaAutogen* this, const gchar* filename)
/**
* anjuta_autogen_set_output_callback
* @this: A #AnjutaAutogen object
- * @func: Function call each time we get new data from autogen
- * @user_data: (allow none): User data to pass to @func, or %NULL
+ * @func: (scope notified) (allow-none): Function call each time we get new data from autogen
+ * @user_data: (allow-none): User data to pass to @func, or %NULL
+ * @destroy: Function call when the process is complete to free user data
*
* Define that autogen output should be send to a function as soon as it arrives.
*
@@ -453,13 +465,14 @@ anjuta_autogen_set_output_file (AnjutaAutogen* this, const gchar* filename)
*/
gboolean
-anjuta_autogen_set_output_callback (AnjutaAutogen* this, AnjutaAutogenOutputFunc func, gpointer user_data)
+anjuta_autogen_set_output_callback (AnjutaAutogen* this, AnjutaAutogenOutputFunc func, gpointer user_data, GDestroyNotify destroy)
{
/* Autogen should not be running */
g_return_val_if_fail (this->busy == FALSE, FALSE);
this->outfunc = func;
this->outdata = user_data;
+ this->destroy = destroy;
this->outfilename = NULL;
return TRUE;
@@ -504,6 +517,10 @@ on_autogen_terminated (AnjutaLauncher* launcher, gint pid, gint status, gulong t
}
}
+ if (this->destroy)
+ {
+ (this->destroy)(this->outdata);
+ }
if (this->endfunc)
{
(this->endfunc)(this, this->enddata);
@@ -513,9 +530,9 @@ on_autogen_terminated (AnjutaLauncher* launcher, gint pid, gint status, gulong t
/**
* anjuta_autogen_execute
* @this: A #AnjutaAutogen object
- * @func: (transfer async) (allow none): A function called when autogen is terminated
- * @data: (allow none): User data to pass to @func, or %NULL
- * @error: Error propagation and reporting
+ * @func: (scope async) (allow-none): A function called when autogen is terminated
+ * @data: (allow-none): User data to pass to @func, or %NULL
+ * @error: (allow-none): Error propagation and reporting
*
* Asynchronously execute autogen to generate the output, calling @func when the
* process is completed.
@@ -595,48 +612,44 @@ anjuta_autogen_execute (AnjutaAutogen* this, AnjutaAutogenFunc func, gpointer da
return TRUE;
}
-/* Creation and Destruction
+/* Implement GObject
*---------------------------------------------------------------------------*/
-/**
- * anjuta_autogen_new
- *
- * Create a new autogen object.
- *
- * Returns: A #AnjutaAutogen object.
- */
+G_DEFINE_TYPE (AnjutaAutogen, anjuta_autogen, G_TYPE_OBJECT);
-AnjutaAutogen* anjuta_autogen_new (void)
+static void
+anjuta_autogen_init (AnjutaAutogen *this)
{
- AnjutaAutogen* this;
-
- this = g_new0(AnjutaAutogen, 1);
-
this->launcher = anjuta_launcher_new ();
g_signal_connect (G_OBJECT (this->launcher), "child-exited", G_CALLBACK (on_autogen_terminated), this);
/* Create a temporary file for definitions */
this->deffilename = g_build_filename (g_get_tmp_dir (), TMP_DEF_FILENAME, NULL);
mktemp (this->deffilename);
-
- return this;
}
-/**
- * anjuta_autogen_free
- * @this: A #AnjutaAutogen object
- *
- * Free the #AnjutaAutogen object.
- */
-
-void anjuta_autogen_free (AnjutaAutogen* this)
+static void
+anjuta_autogen_dispose (GObject *object)
{
- g_return_if_fail(this != NULL);
+ AnjutaAutogen *this = ANJUTA_AUTOGEN (object);
if (this->output != NULL)
{
/* output is not used if a callback function is used */
fclose (this->output);
+ this->output = NULL;
+ }
+
+ if (this->outfilename != NULL)
+ {
+ g_free (this->outfilename);
+ this->outfilename = NULL;
+ }
+
+ if (this->tplfilename != NULL)
+ {
+ g_free (this->tplfilename);
+ this->tplfilename = NULL;
}
if (this->temptplfilename != NULL)
@@ -644,23 +657,54 @@ void anjuta_autogen_free (AnjutaAutogen* this)
/* temptplfilename is not used if input file already
* contains autogen marker */
remove (this->temptplfilename);
- g_free (this->temptplfilename);
+ this->temptplfilename = NULL;
}
g_list_foreach (this->library_paths, (GFunc)g_free, NULL);
g_list_free (this->library_paths);
+ this->library_paths = NULL;
- /* deffilename should always be here (created in new) */
- g_return_if_fail (this->deffilename);
- remove (this->deffilename);
- g_free (this->deffilename);
+ if (this->deffilename != NULL)
+ {
+ remove (this->deffilename);
+ g_free (this->deffilename);
+ this->deffilename = NULL;
+ }
+
+ if (this->launcher != NULL)
+ {
+ g_signal_handlers_disconnect_by_func (G_OBJECT (this->launcher), G_CALLBACK (on_autogen_terminated), this);
+ g_object_unref (this->launcher);
+ this->launcher = NULL;
+ }
- g_signal_handlers_disconnect_by_func (G_OBJECT (this->launcher), G_CALLBACK (on_autogen_terminated), this);
- g_object_unref (this->launcher);
+ G_OBJECT_CLASS (anjuta_autogen_parent_class)->dispose (object);
+}
+
+static void
+anjuta_autogen_class_init (AnjutaAutogenClass *klass)
+{
+ GObjectClass* object_class = G_OBJECT_CLASS (klass);
- g_free (this);
+ object_class->dispose = anjuta_autogen_dispose;
}
+/* Creation and Destruction
+ *---------------------------------------------------------------------------*/
+
+/**
+ * anjuta_autogen_new
+ *
+ * Create a new autogen object.
+ *
+ * Returns: (transfer full): A new #AnjutaAutogen object. Free it using g_object_unref.
+ */
+
+AnjutaAutogen* anjuta_autogen_new (void)
+{
+ return g_object_new (ANJUTA_TYPE_AUTOGEN, NULL);
+}
+
diff --git a/libanjuta/anjuta-autogen.h b/libanjuta/anjuta-autogen.h
index 6197b36..bb6ff0c 100644
--- a/libanjuta/anjuta-autogen.h
+++ b/libanjuta/anjuta-autogen.h
@@ -30,6 +30,16 @@
**/
typedef struct _AnjutaAutogen AnjutaAutogen;
+typedef struct _AnjutaAutogenClass AnjutaAutogenClass;
+
+#define ANJUTA_TYPE_AUTOGEN (anjuta_autogen_get_type ())
+#define ANJUTA_AUTOGEN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ANJUTA_TYPE_AUTOGEN, AnjutaAutogen))
+#define ANJUTA_AUTOGEN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ANJUTA_TYPE_AUTOGEN, AnjutaAutogenClass))
+#define ANJUTA_IS_AUTOGEN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ANJUTA_TYPE_AUTOGEN))
+#define ANJUTA_IS_AUTOGEN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ANJUTA_TYPE_AUTOGEN))
+#define ANJUTA_AUTOGEN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ANJUTA_TYPE_AUTOGEN, AnjutaAutogenClass))
+
+GType anjuta_autogen_get_type (void) G_GNUC_CONST;
/**
* AnjutaAutogenFunc:
@@ -75,7 +85,6 @@ GQuark anjuta_autogen_error_quark (void);
AnjutaAutogen* anjuta_autogen_new (void);
-void anjuta_autogen_free (AnjutaAutogen* this);
gboolean anjuta_autogen_write_definition_file (AnjutaAutogen* this, GHashTable* values, GError **error);
@@ -84,7 +93,7 @@ void anjuta_autogen_clear_library_path (AnjutaAutogen* this);
GList *anjuta_autogen_get_library_paths (AnjutaAutogen* this);
gboolean anjuta_autogen_set_input_file (AnjutaAutogen* this, const gchar* filename, const gchar* start_marker, const gchar* end_marker);
gboolean anjuta_autogen_set_output_file (AnjutaAutogen* this, const gchar* filename);
-gboolean anjuta_autogen_set_output_callback (AnjutaAutogen* this, AnjutaAutogenOutputFunc func, gpointer user_data);
+gboolean anjuta_autogen_set_output_callback (AnjutaAutogen* this, AnjutaAutogenOutputFunc func, gpointer user_data, GDestroyNotify destroy);
gboolean anjuta_autogen_execute (AnjutaAutogen* this, AnjutaAutogenFunc func, gpointer data, GError** error);
diff --git a/plugins/class-gen/generator.c b/plugins/class-gen/generator.c
index ad7e90b..c485004 100644
--- a/plugins/class-gen/generator.c
+++ b/plugins/class-gen/generator.c
@@ -190,7 +190,7 @@ cg_generator_finalize (GObject *object)
generator = CG_GENERATOR (object);
priv = CG_GENERATOR_PRIVATE (generator);
- anjuta_autogen_free (priv->autogen);
+ g_object_unref (G_OBJECT (priv->autogen));
g_free (priv->header_template);
g_free (priv->source_template);
diff --git a/plugins/project-wizard/druid.c b/plugins/project-wizard/druid.c
index d50298a..5730630 100644
--- a/plugins/project-wizard/druid.c
+++ b/plugins/project-wizard/druid.c
@@ -1065,7 +1065,7 @@ on_druid_real_prepare (GtkAssistant* assistant, GtkWidget *page, NPWDruid* druid
npw_page_parser_free (druid->parser);
druid->parser = npw_page_parser_new (npw_druid_add_new_page (druid), druid->project_file, previous);
- anjuta_autogen_set_output_callback (druid->gen, on_druid_parse_page, druid->parser);
+ anjuta_autogen_set_output_callback (druid->gen, on_druid_parse_page, druid->parser, NULL);
anjuta_autogen_write_definition_file (druid->gen, druid->values, NULL);
anjuta_autogen_execute (druid->gen, on_druid_get_new_page, druid, NULL);
}
@@ -1296,7 +1296,7 @@ npw_druid_free (NPWDruid* druid)
}
g_queue_free (druid->page_list);
g_hash_table_destroy (druid->values);
- anjuta_autogen_free (druid->gen);
+ g_object_unref (G_OBJECT (druid->gen));
if (druid->parser != NULL) npw_page_parser_free (druid->parser);
npw_header_list_free (druid->header_list);
gtk_widget_destroy (GTK_WIDGET (druid->window));
diff --git a/plugins/project-wizard/install.c b/plugins/project-wizard/install.c
index 26ffdc7..833ab57 100644
--- a/plugins/project-wizard/install.c
+++ b/plugins/project-wizard/install.c
@@ -228,7 +228,7 @@ void npw_install_free (NPWInstall* this)
g_signal_handlers_disconnect_by_func (G_OBJECT (this->launcher), G_CALLBACK (on_run_terminated), this);
g_object_unref (this->launcher);
}
- anjuta_autogen_free (this->gen);
+ g_object_unref (this->gen);
this->plugin->install = NULL;
g_free (this);
}
@@ -364,7 +364,7 @@ on_install_read_all_file_list (AnjutaAutogen* gen, gpointer data)
npw_action_list_parser_free (this->action_parser);
}
this->action_parser = npw_action_list_parser_new ();
- anjuta_autogen_set_output_callback (this->gen, on_install_read_action_list, this);
+ anjuta_autogen_set_output_callback (this->gen, on_install_read_action_list, this, NULL);
anjuta_autogen_execute (this->gen, on_install_read_all_action_list, this, NULL);
}
@@ -440,7 +440,7 @@ on_install_end_install_file (AnjutaAutogen* gen, gpointer data)
gboolean
npw_install_launch (NPWInstall* this)
{
- anjuta_autogen_set_output_callback (this->gen, on_install_read_file_list, this);
+ anjuta_autogen_set_output_callback (this->gen, on_install_read_file_list, this, NULL);
anjuta_autogen_execute (this->gen, on_install_read_all_file_list, this, NULL);
return TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]