From 42d94c84a262f58fb44a1475b7960a1edd3301e8 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 7 Jul 2011 13:33:42 +0200 Subject: [PATCH] gobex: Add support for suspend & resume --- gobex/gobex.c | 28 ++++++++++++++++++++++++++++ gobex/gobex.h | 4 ++++ 2 files changed, 32 insertions(+) diff --git a/gobex/gobex.c b/gobex/gobex.c index 3ad645a67..c3a8b2c52 100644 --- a/gobex/gobex.c +++ b/gobex/gobex.c @@ -53,6 +53,8 @@ struct _GObex { size_t tx_data; size_t tx_sent; + gboolean suspended; + guint write_source; gssize io_rx_mtu; @@ -250,6 +252,11 @@ static gboolean write_data(GIOChannel *io, GIOCondition cond, obex->tx_sent = 0; } + if (obex->suspended) { + obex->write_source = 0; + return FALSE; + } + if (!obex->write(obex, NULL)) goto stop_tx; @@ -268,6 +275,9 @@ static void enable_tx(GObex *obex) { GIOCondition cond; + if (obex->suspended) + return; + if (obex->write_source > 0) return; @@ -512,6 +522,24 @@ gboolean g_obex_remove_request_function(GObex *obex, gint id) return TRUE; } +void g_obex_suspend(GObex *obex) +{ + if (obex->write_source > 0) { + g_source_remove(obex->write_source); + obex->write_source = 0; + } + + obex->suspended = TRUE; +} + +void g_obex_resume(GObex *obex) +{ + obex->suspended = FALSE; + + if (g_queue_get_length(obex->tx_queue) > 0 || obex->tx_data > 0) + enable_tx(obex); +} + static void parse_connect_data(GObex *obex, GObexPacket *pkt) { const struct connect_data *data; diff --git a/gobex/gobex.h b/gobex/gobex.h index 034213faf..318add950 100644 --- a/gobex/gobex.h +++ b/gobex/gobex.h @@ -53,6 +53,10 @@ gint g_obex_add_request_function(GObex *obex, guint8 opcode, GObexRequestFunc func, gpointer user_data); gboolean g_obex_remove_request_function(GObex *obex, gint id); + +void g_obex_suspend(GObex *obex); +void g_obex_resume(GObex *obex); + GObex *g_obex_new(GIOChannel *io, GObexTransportType transport_type, gssize rx_mtu, gssize tx_mtu); -- 2.47.3