Add some comments
[mmediamanager.git] / src / mm-manager.c
blob653605f748cf1f85f0ea4f557e85b4447c4c5c3e
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.
21 #include <glib-object.h>
22 #include <glib.h>
24 #include "mm-manager.h"
26 G_DEFINE_TYPE (MMManager, mm_manager, G_TYPE_OBJECT);
28 #define MM_MANAGER_GET_PRIVATE(o) \
29 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_MANAGER, MMManagerDetails))
31 MMManager* mm_manager_singleton = NULL;
33 struct _MMManagerDetails {
34 MMModuleManager *module_manager;
35 GHashTable *applications;
38 static void
39 mm_manager_finalize (GObject *o)
41 MMManager *manager = MM_MANAGER (o);
43 g_hash_table_destroy (manager->details->applications);
45 G_OBJECT_CLASS (mm_manager_parent_class)->finalize (o);
48 static void
49 mm_manager_class_init (MMManagerClass *klass)
51 G_OBJECT_CLASS (klass)->finalize = mm_manager_finalize;
53 g_type_class_add_private (klass, sizeof (MMManagerDetails));
56 static void
57 populate_applications_table (MMManager *manager)
59 GHashTable *applications = manager->details->applications;
60 GList *app_providers, *l;
61 MMApplication *application;
62 MMApplicationProvider *provider;
64 app_providers = mm_module_manager_get_all_application_providers (manager->details->module_manager);
65 for (l = app_providers; l; l = l->next) {
66 provider = MM_APPLICATION_PROVIDER (l->data);
67 application = mm_application_provider_get_application (provider);
68 g_hash_table_insert (applications,
69 application, /* key */
70 provider); /* value */
74 static void
75 mm_manager_init (MMManager *manager)
77 MMManagerDetails *details = manager->details = MM_MANAGER_GET_PRIVATE (manager);
79 details->module_manager = MM_MODULE_MANAGER (g_object_new (MM_TYPE_MODULE_MANAGER, NULL));
80 details->applications = g_hash_table_new (g_direct_hash, g_direct_equal);
82 populate_applications_table (manager);
85 /* public methods */
87 MMManager *
88 mm_manager_get (void)
90 if (!mm_manager_singleton) {
91 mm_manager_singleton = MM_MANAGER (g_object_new (MM_TYPE_MANAGER, NULL));
94 return mm_manager_singleton;
97 GList *
98 mm_manager_get_application_list_for_type (MMManager *m,
99 MMApplicationType type)
101 GList *all_apps, *l;
102 GList *app_list = NULL;
103 MMApplicationType supported_type;
105 g_return_val_if_fail (m != NULL, NULL);
106 g_return_val_if_fail (MM_IS_MANAGER (m), NULL);
108 /* this should be fine anyway, as the hash table is created only when
109 * initializing the manager.
111 all_apps = g_hash_table_get_keys (m->details->applications);
112 for (l = all_apps; l; l = l->next) {
113 g_object_get (l->data,
114 "supported-type", &supported_type,
115 NULL);
116 if (supported_type == type) {
117 app_list = g_list_prepend (app_list, l->data);
121 g_list_free (all_apps);
123 return app_list;
126 GList *
127 mm_manager_get_application_list (MMManager *m)
129 g_return_val_if_fail (m != NULL, NULL);
130 g_return_val_if_fail (MM_IS_MANAGER (m), NULL);
132 /* see the comment in _get_application_list_for_type () */
133 return g_hash_table_get_keys (m->details->applications);
136 MMApplicationProvider *
137 mm_manager_get_application_provider_for_application (MMManager *m,
138 MMApplication *app)
140 g_return_val_if_fail (m != NULL, NULL);
141 g_return_val_if_fail (MM_IS_MANAGER (m), NULL);
143 return g_hash_table_lookup (m->details->applications, app);
146 MMModuleManager *
147 mm_manager_get_module_manager (MMManager *m)
149 g_return_val_if_fail (m != NULL, NULL);
150 g_return_val_if_fail (MM_IS_MANAGER (m), NULL);
152 return m->details->module_manager;