Class: Stf::ConnectIosInteractor
- Inherits:
-
Object
- Object
- Stf::ConnectIosInteractor
- Includes:
- Log
- Defined in:
- lib/stf/interactor/connect_ios_interactor.rb
Instance Method Summary collapse
- #connect(url) ⇒ Object
- #disconnect(url) ⇒ Object
-
#initialize ⇒ ConnectIosInteractor
constructor
A new instance of ConnectIosInteractor.
- #ios_serials_to_urls ⇒ Object
Methods included from Log
Constructor Details
#initialize ⇒ ConnectIosInteractor
Returns a new instance of ConnectIosInteractor.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/stf/interactor/connect_ios_interactor.rb', line 13 def initialize if find_executable('usbfluxctl') != nil stdout, stderr, status = Open3.capture3("usbfluxctl list xml") unless stderr.include? "Failed" @active = true end end unless @active logger.info "iOS dependencies not available. Install 'usbfluxd' distributed by SmartDust. Make sure to start 'usbfluxd -n' with root permissions before connecting to iOS devices. Also ensure that 'usbfluxctl' is in your $PATH." end end |
Instance Method Details
#connect(url) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/stf/interactor/connect_ios_interactor.rb', line 26 def connect(url) raise "iOS connecting is not active" unless @active Open3.capture3("usbfluxctl add #{url}") sleep(1) logger.info ios_serials_to_urls.to_s unless ios_serials_to_urls.values.include? url raise "Cannot connect to iOS device" end end |
#disconnect(url) ⇒ Object
36 37 38 39 |
# File 'lib/stf/interactor/connect_ios_interactor.rb', line 36 def disconnect(url) raise "iOS connecting is not active" unless @active Open3.capture3("usbfluxctl del #{url}") end |
#ios_serials_to_urls ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/stf/interactor/connect_ios_interactor.rb', line 41 def ios_serials_to_urls return {} unless @active stdout, stderr, status = Open3.capture3("usbfluxctl list xml") result = {} doc = REXML::Document.new(stdout) instances = doc.elements['plist/dict/dict'] if instances.nil? return {} end instances.elements.each('dict') do |instance| host = instance.elements["string[preceding-sibling::key[text()='Host']]"] port = instance.elements["integer[preceding-sibling::key[text()='Port']]"] if host.nil? || port.nil? next end url = "#{host.text}:#{port.text}" devices = instance.elements['array'] if devices devices.elements.each do |device| serial = device.text result[serial] = url end end end result end |