1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Refactored calling plugin functions

This commit is contained in:
James Booth 2013-08-03 00:40:10 +01:00
parent d3a8d0c610
commit bf19ffb910

View File

@ -28,6 +28,7 @@
static GSList* _get_module_names(void); static GSList* _get_module_names(void);
static void _init(void); static void _init(void);
static void _on_start(void); static void _on_start(void);
static void _run_plugins(const char * const function, PyObject *p_args);
static GSList* plugins; static GSList* plugins;
static PyObject *prof_module; static PyObject *prof_module;
@ -119,53 +120,35 @@ _get_module_names(void)
static void static void
_init(void) _init(void)
{ {
GSList *plugin = plugins; PyObject *p_args = Py_BuildValue("ss", PACKAGE_VERSION, PACKAGE_STATUS);
PyObject *p_prof_init, *p_args; _run_plugins("prof_init", p_args);
Py_XDECREF(p_args);
while (plugin != NULL) {
PyObject *module = plugin->data;
p_prof_init = PyObject_GetAttrString(module, "prof_init");
if (p_prof_init && PyCallable_Check(p_prof_init)) {
p_args = Py_BuildValue("ss", PACKAGE_VERSION, PACKAGE_STATUS);
PyObject_CallObject(p_prof_init, p_args);
Py_XDECREF(p_args);
Py_XDECREF(p_prof_init);
}
plugin = g_slist_next(plugin);
}
} }
static void static void
_on_start(void) _on_start(void)
{ {
GSList *plugin = plugins; _run_plugins("prof_on_start", NULL);
PyObject *p_prof_on_start;
while (plugin != NULL) {
PyObject *module = plugin->data;
p_prof_on_start = PyObject_GetAttrString(module, "prof_on_start");
if (p_prof_on_start && PyCallable_Check(p_prof_on_start)) {
PyObject_CallObject(p_prof_on_start, NULL);
Py_XDECREF(p_prof_on_start);
}
plugin = g_slist_next(plugin);
}
} }
void void
plugins_on_connect(void) plugins_on_connect(void)
{
_run_plugins("prof_on_connect", NULL);
}
static void
_run_plugins(const char * const function, PyObject *p_args)
{ {
GSList *plugin = plugins; GSList *plugin = plugins;
PyObject *p_prof_on_connect; PyObject *p_function;
while (plugin != NULL) { while (plugin != NULL) {
PyObject *module = plugin->data; PyObject *p_module = plugin->data;
p_prof_on_connect = PyObject_GetAttrString(module, "prof_on_connect"); p_function = PyObject_GetAttrString(p_module, function);
if (p_prof_on_connect && PyCallable_Check(p_prof_on_connect)) { if (p_function && PyCallable_Check(p_function)) {
PyObject_CallObject(p_prof_on_connect, NULL); PyObject_CallObject(p_function, p_args);
Py_XDECREF(p_prof_on_connect); Py_XDECREF(p_function);
} }
plugin = g_slist_next(plugin); plugin = g_slist_next(plugin);