diff options
author | Jens Georg <mail@jensge.org> | 2016-02-26 20:44:48 +0100 |
---|---|---|
committer | Jens Georg <mail@jensge.org> | 2016-02-27 00:48:46 +0100 |
commit | 2cfbcd1a22344f79a2c768a9ce7bc63940ced327 (patch) | |
tree | db2f5085c4cdba47045899eb9ce4bd95d14513ea | |
parent | ac3a2ad82fd23eb8a104d22eaf119525ba1c736a (diff) | |
download | rygel-2cfbcd1a22344f79a2c768a9ce7bc63940ced327.tar.gz |
rygel: Chage user config change event logic
Instead of re-reading on every file event, either do it on "changes done" or
after 500ms with no file event.
Signed-off-by: Jens Georg <mail@jensge.org>
-rw-r--r-- | src/rygel/rygel-user-config.vala | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/src/rygel/rygel-user-config.vala b/src/rygel/rygel-user-config.vala index be31a233..7998c1fd 100644 --- a/src/rygel/rygel-user-config.vala +++ b/src/rygel/rygel-user-config.vala @@ -61,6 +61,9 @@ public class Rygel.UserConfig : GLib.Object, Configuration { // Our singleton private static UserConfig config; + private uint system_config_timer_id = 0; + private uint local_config_timer_id = 0; + private class ConfigPair { public ConfigurationEntry entry; public EntryType type; @@ -724,7 +727,6 @@ public class Rygel.UserConfig : GLib.Object, Configuration { sys_key_file.load_from_file (system.get_path (), KeyFileFlags.KEEP_COMMENTS | KeyFileFlags.KEEP_TRANSLATIONS); - } catch (GLib.Error e) {} this.compare_and_notify (this.key_file, sys_key_file); @@ -737,7 +739,6 @@ public class Rygel.UserConfig : GLib.Object, Configuration { key_file.load_from_file (local.get_path (), KeyFileFlags.KEEP_COMMENTS | KeyFileFlags.KEEP_TRANSLATIONS); - } catch (GLib.Error e) {} this.compare_and_notify (key_file, this.sys_key_file); @@ -747,13 +748,46 @@ public class Rygel.UserConfig : GLib.Object, Configuration { File file, File? other_file, FileMonitorEvent event_type) { - this.reload_compare_and_notify_system (file); + if (event_type == FileMonitorEvent.CHANGES_DONE_HINT) { + if (this.system_config_timer_id != 0) { + Source.remove (this.system_config_timer_id); + this.system_config_timer_id = 0; + } + this.reload_compare_and_notify_system (file); + } else { + if (this.system_config_timer_id != 0) { + Source.remove (this.system_config_timer_id); + } + this.system_config_timer_id = Timeout.add (500, () => { + this.system_config_timer_id = 0; + this.reload_compare_and_notify_system (file); + + return false; + }); + } } private void on_local_config_changed (FileMonitor monitor, File file, File? other_file, FileMonitorEvent event_type) { - this.reload_compare_and_notify_local (file); + if (event_type == FileMonitorEvent.CHANGES_DONE_HINT) { + if (this.local_config_timer_id != 0) { + Source.remove (this.local_config_timer_id); + this.local_config_timer_id = 0; + } + this.reload_compare_and_notify_local (file); + } else { + if (this.local_config_timer_id != 0) { + Source.remove (this.local_config_timer_id); + } + + this.local_config_timer_id = Timeout.add (500, () => { + this.local_config_timer_id = 0; + this.reload_compare_and_notify_local (file); + + return false; + }); + } } } |