Audacious
$Id:Doxyfile42802007-03-2104:39:00Znenolod$
|
00001 /* 00002 * general.c 00003 * Copyright 2010 John Lindgren 00004 * 00005 * This file is part of Audacious. 00006 * 00007 * Audacious is free software: you can redistribute it and/or modify it under 00008 * the terms of the GNU General Public License as published by the Free Software 00009 * Foundation, version 2 or version 3 of the License. 00010 * 00011 * Audacious is distributed in the hope that it will be useful, but WITHOUT ANY 00012 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00013 * A PARTICULAR PURPOSE. See the GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along with 00016 * Audacious. If not, see <http://www.gnu.org/licenses/>. 00017 * 00018 * The Audacious team does not consider modular code linking to Audacious or 00019 * using our public API to be a derived work. 00020 */ 00021 00022 #include <glib.h> 00023 00024 #include "debug.h" 00025 #include "general.h" 00026 #include "plugin.h" 00027 #include "plugins.h" 00028 00029 static GList * loaded_general_plugins = NULL; 00030 00031 static void general_load (PluginHandle * plugin) 00032 { 00033 GList * node = g_list_find (loaded_general_plugins, plugin); 00034 if (node != NULL) 00035 return; 00036 00037 AUDDBG ("Loading %s.\n", plugin_get_name (plugin)); 00038 GeneralPlugin * header = plugin_get_header (plugin); 00039 g_return_if_fail (header != NULL); 00040 00041 if (header->init != NULL) 00042 header->init (); 00043 00044 loaded_general_plugins = g_list_prepend (loaded_general_plugins, plugin); 00045 } 00046 00047 static void general_unload (PluginHandle * plugin) 00048 { 00049 GList * node = g_list_find (loaded_general_plugins, plugin); 00050 if (node == NULL) 00051 return; 00052 00053 AUDDBG ("Unloading %s.\n", plugin_get_name (plugin)); 00054 GeneralPlugin * header = plugin_get_header (plugin); 00055 g_return_if_fail (header != NULL); 00056 00057 loaded_general_plugins = g_list_delete_link (loaded_general_plugins, node); 00058 00059 if (header->cleanup != NULL) 00060 header->cleanup (); 00061 } 00062 00063 static gboolean general_init_cb (PluginHandle * plugin) 00064 { 00065 general_load (plugin); 00066 return TRUE; 00067 } 00068 00069 void general_init (void) 00070 { 00071 plugin_for_enabled (PLUGIN_TYPE_GENERAL, (PluginForEachFunc) 00072 general_init_cb, NULL); 00073 } 00074 00075 void general_cleanup (void) 00076 { 00077 g_list_foreach (loaded_general_plugins, (GFunc) general_unload, NULL); 00078 } 00079 00080 void general_plugin_enable (PluginHandle * plugin, gboolean enable) 00081 { 00082 plugin_set_enabled (plugin, enable); 00083 00084 if (enable) 00085 general_load (plugin); 00086 else 00087 general_unload (plugin); 00088 }