コード例 #1
0
bool wxFsEventsFileSystemWatcher::RemoveTree(const wxFileName& path)
{
    wxString canonical = GetCanonicalPath(path);
    if ( canonical.empty() )
    {
        return false;
    }

    // Remove any kqueue watches created with Add()
    // RemoveTree() should remove all watches no matter
    // if they are tree watches or single directory watches.
    wxArrayString dirsWatched;
    wxKqueueFileSystemWatcher::GetWatchedPaths(&dirsWatched);
    for ( size_t i = 0; i < dirsWatched.size(); i++ )
    {
        if (dirsWatched[i].Find(canonical) == 0)
        {
            wxKqueueFileSystemWatcher::Remove(dirsWatched[i]);
        }
    }

    FSEventStreamRefMap::iterator it = m_streams.find(canonical);
    bool removed = false;
    if ( it != m_streams.end() )
    {
        FSEventStreamStop(it->second);
        FSEventStreamInvalidate(it->second);
        FSEventStreamRelease(it->second);
        m_streams.erase(it);
        removed = true;
    }
    return removed;
}
コード例 #2
0
ファイル: fsevent.c プロジェクト: hotchpotch/ruby-fsevent
static VALUE t_stop(VALUE self) {
  FSEventStreamStop(stream);
  FSEventStreamInvalidate(stream);
  FSEventStreamRelease(stream);
  CFRunLoopStop(CFRunLoopGetCurrent());
  return self;
}
コード例 #3
0
ファイル: wt-monitor-macos.c プロジェクト: sheyong/seafile
static int handle_rm_repo (SeafWTMonitorPriv *priv, gpointer handle)
{
    FSEventStreamRef stream = (FSEventStreamRef)handle;
    FSEventStreamStop (stream);
    FSEventStreamInvalidate (stream);
    FSEventStreamRelease (stream);
    return 0;
}
コード例 #4
0
void FileSystem::deinitializeInternalApple() {
    for (auto d : _directories) {
        DirectoryHandle* dh = d.second;
        FSEventStreamStop(dh->_eventStream);
        FSEventStreamInvalidate(dh->_eventStream);
        FSEventStreamRelease(dh->_eventStream);
        delete dh;
    }
}
コード例 #5
0
ファイル: fsevents.cpp プロジェクト: niclasr/watchman
fse_stream::~fse_stream() {
  if (stream) {
    FSEventStreamStop(stream);
    FSEventStreamInvalidate(stream);
    FSEventStreamRelease(stream);
  }
  if (uuid) {
    CFRelease(uuid);
  }
}
コード例 #6
0
AppleReloadManager::~AppleReloadManager()
{
   //Unregister from file system
   FSEventStreamStop(stream);
   FSEventStreamUnscheduleFromRunLoop(stream,CFRunLoopGetCurrent(),kCFRunLoopDefaultMode);
   FSEventStreamInvalidate(stream);
   FSEventStreamRelease(stream);

   //Destory the lock
   pthread_mutex_destroy(&AppleReloadManager::reloadMutex);
}
コード例 #7
0
MacFileSystemChangeNotifier::~MacFileSystemChangeNotifier()
{
    for( U32 i = 0, num = mEvents.size(); i < num; ++ i )
    {
        FSEventStreamStop( mEvents[ i ]->mStream );
        FSEventStreamInvalidate( mEvents[ i ]->mStream );
        FSEventStreamRelease( mEvents[ i ]->mStream );

        SAFE_DELETE( mEvents[ i ] );
    }
}
コード例 #8
0
void DeleteEventStream()
{
  if ( g_Stream != NULL )
  {
    FSEventStreamStop(g_Stream);
    FSEventStreamInvalidate(g_Stream);
    FSEventStreamRelease(g_Stream);

    g_Stream = NULL;
  }
}
コード例 #9
0
static PyObject* pyfsevents_unschedule(PyObject* self, PyObject* stream) {
    PyObject* value = PyDict_GetItem(streams, stream);
    PyDict_DelItem(streams, stream);
    FSEventStreamRef fsstream = PyCObject_AsVoidPtr(value);

    FSEventStreamStop(fsstream);
    FSEventStreamInvalidate(fsstream);
    FSEventStreamRelease(fsstream);

    Py_INCREF(Py_None);
    return Py_None;
}
void FDirectoryWatchRequestMac::Shutdown( void )
{
	if( bRunning )
	{
		check(EventStream);

		FSEventStreamStop(EventStream);
		FSEventStreamUnscheduleFromRunLoop(EventStream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
		FSEventStreamInvalidate(EventStream);
		FSEventStreamRelease(EventStream);

		bRunning = false;
	}
}
コード例 #11
0
static int
handle_rm_repo (SeafWTMonitor *monitor, const char *repo_id, gpointer handle)
{
    SeafWTMonitorPriv *priv = monitor->priv;
    FSEventStreamRef stream = (FSEventStreamRef)handle;
    FSEventStreamStop (stream);
    FSEventStreamInvalidate (stream);
    FSEventStreamRelease (stream);

    pthread_mutex_lock (&priv->hash_lock);
    g_hash_table_remove (priv->handle_hash, repo_id);
    g_hash_table_remove (priv->info_hash, (gpointer)(long)stream);
    pthread_mutex_unlock (&priv->hash_lock);
    return 0;
}
コード例 #12
0
ファイル: eyed.c プロジェクト: rsms/eye
int
main(int argc, const char * argv[])
{
  int result = 0;
  FSEventStreamRef streamRef;
  Boolean startedOK;
  int flush_seconds = 3600; // When to force-flush any queued events
  
  if(argc < 2 || strcasecmp(argv[1], "--help") == 0) {
    fprintf(stderr, "usage: %s path ...\n", argv[0]);
    exit(1);
  }
  
  const char **paths = &argv[1];
  streamRef = my_FSEventStreamCreate(paths, argc-1);
  
  FSEventStreamScheduleWithRunLoop(streamRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
  
  startedOK = FSEventStreamStart(streamRef);
  if (!startedOK) {
    log_error("FSEventStreamStart(streamRef) failed");
    goto out;
  }
  
  if (flush_seconds >= 0) {
    log_debug("CFAbsoluteTimeGetCurrent() => %.3f", CFAbsoluteTimeGetCurrent());
    CFAllocatorRef allocator = kCFAllocatorDefault;
    CFAbsoluteTime fireDate = CFAbsoluteTimeGetCurrent() + /*settings->*/flush_seconds;
    CFTimeInterval interval = /*settings->*/flush_seconds;
    CFOptionFlags flags = 0;
    CFIndex order = 0;
    CFRunLoopTimerCallBack callback = (CFRunLoopTimerCallBack)timer_callback;
    CFRunLoopTimerContext context = { 0, streamRef, NULL, NULL, NULL };
    CFRunLoopTimerRef timer = CFRunLoopTimerCreate(allocator, fireDate, interval, flags, order, callback, &context);
    CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopDefaultMode);
  }
  
  // Run
  CFRunLoopRun();
  
  // Stop / Invalidate / Release
  FSEventStreamStop(streamRef);
out:
  FSEventStreamInvalidate(streamRef);
  FSEventStreamRelease(streamRef);
  
  return result;
}
コード例 #13
0
bool wxFsEventsFileSystemWatcher::RemoveAll()
{
    // remove all watches created with Add()
    bool ret = wxKqueueFileSystemWatcher::RemoveAll();
    FSEventStreamRefMap::iterator it = m_streams.begin();
    while ( it != m_streams.end() )
    {
        FSEventStreamStop(it->second);
        FSEventStreamInvalidate(it->second);
        FSEventStreamRelease(it->second);
        it++;
        ret |= true;
    }
    m_streams.clear();
    return ret;
}
コード例 #14
0
  fsevents_monitor::~fsevents_monitor()
  {
    if (stream)
    {
      FSW_ELOG(_("Stopping event stream...\n"));
      FSEventStreamStop(stream);

      FSW_ELOG(_("Invalidating event stream...\n"));
      FSEventStreamInvalidate(stream);

      FSW_ELOG(_("Releasing event stream...\n"));
      FSEventStreamRelease(stream);
    }

    stream = nullptr;
  }
コード例 #15
0
ファイル: fsevents.cpp プロジェクト: timzimmermann/osquery
void FSEventsEventPublisher::stop() {
  // Stop the stream.
  if (stream_ != nullptr) {
    FSEventStreamStop(stream_);
    stream_started_ = false;
    FSEventStreamUnscheduleFromRunLoop(
        stream_, run_loop_, kCFRunLoopDefaultMode);
    FSEventStreamInvalidate(stream_);
    FSEventStreamRelease(stream_);
    stream_ = nullptr;
  }

  // Stop the run loop.
  if (run_loop_ != nullptr) {
    CFRunLoopStop(run_loop_);
  }
}
コード例 #16
0
ファイル: fsevents.cpp プロジェクト: FritzX6/osquery
void FSEventsEventPublisher::stop() {
  // Stop the stream.
  WriteLock lock(mutex_);
  if (run_loop_ == nullptr) {
    // No need to stop if there is not run loop.
    return;
  }

  if (stream_ != nullptr) {
    FSEventStreamStop(stream_);
    stream_started_ = false;
    FSEventStreamUnscheduleFromRunLoop(
        stream_, run_loop_, kCFRunLoopDefaultMode);
    FSEventStreamInvalidate(stream_);
    FSEventStreamRelease(stream_);
    stream_ = nullptr;
  }

  // Stop the run loop.
  CFRunLoopStop(run_loop_);
}
コード例 #17
0
bool MacFileSystemChangeNotifier::internalRemoveNotification( const Torque::Path& dir )
{
    for( U32 i = 0, num = mEvents.size(); i < num; ++ i )
        if( mEvents[ i ]->mDir == dir )
        {
#ifdef DEBUG_SPEW
            Platform::outputDebugString( "[MacFileSystemChangeNotifier] Removing change notification %i from '%s'",
                                         i + 1, dir.getFullPath().c_str() );
#endif

            FSEventStreamStop( mEvents[ i ]->mStream );
            FSEventStreamInvalidate( mEvents[ i ]->mStream );
            FSEventStreamRelease( mEvents[ i ]->mStream );

            SAFE_DELETE( mEvents[ i ] );

            mEvents.erase( i );

            return true;
        }

    return false;
}
コード例 #18
0
ファイル: FSEventsWatcher.cpp プロジェクト: DX94/BumpTop
FSEventsWatcher::~FSEventsWatcher() {
  FSEventStreamStop(stream_);
  FSEventStreamInvalidate(stream_); /* will remove from runloop */
  FSEventStreamRelease(stream_);
  delete context_;
}
コード例 #19
0
XMacFileSystemNotification::XMacChangeData::~XMacChangeData()
{
	if (fStreamRef != NULL)
		FSEventStreamRelease( fStreamRef );
	ClearDirectorySnapshot( fSnapshot );
}
コード例 #20
0
static void cleanupFSStream(FSEventStreamRef stream)
{
    if (stream)
        FSEventStreamRelease(stream);
}
コード例 #21
0
ファイル: folderwatcher_mac.cpp プロジェクト: 24killen/client
FolderWatcherPrivate::~FolderWatcherPrivate()
{
    FSEventStreamStop(_stream);
    FSEventStreamInvalidate(_stream);
    FSEventStreamRelease(_stream);
}
コード例 #22
0
ファイル: Watcher.c プロジェクト: nkpart/fsevents-api
void WatcherRelease(Watcher *w) {
    CancelWatcher(w);
    FSEventStreamRelease(w->stream);
    CFRelease(w->pathsToWatch);
}
コード例 #23
0
ファイル: fsevents.c プロジェクト: kwlzn/watchman
static void *fsevents_thread(void *arg)
{
  w_root_t *root = arg;
  FSEventStreamContext ctx;
  CFMutableArrayRef parray;
  CFStringRef cpath;
  FSEventStreamRef fs_stream = NULL;
  CFFileDescriptorContext fdctx;
  CFFileDescriptorRef fdref;
  struct fsevents_root_state *state = root->watch;
  double latency;

  w_set_thread_name("fsevents %.*s", root->root_path->len,
      root->root_path->buf);

  // Block until fsevents_root_start is waiting for our initialization
  pthread_mutex_lock(&state->fse_mtx);

  memset(&ctx, 0, sizeof(ctx));
  ctx.info = root;

  memset(&fdctx, 0, sizeof(fdctx));
  fdctx.info = root;

  fdref = CFFileDescriptorCreate(NULL, state->fse_pipe[0], true,
      fse_pipe_callback, &fdctx);
  CFFileDescriptorEnableCallBacks(fdref, kCFFileDescriptorReadCallBack);
  {
    CFRunLoopSourceRef fdsrc;

    fdsrc = CFFileDescriptorCreateRunLoopSource(NULL, fdref, 0);
    if (!fdsrc) {
      root->failure_reason = w_string_new(
          "CFFileDescriptorCreateRunLoopSource failed");
      goto done;
    }
    CFRunLoopAddSource(CFRunLoopGetCurrent(), fdsrc, kCFRunLoopDefaultMode);
    CFRelease(fdsrc);
  }

  parray = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
  if (!parray) {
    root->failure_reason = w_string_new("CFArrayCreateMutable failed");
    goto done;
  }

  cpath = CFStringCreateWithBytes(NULL, (const UInt8*)root->root_path->buf,
      root->root_path->len, kCFStringEncodingUTF8,
      false);
  if (!cpath) {
    root->failure_reason = w_string_new("CFStringCreateWithBytes failed");
    goto done;
  }

  CFArrayAppendValue(parray, cpath);
  CFRelease(cpath);

  latency = cfg_get_double(root, "fsevents_latency", 0.01),
  w_log(W_LOG_DBG,
      "FSEventStreamCreate for path %.*s with latency %f seconds\n",
      root->root_path->len,
      root->root_path->buf,
      latency);

  fs_stream = FSEventStreamCreate(NULL, fse_callback,
      &ctx, parray, kFSEventStreamEventIdSinceNow,
      latency,
      kFSEventStreamCreateFlagNoDefer|
      kFSEventStreamCreateFlagWatchRoot|
      kFSEventStreamCreateFlagFileEvents);

  if (!fs_stream) {
    root->failure_reason = w_string_new("FSEventStreamCreate failed");
    goto done;
  }

  FSEventStreamScheduleWithRunLoop(fs_stream,
      CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
  if (!FSEventStreamStart(fs_stream)) {
    root->failure_reason = w_string_make_printf(
        "FSEventStreamStart failed, look at your log file %s for "
        "lines mentioning FSEvents and see "
        "https://facebook.github.io/watchman/docs/troubleshooting.html#"
        "fsevents for more information\n", log_name);
    goto done;
  }

  // Signal to fsevents_root_start that we're done initializing
  pthread_cond_signal(&state->fse_cond);
  pthread_mutex_unlock(&state->fse_mtx);

  // Process the events stream until we get signalled to quit
  CFRunLoopRun();

  // Since the goto's above hold fse_mtx, we should grab it here
  pthread_mutex_lock(&state->fse_mtx);
done:
  if (fs_stream) {
    FSEventStreamStop(fs_stream);
    FSEventStreamInvalidate(fs_stream);
    FSEventStreamRelease(fs_stream);
  }
  if (fdref) {
    CFRelease(fdref);
  }

  // Signal to fsevents_root_start that we're done initializing in
  // the failure path.  We'll also do this after we've completed
  // the run loop in the success path; it's a spurious wakeup but
  // harmless and saves us from adding and setting a control flag
  // in each of the failure `goto` statements. fsevents_root_dtor
  // will `pthread_join` us before `state` is freed.
  pthread_cond_signal(&state->fse_cond);
  pthread_mutex_unlock(&state->fse_mtx);

  w_log(W_LOG_DBG, "fse_thread done\n");
  w_root_delref(root);
  return NULL;
}
コード例 #24
0
static PyObject* pyfsevents_schedule(PyObject* self, PyObject* args,
                                     PyObject *keywds) {
    PyObject* thread;
    PyObject* stream;
    PyObject* paths;
    PyObject* callback;
    PyObject* show_file_events;

    // default latency to be used.
    double latency = 0.01; 
    
    static char *kwlist[] = {"thread", "stream", "callback", "paths", 
                             "show_file_events", "latency", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, keywds, "OOOOO|d:schedule", kwlist,
                                     &thread, &stream, &callback, &paths,
                                     &show_file_events, &latency))
        return NULL;
    
    /* stream must not already have been scheduled */
    if (PyDict_Contains(streams, stream) == 1) {
        return NULL;
    }

    /* create path array */
    CFMutableArrayRef cfArray;
    cfArray = CFArrayCreateMutable(kCFAllocatorDefault, 1,
                                   &kCFTypeArrayCallBacks);
    if (cfArray == NULL)
        return NULL;

    int i;
    Py_ssize_t size = PyList_Size(paths);
    const char* path;
    CFStringRef cfStr;
    for (i=0; i<size; i++) {
        path = PyString_AS_STRING(PyList_GetItem(paths, i));
        cfStr = CFStringCreateWithCString(kCFAllocatorDefault,
                                          path,
                                          kCFStringEncodingUTF8);
        CFArraySetValueAtIndex(cfArray, i, cfStr);
        CFRelease(cfStr);
    }

    /* allocate stream info structure */
    FSEventStreamInfo * info = PyMem_New(FSEventStreamInfo, 1);

    /* create event stream */
    FSEventStreamContext context = {0, (void*) info, NULL, NULL, NULL};
    FSEventStreamRef fsstream = NULL;
    
    UInt32 flags = kFSEventStreamCreateFlagNoDefer;
    if(show_file_events == Py_True){
        flags = flags | kFSEventStreamCreateFlagFileEvents;
    }

    fsstream = FSEventStreamCreate(kCFAllocatorDefault,
                                   (FSEventStreamCallback)&handler,
                                   &context,
                                   cfArray,
                                   kFSEventStreamEventIdSinceNow,
                                   latency,
                                   flags);
    CFRelease(cfArray);

    PyObject* value = PyCObject_FromVoidPtr((void*) fsstream, PyMem_Free);
    PyDict_SetItem(streams, stream, value);

    /* get runloop reference from observer info data or current */
    value = PyDict_GetItem(loops, thread);
    CFRunLoopRef loop;
    if (value == NULL) {
        loop = CFRunLoopGetCurrent();
    } else {
        loop = (CFRunLoopRef) PyCObject_AsVoidPtr(value);
    }

    FSEventStreamScheduleWithRunLoop(fsstream, loop, kCFRunLoopDefaultMode);

    /* set stream info for callback */
    info->callback = callback;
    info->stream = fsstream;
    info->loop = loop;
    info->state = PyThreadState_Get();
    Py_INCREF(callback);

    /* start event streams */
    if (!FSEventStreamStart(fsstream)) {
        FSEventStreamInvalidate(fsstream);
        FSEventStreamRelease(fsstream);
        return NULL;
    }

    Py_INCREF(Py_None);
    return Py_None;
}
コード例 #25
0
ファイル: autobuild_osx.cpp プロジェクト: scoopr/autobuild
Autobuild::~Autobuild() {

    FSEventStreamRelease(mPimpl->stream);

    delete mPimpl;
}