diff options
author | Vinicius Costa Gomes <vinicius.gomes@openbossa.org> | 2010-08-19 19:24:31 -0300 |
---|---|---|
committer | Vinicius Costa Gomes <vinicius.gomes@openbossa.org> | 2010-08-20 15:15:09 -0300 |
commit | f9778e74d0c48933ffb5c1028311aae666350e1f (patch) | |
tree | d44c88326d417f76321a09e5ffe8068f76f7758a /attrib/gattrib.c | |
parent | a31269eb5775faccf0068c306668a715196b7516 (diff) | |
download | bluez-f9778e74d0c48933ffb5c1028311aae666350e1f.tar.gz |
Add g_attrib_set_disconnect_function()
The function set will be called when GAttrib detects that the link
was cut off. This will allow apps to take the proper actions in this
situation.
Diffstat (limited to 'attrib/gattrib.c')
-rw-r--r-- | attrib/gattrib.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/attrib/gattrib.c b/attrib/gattrib.c index c2798cb7e..36ab2e849 100644 --- a/attrib/gattrib.c +++ b/attrib/gattrib.c @@ -44,6 +44,8 @@ struct _GAttrib { GSList *events; guint next_cmd_id; guint next_evt_id; + GAttribDisconnectFunc disconnect; + gpointer disc_user_data; }; struct command { @@ -188,11 +190,24 @@ void g_attrib_unref(GAttrib *attrib) g_free(attrib); } +gboolean g_attrib_set_disconnect_function(GAttrib *attrib, + GAttribDisconnectFunc disconnect, gpointer user_data) +{ + if (attrib == NULL) + return FALSE; + + attrib->disconnect = disconnect; + attrib->disc_user_data = user_data; + + return TRUE; +} + static void destroy_receiver(gpointer data) { struct _GAttrib *attrib = data; - attrib->read_watch = 0; + if (attrib->disconnect) + attrib->disconnect(attrib->disc_user_data); } static void wake_up_sender(struct _GAttrib *attrib); @@ -267,8 +282,12 @@ static gboolean can_write_data(GIOChannel *io, GIOCondition cond, gpointer data) GError *gerr = NULL; gsize len; - if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) + if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) { + if (attrib->disconnect) + attrib->disconnect(attrib->disc_user_data); + return FALSE; + } cmd = g_queue_peek_head(attrib->queue); if (cmd == NULL) @@ -304,9 +323,8 @@ static void wake_up_sender(struct _GAttrib *attrib) { if (attrib->write_watch == 0) attrib->write_watch = g_io_add_watch_full(attrib->io, - G_PRIORITY_DEFAULT, - G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL, - can_write_data, attrib, destroy_sender); + G_PRIORITY_DEFAULT, G_IO_OUT, can_write_data, + attrib, destroy_sender); } GAttrib *g_attrib_new(GIOChannel *io) |