(module fam-base (lib "swindle.ss" "swindle")
(provide (all-from (lib "swindle.ss" "swindle")))
(require (lib "async-channel.ss"))
(provide fam-monitor-path
fam-monitored-paths
fam-suspend-path-monitoring
fam-resume-path-monitoring
fam-cancel-path-monitoring
fam-any-event?
fam-next-event
fam-pending-events
fam-release
fam-event-type->string
fam-event-path
fam-event-monitored-path
fam-event-type
fam-event-timestamp
fam-make-event-stream
<fam-event>)
(defgeneric (fam-release fc))
(defgeneric (fam-monitor-path fc path))
(defgeneric (fam-monitored-paths fc))
(defgeneric (fam-suspend-path-monitoring fc path))
(defgeneric (fam-resume-path-monitoring fc path))
(defgeneric (fam-cancel-path-monitoring fc path))
(defgeneric (fam-any-event? fc))
(defgeneric (fam-next-event fc &optional wait))
(defgeneric (fam-pending-events fc))
(defclass <fam-event> () path type monitored-path timestamp :auto #t)
(defmethod (print-object (fev <fam-event>) esc? port)
(print-object-with-slots fev esc? port))
(define (fam-event-type->string type)
(define descs '((fam-event-created . "Created")
(fam-event-found . "Found")
(fam-event-eol . "End of found files list")
(fam-event-moved . "Moved")
(fam-event-modified . "Modified")
(fam-event-deleted . "Deleted")
(fam-event-exec-start . "Execution started")
(fam-event-exec-stop . "Execution stopped")
(fam-event-acknowledge . "Acknowledge")))
(cond ((assoc type descs) => cdr)
(else (format "Unknown type (~A)" type))))
(define (fam-make-event-stream)
(let ((channel (make-async-channel)))
(define dispatch
(case-lambda
(() (async-channel-try-get channel))
((x) (cond ((fam-event? x) (async-channel-put channel x))
((eq? x #t) (async-channel-get channel))
(else (async-channel-try-get channel))))))
dispatch))
)