mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Added prof_on_shutdown hook
This commit is contained in:
parent
54ea41d5b6
commit
7c27060e73
@ -52,6 +52,7 @@ c_plugin_create(const char * const filename)
|
||||
plugin->on_connect_func = c_on_connect_hook;
|
||||
plugin->on_message_received_func = c_on_message_received_hook;
|
||||
plugin->on_message_send_func = c_on_message_send_hook;
|
||||
plugin->on_shutdown_func = c_on_shutdown_hook;
|
||||
|
||||
g_string_free(path, TRUE);
|
||||
g_free(module_name);
|
||||
@ -78,7 +79,6 @@ c_init_hook(ProfPlugin *plugin, const char * const version, const char * const
|
||||
func (version, status);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
c_on_start_hook (ProfPlugin *plugin)
|
||||
{
|
||||
@ -93,7 +93,6 @@ c_on_start_hook (ProfPlugin *plugin)
|
||||
func ();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
c_on_connect_hook (ProfPlugin *plugin, const char * const account_name, const char * const fulljid)
|
||||
{
|
||||
@ -108,7 +107,6 @@ c_on_connect_hook (ProfPlugin *plugin, const char * const account_name, const ch
|
||||
func (account_name, fulljid);
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
c_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message)
|
||||
{
|
||||
@ -139,6 +137,20 @@ c_on_message_send_hook(ProfPlugin *plugin, const char * const jid, const char *m
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
c_on_shutdown_hook(ProfPlugin *plugin)
|
||||
{
|
||||
void * f = NULL;
|
||||
void (*func)(void);
|
||||
assert (plugin && plugin->module);
|
||||
|
||||
if (NULL == (f = dlsym (plugin->module, "prof_on_shutdown")))
|
||||
return ;
|
||||
|
||||
func = (void (*)(void)) f;
|
||||
func ();
|
||||
}
|
||||
|
||||
void
|
||||
c_plugin_destroy(ProfPlugin *plugin)
|
||||
{
|
||||
|
@ -8,11 +8,12 @@ void c_env_init(void);
|
||||
ProfPlugin* c_plugin_create(const char * const filename);
|
||||
|
||||
void c_init_hook(ProfPlugin *plugin, const char * const version, const char * const status);
|
||||
void c_on_start_hook (ProfPlugin *plugin);
|
||||
void c_on_connect_hook (ProfPlugin *plugin, const char * const account_name, const char * const fulljid);
|
||||
void c_on_start_hook(ProfPlugin *plugin);
|
||||
void c_on_connect_hook(ProfPlugin *plugin, const char * const account_name, const char * const fulljid);
|
||||
char * c_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message);
|
||||
char * c_on_message_send_hook(ProfPlugin *plugin, const char * const jid, const char *message);
|
||||
void c_plugin_destroy(ProfPlugin * plugin);
|
||||
void c_on_shutdown_hook(ProfPlugin *plugin);
|
||||
|
||||
void c_shutdown(void);
|
||||
|
||||
|
@ -177,6 +177,17 @@ plugins_on_message_send(const char * const jid, const char *message)
|
||||
return curr_message;
|
||||
}
|
||||
|
||||
void
|
||||
plugins_on_shutdown(void)
|
||||
{
|
||||
GSList *curr = plugins;
|
||||
while (curr != NULL) {
|
||||
ProfPlugin *plugin = curr->data;
|
||||
plugin->on_shutdown_func(plugin);
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
plugins_shutdown(void)
|
||||
{
|
||||
|
@ -42,6 +42,7 @@ typedef struct prof_plugin_t {
|
||||
const char * const jid, const char * const message);
|
||||
char* (*on_message_send_func)(struct prof_plugin_t* plugin,
|
||||
const char * const jid, const char * const message);
|
||||
void (*on_shutdown_func)(struct prof_plugin_t* plugin);
|
||||
} ProfPlugin;
|
||||
|
||||
void plugins_init(void);
|
||||
@ -51,6 +52,7 @@ void plugins_on_start(void);
|
||||
void plugins_on_connect(const char * const account_name, const char * const fulljid);
|
||||
char * plugins_on_message_received(const char * const jid, const char *message);
|
||||
char * plugins_on_message_send(const char * const jid, const char *message);
|
||||
void plugins_on_shutdown(void);
|
||||
void plugins_shutdown(void);
|
||||
gboolean plugins_run_command(const char * const cmd);
|
||||
void plugins_run_timed(void);
|
||||
|
@ -65,6 +65,7 @@ python_plugin_create(const char * const filename)
|
||||
plugin->on_connect_func = python_on_connect_hook;
|
||||
plugin->on_message_received_func = python_on_message_received_hook;
|
||||
plugin->on_message_send_func = python_on_message_send_hook;
|
||||
plugin->on_shutdown_func = python_on_shutdown_hook;
|
||||
g_free(module_name);
|
||||
return plugin;
|
||||
} else {
|
||||
@ -183,6 +184,23 @@ python_on_message_send_hook(ProfPlugin *plugin, const char * const jid,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
python_on_shutdown_hook(ProfPlugin *plugin)
|
||||
{
|
||||
PyObject *p_function;
|
||||
|
||||
PyObject *p_module = plugin->module;
|
||||
if (PyObject_HasAttrString(p_module, "prof_on_shutdown")) {
|
||||
p_function = PyObject_GetAttrString(p_module, "prof_on_shutdown");
|
||||
python_check_error();
|
||||
if (p_function && PyCallable_Check(p_function)) {
|
||||
PyObject_CallObject(p_function, NULL);
|
||||
python_check_error();
|
||||
Py_XDECREF(p_function);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
python_check_error(void)
|
||||
{
|
||||
|
@ -32,6 +32,7 @@ void python_on_start_hook(ProfPlugin *plugin);
|
||||
void python_on_connect_hook(ProfPlugin *plugin, const char * const account_name, const char * const fulljid);
|
||||
char * python_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message);
|
||||
char * python_on_message_send_hook(ProfPlugin *plugin, const char * const jid, const char *message);
|
||||
void python_on_shutdown_hook(ProfPlugin *plugin);
|
||||
|
||||
void python_plugin_destroy(ProfPlugin *plugin);
|
||||
void python_check_error(void);
|
||||
|
@ -62,6 +62,7 @@ ruby_plugin_create(const char * const filename)
|
||||
plugin->on_connect_func = ruby_on_connect_hook;
|
||||
plugin->on_message_received_func = ruby_on_message_received_hook;
|
||||
plugin->on_message_send_func = ruby_on_message_send_hook;
|
||||
plugin->on_shutdown_func = ruby_on_shutdown_hook;
|
||||
g_free(module_name);
|
||||
return plugin;
|
||||
}
|
||||
@ -143,6 +144,15 @@ ruby_on_message_send_hook(ProfPlugin *plugin, const char * const jid,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
ruby_on_shutdown_hook(ProfPlugin *plugin)
|
||||
{
|
||||
VALUE module = (VALUE) plugin->module;
|
||||
if (_method_exists(plugin, "prof_on_shutdown")) {
|
||||
rb_funcall(module, rb_intern("prof_on_shutdown"), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ruby_check_error(void)
|
||||
{
|
||||
|
@ -32,6 +32,7 @@ void ruby_on_start_hook(ProfPlugin *plugin);
|
||||
void ruby_on_connect_hook(ProfPlugin *plugin, const char * const account_name, const char * const fulljid);
|
||||
char * ruby_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message);
|
||||
char * ruby_on_message_send_hook(ProfPlugin *plugin, const char * const jid, const char *message);
|
||||
void ruby_on_shutdown_hook(ProfPlugin *plugin);
|
||||
|
||||
void ruby_plugin_destroy(ProfPlugin *plugin);
|
||||
void ruby_check_error(void);
|
||||
|
Loading…
Reference in New Issue
Block a user