summaryrefslogtreecommitdiffstats
path: root/gatchat/gatchat.c
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2010-10-21 18:28:08 +0200
committerMarcel Holtmann <marcel@holtmann.org>2010-10-21 18:41:38 +0200
commit7492223f49f668c66639c35c2a29ff77fdb47452 (patch)
tree57b36c888a777963c6eb70faabf84b1f0e8683ef /gatchat/gatchat.c
parentd0cbae0092721bfd3d97f41337db966c446f460a (diff)
downloadofono-7492223f49f668c66639c35c2a29ff77fdb47452.tar.bz2
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.
Diffstat (limited to 'gatchat/gatchat.c')
-rw-r--r--gatchat/gatchat.c31
1 files changed, 31 insertions, 0 deletions
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);