[maemo-commits] [maemo-commits] r16177 - in projects/haf/branches/hildon-thumbnail/daemonize: . daemon
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Thu Sep 18 12:20:08 EEST 2008
- Previous message: [maemo-commits] r16176 - projects/haf/tags/shared-mime-info
- Next message: [maemo-commits] r16178 - in projects/haf/branches/hildon-thumbnail/daemonize: . daemon
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: pvanhoof Date: 2008-09-18 12:20:07 +0300 (Thu, 18 Sep 2008) New Revision: 16177 Modified: projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog projects/haf/branches/hildon-thumbnail/daemonize/daemon/hildon-thumbnail-daemon.c Log: 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/ChangeLog =================================================================== --- projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog 2008-09-17 15:44:48 UTC (rev 16176) +++ projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog 2008-09-18 09:20:07 UTC (rev 16177) @@ -1,3 +1,7 @@ +2008-09-18 Philip Van Hoof <pvanhoof at gnome.org> + + * daemon/hildon-thumbnail-daemon.c: File monitoring the plugins + 2008-09-17 Philip Van Hoof <pvanhoof at gnome.org> * daemon/plugins/gdkpixbuf-plugin.c: Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/hildon-thumbnail-daemon.c =================================================================== --- projects/haf/branches/hildon-thumbnail/daemonize/daemon/hildon-thumbnail-daemon.c 2008-09-17 15:44:48 UTC (rev 16176) +++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/hildon-thumbnail-daemon.c 2008-09-18 09:20:07 UTC (rev 16177) @@ -25,12 +25,14 @@ #include <glib.h> #include <dbus/dbus-glib-bindings.h> +#include <gio/gio.h> #include "hildon-thumbnail-plugin.h" #include "thumbnailer.h" #include "manager.h" +static GHashTable *registrations; static gboolean do_shut_down_next_time = TRUE; void @@ -54,11 +56,117 @@ return shut; } + +static GHashTable* +init_plugins (DBusGConnection *connection, Thumbnailer *thumbnailer) +{ + GHashTable *regs; + GModule *module; + GError *error = NULL; + GDir *dir; + const gchar *plugin; + + regs = g_hash_table_new_full (g_str_hash, g_str_equal, + (GDestroyNotify) g_free, + (GDestroyNotify) NULL); + + + /* TODO: Monitor this directory for plugin removals and additions */ + + dir = g_dir_open (PLUGINS_DIR, 0, &error); + + if (dir) { + while ((plugin = g_dir_read_name (dir)) != NULL) { + gboolean cropping; + + if (!g_str_has_suffix (plugin, "." G_MODULE_SUFFIX)) { + continue; + } + + module = hildon_thumbnail_plugin_load (plugin); + hildon_thumbnail_plugin_do_init (module, &cropping, + (register_func) thumbnailer_register_plugin, + thumbnailer, + &error); + if (error) { + g_warning ("Can't load plugin [%s]: %s\n", plugin, + error->message); + g_error_free (error); + } else + g_hash_table_replace (regs, g_strdup (plugin), + module); + } + g_dir_close (dir); + } + + return regs; +} + +static void +stop_plugins (GHashTable *regs, Thumbnailer *thumbnailer) +{ + GHashTableIter iter; + gpointer key, value; + + g_hash_table_iter_init (&iter, regs); + + while (g_hash_table_iter_next (&iter, &key, &value)) { + thumbnailer_unregister_plugin (thumbnailer, value); + hildon_thumbnail_plugin_do_stop (value); + } +} + + +static void +on_plugin_changed (GFileMonitor *monitor, GFile *file, GFile *other_file, GFileMonitorEvent event_type, gpointer user_data) +{ + Thumbnailer *thumbnailer = user_data; + GModule *module = NULL; + gchar *path = g_file_get_path (other_file); + + if (path) { + switch (event_type) { + case G_FILE_MONITOR_EVENT_DELETED: { + GModule *module = g_hash_table_lookup (registrations, path); + if (module) { + thumbnailer_unregister_plugin (thumbnailer, module); + hildon_thumbnail_plugin_do_stop (module); + } + } + case G_FILE_MONITOR_EVENT_CREATED: { + GModule *module = hildon_thumbnail_plugin_load (path); + gboolean cropping = FALSE; + + if (module) { + GError *error = NULL; + + hildon_thumbnail_plugin_do_init (module, &cropping, + (register_func) thumbnailer_register_plugin, + thumbnailer, + &error); + if (error) { + g_warning ("Can't load plugin [%s]: %s\n", path, + error->message); + g_error_free (error); + } else + g_hash_table_replace (registrations, g_strdup (path), + module); + } + } + break; + default: + break; + } + } + + g_free (path); +} + + int main (int argc, char **argv) { DBusGConnection *connection; - GModule *module; GError *error = NULL; g_type_init (); @@ -77,12 +185,8 @@ Manager *manager; Thumbnailer *thumbnailer; DBusGProxy *manager_proxy; - gboolean cropping; - GDir *dir; - const gchar *plugin; - GHashTable *registrations; - GHashTableIter iter; - gpointer key, value; + GFile *file; + GFileMonitor *monitor; manager_do_init (connection, &manager, &error); thumbnailer_do_init (connection, manager, &thumbnailer, &error); @@ -92,32 +196,16 @@ MANAGER_PATH, MANAGER_INTERFACE); - registrations = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) NULL); + registrations = init_plugins (connection, thumbnailer); - /* TODO: Monitor this directory for plugin removals and additions */ - - dir = g_dir_open (PLUGINS_DIR, 0, &error); + file = g_file_new_for_path (PLUGINS_DIR); + monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL); + g_signal_connect (G_OBJECT (monitor), "changed", + G_CALLBACK (on_plugin_changed), thumbnailer); - if (dir) { - while ((plugin = g_dir_read_name (dir)) != NULL) { + // g_object_unref (file) + // g_object_unref (monitor); - if (!g_str_has_suffix (plugin, "." G_MODULE_SUFFIX)) { - continue; - } - - module = hildon_thumbnail_plugin_load (plugin); - hildon_thumbnail_plugin_do_init (module, &cropping, - (register_func) thumbnailer_register_plugin, - thumbnailer, - &error); - g_hash_table_replace (registrations, g_strdup (plugin), - module); - } - g_dir_close (dir); - } - main_loop = g_main_loop_new (NULL, FALSE); g_timeout_add_seconds (600, @@ -126,13 +214,8 @@ g_main_loop_run (main_loop); - g_hash_table_iter_init (&iter, registrations); + stop_plugins (registrations, thumbnailer); - while (g_hash_table_iter_next (&iter, &key, &value)) { - thumbnailer_unregister_plugin (thumbnailer, value); - hildon_thumbnail_plugin_do_stop (value); - } - g_hash_table_unref (registrations); thumbnailer_do_stop ();
- Previous message: [maemo-commits] r16176 - projects/haf/tags/shared-mime-info
- Next message: [maemo-commits] r16178 - in projects/haf/branches/hildon-thumbnail/daemonize: . daemon
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]