Use glib style for function names.
[tele.git] / src / plugin.c
blob576dd1c432e47411dc2885cb49a509c6fb189bcf
1 /**
3 * Teleport plugin management
5 * plugin.c
7 * Copyright : (C) 2007 by Diogo Ferreira <diogo@underdev.org>
8 * (C) 2007 by João Oliveirinha <joliveirinha@floodbit.org>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 3
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 **/
23 #include "teleport-private.h"
24 #include "teleport.h"
26 GList *pluginList = NULL;
28 TeleportPlugin *
29 teleport_load_plugin (const gchar* name)
31 TeleportPlugin *plug;
32 GModule *dlm;
33 gchar* pluginPath;
35 g_log (NULL, G_LOG_LEVEL_DEBUG, "%s: Attempting to load", name);
37 if (!g_module_supported())
39 g_log (NULL, G_LOG_LEVEL_DEBUG, "%s: This platform doesn't support modules", name);
40 return NULL;
43 plug = g_new (TeleportPlugin, 1);
45 pluginPath = g_module_build_path ("plugins",name);
47 g_log (NULL, G_LOG_LEVEL_DEBUG, "%s: Loading %s", name, pluginPath);
49 dlm = g_module_open (pluginPath, G_MODULE_BIND_LAZY);
50 if (dlm)
52 GetVTableProc getVTable;
54 g_log (NULL, G_LOG_LEVEL_DEBUG, "%s: Loaded", name);
56 if (!g_module_symbol(dlm, "teleportGetVTable", (gpointer)(&getVTable)))
58 g_log (NULL, G_LOG_LEVEL_DEBUG, "%s: Unable to find teleportGetVTable", name);
59 g_module_close (dlm);
60 g_free (pluginPath);
61 g_free (plug);
63 return NULL;
67 plug->priority = 0;
68 plug->modulePtr = dlm;
69 plug->vTable = (*getVTable) ();
71 g_log (NULL, G_LOG_LEVEL_DEBUG, "%s: VTable loaded", name);
73 if (!(*plug->vTable->initPlugin) (plug))
75 g_log (NULL, G_LOG_LEVEL_DEBUG, "%s: unable to init plugin",name);
76 g_module_close (dlm);
77 g_free (pluginPath);
78 g_free (plug);
79 return NULL;
82 pluginList = g_list_append (pluginList, plug);
84 else {
85 g_log (NULL, G_LOG_LEVEL_DEBUG, "%s: Unable to load %s", name,pluginPath);
86 g_free (plug);
89 g_free (pluginPath);
91 return plug;
94 void
95 teleport_unload_plugin (TeleportPlugin *plug)
97 (*plug->vTable->finiPlugin) (plug);
99 pluginList = g_list_remove (pluginList, (gpointer)plug);
101 g_module_close (plug->modulePtr);
103 free (plug);
106 void
107 teleport_traverse_plugins ()
109 GList *iterator;
110 for (iterator = pluginList; iterator; iterator = iterator->next)
112 TeleportPlugin *plug = (TeleportPlugin*)iterator->data;
113 g_print ("Priority: %d\n",plug->priority);
114 g_print ("Loaded: %s\n",plug->vTable->name);
118 void
119 teleport_perform_query (const gchar *s)
121 GList *iterator;
122 for (iterator = pluginList; iterator; iterator = iterator->next)
124 TeleportPlugin *plug = (TeleportPlugin*)iterator->data;
126 if (plug->vTable->cancelQuery)
127 (*plug->vTable->cancelQuery)();
129 (*plug->vTable->query) (plug, s);