Class: Wifidiag::Collector
- Inherits:
-
Object
- Object
- Wifidiag::Collector
- Defined in:
- lib/wifidiag/collector.rb
Overview
Collect client and AP information from an adapter
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#last_update ⇒ Object
readonly
Returns the value of attribute last_update.
Instance Method Summary collapse
- #client_data_for_ip_address(address) ⇒ Object
- #client_data_for_mac_address(address) ⇒ Object
- #collect ⇒ Object
-
#initialize(adapter) ⇒ Collector
constructor
A new instance of Collector.
-
#start_periodic_update(interval) ⇒ Object
XXX:.
Constructor Details
#initialize(adapter) ⇒ Collector
Returns a new instance of Collector.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/wifidiag/collector.rb', line 6 def initialize(adapter) @lock = Mutex.new @adapter = adapter @clients = nil @clients_by_ip_address = nil @clients_by_mac_address = nil @last_update = nil end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
17 18 19 |
# File 'lib/wifidiag/collector.rb', line 17 def adapter @adapter end |
#last_update ⇒ Object (readonly)
Returns the value of attribute last_update.
17 18 19 |
# File 'lib/wifidiag/collector.rb', line 17 def last_update @last_update end |
Instance Method Details
#client_data_for_ip_address(address) ⇒ Object
50 51 52 |
# File 'lib/wifidiag/collector.rb', line 50 def client_data_for_ip_address(address) @clients_by_ip_address[address] end |
#client_data_for_mac_address(address) ⇒ Object
54 55 56 |
# File 'lib/wifidiag/collector.rb', line 54 def client_data_for_mac_address(address) @clients_by_mac_address[address] end |
#collect ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/wifidiag/collector.rb', line 38 def collect @lock.synchronize do clients = adapter.collect() clients_by_ip_address = clients.map { |_| [_.ip_address, _] }.to_h clients_by_mac_address = clients.map { |_| [_.mac_address, _] }.to_h @clients = clients @clients_by_ip_address = clients_by_ip_address @clients_by_mac_address = clients_by_mac_address @last_update = Time.now end end |
#start_periodic_update(interval) ⇒ Object
XXX:
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/wifidiag/collector.rb', line 19 def start_periodic_update(interval) # XXX: self.collect Thread.new do loop do begin self.collect sleep interval rescue Exception => e $stderr.puts "Periodic update error: #{e.inspect}" e.backtrace.each do |x| $stderr.puts "\t#{x}" end sleep interval end end end end |