Class: Presence::Tracker
- Inherits:
-
Object
- Object
- Presence::Tracker
- Defined in:
- lib/presence/listeners/tracker.rb
Overview
Scanner listener that tracks all MACs found by the scanner. This listener is intended to be used when scanning in a loop. The tracker will maintain a list of MAC addresses on the network and detect when a new client connects or when a connected client disconnects.
Instance Method Summary collapse
- #dispatch(event, *args) ⇒ Object
-
#initialize ⇒ Tracker
constructor
A new instance of Tracker.
- #listener_registered(l, scanner) ⇒ Object
- #mac_found(ip, mac) ⇒ Object
- #scan_finished(ip_prefix, range) ⇒ Object
Constructor Details
Instance Method Details
#dispatch(event, *args) ⇒ Object
41 42 43 |
# File 'lib/presence/listeners/tracker.rb', line 41 def dispatch(event, *args) @scanner.dispatch(event, *args) end |
#listener_registered(l, scanner) ⇒ Object
16 17 18 19 |
# File 'lib/presence/listeners/tracker.rb', line 16 def listener_registered(l, scanner) @scanner ||= scanner @scanner.register_listener(@current_list) if l == self end |
#mac_found(ip, mac) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/presence/listeners/tracker.rb', line 21 def mac_found(ip, mac) if @mac_history[mac].nil? dispatch(:mac_connected, mac, ip) elsif @mac_history[mac] != ip old_ip = @mac_history[mac] dispatch(:mac_changed, mac, old_ip, ip) end @mac_history[mac] = ip end |
#scan_finished(ip_prefix, range) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/presence/listeners/tracker.rb', line 31 def scan_finished(ip_prefix, range) macs_left = @mac_history.keys - @current_list.macs_found.keys macs_left.each do |mac| old_ip = @mac_history[mac] dispatch(:mac_disconnected, mac, old_ip) @mac_history.delete(mac) end @current_list.macs_found.clear end |