1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
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
22 * SECTION:anjuta-glue-c-plugin
23 * @short_description: Anjuta glue C plugin
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 *---------------------------------------------------------------------------*/
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
;
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
;
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 ());
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
;
90 /* Register all types */
93 /* Call parent function */
94 return G_TYPE_MODULE_CLASS (parent_class
)->load (module
);
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
);
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
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
);
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
;
150 anjuta_glue_c_plugin_init (AnjutaGlueCPlugin
*plugin
)
152 plugin
->module
= NULL
;
156 anjuta_glue_c_plugin_get_type (void)
158 static GType type
= 0;
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
,
170 sizeof (AnjutaGlueCPlugin
),
172 (GInstanceInitFunc
) anjuta_glue_c_plugin_init
,
175 type
= g_type_register_static (ANJUTA_GLUE_TYPE_PLUGIN
,
183 /* Creation and Destruction
184 *---------------------------------------------------------------------------*/
187 anjuta_glue_c_plugin_new (void)
189 AnjutaGluePlugin
*plugin
;
191 plugin
= g_object_new (ANJUTA_GLUE_TYPE_C_PLUGIN
, NULL
);