Enlightenment CVS committal

Author  : barbieri
Project : e17
Module  : libs/epsilon

Dir     : e17/libs/epsilon/src/lib


Modified Files:
        Epsilon.c Epsilon.h Makefile.am epsilon_thumb.c 


Log Message:
Epsilon major overhaul, breaks API.

I fixed many issues with epsilon, mainly the Epsilon_Requests, since
it broke the ABI, I also changed the API and now it looks a bit
better.

Changes overview:
 - epsilon_thumb_{init,shutdown} -> epsilon_request_{init,shutdown}
 - epsilon_del -> epsilon_request_del()
 - epsilon_add(file, dest, size, data) -> epsilon_request_add(file, size, data)
   reason: nobody was using "dest", and if one tried to, it was not
   implemented. Instead of implementing this, leave to users that
   could call ecore_file_cp() on the handler.
 - epsilon_request_add() has a fast path check for already existent
   thumbnails, instead of going to the server, just
   ecore_event_add(). To handle epsilon_request_del() fine, we now
   have to keep the Ecore_Event for further deletion.
 - epsilon_exists() now just checks the mtime of source and thumbnail,
   if source is newer, then return EPSILON_FAIL so users regenerate
   it. There is a possible optimization to be done (it's marked on
   code in the right place) that can read original file tags to avoid
   regenerating for copies, but it's not reliable and should be
   checked after the current ones.
 - reoder CFLAGS path order to first use local headers instead of the
   system.
 - check for errors when loading plugins.
 - updated every use of these API in e17 CVS.

If you find a problem with these, let me know and I'll fix.


===================================================================
RCS file: /cvs/e/e17/libs/epsilon/src/lib/Epsilon.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -3 -r1.40 -r1.41
--- Epsilon.c   1 Nov 2007 21:50:31 -0000       1.40
+++ Epsilon.c   2 Nov 2007 08:03:46 -0000       1.41
@@ -56,10 +56,6 @@
 
 static int _epsilon_exists_ext(Epsilon *e, const char *ext, char *path, int 
path_size, time_t *mtime);
 static char *epsilon_hash (const char *file);
-static time_t _epsilon_png_mtime_get (const char *file);
-#ifdef HAVE_EPEG_H
-static time_t _epsilon_jpg_mtime_get (const char *file);
-#endif
 #ifdef HAVE_PNG_H
 static FILE *_epsilon_open_png_file_reading (const char *filename);
 static int _epsilon_png_write (const char *file, DATA32 * ptr,
@@ -118,6 +114,11 @@
        dl_ref = dlopen(path, RTLD_LAZY);
        if (dl_ref) {
                epsilon_plugin_init = dlsym(dl_ref, "epsilon_plugin_init");
+               if (!epsilon_plugin_init) {
+                  fprintf(stderr, "Failed to load %s: %s", path, dlerror());
+                  dlclose(dl_ref);
+                  return NULL;
+               }
                plugin = (*epsilon_plugin_init)();
        }
 
@@ -482,10 +483,16 @@
 epsilon_exists (Epsilon * e)
 {
   int ok = 0;
+  struct stat st;
+  time_t srcmtime;
 
   if (!e || !e->src)
     return (EPSILON_FAIL);
 
+  if (stat(e->src, &st) != 0)
+    return (EPSILON_FAIL);
+  srcmtime = st.st_mtime;
+
   if (!e->hash)
     {
        char hash_seed[PATH_MAX] = "";
@@ -516,12 +523,11 @@
     {
        char path[PATH_MAX];
        time_t filemtime;
-       if (_epsilon_exists_ext(e, "jpg", path, sizeof(path), &filemtime))
-        {
-           time_t epsilonmtime = _epsilon_jpg_mtime_get(path);
-           if (filemtime >= epsilonmtime)
-             return (EPSILON_OK);
-        }
+       if (_epsilon_exists_ext(e, "jpg", path, sizeof(path), &filemtime)) {
+         if (filemtime >= srcmtime)
+           return (EPSILON_OK);
+         /* XXX compare with time from e->src exif tag? */
+       }
     }
 #endif
 #ifdef HAVE_PNG_H
@@ -529,12 +535,11 @@
     {
        char path[PATH_MAX];
        time_t filemtime;
-       if (_epsilon_exists_ext(e, "png", path, sizeof(path), &filemtime))
-        {
-           time_t epsilonmtime = _epsilon_png_mtime_get(path);
-           if (filemtime >= epsilonmtime)
-             return (EPSILON_OK);
-        }
+       if (_epsilon_exists_ext(e, "png", path, sizeof(path), &filemtime)) {
+        if (filemtime >= srcmtime)
+          return (EPSILON_OK);
+         /* XXX compare with time from e->src png tag? */
+       }
 #endif
     }
   return (EPSILON_FAIL);
@@ -747,25 +752,6 @@
 }
 
 
-#ifdef HAVE_EPEG_H
-static time_t
-_epsilon_jpg_mtime_get (const char *file)
-{
-  time_t result = 0;
-  Epeg_Image *im;
-  Epeg_Thumbnail_Info info;
-
-  if ((im = epeg_file_open (file)))
-    {
-      epeg_thumbnail_comments_get (im, &info);
-      if (info.mimetype)
-       result = info.mtime;
-      epeg_close (im);
-    }
-  return (result);
-}
-#endif
-
 #ifdef HAVE_PNG_H
 static FILE *
 _epsilon_open_png_file_reading (const char *filename)
@@ -796,52 +782,6 @@
        }
     }
   return fp;
