mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-22 12:36:21 +00:00
Introduce our own shutdown callback mechanism.
Instead of adding stuff to `_shutdown()`, we can now register a shutdown routine from the respective `init()` function of our modules. This also has the advantage, that we're sure they're called in reverse order from how the initialization happened. I didn't simply use `atexit()` because POSIX says that the number of possible callbacks is limited (min 32) and I was not sure whether we will maybe extend this number at one point. Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
@@ -73,12 +73,25 @@ static void _chat_log_chat(const char* const login, const char* const other, con
|
||||
chat_log_direction_t direction, GDateTime* timestamp, const char* const resourcepart);
|
||||
static void _groupchat_log_chat(const gchar* const login, const gchar* const room, const gchar* const nick,
|
||||
const gchar* const msg);
|
||||
|
||||
void
|
||||
chat_log_init(void)
|
||||
_chatlog_close(void)
|
||||
{
|
||||
g_hash_table_destroy(logs);
|
||||
g_hash_table_destroy(groupchat_logs);
|
||||
}
|
||||
|
||||
void
|
||||
chatlog_init(void)
|
||||
{
|
||||
log_info("Initialising chat logs");
|
||||
|
||||
prof_add_shutdown_routine(_chatlog_close);
|
||||
|
||||
logs = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, free,
|
||||
(GDestroyNotify)_free_chat_log);
|
||||
groupchat_logs = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, free,
|
||||
(GDestroyNotify)_free_chat_log);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -295,14 +308,6 @@ _chat_log_chat(const char* const login, const char* const other, const char* msg
|
||||
g_date_time_unref(timestamp);
|
||||
}
|
||||
|
||||
void
|
||||
groupchat_log_init(void)
|
||||
{
|
||||
log_info("Initialising groupchat logs");
|
||||
groupchat_logs = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, free,
|
||||
(GDestroyNotify)_free_chat_log);
|
||||
}
|
||||
|
||||
void
|
||||
groupchat_log_msg_out(const gchar* const room, const gchar* const msg)
|
||||
{
|
||||
@@ -391,13 +396,6 @@ _groupchat_log_chat(const gchar* const login, const gchar* const room, const gch
|
||||
g_date_time_unref(dt_tmp);
|
||||
}
|
||||
|
||||
void
|
||||
chat_log_close(void)
|
||||
{
|
||||
g_hash_table_destroy(logs);
|
||||
g_hash_table_destroy(groupchat_logs);
|
||||
}
|
||||
|
||||
static char*
|
||||
_get_log_filename(const char* const other, const char* const login, GDateTime* dt, gboolean is_room)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user