Ejemplo n.º 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;
}
Ejemplo n.º 2
0
static VALUE t_stop(VALUE self) {
  FSEventStreamStop(stream);
  FSEventStreamInvalidate(stream);
  FSEventStreamRelease(stream);
  CFRunLoopStop(CFRunLoopGetCurrent());
  return self;
}
static void stopFSStream(FSEventStreamRef stream)
{
    if (stream) {
        FSEventStreamStop(stream);
        FSEventStreamInvalidate(stream);
    }
}
Ejemplo n.º 4
0
static int handle_rm_repo (SeafWTMonitorPriv *priv, gpointer handle)
{
    FSEventStreamRef stream = (FSEventStreamRef)handle;
    FSEventStreamStop (stream);
    FSEventStreamInvalidate (stream);
    FSEventStreamRelease (stream);
    return 0;
}
Ejemplo n.º 5
0
void FileSystem::deinitializeInternalApple() {
    for (auto d : _directories) {
        DirectoryHandle* dh = d.second;
        FSEventStreamStop(dh->_eventStream);
        FSEventStreamInvalidate(dh->_eventStream);
        FSEventStreamRelease(dh->_eventStream);
        delete dh;
    }
}
Ejemplo n.º 6
0
fse_stream::~fse_stream() {
  if (stream) {
    FSEventStreamStop(stream);
    FSEventStreamInvalidate(stream);
    FSEventStreamRelease(stream);
  }
  if (uuid) {
    CFRelease(uuid);
  }
}
AppleReloadManager::~AppleReloadManager()
{
   //Unregister from file system
   FSEventStreamStop(stream);
   FSEventStreamUnscheduleFromRunLoop(stream,CFRunLoopGetCurrent(),kCFRunLoopDefaultMode);
   FSEventStreamInvalidate(stream);
   FSEventStreamRelease(stream);

   //Destory the lock
   pthread_mutex_destroy(&AppleReloadManager::reloadMutex);
}
Ejemplo n.º 8
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 ] );
    }
}
Ejemplo n.º 9
0
void DeleteEventStream()
{
  if ( g_Stream != NULL )
  {
    FSEventStreamStop(g_Stream);
    FSEventStreamInvalidate(g_Stream);
    FSEventStreamRelease(g_Stream);

    g_Stream = NULL;
  }
}
Ejemplo n.º 10
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;
}
VError XMacFileSystemNotification::StopWatchingForChanges( VFileSystemNotifier::VChangeData *inChangeData, bool inIsLastOne)
{	
	// First, we need to find the folder's path so that we can locate our entry
	// in the watch list

	XMacChangeData *data = dynamic_cast<XMacChangeData*>( inChangeData);

	// We are watching this, so we need to stop that
	FSEventStreamStop( data->fStreamRef );
	FSEventStreamInvalidate( data->fStreamRef );
	
	return VE_OK;
}
void FDirectoryWatchRequestMac::Shutdown( void )
{
	if( bRunning )
	{
		check(EventStream);

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

		bRunning = false;
	}
}
Ejemplo n.º 13
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;
}
Ejemplo n.º 14
0
Archivo: eyed.c Proyecto: 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;
}
Ejemplo n.º 15
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;
}
Ejemplo n.º 16
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;
  }
