changeset 727:ee5679e79f9d

[mq]: dicache-cleanup7
author Jorge Arellano Cid <jcid@dillo.org>
date Sat, 03 Jan 2009 12:37:34 -0300
parents 6a590c3e0db9
children 23115ab58666
files src/dicache.c src/image.cc src/jpeg.c src/png.c
diffstat 4 files changed, 78 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/src/dicache.c	Fri Jan 02 18:20:49 2009 -0300
+++ b/src/dicache.c	Sat Jan 03 12:37:34 2009 -0300
@@ -245,67 +245,6 @@
 /* ------------------------------------------------------------------------- */
 
 /*
- * This function is a cache client; (but feeds its clients from dicache)
- */
-void a_Dicache_callback(int Op, CacheClient_t *Client)
-{
-   uint_t i;
-   DilloWeb *Web = Client->Web;
-   DilloImage *Image = Web->Image;
-   DICacheEntry *DicEntry = a_Dicache_get_entry(Web->url, DIC_Last);
-
-   dReturn_if_fail ( DicEntry != NULL );
-
-   /* Copy the version number in the Client */
-   if (Client->Version == 0)
-      Client->Version = DicEntry->version;
-
-   /* Only call the decoder when necessary */
-   if (Op == CA_Send && DicEntry->State < DIC_Close &&
-       DicEntry->DecodedSize < Client->BufSize) {
-      DicEntry->Decoder(Op, Client);
-      DicEntry->DecodedSize = Client->BufSize; /* necessary ?? */
-   } else if (Op == CA_Close || Op == CA_Abort) {
-      a_Dicache_close(DicEntry->url, DicEntry->version, Client);
-   }
-
-   /* when the data stream is not an image 'v_imgbuf' remains NULL */
-   if (Op == CA_Send && DicEntry->v_imgbuf) {
-      if (Image->height == 0 && DicEntry->State >= DIC_SetParms) {
-         /* Set parms */
-         a_Image_set_parms(
-            Image, DicEntry->v_imgbuf, DicEntry->url,
-            DicEntry->version, DicEntry->width, DicEntry->height,
-            DicEntry->type);
-      }
-      if (DicEntry->State == DIC_Write) {
-         if (DicEntry->ScanNumber == Image->ScanNumber) {
-            for (i = 0; i < DicEntry->height; ++i)
-               if (a_Bitvec_get_bit(DicEntry->BitVec, (int)i) &&
-                   !a_Bitvec_get_bit(Image->BitVec, (int)i) )
-                  a_Image_write(Image, i);
-         } else {
-            for (i = 0; i < DicEntry->height; ++i) {
-               if (a_Bitvec_get_bit(DicEntry->BitVec, (int)i) ||
-                   !a_Bitvec_get_bit(Image->BitVec, (int)i)   ||
-                   DicEntry->ScanNumber > Image->ScanNumber + 1) {
-                  a_Image_write(Image, i);
-               }
-               if (!a_Bitvec_get_bit(DicEntry->BitVec, (int)i))
-                  a_Bitvec_clear_bit(Image->BitVec, (int)i);
-            }
-            Image->ScanNumber = DicEntry->ScanNumber;
-         }
-      }
-   } else if (Op == CA_Close || Op == CA_Abort) {
-      a_Image_close(Image);
-      a_Bw_close_client(Web->bw, Client->Key);
-   }
-}
-
-/* ------------------------------------------------------------------------- */
-
-/*
  * Set image's width, height & type
  * (By now, we'll use the image information despite the html tags --Jcid)
  */
@@ -416,18 +355,87 @@
    DICacheEntry *DicEntry = a_Dicache_get_entry(url, version);
 
    dReturn_if_fail ( DicEntry != NULL );
-   _MSG("a_Dicache_close RefCount=%d\n", DicEntry->RefCount);
 
-   DicEntry->State = DIC_Close;
-   dFree(DicEntry->cmap);
-   DicEntry->cmap = NULL;
-   DicEntry->Decoder = NULL;
-   DicEntry->DecoderData = NULL;
+   if (DicEntry->State < DIC_Close) {
+      DicEntry->State = DIC_Close;
+      dFree(DicEntry->cmap);
+      DicEntry->cmap = NULL;
+      DicEntry->Decoder = NULL;
+      DicEntry->DecoderData = NULL;
+   }
    a_Dicache_unref(url, version);
+   MSG("a_Dicache_close RefCount=%d\n", DicEntry->RefCount);
 
    a_Bw_close_client(Web->bw, Client->Key);
 }
 
