Skip to content

Commit

Permalink
Merge pull request #82 from RuntimeCompiledCPlusPlus/FileMonitor
Browse files Browse the repository at this point in the history
File monitor simplification and bug fix. Fixes #79
  • Loading branch information
dougbinks committed Dec 16, 2015
2 parents 1c22799 + 6b048a8 commit 05e9333
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 435 deletions.
42 changes: 28 additions & 14 deletions Aurora/RuntimeCompiler/FileChangeNotifier.cpp
Expand Up @@ -17,7 +17,6 @@

#include "FileChangeNotifier.h"

#include "FileMonitor.h"
#include <algorithm>
using namespace std;

Expand All @@ -33,15 +32,15 @@ FileChangeNotifier::FileChangeNotifier()
, m_fChangeNotifyDelay(DEFAULT_NOTIFY_DELAY)
, m_fTimeUntilNextAllowedRecompile(0.0f)
, m_fFileChangeSpamTimeRemaining(0.0f)
, m_pFileWatcher( new FW::FileWatcher() ) // Create the file watch object
{
m_pFileMonitor = new FileMonitor();
m_LastFileChanged = "";
}


FileChangeNotifier::~FileChangeNotifier()
{
delete m_pFileMonitor;
delete m_pFileWatcher;
}


Expand All @@ -59,7 +58,7 @@ void FileChangeNotifier::Update( float fDeltaTime )
{
if (m_bActive)
{
m_pFileMonitor->Update(fDeltaTime);
m_pFileWatcher->update();
m_fTimeUntilNextAllowedRecompile = max(0.0f, m_fTimeUntilNextAllowedRecompile - fDeltaTime);
m_fFileChangeSpamTimeRemaining = max(0.0f, m_fFileChangeSpamTimeRemaining - fDeltaTime);

Expand All @@ -78,8 +77,15 @@ void FileChangeNotifier::Watch( const FileSystemUtils::Path& filename, IFileChan
fixedFilename = fixedFilename.GetCleanPath();
fixedFilename.ToOSCanonicalCase();

m_pFileMonitor->Watch(fixedFilename, this);
m_fileListenerMap[fixedFilename].insert(pListener);
if( m_fileListenerMap[fixedFilename].insert(pListener).second )
{
bool bPathIsDir = !fixedFilename.HasExtension();
FileSystemUtils::Path pathDir = bPathIsDir ? fixedFilename : fixedFilename.ParentPath();
if( m_WatchedDirs.insert( pathDir.m_string ).second )
{
m_pFileWatcher->addWatch( pathDir.m_string, this );
}
}
pListener->OnRegisteredWithNotifier(this);
}

Expand All @@ -102,23 +108,31 @@ void FileChangeNotifier::RemoveListener( IFileChangeListener *pListener )
pListener->OnRegisteredWithNotifier(NULL);
}

void FileChangeNotifier::OnFileChange( const FileSystemUtils::Path& filename )
void FileChangeNotifier::handleFileAction( FW::WatchID watchid, const FW::String& dir, const FW::String& filename,
FW::Action action )
{
if (m_bActive)
{
FileSystemUtils::Path filePath(filename);
if( !filename.HasParentPath() )
{
filePath = dir / filePath;
}

filePath = filePath.DelimitersToOSDefault();
filePath.ToOSCanonicalCase();


// Check for multiple hits on the same file in close succession
// (Can be caused by NTFS system making multiple changes even though only
// one actual change occurred)
bool bIgnoreFileChange = (filename == m_LastFileChanged) &&
bool bIgnoreFileChange = (filePath == m_LastFileChanged) &&
m_fFileChangeSpamTimeRemaining > 0.0f;
m_LastFileChanged = filename;
m_LastFileChanged = filePath;

if (!bIgnoreFileChange)
{
FileSystemUtils::Path filePath = filename;
filePath.ToOSCanonicalCase();

m_changedFileList.push_back(filePath.m_string);
{
m_changedFileList.insert(filePath.m_string);

if (!m_bRecompilePending)
{
Expand Down
21 changes: 11 additions & 10 deletions Aurora/RuntimeCompiler/FileChangeNotifier.h
Expand Up @@ -21,7 +21,7 @@
#define FILECHANGENOTIFIER_INCLUDED

#include "IFileChangeNotifier.h"
#include "IFileMonitor.h"
#include "SimpleFileWatcher/FileWatcher.h"
#include <vector>
#include <map>
#include <set>
Expand All @@ -31,7 +31,7 @@

// Manages the registering of files with the file monitor and triggering
// Of compilation when a registered file changes
class FileChangeNotifier : public IFileChangeNotifier, public IFileMonitorListener
class FileChangeNotifier : public IFileChangeNotifier, public FW::FileWatchListener
{
public:
FileChangeNotifier();
Expand Down Expand Up @@ -74,12 +74,13 @@ class FileChangeNotifier : public IFileChangeNotifier, public IFileMonitorListen
// ~IFileChangeNotifier


// IFileMonitorListener
// FW::FileWatchListener

void OnFileChange( const FileSystemUtils::Path& filename );
void handleFileAction(FW::WatchID watchid, const FW::String& dir, const FW::String& filename,
FW::Action action);

// ~FW::FileWatchListener

// ~IFileMonitorListener


private:

Expand All @@ -88,14 +89,14 @@ class FileChangeNotifier : public IFileChangeNotifier, public IFileMonitorListen

typedef std::set<IFileChangeListener*> TFileChangeListeners;
typedef std::map<FileSystemUtils::Path, TFileChangeListeners> TFileListenerMap;
typedef std::vector<std::string> TPathNameList;
typedef std::set<std::string> TPathNameList;

// Private members
FW::FileWatcher* m_pFileWatcher;
TPathNameList m_WatchedDirs;

TFileListenerMap m_fileListenerMap;
TPathNameList m_changedFileList;

IFileMonitor *m_pFileMonitor;
TPathNameList m_changedFileList;

bool m_bActive;
bool m_bRecompilePending;
Expand Down
218 changes: 0 additions & 218 deletions Aurora/RuntimeCompiler/FileMonitor.cpp

This file was deleted.

0 comments on commit 05e9333

Please sign in to comment.