[maemo-commits] [maemo-commits] r16180 - in projects/haf/branches/hildon-thumbnail/daemonize: . daemon thumbs
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Sat Sep 20 16:21:54 EEST 2008
- Previous message: [maemo-commits] r16179 - projects/haf/branches/hildon-thumbnail/daemonize/daemon
- Next message: [maemo-commits] r16181 - projects/connectivity/bluez-debian/trunk
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: pvanhoof Date: 2008-09-20 16:21:51 +0300 (Sat, 20 Sep 2008) New Revision: 16180 Modified: projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog projects/haf/branches/hildon-thumbnail/daemonize/daemon/manager.c projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugin-runner.c projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.c projects/haf/branches/hildon-thumbnail/daemonize/thumbs/hildon-thumbnail-factory.c Log: 2008-09-20 Philip Van Hoof <pvanhoof at gnome.org> * thumbs/hildon-thumbnail-factory.c * daemon/plugin-runner.c * daemon/manager.c * daemon/thumbnailer.c: Various comments and leak fixes Modified: projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog =================================================================== --- projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog 2008-09-18 09:37:43 UTC (rev 16179) +++ projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog 2008-09-20 13:21:51 UTC (rev 16180) @@ -1,3 +1,10 @@ +2008-09-20 Philip Van Hoof <pvanhoof at gnome.org> + + * thumbs/hildon-thumbnail-factory.c + * daemon/plugin-runner.c + * daemon/manager.c + * daemon/thumbnailer.c: Various comments and leak fixes + 2008-09-18 Philip Van Hoof <pvanhoof at gnome.org> * daemon/hildon-thumbnail-daemon.c: File monitoring the plugins Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/manager.c =================================================================== --- projects/haf/branches/hildon-thumbnail/daemonize/daemon/manager.c 2008-09-18 09:37:43 UTC (rev 16179) +++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/manager.c 2008-09-20 13:21:51 UTC (rev 16180) @@ -32,6 +32,9 @@ #include "dbus-utils.h" #include "thumbnailer.h" +static GFile *homedir, *thumbdir; +static GFileMonitor *homemon, *thumbmon; + #define MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_MANAGER, ManagerPrivate)) G_DEFINE_TYPE (Manager, manager, G_TYPE_OBJECT) @@ -325,7 +328,7 @@ gchar *path = g_file_get_path (file); gboolean override = (strcmp (THUMBNAILERS_DIR, path) == 0); - /* We override when it's the one in the user's homedir*/ + /* We override when it's the dir in the user's homedir*/ manager_check_dir (MANAGER (user_data), path, override); g_free (path); @@ -353,25 +356,19 @@ manager_check_dir (object, home_thumbnlrs, TRUE); /* Monitor the dir for changes */ - file = g_file_new_for_path (home_thumbnlrs); - monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL); - g_signal_connect (G_OBJECT (monitor), "changed", + homedir = g_file_new_for_path (home_thumbnlrs); + homemon = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL); + g_signal_connect (G_OBJECT (homemon), "changed", G_CALLBACK (on_dir_changed), NULL); - // g_object_unref (file) - // g_object_unref (monitor) - /* Monitor the dir for changes */ - file = g_file_new_for_path (THUMBNAILERS_DIR); - monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL); - g_signal_connect (G_OBJECT (monitor), "changed", + thumbdir = g_file_new_for_path (THUMBNAILERS_DIR); + thumbmon = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL); + g_signal_connect (G_OBJECT (thumbmon), "changed", G_CALLBACK (on_dir_changed), NULL); g_mutex_unlock (priv->mutex); - // g_object_unref (file) - // g_object_unref (monitor) - g_free (home_thumbnlrs); } @@ -600,6 +597,10 @@ void manager_do_stop (void) { + g_object_unref (homemon); + g_object_unref (thumbmon); + g_object_unref (homedir); + g_object_unref (thumbdir); } void Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugin-runner.c =================================================================== --- projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugin-runner.c 2008-09-18 09:37:43 UTC (rev 16179) +++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugin-runner.c 2008-09-20 13:21:51 UTC (rev 16180) @@ -67,11 +67,38 @@ #define plugin_runner_create daemon_create + +static gboolean do_shut_down_next_time = TRUE; + +static void +keep_alive (void) +{ + do_shut_down_next_time = FALSE; +} + +static gboolean +shut_down_after_timeout (gpointer user_data) +{ + GMainLoop *main_loop = user_data; + gboolean shut = FALSE; + + if (do_shut_down_next_time) { + g_main_loop_quit (main_loop); + shut = TRUE; + } else + do_shut_down_next_time = TRUE; + + return shut; +} + void daemon_create (Daemon *object, GStrv uris, DBusGMethodInvocation *context) { DaemonPrivate *priv = DAEMON_GET_PRIVATE (object); GError *error = NULL; + + keep_alive (); + hildon_thumbnail_plugin_do_create (priv->module, uris, &error); if (error) { dbus_g_method_return_error (context, error); @@ -230,6 +257,7 @@ static gboolean dynamic_register = FALSE; static gchar *bus_name; static gchar *bus_path; +static gint timeout = 600; static GOptionEntry entries_daemon[] = { { "module-name", 'm', G_OPTION_FLAG_REVERSE|G_OPTION_FLAG_OPTIONAL_ARG, @@ -240,6 +268,10 @@ G_OPTION_ARG_STRING, &bus_name, "Busname to use (eg. com.company.Thumbnailer) ", NULL }, + { "timeout", 't', 0, + G_OPTION_ARG_INT, &timeout, + "Timeout before the specialized thumbnailer dies (use -1 for inlimited)", + NULL }, { "bus-path", 'p', 0, G_OPTION_ARG_STRING, &bus_path, "Buspath to use (eg. /com/company/Thumbnailer) ", @@ -316,6 +348,11 @@ daemon_start (DAEMON (object), dynamic_register); + if (timeout > -1) + g_timeout_add_seconds (timeout, + shut_down_after_timeout, + main_loop); + main_loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (main_loop); Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.c =================================================================== --- projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.c 2008-09-18 09:37:43 UTC (rev 16179) +++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.c 2008-09-20 13:21:51 UTC (rev 16180) @@ -503,6 +503,9 @@ for (n = 0; n<3; n++) { GFile *from, *to; + if (!from_s[n] || !to_s[n]) + continue; + from = g_file_new_for_path (from_s[n]); to = g_file_new_for_path (to_s[n]); @@ -531,6 +534,7 @@ } for (n = 0; n<3; n++) { + /* These can be NULL, but that's ok for g_free */ g_free (from_s[n]); g_free (to_s[n]); } Modified: projects/haf/branches/hildon-thumbnail/daemonize/thumbs/hildon-thumbnail-factory.c =================================================================== --- projects/haf/branches/hildon-thumbnail/daemonize/thumbs/hildon-thumbnail-factory.c 2008-09-18 09:37:43 UTC (rev 16179) +++ projects/haf/branches/hildon-thumbnail/daemonize/thumbs/hildon-thumbnail-factory.c 2008-09-20 13:21:51 UTC (rev 16180) @@ -116,11 +116,18 @@ GFile *filei = NULL; GInputStream *stream = NULL; - hildon_thumbnail_util_get_thumb_paths (item->uri, &large, &normal, &cropped, &error); + /* Get the large small and cropped path for the original + * URI */ + + hildon_thumbnail_util_get_thumb_paths (item->uri, &large, + &normal, &cropped, + &error); if (error) goto error_handler; + /* Determine the exact type of thumbnail being requested */ + if (item->flags & HILDON_THUMBNAIL_FLAG_CROP) { path = g_strdup (cropped); } else if (item->width > 128) { @@ -129,20 +136,26 @@ path = g_strdup (normal); } + /* Open the original thumbnail as a stream */ + filei = g_file_new_for_path (path); stream = G_INPUT_STREAM (g_file_read (filei, NULL, &error)); if (error) goto error_handler; + /* Read the stream as a pixbuf at the requested exact scale */ pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream, item->width, item->height, TRUE, NULL, &error); error_handler: + /* Callback user function, passing the pixbuf and error */ + item->callback (item, item->user_data, pixbuf, error); + /* Cleanup */ if (filei) g_object_unref (filei); @@ -161,6 +174,8 @@ g_free (normal); g_free (large); + /* Remove the key from the hash, which means that we declare it + * handled. */ g_hash_table_remove (tasks, key); } @@ -185,10 +200,10 @@ GError *error = NULL; guint64 mtime, size; - file_path = g_build_filename(path, file, NULL); + file_path = g_build_filename (path, file, NULL); if(file[0] == '.' || !g_file_test(file_path, G_FILE_TEST_IS_REGULAR)) { - g_free(file_path); + g_free (file_path); continue; } @@ -202,6 +217,7 @@ if (error) { g_error_free (error); g_object_unref (filei); + g_free (file_path); continue; } @@ -226,15 +242,15 @@ static void cache_file_free(ThumbsCacheFile *item) { - g_free(item->file); - g_free(item); + g_free (item->file); + g_free (item); } static gint cache_file_compare(gconstpointer a, gconstpointer b) { ThumbsCacheFile *f1 = *(ThumbsCacheFile**)a, - *f2 = *(ThumbsCacheFile**)b; + *f2 = *(ThumbsCacheFile**)b; /* Sort in descending order */ if(f2->mtime == f1->mtime) { @@ -251,10 +267,8 @@ void hildon_thumbnail_factory_clean_cache(gint max_size, time_t min_mtime) { - GPtrArray *files; int i, size = 0; - gboolean deleting = FALSE; gchar *large_dir = g_build_filename (g_get_home_dir (), ".thumbnails", "large", NULL); gchar *normal_dir = g_build_filename (g_get_home_dir (), ".thumbnails", "normal", NULL); gchar *cropped_dir = g_build_filename (g_get_home_dir (), ".thumbnails", "cropped", NULL); @@ -264,30 +278,25 @@ files = g_ptr_array_new(); - read_cache_dir(fail_dir, files); - read_cache_dir(large_dir, files); - read_cache_dir(normal_dir, files); - read_cache_dir(cropped_dir, files); + read_cache_dir (fail_dir, files); + read_cache_dir (large_dir, files); + read_cache_dir (normal_dir, files); + read_cache_dir (cropped_dir, files); - g_ptr_array_sort(files, cache_file_compare); + g_ptr_array_sort (files, cache_file_compare); for(i = 0; i < files->len; i++) { - ThumbsCacheFile *item = g_ptr_array_index(files, i); + ThumbsCacheFile *item = g_ptr_array_index (files, i); size += item->size; - - if((max_size >= 0 && size >= max_size) || item->mtime < min_mtime) { - deleting = TRUE; + if ((max_size >= 0 && size >= max_size) || item->mtime < min_mtime) { + unlink (item->file); } - - if(deleting) { - unlink(item->file); - } } - g_ptr_array_foreach(files, (GFunc)cache_file_free, NULL); + g_ptr_array_foreach (files, (GFunc)cache_file_free, NULL); + g_ptr_array_free (files, TRUE); - g_ptr_array_free(files, TRUE); g_free (fail_dir); g_free (normal_dir); g_free (large_dir); @@ -300,6 +309,8 @@ ThumbsItem *item = userdata; gchar *key = g_strdup_printf ("%d", OUT_handle); item->handle_id = OUT_handle; + + /* Register the item as being handled */ g_hash_table_replace (tasks, key, item); } @@ -337,7 +348,7 @@ g_free (cropped); } - item = g_new(ThumbsItem, 1); + item = g_new (ThumbsItem, 1); item->uri = g_strdup(uri); item->mime_type = g_strdup(mime_type); @@ -374,6 +385,8 @@ { ThumbsItem *item = userdata; gchar *key = g_strdup_printf ("%d", item->handle_id); + + /* Unregister the item */ g_hash_table_remove (tasks, key); g_free (key); } @@ -387,6 +400,7 @@ if (item->handle_id == 0) return; + /* We don't do real canceling, we just do unqueing */ org_freedesktop_thumbnailer_Generic_unqueue_async (proxy, item->handle_id, on_cancelled, item);
- Previous message: [maemo-commits] r16179 - projects/haf/branches/hildon-thumbnail/daemonize/daemon
- Next message: [maemo-commits] r16181 - projects/connectivity/bluez-debian/trunk
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]