OSDN Git Service

gobex: Add support for suspend & resume
authorJohan Hedberg <johan.hedberg@intel.com>
Thu, 7 Jul 2011 11:33:42 +0000 (13:33 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Tue, 4 Dec 2012 21:22:00 +0000 (22:22 +0100)
gobex/gobex.c
gobex/gobex.h

index 3ad645a..c3a8b2c 100644 (file)
@@ -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;
index 034213f..318add9 100644 (file)
@@ -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);