Class: Synchrotron::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/synchrotron/stream.rb

Instance Method Summary collapse

Constructor Details

#initialize(paths, callback, since = OSX::KFSEventStreamEventIdSinceNow) ⇒ Stream

Returns a new instance of Stream.



3
4
5
6
7
8
9
10
11
12
# File 'lib/synchrotron/stream.rb', line 3

def initialize(paths, callback, since = OSX::KFSEventStreamEventIdSinceNow)
  @log     = Synchrotron.log
  @started = false
  @stream  = OSX.FSEventStreamCreate(nil, callback, nil, paths.to_a, since, 0.5, 0)

  raise "failed to create FSEventStream" unless check_stream

  OSX.FSEventStreamScheduleWithRunLoop(@stream, OSX.CFRunLoopGetCurrent(),
      OSX::KCFRunLoopDefaultMode)
end

Instance Method Details

#releaseObject



14
15
16
17
18
19
20
# File 'lib/synchrotron/stream.rb', line 14

def release
  stop
  OSX.FSEventStreamInvalidate(@stream)
  OSX.FSEventStreamRelease(@stream)

  @log.debug "FSEventStream released"
end

#startObject



22
23
24
25
26
27
28
# File 'lib/synchrotron/stream.rb', line 22

def start
  return if @started
  raise "failed to start FSEventStream" unless OSX.FSEventStreamStart(@stream)
  @started = true

  @log.debug "FSEventStream started"
end

#stopObject



30
31
32
33
34
35
36
# File 'lib/synchrotron/stream.rb', line 30

def stop
  return unless @started
  OSX.FSEventStreamStop(@stream)
  @started = false

  @log.debug "FSEventStream stopped"
end