b49b6b31f6e521ea0dc2c5008b86f65a2bd319ac
1 /* MManager - a Desktop wide manager for multimedia applications.
3 * Copyright (C) 2008 Cosimo Cecchi <cosimoc@gnome.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library 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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 #include <glib-object.h>
24 #include "mm-application-provider.h"
25 #include "mm-category-provider.h"
26 #include "mm-hit-collection-provider.h"
27 #include "mm-module.h"
29 #define MM_MODULE_GET_PRIVATE(o) \
30 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_MODULE, MMModuleDetails))
32 G_DEFINE_TYPE (MMModule
, mm_module
, G_TYPE_TYPE_MODULE
);
34 struct _MMModuleDetails
{
39 /* providers implemented by the module */
40 MMApplicationProvider
*app_provider
;
41 MMCategoryProvider
*category_provider
;
42 MMHitCollectionProvider
*collection_provider
;
49 static gboolean
mm_module_load (GTypeModule
*gtm
);
50 static void mm_module_unload (GTypeModule
*gtm
);
53 mm_module_finalize (GObject
*o
)
55 MMModule
*module
= MM_MODULE (o
);
57 g_free (module
->details
->filename
);
58 G_OBJECT_CLASS (mm_module_parent_class
)->finalize (o
);
62 mm_module_class_init (MMModuleClass
*klass
)
64 GTypeModuleClass
*type_module_class
= G_TYPE_MODULE_CLASS (klass
);
66 type_module_class
->load
= mm_module_load
;
67 type_module_class
->unload
= mm_module_unload
;
68 G_OBJECT_CLASS (klass
)->finalize
= mm_module_finalize
;
70 g_type_class_add_private (klass
, sizeof (MMModuleDetails
));
74 mm_module_init (MMModule
*module
)
76 MMModuleDetails
*details
= module
->details
= MM_MODULE_GET_PRIVATE (module
);
78 details
->filename
= NULL
;
79 details
->library
= NULL
;
84 mm_module_load (GTypeModule
*gtm
)
86 MMModule
*module
= MM_MODULE (gtm
);
87 MMModuleDetails
*details
= module
->details
;
88 gpointer m_initialize
, m_shutdown
, m_get_types
, m_get_name
;
90 details
->library
= g_module_open (details
->filename
,
93 if (!details
->library
) {
94 g_warning ("error while loading module %s: %s",
95 details
->filename
, g_module_error ());
99 if (!g_module_symbol (details
->library
,
100 "mm_module_initialize",
102 !g_module_symbol (details
->library
,
103 "mm_module_shutdown",
105 !g_module_symbol (details
->library
,
106 "mm_module_get_types",
108 !g_module_symbol (details
->library
,
109 "mm_module_get_name",
111 g_warning ("Unable to resolve symbols inside the module %s: %s",
112 details
->filename
, g_module_error ());
113 g_module_close (details
->library
);
118 module
->initialize
= m_initialize
;
119 module
->shutdown
= m_shutdown
;
120 module
->get_types
= m_get_types
;
121 module
->get_name
= m_get_name
;
123 module
->initialize (gtm
);
129 mm_module_unload (GTypeModule
*gtm
)
131 MMModule
*module
= MM_MODULE (gtm
);
135 g_module_close (module
->details
->library
);
137 module
->initialize
= NULL
;
138 module
->shutdown
= NULL
;
139 module
->get_types
= NULL
;
143 mm_module_create_provider (MMModule
*module
, GType type
)
145 return g_object_new (type
, NULL
);
149 mm_module_add_types (MMModule
*module
, GType
*types
)
151 /* types[0] implements MMApplicationProvider
152 * types[1] implements MMCategoryProvider
153 * types[2] implements MMHitCollectionProvider
155 MMModuleDetails
*details
= module
->details
;
157 details
->app_provider
=
158 MM_APPLICATION_PROVIDER (mm_module_create_provider (module
, types
[0]));
159 details
->category_provider
=
160 MM_CATEGORY_PROVIDER (mm_module_create_provider (module
, types
[1]));
161 details
->collection_provider
=
162 MM_HIT_COLLECTION_PROVIDER (mm_module_create_provider (module
, types
[2]));
166 add_module_objects (MMModule
*module
)
170 module
->get_types (>ypes
);
172 mm_module_add_types (module
, gtypes
);
178 * mm_module_load_file:
179 * @path: the path of the module to load.
181 * Creates a #MMModule object for the specified path.
183 * Return value: a #MMModule object or %NULL.
187 mm_module_load_file (const char *path
)
191 module
= g_object_new (MM_TYPE_MODULE
, NULL
);
192 module
->details
->filename
= g_strdup (path
);
194 if (g_type_module_use (G_TYPE_MODULE (module
))) {
195 add_module_objects (module
);
196 g_type_module_unuse (G_TYPE_MODULE (module
));
199 g_object_unref (module
);
205 * mm_module_get_application_provider:
206 * @module: a #MMModule.
208 * Gets the #MMApplicationProvider for the module.
210 * Return value: a #MMApplicationProvider object or %NULL.
213 MMApplicationProvider
*
214 mm_module_get_application_provider (MMModule
*module
)
216 g_return_val_if_fail (module
!= NULL
, NULL
);
218 return module
->details
->app_provider
;
222 * mm_module_get_category_provider:
223 * @module: a #MMModule.
225 * Gets the #MMCategoryProvider for the module.
227 * Return value: a #MMCategoryProvider object or %NULL.
231 mm_module_get_category_provider (MMModule
*module
)
233 g_return_val_if_fail (module
!= NULL
, NULL
);
235 return module
->details
->category_provider
;
239 * mm_module_get_hit_collection_provider:
240 * @module: a #MMModule.
242 * Gets the #MMHitCollectionProvider for the module.
244 * Return value: a #MMHitCollectionProvider object or %NULL.
247 MMHitCollectionProvider
*
248 mm_module_get_hit_collection_provider (MMModule
*module
)
250 g_return_val_if_fail (module
!= NULL
, NULL
);
252 return module
->details
->collection_provider
;
256 * mm_module_get_name:
257 * @module: a #MMModule.
259 * Gets the name of the module.
261 * Return value: a string containing the module name.
265 mm_module_get_name (MMModule
*module
)
269 module
->get_name (&name
);