Source

NPAPI-chrome-file-api / Win / FileWatcherTaskWin.h

#pragma once

#include "JSObject.h"
#include "windows.h"

class FileWatcherTaskWin
{
public:
	FileWatcherTaskWin(std::string path, FB::JSObjectPtr callback);
	~FileWatcherTaskWin(){};

	void StartWatching();
	void StopWatching();

private:

	static void CALLBACK WatcherCallback(DWORD dwErrorCode,DWORD dwNumberOfBytesTransfered,	LPOVERLAPPED lpOverlapped);

	static void CALLBACK InitDirectoryWatcher(ULONG_PTR arg);

	static void CALLBACK TerminateWatch(ULONG_PTR arg);
	
	void StartAlertLoop();
	BOOL ListenForFileEvents();
	void CloseHandlesStopAlertLoop();
	//bool ShouldStop();
	
	HANDLE m_handle;
	char m_buffer[4096];
	
	bool stop;
	std::wstring m_path;
	FB::JSObjectPtr m_callback;
	OVERLAPPED m_ol;
	boost::thread m_thread;
};