Define new 'pivot-prop-loadable' property
[nautilus-actions.git] / src / core / na-ifactory-provider.c
blob917cd48eecb22f7070d2e8bbd5cdb07ea9022949
1 /*
2 * Nautilus-Actions
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.
24 * Authors:
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)
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
35 #include <api/na-iio-provider.h>
36 #include <api/na-ifactory-provider.h>
38 #include "na-factory-object.h"
39 #include "na-factory-provider.h"
41 /* private interface data
43 struct _NAIFactoryProviderInterfacePrivate {
44 void *empty; /* so that gcc -pedantic is happy */
47 gboolean ifactory_provider_initialized = FALSE;
48 gboolean ifactory_provider_finalized = FALSE;
50 static GType register_type( void );
51 static void interface_base_init( NAIFactoryProviderInterface *klass );
52 static void interface_base_finalize( NAIFactoryProviderInterface *klass );
54 static guint ifactory_provider_get_version( const NAIFactoryProvider *instance );
56 static void v_factory_provider_read_start( const NAIFactoryProvider *reader, void *reader_data, NAIFactoryObject *serializable, GSList **messages );
57 static void v_factory_provider_read_done( const NAIFactoryProvider *reader, void *reader_data, NAIFactoryObject *serializable, GSList **messages );
58 static guint v_factory_provider_write_start( const NAIFactoryProvider *writer, void *writer_data, NAIFactoryObject *serializable, GSList **messages );
59 static guint v_factory_provider_write_done( const NAIFactoryProvider *writer, void *writer_data, NAIFactoryObject *serializable, GSList **messages );
61 /**
62 * na_ifactory_provider_get_type:
64 * Registers the GType of this interface.
66 * Returns: the #NAIFactoryProvider #GType.
68 GType
69 na_ifactory_provider_get_type( void )
71 static GType object_type = 0;
73 if( !object_type ){
74 object_type = register_type();
77 return( object_type );
80 static GType
81 register_type( void )
83 static const gchar *thisfn = "na_ifactory_provider_register_type";
84 GType type;
86 static const GTypeInfo info = {
87 sizeof( NAIFactoryProviderInterface ),
88 ( GBaseInitFunc ) interface_base_init,
89 ( GBaseFinalizeFunc ) interface_base_finalize,
90 NULL,
91 NULL,
92 NULL,
95 NULL
98 g_debug( "%s", thisfn );
100 type = g_type_register_static( G_TYPE_INTERFACE, "NAIFactoryProvider", &info, 0 );
102 g_type_interface_add_prerequisite( type, G_TYPE_OBJECT );
104 return( type );
107 static void
108 interface_base_init( NAIFactoryProviderInterface *klass )
110 static const gchar *thisfn = "na_ifactory_provider_interface_base_init";
112 if( !ifactory_provider_initialized ){
114 g_debug( "%s: klass=%p (%s)", thisfn, ( void * ) klass, G_OBJECT_CLASS_NAME( klass ));
116 klass->private = g_new0( NAIFactoryProviderInterfacePrivate, 1 );
118 klass->get_version = ifactory_provider_get_version;
119 klass->read_start = NULL;
120 klass->read_data = NULL;
121 klass->read_done = NULL;
122 klass->write_start = NULL;
123 klass->write_data = NULL;
124 klass->write_done = NULL;
126 ifactory_provider_initialized = TRUE;
130 static void
131 interface_base_finalize( NAIFactoryProviderInterface *klass )
133 static const gchar *thisfn = "na_ifactory_provider_interface_base_finalize";
135 if( ifactory_provider_initialized && !ifactory_provider_finalized ){
137 g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
139 ifactory_provider_finalized = TRUE;
141 g_free( klass->private );
145 static guint
146 ifactory_provider_get_version( const NAIFactoryProvider *instance )
148 return( 1 );
152 * na_ifactory_provider_read_item:
153 * @reader: the instance which implements this #NAIFactoryProvider interface.
154 * @reader_data: instance data which will be provided back to the interface
155 * methods
156 * @object: the #NAIFactoryObject object to be unserialilzed.
157 * @messages: a pointer to a #GSList list of strings; the implementation
158 * may append messages to this list, but shouldn't reinitialize it.
160 * This function is to be called by a #NAIIOProvider which would wish read
161 * its items. The function takes care of collecting and structuring data,
162 * while the callback interface methods #NAIFactoryProviderInterface.read_start(),
163 * #NAIFactoryProviderInterface.read_data() and #NAIFactoryProviderInterface.read_done()
164 * just have to fill a given #NADataBoxed with the ad-hoc data type.
166 * <example>
167 * <programlisting>
168 * &lcomment;
169 * * allocate the object to be read
170 * &rcomment;
171 * NAObjectItem *item = NA_OBJECT_ITEM( na_object_action_new());
172 * &lcomment;
173 * * some data we may need to have access to in callback methods
174 * &rcomment;
175 * void *data;
176 * &lcomment;
177 * * now call interface function
178 * &rcomment;
179 * na_ifactory_provider_read_item(
180 * NA_IFACTORY_PROVIDER( provider ),
181 * data,
182 * NA_IFACTORY_OBJECT( item ),
183 * messages );
184 * </programlisting>
185 * </example>
187 * Since: 2.30
189 void
190 na_ifactory_provider_read_item( const NAIFactoryProvider *reader, void *reader_data, NAIFactoryObject *object, GSList **messages )
192 g_return_if_fail( NA_IS_IFACTORY_PROVIDER( reader ));
193 g_return_if_fail( NA_IS_IFACTORY_OBJECT( object ));
195 if( ifactory_provider_initialized && !ifactory_provider_finalized ){
197 v_factory_provider_read_start( reader, reader_data, object, messages );
198 na_factory_object_read_item( object, reader, reader_data, messages );
199 v_factory_provider_read_done( reader, reader_data, object, messages );
204 * na_ifactory_provider_write_item:
205 * @writer: the instance which implements this #NAIFactoryProvider interface.
206 * @writer_data: instance data.
207 * @object: the #NAIFactoryObject derived object to be serialized.
208 * @messages: a pointer to a #GSList list of strings; the implementation
209 * may append messages to this list, but shouldn't reinitialize it.
211 * This function is to be called by a #NAIIOProvider which would wish write
212 * an item. The function takes care of collecting and writing elementary data.
214 * Returns: a NAIIOProvider operation return code.
216 * Since: 2.30
218 guint
219 na_ifactory_provider_write_item( const NAIFactoryProvider *writer, void *writer_data, NAIFactoryObject *object, GSList **messages )
221 static const gchar *thisfn = "na_ifactory_provider_write_item";
222 guint code;
224 g_return_val_if_fail( NA_IS_IFACTORY_PROVIDER( writer ), NA_IIO_PROVIDER_CODE_PROGRAM_ERROR );
225 g_return_val_if_fail( NA_IS_IFACTORY_OBJECT( object ), NA_IIO_PROVIDER_CODE_PROGRAM_ERROR );
227 code = NA_IIO_PROVIDER_CODE_NOT_WILLING_TO_RUN;
229 if( ifactory_provider_initialized && !ifactory_provider_finalized ){
231 g_debug( "%s: writer=%p, writer_data=%p, object=%p (%s)",
232 thisfn, ( void * ) writer, ( void * ) writer_data, ( void * ) object, G_OBJECT_TYPE_NAME( object ));
234 code = v_factory_provider_write_start( writer, writer_data, object, messages );
236 if( code == NA_IIO_PROVIDER_CODE_OK ){
237 code = na_factory_object_write_item( object, writer, writer_data, messages );
240 if( code == NA_IIO_PROVIDER_CODE_OK ){
241 code = v_factory_provider_write_done( writer, writer_data, object, messages );
245 return( code );
248 static void
249 v_factory_provider_read_start( const NAIFactoryProvider *reader, void *reader_data, NAIFactoryObject *serializable, GSList **messages )
251 if( NA_IFACTORY_PROVIDER_GET_INTERFACE( reader )->read_start ){
252 NA_IFACTORY_PROVIDER_GET_INTERFACE( reader )->read_start( reader, reader_data, serializable, messages );
256 static void
257 v_factory_provider_read_done( const NAIFactoryProvider *reader, void *reader_data, NAIFactoryObject *serializable, GSList **messages )
259 if( NA_IFACTORY_PROVIDER_GET_INTERFACE( reader )->read_done ){
260 NA_IFACTORY_PROVIDER_GET_INTERFACE( reader )->read_done( reader, reader_data, serializable, messages );
264 static guint
265 v_factory_provider_write_start( const NAIFactoryProvider *writer, void *writer_data, NAIFactoryObject *serializable, GSList **messages )
267 guint code = NA_IIO_PROVIDER_CODE_OK;
269 if( NA_IFACTORY_PROVIDER_GET_INTERFACE( writer )->write_start ){
270 code = NA_IFACTORY_PROVIDER_GET_INTERFACE( writer )->write_start( writer, writer_data, serializable, messages );
273 return( code );
276 static guint
277 v_factory_provider_write_done( const NAIFactoryProvider *writer, void *writer_data, NAIFactoryObject *serializable, GSList **messages )
279 guint code = NA_IIO_PROVIDER_CODE_OK;
281 if( NA_IFACTORY_PROVIDER_GET_INTERFACE( writer )->write_done ){
282 code = NA_IFACTORY_PROVIDER_GET_INTERFACE( writer )->write_done( writer, writer_data, serializable, messages );
285 return( code );