From 7492223f49f668c66639c35c2a29ff77fdb47452 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 21 Oct 2010 18:28:08 +0200 Subject: [PATCH] gatchat: Add support for slave chat instances This adds support to assign a slave chat instance to an existing chat instance. The slave chat is now additionally bound by the lifetime of its master chat instance. In case the master is cloned, the slave chat instance will also be cloned as well. With this it is possible to suspend the master while still have an active slave for notifications or extra commands. --- gatchat/gatchat.c | 31 +++++++++++++++++++++++++++++++ gatchat/gatchat.h | 3 +++ 2 files changed, 34 insertions(+) diff --git a/gatchat/gatchat.c b/gatchat/gatchat.c index d05f4668..f3bd3ec6 100644 --- a/gatchat/gatchat.c +++ b/gatchat/gatchat.c @@ -105,6 +105,7 @@ struct _GAtChat { gint ref_count; struct at_chat *parent; guint group; + GAtChat *slave; }; struct terminator_info { @@ -1304,9 +1305,36 @@ GAtChat *g_at_chat_clone(GAtChat *clone) chat->ref_count = 1; g_atomic_int_inc(&chat->parent->ref_count); + if (clone->slave != NULL) + chat->slave = g_at_chat_clone(clone->slave); + return chat; } +GAtChat *g_at_chat_set_slave(GAtChat *chat, GAtChat *slave) +{ + if (chat == NULL) + return; + + if (chat->slave != NULL) + g_at_chat_unref(chat->slave); + + if (slave != NULL) + chat->slave = g_at_chat_ref(slave); + else + chat->slave = NULL; + + return chat->slave; +} + +GAtChat *g_at_chat_get_slave(GAtChat *chat) +{ + if (chat == NULL) + return NULL; + + return chat->slave; +} + GIOChannel *g_at_chat_get_channel(GAtChat *chat) { if (chat == NULL || chat->parent->io == NULL) @@ -1361,6 +1389,9 @@ void g_at_chat_unref(GAtChat *chat) if (is_zero == FALSE) return; + if (chat->slave != NULL) + g_at_chat_unref(chat->slave); + at_chat_cancel_group(chat->parent, chat->group); g_at_chat_unregister_all(chat); at_chat_unref(chat->parent); diff --git a/gatchat/gatchat.h b/gatchat/gatchat.h index f61fe538..8cbb5598 100644 --- a/gatchat/gatchat.h +++ b/gatchat/gatchat.h @@ -50,6 +50,9 @@ void g_at_chat_unref(GAtChat *chat); GAtChat *g_at_chat_clone(GAtChat *chat); +GAtChat *g_at_chat_set_slave(GAtChat *chat, GAtChat *slave); +GAtChat *g_at_chat_get_slave(GAtChat *chat); + void g_at_chat_suspend(GAtChat *chat); void g_at_chat_resume(GAtChat *chat);