Class: Argus::NavMonitor

Inherits:
Object
  • Object
show all
Defined in:
lib/argus/nav_monitor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, remote_host, opts = {}) ⇒ NavMonitor

Returns a new instance of NavMonitor


6
7
8
9
10
11
12
13
# File 'lib/argus/nav_monitor.rb', line 6

def initialize(controller, remote_host, opts={})
  @controller = controller
  @streamer = opts.fetch(:streamer) { NavStreamer.new(remote_host: remote_host) }
  @callbacks = []
  @mutex = Mutex.new
  @nav_data = nil
  @nav_options = {}
end

Instance Attribute Details

#streamerObject (readonly)

Returns the value of attribute streamer


4
5
6
# File 'lib/argus/nav_monitor.rb', line 4

def streamer
  @streamer
end

Instance Method Details

#callback(callback = nil, &block) ⇒ Object


35
36
37
38
39
40
# File 'lib/argus/nav_monitor.rb', line 35

def callback(callback=nil, &block)
  @mutex.synchronize do
    @callbacks << callback unless callback.nil?
    @callbacks << block if block_given?
  end
end

#dataObject


42
43
44
# File 'lib/argus/nav_monitor.rb', line 42

def data
  @mutex.synchronize { @nav_data }
end

#joinObject


30
31
32
33
# File 'lib/argus/nav_monitor.rb', line 30

def join
  stop
  @nav_thread.join
end

#option(tag) ⇒ Object


46
47
48
# File 'lib/argus/nav_monitor.rb', line 46

def option(tag)
  @mutex.synchronize { @nav_options[tag] }
end

#startObject


15
16
17
18
19
20
21
22
23
24
# File 'lib/argus/nav_monitor.rb', line 15

def start
  @streamer.start
  @running = true
  @nav_thread = Thread.new do
    while @running
      data = @streamer.receive_data
      update_nav_data(data) if data
    end
  end
end

#stopObject


26
27
28
# File 'lib/argus/nav_monitor.rb', line 26

def stop
  @running = false
end

#update_nav_data(data) ⇒ Object


50
51
52
53
54
55
56
57
58
59
60
# File 'lib/argus/nav_monitor.rb', line 50

def update_nav_data(data)
  @mutex.synchronize do
    update_internal_nav_data(data)
    do_callbacks(data)
  end
rescue Exception => ex
  puts "ERROR in callback: #{ex}"
  puts ex.message
  puts ex.backtrace
  $stdout.flush
end