-}
-
-static time_t
-_epsilon_png_mtime_get (const char *file)
-{
-  time_t result = 0;
-  FILE *fp = NULL;
-
-  if ((fp = _epsilon_open_png_file_reading (file)))
-    {
-      png_structp png_ptr = NULL;
-      png_infop info_ptr = NULL;
-      png_textp text_ptr;
-      int num_text = 0, i;
-
-      if (!
-         (png_ptr =
-          png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL)))
-       {
-         fclose (fp);
-         return (result);
-       }
-
-      if (!(info_ptr = png_create_info_struct (png_ptr)))
-       {
-         png_destroy_read_struct (&png_ptr, (png_infopp) NULL,
-                                  (png_infopp) NULL);
-         fclose (fp);
-         return (result);
-       }
-      png_init_io (png_ptr, fp);
-      png_read_info (png_ptr, info_ptr);
-
-      num_text = png_get_text (png_ptr, info_ptr, &text_ptr, &num_text);
-      for (i = 0; (i < num_text) && (i < 10); i++)
-       {
-         png_text text = text_ptr[i];
-
-         if (!strcmp (text.key, "Thumb::MTime"))
-           result = atoi (text.text);
-       }
-      /* png_read_end(png_ptr,info_ptr); */
-      png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp) NULL);
-      fclose (fp);
-    }
-  return (result);
 }
 
 #define GET_TMPNAME(_tmpbuf,_file) { \
===================================================================
RCS file: /cvs/e/e17/libs/epsilon/src/lib/Epsilon.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -3 -r1.13 -r1.14
--- Epsilon.h   30 Oct 2007 23:59:31 -0000      1.13
+++ Epsilon.h   2 Nov 2007 08:03:46 -0000       1.14
@@ -22,6 +22,10 @@
 # endif
 #endif
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define EPSILON_FAIL 0
 #define EPSILON_OK 1
 
@@ -105,4 +109,7 @@
 EAPI void epsilon_info_exif_props_print (Epsilon_Info * ei);
 EAPI int epsilon_info_exif_get (Epsilon_Info * ei);
 
+#ifdef __cplusplus
+}
+#endif
 #endif
===================================================================
RCS file: /cvs/e/e17/libs/epsilon/src/lib/Makefile.am,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -3 -r1.12 -r1.13
--- Makefile.am 9 Jul 2007 16:10:36 -0000       1.12
+++ Makefile.am 2 Nov 2007 08:03:46 -0000       1.13
@@ -6,8 +6,8 @@
 MAINTAINERCLEANFILES = Makefile.in
 SUBDIRS              = exiftags
 
-INCLUDES            = @IMLIB2_CFLAGS@ @EPEG_CFLAGS@ @PNG_CFLAGS@ 
@ECORE_CFLAGS@ @EVAS_CFLAGS@ @EDJE_CFLAGS@ \
-                       -I$(top_srcdir)/src/include \
+INCLUDES            = -I$(top_srcdir)/src/include \
+                       @IMLIB2_CFLAGS@ @EPEG_CFLAGS@ @PNG_CFLAGS@ 
@ECORE_CFLAGS@ @EVAS_CFLAGS@ @EDJE_CFLAGS@ \
                        -DPACKAGE_BIN_DIR=\""$(bindir)"\" \
                        -DPACKAGE_LIB_DIR=\""$(libdir)"\"
 