Ejemplo n.º 17
0
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_);
  }
}
Ejemplo n.º 18
0
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_);
}
Ejemplo n.º 19
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;
}
Ejemplo n.º 20
0
FSEventsWatcher::~FSEventsWatcher() {
  FSEventStreamStop(stream_);
  FSEventStreamInvalidate(stream_); /* will remove from runloop */
  FSEventStreamRelease(stream_);
  delete context_;
}
Ejemplo n.º 21
0
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;
}
Ejemplo n.º 22
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;
}
Ejemplo n.º 23
0
FolderWatcherPrivate::~FolderWatcherPrivate()
{
    FSEventStreamStop(_stream);
    FSEventStreamInvalidate(_stream);
    FSEventStreamRelease(_stream);
}
Ejemplo n.º 24
0
void WatcherData::perform(void* thread)
{
    WatcherData* watcher = static_cast<WatcherData*>(thread);
    std::unique_lock<std::mutex> locker(watcher->mutex);
    if (watcher->flags & Stop) {
        if (watcher->fss) {
            FSEventStreamStop(watcher->fss);
            FSEventStreamInvalidate(watcher->fss);
        }
        CFRunLoopSourceInvalidate(watcher->source);
        CFRunLoopStop(watcher->loop);
        return;
    } else if (watcher->flags & Clear) {
        watcher->flags &= ~Clear;

        if (watcher->fss) {
            FSEventStreamStop(watcher->fss);
            FSEventStreamInvalidate(watcher->fss);
            watcher->fss = 0;
        }

        // We might have paths added since the clear operation was inititated
        if (watcher->paths.empty())
            return;
    }

    // ### might make sense to have multiple streams instead of recreating one for each change
    // ### and then merge them if the stream count reaches a given treshold

    const int pathSize = watcher->paths.size();
    FSEventStreamRef newfss = 0;

    if (pathSize) {
        StackBuffer<1024, CFStringRef> refs(pathSize);
        int i = 0;
        const Set<Path> copy = watcher->paths;
        for (const Path &path : copy) {
            refs[i++] = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault,
                                                        path.constData(),
                                                        kCFStringEncodingUTF8,
                                                        kCFAllocatorNull);
        }

        // don't need to hold the mutex beyond this point
        locker.unlock();

        CFArrayRef list = CFArrayCreate(kCFAllocatorDefault,
                                        reinterpret_cast<const void**>(&refs[0]),
                                        pathSize,
                                        &kCFTypeArrayCallBacks);

        for (int j = 0; j < i; ++j)
            CFRelease(refs[j]);

        FSEventStreamContext ctx = { 0, watcher, 0, 0, 0 };
        newfss = FSEventStreamCreate(kCFAllocatorDefault,
                                     notifyCallback,
                                     &ctx,
                                     list,
                                     watcher->since,
                                     .1,
                                     kFSEventStreamCreateFlagIgnoreSelf
                                     | kFSEventStreamCreateFlagFileEvents
                                     );

        CFRelease(list);
    }

    if (!newfss)
        return;

    if (watcher->fss) {
        FSEventStreamStop(watcher->fss);
        FSEventStreamInvalidate(watcher->fss);
    }

    watcher->fss = newfss;

    FSEventStreamScheduleWithRunLoop(watcher->fss, watcher->loop, kCFRunLoopDefaultMode);
    FSEventStreamStart(watcher->fss);
}
void WatcherThread::perform(void* thread)
{
    WatcherThread* watcher = static_cast<WatcherThread*>(thread);
    MutexLocker locker(&watcher->mutex);
    if (watcher->flags & Stop) {
        if (watcher->fss) {
            FSEventStreamStop(watcher->fss);
            FSEventStreamInvalidate(watcher->fss);
        }
        CFRunLoopSourceInvalidate(watcher->source);
        CFRunLoopStop(watcher->loop);
        return;
    } else if (watcher->flags & Clear) {
        watcher->flags &= ~Clear;

        if (watcher->fss) {
            FSEventStreamStop(watcher->fss);
            FSEventStreamInvalidate(watcher->fss);
            watcher->fss = 0;
        }

        // We might have paths added since the clear operation was inititated
        if (watcher->paths.empty())
            return;
    }

    // ### might make sense to have multiple streams instead of recreating one for each change
    // ### and then merge them if the stream count reaches a given treshold

    const int pathSize = watcher->paths.size();
    FSEventStreamRef newfss = 0;

    if (pathSize) {
        CFStringRef refs[pathSize];
        int i = 0;
        Set<Path>::const_iterator path = watcher->paths.begin();
        const Set<Path>::const_iterator end = watcher->paths.end();
        while (path != end) {
            // CFStringCreateWithCString copies the string data
            // ### use CFStringCreateWithCStringNoCopy instead?
            refs[i++] = CFStringCreateWithCString(kCFAllocatorDefault,
                                                  path->nullTerminated(),
                                                  kCFStringEncodingUTF8);
            ++path;
        }

        // don't need to hold the mutex beyond this point
        locker.unlock();

        CFArrayRef list = CFArrayCreate(kCFAllocatorDefault,
                                        reinterpret_cast<const void**>(refs),
                                        pathSize,
                                        0);

        FSEventStreamContext ctx = { 0, watcher, 0, 0, 0 };
        newfss = FSEventStreamCreate(kCFAllocatorDefault,
                                     notifyCallback,
                                     &ctx,
                                     list,
                                     watcher->since,
                                     .5,
                                     kFSEventStreamCreateFlagWatchRoot
                                     | kFSEventStreamCreateFlagIgnoreSelf
                                     | kFSEventStreamCreateFlagFileEvents);
    }

    if (!newfss)
        return;

    if (watcher->fss) {
        FSEventStreamStop(watcher->fss);
        FSEventStreamInvalidate(watcher->fss);
    }

    watcher->fss = newfss;

    FSEventStreamScheduleWithRunLoop(watcher->fss, watcher->loop, kCFRunLoopDefaultMode);
    FSEventStreamStart(watcher->fss);
}