2 * Copyright © 2003 Marco Pesenti Gritti
3 * Copyright © 2003, 2004 Christian Persch
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * $Id: ephy-shlib-loader.c 6952 2007-03-11 19:42:02Z chpe $
24 #include "ephy-shlib-loader.h"
25 #include "ephy-loader.h"
26 #include "ephy-module.h"
27 #include "ephy-debug.h"
31 #define DATA_KEY "EphyShlibLoader::LoaderData"
39 #define EPHY_SHLIB_LOADER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_SHLIB_LOADER, EphyShlibLoaderPrivate))
41 struct _EphyShlibLoaderPrivate
46 static void ephy_shlib_loader_class_init (EphyShlibLoaderClass
*klass
);
47 static void ephy_shlib_loader_iface_init (EphyLoaderIface
*iface
);
48 static void ephy_shlib_loader_init (EphyShlibLoader
*loader
);
50 static GObjectClass
*parent_class
= NULL
;
53 ephy_shlib_loader_get_type (void)
55 static GType type
= 0;
57 if (G_UNLIKELY (type
== 0))
59 const GTypeInfo our_info
=
61 sizeof (EphyShlibLoaderClass
),
63 NULL
, /* base_finalize */
64 (GClassInitFunc
) ephy_shlib_loader_class_init
,
66 NULL
, /* class_data */
67 sizeof (EphyShlibLoader
),
69 (GInstanceInitFunc
) ephy_shlib_loader_init
72 const GInterfaceInfo loader_info
=
74 (GInterfaceInitFunc
) ephy_shlib_loader_iface_init
,
79 type
= g_type_register_static (G_TYPE_OBJECT
,
83 g_type_add_interface_static (type
,
92 free_loader_data (LoaderData
*data
)
94 g_return_if_fail (data
!= NULL
);
96 /* data->module must NOT be unreffed! */
98 if (data
->object
!= NULL
)
100 g_object_unref (data
->object
);
107 ephy_shlib_loader_init (EphyShlibLoader
*loader
)
109 loader
->priv
= EPHY_SHLIB_LOADER_GET_PRIVATE (loader
);
111 LOG ("EphyShlibLoader initialising");
115 ephy_shlib_loader_finalize (GObject
*object
)
117 EphyShlibLoader
*loader
= EPHY_SHLIB_LOADER (object
);
119 LOG ("EphyShlibLoader finalising");
121 g_slist_foreach (loader
->priv
->data
, (GFunc
) free_loader_data
, NULL
);
122 g_slist_free (loader
->priv
->data
);
124 parent_class
->finalize (object
);
128 find_library (const LoaderData
*data
,
131 return strcmp (ephy_module_get_path (data
->module
), library
);
135 find_object (const LoaderData
*data
,
136 const GObject
*object
)
138 return data
->object
!= object
;
142 impl_get_object (EphyLoader
*eloader
,
145 EphyShlibLoader
*loader
= EPHY_SHLIB_LOADER (eloader
);
147 LoaderData
*data
= NULL
;
151 g_return_val_if_fail (keyfile
!= NULL
, NULL
);
153 library
= g_key_file_get_string (keyfile
, "Loader", "Library", NULL
);
156 g_warning ("NULL library name!\n");
160 resident
= g_key_file_get_boolean (keyfile
, "Loader", "Resident", NULL
);
162 l
= g_slist_find_custom (loader
->priv
->data
, library
,
163 (GCompareFunc
) find_library
);
168 g_return_val_if_fail (data
!= NULL
, NULL
);
170 if (data
->object
!= NULL
)
173 return g_object_ref (data
->object
);
178 data
= g_new0 (LoaderData
, 1);
179 loader
->priv
->data
= g_slist_prepend (loader
->priv
->data
, data
);
182 if (data
->module
== NULL
)
184 data
->module
= ephy_module_new (library
, resident
);
187 g_return_val_if_fail (data
->object
== NULL
, data
->object
);
189 if (g_type_module_use (G_TYPE_MODULE (data
->module
)) == FALSE
)
192 g_warning ("Could not load extension file at %s\n",
193 ephy_module_get_path (data
->module
));
197 data
->object
= ephy_module_new_object (data
->module
);
199 g_type_module_unuse (G_TYPE_MODULE (data
->module
));
201 if (data
->object
!= NULL
)
203 g_object_set_data (G_OBJECT (data
->object
), DATA_KEY
, data
);
212 impl_release_object (EphyLoader
*eloader
,
215 EphyShlibLoader
*loader
= EPHY_SHLIB_LOADER (eloader
);
219 l
= g_slist_find_custom (loader
->priv
->data
, object
,
220 (GCompareFunc
) find_object
);
221 g_return_if_fail (l
!= NULL
);
224 g_object_unref (data
->object
);
229 ephy_shlib_loader_iface_init (EphyLoaderIface
*iface
)
231 iface
->type
= "shlib";
232 iface
->get_object
= impl_get_object
;
233 iface
->release_object
= impl_release_object
;
237 ephy_shlib_loader_class_init (EphyShlibLoaderClass
*klass
)
239 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
241 parent_class
= g_type_class_peek_parent (klass
);
243 object_class
->finalize
= ephy_shlib_loader_finalize
;
245 g_type_class_add_private (object_class
, sizeof (EphyShlibLoaderPrivate
));