From 657eb02f063fe6d046cefaecc5982b0b5ae35bf6 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Tue, 9 Aug 2011 10:25:28 +0200 Subject: Make AutoReloadHelper truly "automatic" by adding the ability to automatically check for modifications at specified intervals. Using inotify() would be better, but that's not always present. --- src/FbTk/AutoReloadHelper.cc | 8 ++++++++ src/FbTk/AutoReloadHelper.hh | 8 +++++++- src/Keys.cc | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/FbTk/AutoReloadHelper.cc b/src/FbTk/AutoReloadHelper.cc index 17124d4..a9f2f5c 100644 --- a/src/FbTk/AutoReloadHelper.cc +++ b/src/FbTk/AutoReloadHelper.cc @@ -22,10 +22,18 @@ #include "AutoReloadHelper.hh" #include "FileUtil.hh" +#include "MemFun.hh" #include "StringUtil.hh" namespace FbTk { +AutoReloadHelper::AutoReloadHelper(int interval) { + m_timer.setFunctor(MemFun(*this, &AutoReloadHelper::checkReload)); + m_timer.setInterval(interval); + if(interval > 0) + m_timer.start(); +} + void AutoReloadHelper::checkReload() { if (!m_reload_cmd.get()) return; diff --git a/src/FbTk/AutoReloadHelper.hh b/src/FbTk/AutoReloadHelper.hh index b337a4a..216b3f5 100644 --- a/src/FbTk/AutoReloadHelper.hh +++ b/src/FbTk/AutoReloadHelper.hh @@ -28,11 +28,16 @@ #include "Command.hh" #include "RefCount.hh" +#include "Timer.hh" namespace FbTk { -class AutoReloadHelper { +class AutoReloadHelper: private NotCopyable { public: + /** + * @param interval time interval (in seconds) between automatic reload checks + */ + AutoReloadHelper(int interval = 0); void setMainFile(const std::string& filename); void addFile(const std::string& filename); @@ -44,6 +49,7 @@ public: private: RefCount > m_reload_cmd; std::string m_main_file; + Timer m_timer; typedef std::map TimestampMap; TimestampMap m_timestamps; diff --git a/src/Keys.cc b/src/Keys.cc index db60649..081ed8d 100644 --- a/src/Keys.cc +++ b/src/Keys.cc @@ -465,7 +465,7 @@ Keys::t_key::FindPair Keys::t_key::findBinding(vector val, bool insert ) Keys::Keys(): - m_reloader(new FbTk::AutoReloadHelper()), + m_reloader(new FbTk::AutoReloadHelper(5)), m_keylist(0), next_key(0), saved_keymode(0) { -- cgit v0.11.2