3 * A Nautilus extension which offers configurable context menu actions.
5 * Copyright (C) 2005 The GNOME Foundation
6 * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
7 * Copyright (C) 2009, 2010, 2011 Pierre Wieser and others (see AUTHORS)
9 * This Program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This Program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public
20 * License along with this Library; see the file COPYING. If not,
21 * write to the Free Software Foundation, Inc., 59 Temple Place,
22 * Suite 330, Boston, MA 02111-1307, USA.
25 * Frederic Ruaudel <grumz@grumz.net>
26 * Rodrigo Moya <rodrigo@gnome-db.org>
27 * Pierre Wieser <pwieser@trychlos.org>
28 * ... and many others (see AUTHORS)
35 #include <glib-object.h>
38 /* this is a plugin, i.e. a dynamically loaded resource
41 G_MODULE_EXPORT
const gchar
*g_module_check_init( GModule
*module
);
42 G_MODULE_EXPORT
void g_module_unload( GModule
*module
);
45 /* this is first version
46 * the module is loaded, the function called, and then the module is unloaded
47 * note that we do not define any GType here, so do not provide any sort of
48 * GInterface implementation
50 (process:23911): NA-test-DEBUG: in g_module_check_init: module=0xf97f20
51 (process:23911): NA-test-DEBUG: say_hello: module=0xf97f20
52 (process:23911): NA-test-DEBUG: in g_module_unload: module=0xf97f20
56 G_MODULE_EXPORT
void say_hello( GModule
*module
);
58 /* automatically called when the module is loaded
60 G_MODULE_EXPORT
const gchar
*
61 g_module_check_init( GModule
*module
)
66 g_debug( "in g_module_check_init: module=%p", ( void * ) module
);
71 /* automatically called when the module is unloaded
74 g_module_unload( GModule
*module
)
76 g_debug( "in g_module_unload: module=%p", ( void * ) module
);
79 /* a function dynamically called from the program
82 say_hello( GModule
*module
)
84 g_debug( "say_hello: module=%p", ( void * ) module
);
89 * define the module as a GTypeModule-derived one
91 #define TEST_MODULE_PLUGIN_TYPE ( na_module_plugin_get_type())
92 #define TEST_MODULE_PLUGIN( object ) ( G_TYPE_CHECK_INSTANCE_CAST( object, TEST_MODULE_PLUGIN_TYPE, NAModulePlugin ))
93 #define TEST_MODULE_PLUGIN_CLASS( klass ) ( G_TYPE_CHECK_CLASS_CAST( klass, TEST_MODULE_PLUGIN_TYPE, NAModulePluginClass ))
94 #define TEST_IS_MODULE_PLUGIN( object ) ( G_TYPE_CHECK_INSTANCE_TYPE( object, TEST_MODULE_PLUGIN_TYPE ))
95 #define TEST_IS_MODULE_PLUGIN_CLASS( klass ) ( G_TYPE_CHECK_CLASS_TYPE(( klass ), TEST_MODULE_PLUGIN_TYPE ))
96 #define TEST_MODULE_PLUGIN_GET_CLASS( object ) ( G_TYPE_INSTANCE_GET_CLASS(( object ), TEST_MODULE_PLUGIN_TYPE, NAModulePluginClass ))
98 typedef struct _NAModulePluginPrivate NAModulePluginPrivate
;
99 typedef struct _NAModulePluginClassPrivate NAModulePluginClassPrivate
;
103 NAModulePluginPrivate
*private;
109 NAModulePluginClassPrivate
*private;
113 GType
na_module_plugin_get_type( void );
115 /* private instance data
117 struct _NAModulePluginPrivate
{
118 gboolean dispose_has_run
;
121 /* private class data
123 struct _NAModulePluginClassPrivate
{
124 void *empty
; /* so that gcc -pedantic is happy */
127 static GType st_module_type
= 0;
128 static GTypeModuleClass
*st_parent_class
= NULL
;
130 static void na_module_plugin_register_type( GTypeModule
*module
);
131 static void class_init( NAModulePluginClass
*klass
);
132 static void instance_init( GTypeInstance
*instance
, gpointer klass
);
133 static void instance_dispose( GObject
*object
);
134 static void instance_finalize( GObject
*object
);
136 G_MODULE_EXPORT
void plugin_init( GTypeModule
*module
);
139 na_module_plugin_get_type( void )
141 return( st_module_type
);
145 na_module_plugin_register_type( GTypeModule
*module
)
147 static const gchar
*thisfn
= "na_module_plugin_register_type";
149 static GTypeInfo info
= {
150 sizeof( NAModulePluginClass
),
153 ( GClassInitFunc
) class_init
,
156 sizeof( NAModulePlugin
),
158 ( GInstanceInitFunc
) instance_init
161 /*static const GInterfaceInfo iio_provider_iface_info = {
162 ( GInterfaceInitFunc ) iio_provider_iface_init,
167 g_debug( "%s", thisfn
);
169 st_module_type
= g_type_module_register_type( module
, G_TYPE_OBJECT
, "NAModulePlugin", &info
, 0 );
171 /*g_type_module_add_interface( module, st_module_type, NA_IIO_PROVIDER_TYPE, &iio_provider_iface_info );*/
175 class_init( NAModulePluginClass
*klass
)
177 static const gchar
*thisfn
= "na_module_plugin_class_init";
178 GObjectClass
*object_class
;
180 g_debug( "%s: klass=%p", thisfn
, ( void * ) klass
);
182 st_parent_class
= g_type_class_peek_parent( klass
);
184 object_class
= G_OBJECT_CLASS( klass
);
185 object_class
->dispose
= instance_dispose
;
186 object_class
->finalize
= instance_finalize
;
188 klass
->private = g_new0( NAModulePluginClassPrivate
, 1 );
192 instance_init( GTypeInstance
*instance
, gpointer klass
)
194 static const gchar
*thisfn
= "na_module_plugin_instance_init";
195 NAModulePlugin
*self
;
197 g_return_if_fail( TEST_IS_MODULE_PLUGIN( instance
));
199 g_debug( "%s: instance=%p (%s), klass=%p",
200 thisfn
, ( void * ) instance
, G_OBJECT_TYPE_NAME( instance
), ( void * ) klass
);
202 self
= TEST_MODULE_PLUGIN( instance
);
204 self
->private = g_new0( NAModulePluginPrivate
, 1 );
206 self
->private->dispose_has_run
= FALSE
;
210 instance_dispose( GObject
*object
)
212 static const gchar
*thisfn
= "na_module_plugin_instance_dispose";
213 NAModulePlugin
*self
;
215 g_return_if_fail( TEST_IS_MODULE_PLUGIN( object
));
217 self
= TEST_MODULE_PLUGIN( object
);
219 if( !self
->private->dispose_has_run
){
221 g_debug( "%s: object=%p (%s)", thisfn
, ( void * ) object
, G_OBJECT_TYPE_NAME( object
));
223 self
->private->dispose_has_run
= TRUE
;
225 /* chain up to the parent class */
226 if( G_OBJECT_CLASS( st_parent_class
)->dispose
){
227 G_OBJECT_CLASS( st_parent_class
)->dispose( object
);
233 instance_finalize( GObject
*object
)
235 static const gchar
*thisfn
= "na_test_module_plugin_instance_finalize";
236 NAModulePlugin
*self
;
238 g_return_if_fail( TEST_IS_MODULE_PLUGIN( object
));
240 g_debug( "%s: object=%p (%s)", thisfn
, ( void * ) object
, G_OBJECT_TYPE_NAME( object
));
242 self
= TEST_MODULE_PLUGIN( object
);
244 g_free( self
->private );
246 /* chain call to parent class */
247 if( G_OBJECT_CLASS( st_parent_class
)->finalize
){
248 G_OBJECT_CLASS( st_parent_class
)->finalize( object
);
252 /* automatically called when the module is loaded
253 * this is very less useful in this version as we need a GTypeModule to register
256 G_MODULE_EXPORT
const gchar
*
257 g_module_check_init( GModule
*module
)
259 g_debug( "in g_module_check_init: module=%p", ( void * ) module
);
263 /* automatically called when the module is unloaded
266 g_module_unload( GModule
*module
)
268 g_debug( "in g_module_unload: module=%p", ( void * ) module
);
271 /* module is actually a NAModule, but we do not care of that
272 * registering the type - but do not yet allocate an object
275 plugin_init( GTypeModule
*module
)
277 g_debug( "plugin_init: module=%p", ( void * ) module
);
279 na_module_plugin_register_type( module
);