3 * Teleport plugin management
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.
23 #include "teleport-private.h"
26 GList
*pluginList
= NULL
;
29 teleport_load_plugin (const gchar
* name
)
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
);
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
);
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
);
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
);
82 pluginList
= g_list_append (pluginList
, plug
);
85 g_log (NULL
, G_LOG_LEVEL_DEBUG
, "%s: Unable to load %s", name
,pluginPath
);
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
);
107 teleport_traverse_plugins ()
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
);
119 teleport_perform_query (const gchar
*s
)
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
);