I’m trying
Plugin* pluginInstance;
#ifdef WATCHER
#include "../efsw/include/efsw/efsw.hpp"
// File action handler
class UpdateListener : public efsw::FileWatchListener {
public:
void handleFileAction( efsw::WatchID watchid, const std::string& dir,
const std::string& filename, efsw::Action action,
std::string oldFilename ) override {
// old school
callbackWatcher(filename.c_str());
switch ( action ) {
case efsw::Actions::Add:
break;
case efsw::Actions::Delete:
break;
case efsw::Actions::Modified:
break;
case efsw::Actions::Moved:
break;
default:
break;
}
}
};
static struct WatcherDo {
void add() {
wID = fileWatcher.addWatch(asset::plugin(pluginInstance, ""), &listener, true);
fileWatcher.watch();
}
~WatcherDo() {
fileWatcher.removeWatch(wID);//just to be sure
}
//didn't alloc anything but keep in focus for use until
UpdateListener listener;
//de-alloc last (must remove before listener out of focus)
//not sure if it would iterate over active watches
efsw::FileWatcher fileWatcher;
//de-alloc first (auto removed from fileWatcher?)
efsw::WatchID wID;
} watcherInstance;
#endif
void init(Plugin* p) {
pluginInstance = p;
// redefine so that correct include happens
#undef MODEL
#define MODEL(name) p->addModel(name)
#include "modules.hpp"
//not required anymore
#undef MODEL
#ifdef WATCHER
watcherInstance.add();
#endif
}
Is there a better way?