===================================================================
RCS file: /cvs/e/e17/libs/epsilon/src/lib/epsilon_thumb.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -3 -r1.16 -r1.17
--- epsilon_thumb.c     30 Oct 2007 23:59:31 -0000      1.16
+++ epsilon_thumb.c     2 Nov 2007 08:03:46 -0000       1.17
@@ -34,7 +34,7 @@
  * Initialize epsilon subsystem.
  */
 int
-epsilon_thumb_init()
+epsilon_request_init(void)
 {
        /*
         * Init required subsystems.
@@ -100,7 +100,7 @@
  * Shutdown and deallocate epsilon internal variables.
  */
 int
-epsilon_shutdown()
+epsilon_request_shutdown(void)
 {
        if (--epsilon_init_count == 0) {
                ecore_event_handler_del(epsilon_server_data);
@@ -139,24 +139,62 @@
 }
 
 static void
+epsilon_request_free(Epsilon_Request *thumb)
+{
+       free(thumb->path);
+       if (thumb->dest)
+               free(thumb->dest);
+       free(thumb);
+}
+
+static void
 epsilon_event_free(void *data, void *ev)
 {
        Epsilon_Request *thumb = ev;
 
        data = NULL;
 
-       if (!thumb) { 
+       if (!thumb) {
                fprintf(stderr,"!!Warning!! NULL pointer (*ev) : 
epsilon_event_free(void *data, void *ev)\n");
                return;
        }
+       epsilon_request_free(thumb);
+}
 
-       if (thumb->path)
-               free(thumb->path);
-       if (thumb->dest)
-               free(thumb->dest);
-       free(thumb);
+static void
+epsilon_event_inform_done(Epsilon_Request *thumb)
+{
+       if (!thumb)
+               return;
 
-       return;
+       thumb->_event = ecore_event_add(EPSILON_EVENT_DONE, thumb,
+                                       epsilon_event_free, NULL);
+}
+
+static int
+epsilon_request_resolve_thumb_file(Epsilon_Request *thumb)
+{
+       Epsilon* tb;
+
+       if (!thumb)
+               return 0;
+
+       /*
+        * Create a temp thumbnail struct to get the thumbnail
+        * path, don't actually generate the thumbnail here.
+        */
+       tb = epsilon_new(thumb->path);
+       epsilon_thumb_size(tb, thumb->size);
+       if (epsilon_exists(tb) == EPSILON_OK) {
+               const char *dest;
+
+               dest = epsilon_thumb_file_get(tb);
+               if (dest)
+                       thumb->dest = strdup(dest);
+       }
+       epsilon_free(tb);
+
+       return thumb->dest != NULL;
 }
 
 static int
@@ -189,6 +227,7 @@
        while ((thumb = ecore_dlist_current(epsilon_request_queue))) {
                if (thumb->id == msg->mid) {
                        if (debug) printf("Removing %d from queue\n", 
thumb->id);
+                       thumb->status = msg->status;
                        ecore_dlist_remove(epsilon_request_queue);
                        break;
                }
@@ -196,27 +235,10 @@
                if (debug) printf("Cycling %d times looking for %d, current is 
%d\n", i++, msg->mid, thumb->id);
        }
 
-       /*If the thumb dest is not set, but the generation was successful,
-        * try to get the dest now */
-       if ( thumb && (!thumb->dest) && thumb->path && !thumb->status ) {
-               Epsilon* tb;
-               
-               /*
-                * Create a temp thumbnail struct to get the thumbnail
-                * path, don't actually generate the thumbnail here.
-                */
-               tb = epsilon_new(thumb->path);
-               epsilon_thumb_size(tb, thumb->size);
-               epsilon_exists(tb);
-               thumb->dest = (char *)epsilon_thumb_file_get(tb);
-               if (thumb->dest)
-                       thumb->dest = strdup(thumb->dest);
-               epsilon_free(tb);
-       }
+       if (thumb && thumb->status)
+               epsilon_request_resolve_thumb_file(thumb);
 
-       if (thumb) {
-               ecore_event_add(EPSILON_EVENT_DONE, thumb, epsilon_event_free, 
NULL);
-       }
+       epsilon_event_inform_done(thumb);
        if (debug) printf("Jump out\n");
 
        return 1;
@@ -226,7 +248,7 @@
  *
  */
 static int
-epsilon_client_connect()
+epsilon_client_connect(void)
 {
        int retries = 0;
 
@@ -276,17 +298,15 @@
 
 /**
  * @param path Path to the original image that will be thumbnailed.
- * @param dst Destination for generated thumbnail, NULL causes auto-generation.
  * @param size Enum determining the scale of the thumbnail.
  * @param data Data associated with this thumbnail for client use.
  * @brief Request a thumbnail to be generated asynchronously for the specified
  * @a path.
  */
 Epsilon_Request *
-epsilon_add(char *path, char *dst, int size, void *data)
+epsilon_request_add(const char *path, Epsilon_Thumb_Size size, void *data)
 {
        Epsilon_Request *thumb;
-       Epsilon_Message *msg;
 
        if (!epsilon_server) {
                if (!epsilon_client_connect()) {
@@ -296,28 +316,23 @@
        }
 
        thumb = calloc(1, sizeof(Epsilon_Request));
-       if (thumb) {
-               thumb->path = strdup(path);
-               if (dst)
-                       thumb->dest = strdup(dst);
-               else {
-                       Epsilon *tb;
-
-                       /*
-                        * Create a temp thumbnail struct to get the thumbnail
-                        * path, don't actually generate the thumbnail here.
-                        */
-                       tb = epsilon_new(path);
-                       epsilon_exists(tb);
-                       epsilon_thumb_size(tb, size);
-                       thumb->dest = (char *)epsilon_thumb_file_get(tb);
-                       if (thumb->dest)
-                               thumb->dest = strdup(thumb->dest);
-                       epsilon_free(tb);
-               }
-               thumb->data = data;
+       if (!thumb)
+               return NULL;
+
+       thumb->path = strdup(path);
+       if (!thumb->path) {
+               free(thumb);
+               return NULL;
+       }
+       thumb->size = size;
+       thumb->data = data;
+       if (epsilon_request_resolve_thumb_file(thumb)) {
+               thumb->status = 1;
+               epsilon_event_inform_done(thumb);
+       } else {
+               Epsilon_Message *msg;
 
-               msg = epsilon_message_new(epsilon_mid++, (char *)path, dst, 0);
+               msg = epsilon_message_new(epsilon_mid++, path, 0);
                if (msg) {
                        msg->thumbsize = size;
                        if (debug) printf("!! requesting thumbnail for %s 
(request %d)!!, %d\n", path, msg->mid, sizeof(Epsilon_Message)+msg->bufsize);
@@ -326,10 +341,9 @@
                                ecore_dlist_append(epsilon_request_queue, 
thumb);
                        }
                        free(msg);
-               }
-               else {
-                       free(thumb);
-                       thumb = NULL;
+               } else {
+                       epsilon_request_free(thumb);
+                       return NULL;
                }
        }
 
@@ -341,21 +355,32 @@
  * @brief Request a thumbnail request to be cancelled.
  */
 void
-epsilon_del(Epsilon_Request *thumb)
+epsilon_request_del(Epsilon_Request *thumb)
 {
        Epsilon_Request *temp;
 
-       /*
-        * Find the thumbnail request matching this message response and
-        * remove it, at this point we don't bother cancelling the outstanding
-        * request to the daemon.
-        */
-       ecore_dlist_first_goto(epsilon_request_queue);
-       while ((temp = ecore_dlist_current(epsilon_request_queue))) {
-               if (temp->id == thumb->id) {
-                       ecore_dlist_remove(epsilon_request_queue);
-                       break;
+       if (!thumb)
+               return;
+
+       /* was nonexistent and so requested to server */
+       if (thumb->id > 0) {
+               /*
+                * Find the thumbnail request matching this message response and
+                * remove it, at this point we don't bother cancelling the 
outstanding
+                * request to the daemon.
+                */
+               ecore_dlist_first_goto(epsilon_request_queue);
+               while ((temp = ecore_dlist_current(epsilon_request_queue))) {
+                       if (temp->id == thumb->id) {
+                               ecore_dlist_remove(epsilon_request_queue);
+                               break;
+                       }
+                       ecore_dlist_next(epsilon_request_queue);
                }
-               ecore_dlist_next(epsilon_request_queue);
        }
+
+       if (thumb->_event)
+               ecore_event_del(thumb->_event);
+       else
+               epsilon_request_free(thumb);
 }



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to