Source

NPAPI-chrome-file-api / Mac / FileWatcherMac.mm

Full commit
//
//  FileWatcherMac.mm
//  FireBreath
//
//  Created by Ryan Ackley on 5/17/12.
//  Copyright (c) 2012 Benryan Software Inc. All rights reserved.
//
#include "FileWatcherMac.h"

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

void FileWatcherMac::WatchFile(std::string key, std::string path, FB::JSObjectPtr callback)
{
    NSAutoreleasePool * pool = [NSAutoreleasePool new];
    FileWatcherTask* task = [[FileWatcherTask alloc] initWithCallback:callback];
    NSString* strPath = [NSString stringWithUTF8String:path.c_str()];
    [task performSelectorInBackground:@selector(listenForFileEvents:) withObject:strPath];
    watchers[key] = task;
    [pool release];
}

void FileWatcherMac::StopWatching(std::string key)
{
    NSAutoreleasePool * pool = [NSAutoreleasePool new];
    FileWatcherTask* task = watchers[key];
    if (task)
    {
        watchers.erase(key);
        [task stopWatching];
        [task release];
    }
    [pool release]; 
}