Skip to content

Commit

Permalink
Added functionality to monitor multiple dirs.
Browse files Browse the repository at this point in the history
  • Loading branch information
schrammc committed Jun 21, 2015
1 parent 71ec389 commit f84bc94
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
2 changes: 1 addition & 1 deletion delta.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name: delta
-- PVP summary: +-+------- breaking API changes
-- | | +----- non-breaking API additions
-- | | | +--- code changes with no API change
version: 0.1.0.1
version: 0.1.2.0

-- A short (one-line) description of the package.
synopsis: A library for detecting file changes
Expand Down
52 changes: 49 additions & 3 deletions src/System/Delta.hs
Original file line number Diff line number Diff line change
@@ -1,18 +1,64 @@
{-# LANGUAGE RankNTypes #-}
--------------------------------------------------------------------------------
-- |
-- Module : System.Delta
-- Copyright: (c) Christof Schramm 2015
-- License: LGPL v2
--
-- Maintainer: Christof Schramm
-- Stability: Experimental
--
-- = Description
--
-- An umberella package for the delta library. This library can be used to monitor
-- changed / new / deleted files in a given directory (or set of directories).
--
-- Currently this library polls the directories of interest recursively in certain
-- intervals, but I will add OS-specific functionality to monitor the filesystem.
--
-- = Examples
--
-- Create a watcher that prints a line if a new file is created in the monitored
-- directory:
--
-- @
-- printNewFilePaths basePath = do
-- watcher <- deltaDirWithCallbacks basePath
-- withNewCallback watcher (\\x -> putStrLn $ "new file: " ++ x)
-- @
--------------------------------------------------------------------------------
module System.Delta ( module System.Delta.Base
, module System.Delta.Poll
, module System.Delta.Class
, module System.Delta.Callback

-- * Important functions
, deltaDir
, deltaDirWithCallbacks

-- * FRP based interface
, module System.Delta.Class
, FileWatcher(..)

-- * Callback based interface
, module System.Delta.Callback
, CallbackWatcher
, CallbackId
, withCallbacks
-- ** Adding callbacks
, withDeleteCallback
, withChangedCallback
, withNewCallback
-- ** Removing callbacks
, unregisterCallback
, removeAllCallbacks
, closeCallbackWatcher
)where

import System.Delta.Base
import System.Delta.Poll
import System.Delta.Class
import System.Delta.Callback

-- | Build a file watcher
-- | Build a file watcher, this method will change later
deltaDir :: FilePath -> IO PollWatcher
deltaDir path = defaultWatcher path

Expand Down
2 changes: 2 additions & 0 deletions src/System/Delta/Callback.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ import qualified Data.Map as M

import Control.Concurrent.MVar

-- | Id of a callback in a 'CallbackWatcher'
newtype CallbackId = CallbackId Integer
deriving (Eq, Ord)

-- | Provides a callback based interface to an FRP base 'FileWatcher'
data CallbackWatcher w where
CallbackWatcher :: FileWatcher w => {
baseWatcher :: w
Expand Down
8 changes: 8 additions & 0 deletions src/System/Delta/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import System.Delta.Base

import Control.Monad

-- | A class for watching a directory based on functional reactive programming
-- At the core of this class are three event streams:
--
-- * @changedFiles@ is a stream of 'FileInfo's on changed files
--
-- * @newFiles@ is a stream of canonicalized 'FilePath's of newly created files
--
-- * @deletedFiles@ is a stream of canonicalized 'FilePath's of deleted files
class FileWatcher a where
-- | Each type provides a default watcher for a pass
defaultWatcher :: FilePath -> IO a
Expand Down

0 comments on commit f84bc94

Please sign in to comment.