Source

NPAPI-chrome-file-api / X11 / FileWatcherX11.cpp

/*
 * FileWatcherX11.cpp
 *
 *  Created on: 22/05/2012
 *      Author: ryan
 */

#include "FileWatcherX11.h"

FileWatcher* FileWatcher::get()
{
    static FileWatcherX11 inst;
    return &inst;
}

void FileWatcherX11::WatchFile(std::string key, std::string path, FB::JSObjectPtr callback)
{
	FileWatcherTaskX11* task = watchers[key];
	if (!task)
	{
		boost::filesystem::path p(path);
		if (is_directory(p))
		{
			task = new FileWatcherTaskX11();
			task->Watch(p, callback);
			watchers[key] = task;
		}
	}

}
void FileWatcherX11::StopWatching(std::string key)
{
	FileWatcherTaskX11* task = watchers[key];
	if (task)
	{
		task->StopWatching();
		watchers.erase(key);
		delete task;
	}
}