packages feed

hfsevents 0.1.2 → 0.1.3

raw patch · 5 files changed

+79/−6 lines, 5 files

Files

cbits/c_fsevents.c view
@@ -31,6 +31,7 @@   w->runLoop = rl;   FSEventStreamScheduleWithRunLoop(w->eventStream, rl, kCFRunLoopDefaultMode);   FSEventStreamStart(w->eventStream);+  pthread_mutex_unlock(&w->mut);   CFRunLoopRun();   pthread_exit(NULL); }@@ -70,6 +71,8 @@     w->writefd = pfds[1];     w->eventStream = es;     w->runLoop = NULL;+    pthread_mutex_init(&w->mut, NULL);+    pthread_mutex_lock(&w->mut);     pthread_create(&t, NULL, &watchRunLoop, (void*)w);     *fd = pfds[0];     *wp = w;@@ -87,12 +90,15 @@ }  int destroyWatch(watch* w) {+  pthread_mutex_lock(&w->mut);+  FSEventStreamStop(w->eventStream);+  FSEventStreamInvalidate(w->eventStream);+  CFRunLoopStop(w->runLoop);+  CFRelease(w->runLoop);   FSEventStreamRelease(w->eventStream);-  if(w->runLoop != NULL) {-    CFRunLoopStop(w->runLoop);-    CFRelease(w->runLoop);-  }   close(w->writefd);+  pthread_mutex_unlock(&w->mut);+  pthread_mutex_destroy(&w->mut);   free(w); } 
cbits/c_fsevents.h view
@@ -2,11 +2,13 @@ #define CBITS_C_FSEVENTS_H 1  #include <CoreServices/CoreServices.h>+#include <pthread.h>  typedef struct {   FSEventStreamRef eventStream;   CFRunLoopRef runLoop;   int writefd;+  pthread_mutex_t mut; } watch;  
hfsevents.cabal view
@@ -1,5 +1,5 @@ name:                hfsevents-version:             0.1.2+version:             0.1.3 synopsis:            File/folder watching for OS X homepage:            http://github.com/luite/hfsevents license:             BSD3@@ -8,7 +8,7 @@ maintainer:          stegeman@gmail.com category:            System build-type:          Simple-extra-source-files:  cbits/c_fsevents.h+extra-source-files:  cbits/c_fsevents.h, test/test.hs, test/trace.hs cabal-version:       >=1.8  source-repository head
+ test/test.hs view
@@ -0,0 +1,14 @@+module Main where++import System.OSX.FSEvents++import Control.Monad+import Control.Concurrent++main = do+  es <- eventStreamCreate ["/Users"] 1.0 True True True print+  replicateM 30 (threadDelay 1000000)+  putStrLn "destroying event stream"+  eventStreamDestroy es+  replicateM 30 (threadDelay 1000000)+
+ test/trace.hs view
@@ -0,0 +1,51 @@+{-+   simple event tracer that monitors the current+   directory and prints all events+-}++import System.OSX.FSEvents++import Data.Bits+import Data.List (unwords)+import Data.Word++main = do+  es <- eventStreamCreate ["."] 1.0 True True True trace+  getLine+  eventStreamDestroy es+  return ()++trace :: Event -> IO ()+trace e = do+  putStrLn $ "id:    " ++ show (eventId e)+  putStrLn $ "path:  " ++ eventPath e+  putStrLn $ "flags: " ++ showEventFlags (eventFlags e)+  putStrLn ""++showEventFlags :: Word64 -> String+showEventFlags fl = unwords (map fst . filter hasFlag $ flagList)+  where+    hasFlag (_,f) = fl .&. f /= 0++-- fixme come up with some better way to make this list+flagList :: [(String, Word64)]+flagList = [ ("MustScanSubDirs"   , 0x00000001)+           , ("UserDropped"       , 0x00000002)+           , ("KernelDropped"     , 0x00000004)+           , ("EventIdsWrapped"   , 0x00000008)+           , ("HistoryDone"       , 0x00000010)+           , ("RootChanged"       , 0x00000020)+           , ("Mount"             , 0x00000040)+           , ("Unmount"           , 0x00000080)+           , ("ItemCreated"       , 0x00000100)+           , ("ItemRemoved"       , 0x00000200)+           , ("ItemInodeMetaMod"  , 0x00000400)+           , ("ItemRenamed"       , 0x00000800)+           , ("ItemModified"      , 0x00001000)+           , ("ItemFinderInfoMod" , 0x00002000)+           , ("ItemChangeOwner"   , 0x00004000)+           , ("ItemXattrMod"      , 0x00008000)+           , ("ItemIsFile"        , 0x00010000)+           , ("ItemIsDir"         , 0x00020000)+           , ("ItemIsSymlink"     , 0x00040000)+           ]