Added initial Spanish translation
[anjuta-git-plugin.git] / libanjuta / anjuta-glue-c.c
blob37422c59056dcde97dbd7a29b9a36b17818214bb
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 anjuta-glue-c.c
4 Copyright (C) 2007 Sébastien Granjoux
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 /**
22 * SECTION:anjuta-glue-c-plugin
23 * @short_description: Anjuta glue C plugin
24 * @see_also:
25 * @stability: Unstable
26 * @include: libanjuta/anjuta-glue-c.h
30 #include "anjuta-glue-c.h"
32 typedef void (*AnjutaGluePluginRegisterComponentsFunc) (AnjutaGluePlugin *plugin);
34 /* AnjutaGluePlugin functions
35 *---------------------------------------------------------------------------*/
37 static gchar *
38 anjuta_glue_c_plugin_build_component_path (AnjutaGluePlugin* plugin, const gchar *path, const gchar *component_name)
40 gchar *component_path;
42 component_path = g_module_build_path (path, component_name);
44 return component_path;
47 static GType
48 anjuta_glue_c_plugin_get_component_type (AnjutaGluePlugin *plugin, GType parent, const gchar* type_name)
50 g_return_val_if_fail (ANJUTA_GLUE_C_PLUGIN (plugin)->module != NULL, G_TYPE_INVALID);
52 /* Module already loaded, plugin type should be already registered */
53 return g_type_from_name (type_name);
56 /* GTypeModule functions
57 *---------------------------------------------------------------------------*/
59 /* Used in load, unload, dispose and finalize */
60 static AnjutaGluePluginClass *parent_class = NULL;
62 static gboolean
63 anjuta_glue_c_plugin_load (GTypeModule *module)
65 AnjutaGluePlugin *plugin = ANJUTA_GLUE_PLUGIN (module);
66 AnjutaGlueCPlugin *c_plugin = ANJUTA_GLUE_C_PLUGIN (module);
67 AnjutaGluePluginRegisterComponentsFunc func;
69 g_return_val_if_fail (c_plugin->module == NULL, FALSE);
70 g_return_val_if_fail (plugin->path != NULL, FALSE);
72 /* Load the module and register the plugins */
73 c_plugin->module = g_module_open (plugin->path, 0);
75 if (!c_plugin->module)
77 g_warning ("could not load plugin: %s", g_module_error ());
78 return FALSE;
81 if (!g_module_symbol (c_plugin->module, "anjuta_glue_register_components", (gpointer *)&func))
83 g_warning ("unable to find register function in %s", plugin->path);
84 g_module_close (c_plugin->module);
85 c_plugin->module = NULL;
87 return FALSE;
90 /* Register all types */
91 (* func) (plugin);
93 /* Call parent function */
94 return G_TYPE_MODULE_CLASS (parent_class)->load (module);
97 static void
98 anjuta_glue_c_plugin_unload (GTypeModule *module)
100 AnjutaGlueCPlugin *plugin = ANJUTA_GLUE_C_PLUGIN (module);
102 g_return_if_fail (plugin->module != NULL);
104 g_module_close (plugin->module);
105 plugin->module = NULL;
107 /* Call parent function */
108 G_TYPE_MODULE_CLASS (parent_class)->unload (module);
111 /* GObject functions
112 *---------------------------------------------------------------------------*/
114 /* finalize is the last destruction step. It must free all memory allocated
115 * with instance_init. It is called only one time just before releasing all
116 * memory */
118 static void
119 anjuta_glue_c_plugin_finalize (GObject *object)
121 AnjutaGluePlugin* plugin = ANJUTA_GLUE_PLUGIN (object);
123 g_free (plugin->path);
125 G_OBJECT_CLASS (parent_class)->finalize (object);
129 static void
130 anjuta_glue_c_plugin_class_init (AnjutaGluePluginClass *klass)
132 GTypeModuleClass *type_module_class;
133 GObjectClass *gobject_class;
135 parent_class = ANJUTA_GLUE_PLUGIN_CLASS (g_type_class_peek_parent (klass));
137 type_module_class = (GTypeModuleClass *)klass;
138 gobject_class = G_OBJECT_CLASS (klass);
140 gobject_class->finalize = anjuta_glue_c_plugin_finalize;
142 type_module_class->load = anjuta_glue_c_plugin_load;
143 type_module_class->unload = anjuta_glue_c_plugin_unload;
145 klass->build_component_path = anjuta_glue_c_plugin_build_component_path;
146 klass->get_component_type = anjuta_glue_c_plugin_get_component_type;
149 static void
150 anjuta_glue_c_plugin_init (AnjutaGlueCPlugin *plugin)
152 plugin->module = NULL;
155 GType
156 anjuta_glue_c_plugin_get_type (void)
158 static GType type = 0;
160 if (!type)
162 static const GTypeInfo type_info =
164 sizeof (AnjutaGlueCPluginClass),
165 (GBaseInitFunc) NULL,
166 (GBaseFinalizeFunc) NULL,
167 (GClassInitFunc) anjuta_glue_c_plugin_class_init,
168 (GClassFinalizeFunc) NULL,
169 NULL,
170 sizeof (AnjutaGlueCPlugin),
171 0, /* n_preallocs */
172 (GInstanceInitFunc) anjuta_glue_c_plugin_init,
175 type = g_type_register_static (ANJUTA_GLUE_TYPE_PLUGIN,
176 "AnjutaGlueCPlugin",
177 &type_info, 0);
180 return type;
183 /* Creation and Destruction
184 *---------------------------------------------------------------------------*/
186 AnjutaGluePlugin *
187 anjuta_glue_c_plugin_new (void)
189 AnjutaGluePlugin *plugin;
191 plugin = g_object_new (ANJUTA_GLUE_TYPE_C_PLUGIN, NULL);
193 return plugin;