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.
This commit is contained in:
Marcel Holtmann 2010-10-21 18:28:08 +02:00
parent d0cbae0092
commit 7492223f49
2 changed files with 34 additions and 0 deletions

View File

@ -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);

View File

@ -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);