+/* ------------------------------------------------------------------------- */
+
+/*
+ * This function is a cache client; (but feeds its clients from dicache)
+ */
+void a_Dicache_callback(int Op, CacheClient_t *Client)
+{
+   uint_t i;
+   DilloWeb *Web = Client->Web;
+   DilloImage *Image = Web->Image;
+   DICacheEntry *DicEntry = a_Dicache_get_entry(Web->url, DIC_Last);
+
+   dReturn_if_fail ( DicEntry != NULL );
+
+   /* Copy the version number in the Client */
+   if (Client->Version == 0)
+      Client->Version = DicEntry->version;
+
+   /* Only call the decoder when necessary */
+   if (Op == CA_Send && DicEntry->State < DIC_Close &&
+       DicEntry->DecodedSize < Client->BufSize) {
+      DicEntry->Decoder(Op, Client);
+      DicEntry->DecodedSize = Client->BufSize;
+   } else if (Op == CA_Close || Op == CA_Abort) {
+      if (DicEntry->State < DIC_Close) {
+         DicEntry->Decoder(Op, Client);
+      } else {
+         a_Dicache_close(DicEntry->url, DicEntry->version, Client);
+      }
+   }
+
+   /* when the data stream is not an image 'v_imgbuf' remains NULL */
+   if (Op == CA_Send && DicEntry->v_imgbuf) {
+      if (Image->height == 0 && DicEntry->State >= DIC_SetParms) {
+         /* Set parms */
+         a_Image_set_parms(
+            Image, DicEntry->v_imgbuf, DicEntry->url,
+            DicEntry->version, DicEntry->width, DicEntry->height,
+            DicEntry->type);
+      }
+      if (DicEntry->State == DIC_Write) {
+         if (DicEntry->ScanNumber == Image->ScanNumber) {
+            for (i = 0; i < DicEntry->height; ++i)
+               if (a_Bitvec_get_bit(DicEntry->BitVec, (int)i) &&
+                   !a_Bitvec_get_bit(Image->BitVec, (int)i) )
+                  a_Image_write(Image, i);
+         } else {
+            for (i = 0; i < DicEntry->height; ++i) {
+               if (a_Bitvec_get_bit(DicEntry->BitVec, (int)i) ||
+                   !a_Bitvec_get_bit(Image->BitVec, (int)i)   ||
+                   DicEntry->ScanNumber > Image->ScanNumber + 1) {
+                  a_Image_write(Image, i);
+               }
+               if (!a_Bitvec_get_bit(DicEntry->BitVec, (int)i))
+                  a_Bitvec_clear_bit(Image->BitVec, (int)i);
+            }
+            Image->ScanNumber = DicEntry->ScanNumber;
+         }
+      }
+   } else if (Op == CA_Close || Op == CA_Abort) {
+      a_Image_close(Image);
+      a_Bw_close_client(Web->bw, Client->Key);
+   }
+}
+
+/* ------------------------------------------------------------------------- */
+
 /*
  * Free the imgbuf (RGB data) of unused entries.
  */
--- a/src/image.cc	Fri Jan 02 18:20:49 2009 -0300
+++ b/src/image.cc	Sat Jan 03 12:37:34 2009 -0300
@@ -144,7 +144,7 @@
  */
 void a_Image_close(DilloImage *Image)
 {
-   _MSG("a_Image_close\n");
+   MSG("a_Image_close\n");
    a_Image_unref(Image);
 }
 
--- a/src/jpeg.c	Fri Jan 02 18:20:49 2009 -0300
+++ b/src/jpeg.c	Sat Jan 03 12:37:34 2009 -0300
@@ -84,7 +84,6 @@
 static DilloJpeg *Jpeg_new(DilloImage *Image, DilloUrl *url, int version);
 static void Jpeg_callback(int Op, CacheClient_t *Client);
 static void Jpeg_write(DilloJpeg *jpeg, void *Buf, uint_t BufSize);
-static void Jpeg_close(DilloJpeg *jpeg, CacheClient_t *Client);
 METHODDEF(void) Jpeg_errorexit (j_common_ptr cinfo);
 
 /* exported function */
@@ -140,6 +139,7 @@
  */
 static void Jpeg_close(DilloJpeg *jpeg, CacheClient_t *Client)
 {
+   MSG("Jpeg_close\n");
    a_Dicache_close(jpeg->url, jpeg->version, Client);
    jpeg_destroy_decompress(&(jpeg->cinfo));
    dFree(jpeg);
--- a/src/png.c	Fri Jan 02 18:20:49 2009 -0300
+++ b/src/png.c	Sat Jan 03 12:37:34 2009 -0300
@@ -304,6 +304,7 @@
  */
 static void Png_close(DilloPng *png, CacheClient_t *Client)
 {
+   MSG("Png_close\n");
    /* Let dicache know decoding is over */
    a_Dicache_close(png->url, png->version, Client);