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
;
55 g_log (NULL
, G_LOG_LEVEL_DEBUG
, "%s: Loaded", name
);
57 if (!g_module_symbol(dlm
, "teleport_get_abi", (gpointer
)(&getAbi
))
58 || (*getAbi
)() != TELEPORT_ABI
)
60 g_log (NULL
, G_LOG_LEVEL_DEBUG
, "%s: ABI mismatch, recompile the plugin", name
);
69 if (!g_module_symbol(dlm
, "teleport_get_vtable", (gpointer
)(&getVTable
)))
71 g_log (NULL
, G_LOG_LEVEL_DEBUG
, "%s: Unable to find teleportGetVTable", name
);
81 plug
->modulePtr
= dlm
;
82 plug
->vTable
= (*getVTable
) ();
84 g_log (NULL
, G_LOG_LEVEL_DEBUG
, "%s: VTable loaded", name
);
86 if (!(*plug
->vTable
->initPlugin
) (plug
))
88 g_log (NULL
, G_LOG_LEVEL_DEBUG
, "%s: unable to init plugin",name
);
95 pluginList
= g_list_append (pluginList
, plug
);
98 g_log (NULL
, G_LOG_LEVEL_DEBUG
, "%s: Unable to load %s", name
,pluginPath
);
108 teleport_unload_plugin (TeleportPlugin
*plug
)
110 (*plug
->vTable
->finiPlugin
) (plug
);
112 pluginList
= g_list_remove (pluginList
, (gpointer
)plug
);
114 g_module_close (plug
->modulePtr
);
120 teleport_traverse_plugins ()
123 for (iterator
= pluginList
; iterator
; iterator
= iterator
->next
)
125 TeleportPlugin
*plug
= (TeleportPlugin
*)iterator
->data
;
126 g_print ("Priority: %d\n",plug
->priority
);
127 g_print ("Loaded: %s\n",plug
->vTable
->name
);
132 teleport_perform_query (const gchar
*s
)
136 for (iterator
= pluginList
; iterator
; iterator
= iterator
->next
)
138 TeleportPlugin
*plug
= (TeleportPlugin
*)iterator
->data
;
140 if (plug
->vTable
->cancelQuery
)
141 (*plug
->vTable
->cancelQuery
)();
143 queryResult
= (*plug
->vTable
->query
) (plug
, s
);
144 if (queryResult
) /* Possible sync returns */
146 teleport_trigger_query_update (queryResult
);
152 teleport_do_action (TeleportAction
*action
)
154 (*(action
->backend
->vTable
->doAction
))(action
);