[libdmapsharing] Fix use of libsoup's "wrote_chunk" signal Signed-off-by: W. Michael Petullo <mike flyn org>



commit 3293e00565000064e3a9686224e91bf4f9334f81
Author: W. Michael Petullo <mike flyn org>
Date:   Wed Nov 10 20:26:31 2010 -0600

    Fix use of libsoup's "wrote_chunk" signal
    Signed-off-by: W. Michael Petullo <mike flyn org>

 libdmapsharing/dmap-share.c |   60 +++++++++++++++++++++++-------------------
 tests/test-dmap-client.c    |    2 +-
 2 files changed, 34 insertions(+), 28 deletions(-)
---
diff --git a/libdmapsharing/dmap-share.c b/libdmapsharing/dmap-share.c
index 874eb26..7c01a10 100644
--- a/libdmapsharing/dmap-share.c
+++ b/libdmapsharing/dmap-share.c
@@ -94,6 +94,7 @@ struct DMAPSharePrivate {
 struct share_bitwise_t {
 	DMAPShare *share;
 	bitwise bits;
+	GSList *id_list;
 };
 
 static void dmap_share_init       (DMAPShare *share);
@@ -1487,43 +1488,45 @@ write_daap_preamble (SoupMessage *message, GNode *node)
 static void
 write_next_mlit (SoupMessage *message, struct share_bitwise_t *share_bitwise)
 {
-	gchar *data;
-	guint length;
-	DMAPRecord *record;
-	static GSList *id_list = NULL;
-	struct MLCL_Bits mb = {NULL,0};
+	if (share_bitwise->id_list == NULL) {
+		g_debug ("No more ID's, sending message complete.");
+		soup_message_body_complete (message->response_body);
+	} else {
+		gchar *data;
+		guint length;
+		DMAPRecord *record;
+		struct MLCL_Bits mb = {NULL,0};
 
-	if (id_list == NULL) {
-		g_debug ("Initializing ID list.");
-		dmap_db_foreach (share_bitwise->share->priv->db, (GHFunc) accumulate_ids, &id_list);
-	}
+		record = dmap_db_lookup_by_id (share_bitwise->share->priv->db, GPOINTER_TO_UINT (share_bitwise->id_list->data));
 
-	record = dmap_db_lookup_by_id (share_bitwise->share->priv->db, GPOINTER_TO_UINT (id_list->data));
+		mb.bits = share_bitwise->bits;
+		mb.mlcl = dmap_structure_add (NULL, DMAP_CC_MLCL);
 
-	mb.bits = share_bitwise->bits;
-	mb.mlcl = dmap_structure_add (NULL, DMAP_CC_MLCL);
+		DMAP_SHARE_GET_CLASS (share_bitwise->share)->add_entry_to_mlcl (share_bitwise->id_list->data, record, &mb);
+		data = dmap_structure_serialize (g_node_first_child(mb.mlcl), &length);
 
-	DMAP_SHARE_GET_CLASS (share_bitwise->share)->add_entry_to_mlcl (id_list->data, record, &mb);
-	data = dmap_structure_serialize (g_node_first_child(mb.mlcl), &length);
+		soup_message_body_append (message->response_body,
+					  SOUP_MEMORY_TAKE,
+					  data,
+					  length);
+		g_debug ("Sending ID %u.", GPOINTER_TO_UINT (share_bitwise->id_list->data));
+		dmap_structure_destroy (mb.mlcl);
 
-	soup_message_body_append (message->response_body,
-				 SOUP_MEMORY_TAKE,
-				 data,
-				 length);
-	g_debug ("Sending ID %u.", GPOINTER_TO_UINT (id_list->data));
-	dmap_structure_destroy (mb.mlcl);
-
-	id_list = g_slist_remove (id_list, id_list->data);
-	if (id_list == NULL) {
-		g_debug ("No more ID's, sending message complete.");
-		soup_message_body_complete (message->response_body);
-		g_free (share_bitwise);
+		share_bitwise->id_list = g_slist_remove (share_bitwise->id_list, share_bitwise->id_list->data);
+
+		g_object_unref (record);
 	}
 
-	g_object_unref (record);
 	soup_server_unpause_message (share_bitwise->share->priv->server, message);
 }
 
+static void
+chunked_message_finished (SoupMessage *message, struct share_bitwise_t *share_bitwise)
+{
+	g_debug ("Finished sending chunked data.");
+	g_free (share_bitwise);
+}
+
 void
 _dmap_share_databases (DMAPShare *share,
 		       SoupServer        *server,
@@ -1758,7 +1761,10 @@ _dmap_share_databases (DMAPShare *share,
 			share_bitwise = g_new (struct share_bitwise_t, 1);
 			share_bitwise->share = share;
 			share_bitwise->bits = mb.bits;
+			share_bitwise->id_list = NULL;
+			dmap_db_foreach (share->priv->db, (GHFunc) accumulate_ids, &(share_bitwise->id_list));
 			g_signal_connect (message, "wrote_chunk", G_CALLBACK (write_next_mlit), share_bitwise);
+			g_signal_connect (message, "finished", G_CALLBACK (chunked_message_finished), share_bitwise);
 		}
 
 	} else if (g_ascii_strcasecmp ("/1/containers", rest_of_path) == 0) {
diff --git a/tests/test-dmap-client.c b/tests/test-dmap-client.c
index 4149d9d..1d33086 100644
--- a/tests/test-dmap-client.c
+++ b/tests/test-dmap-client.c
@@ -41,7 +41,7 @@ print_record (gpointer id, DMAPRecord *record, gpointer user_data)
 	gchar *artist, *title;
 
 	g_object_get (record,
-		     "artist", &artist,
+		     "songartist", &artist,
 		     "title",  &title,
 		     NULL);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]