Permalink
Browse files

fixes

  • Loading branch information...
swistaczek committed Mar 30, 2013
1 parent de17ccf commit 4f3fc9278059f625da8eb15c5da90bd020556024
Showing with 87 additions and 5 deletions.
  1. +76 −3 lib/network_manager/modem.rb
  2. +11 −2 lib/ruby-network-manager.rb
@@ -1,18 +1,91 @@
# encoding: utf-8
class NetworkManager::Modem
- attr_reader :bus_path
+ attr_reader :bus_path, :service
def initialize(opts)
args.each do |k,v|
instance_variable_set("@#{k}", v) unless v.nil?
end
+
+ # Set DBUS proxy
+ @proxy = @mm_service.object(@bus_path)
+ @proxy.introspect
+
+ @properties = @proxy.dup
+ @properties.default_iface = NetworkManager::DBUS_PROPERTIES
+ @properties.introspect
+
+ @s_modem = @proxy[NetworkManager::MM_DBUS_INTERFACE_MODEM_SIMPLE]
+ @modem = @proxy[NetworkManager::MM_DBUS_INTERFACE_MODEM]
+ @network = @proxy[NetworkManager::MM_DBUS_INTERFACE_MODEM_GSM_NETWORK]
+ @ussd = @proxy[NetworkManager::MM_DBUS_INTERFACE_MODEM_GSM_USSD]
+
+ @device_info = @properties.GetInfo[0] rescue nil
+ end
+
+ def enabled?
+ begin
+ status
+ return true
+ rescue => e
+ return !e.message.include?('device is not enabled')
+ end
+ nil
+ end
+
+ def enable!
+ @modem.Enable(true) if disabled?
+ end
+
+ def disabled?
+ !enabled?
+ end
+
+ def disable!
+ @modem.Enable(false) if enabled?
+ end
+
+ def model
+ @device_info[1] rescue nil
+ end
+
+ def status
+ @s_modem.GetStatus[0]
+ end
+
+ def operator_code
+ status["operator_code"] rescue nil
+ end
+
+ def vendor
+ @device_info[0] rescue nil
+ end
+
+ def version
+ @device_info[2] rescue nil
+ end
+
+ def signal
+ @properties.GetSignalQuality[0] rescue 0
+ end
+
+ def imei
+ @properties.GetImei[0] rescue nil
+ end
+
+ def imsi
+ @properties.GetImsi[0] rescue nil
+ end
+
+ def scan
+ @network.Scan[0] rescue nil
end
class << self
- def fetch(paths_array)
+ def fetch(paths_array, opts = {})
devices = []
paths_array.each do |path|
- devices << self.new(bus_path: path) unless path.nil?
+ devices << self.new(opts.merge({bus_path: path}) unless path.nil?
end
devices
end
@@ -4,6 +4,15 @@
class NetworkManager
attr_reader :service, :bus_path, :mm_object
+ DBUS_PROPERTIES = 'freedesktop.DBus.Properties'
+ MM_DBUS_SERVICE = 'org.freedesktop.ModemManager'
+ MM_DBUS_INTERFACE_MODEM = 'org.freedesktop.ModemManager.Modem'
+ MM_DBUS_INTERFACE_MODEM_CDMA = 'org.freedesktop.ModemManager.Modem.Cdma'
+ MM_DBUS_INTERFACE_MODEM_GSM_CARD = 'org.freedesktop.ModemManager.Modem.Gsm.Card'
+ MM_DBUS_INTERFACE_MODEM_GSM_NETWORK = 'org.freedesktop.ModemManager.Modem.Gsm.Network'
+ MM_DBUS_INTERFACE_MODEM_SIMPLE = 'org.freedesktop.ModemManager.Modem.Simple'
+ MM_DBUS_INTERFACE_MODEM_GSM_USSD = 'org.freedesktop.ModemManager.Modem.Gsm.Ussd'
+
def initialize(opts = {})
set_options opts
@bus = DBus::SystemBus.instance
@@ -16,7 +25,7 @@ def initialize(opts = {})
def devices(opts = {})
@devices = []
@mm_object.introspect
- NetworkManager::Modem.fetch(@mm_object.EnumerateDevices())
+ NetworkManager::Modem.fetch(@mm_object.EnumerateDevices(), service: @mm_service)
end
class << self
@@ -26,7 +35,7 @@ class << self
protected
def set_options(opts = {})
- @service ||= 'org.freedesktop.ModemManager'
+ @service ||= MM_DBUS_SERVICE || 'org.freedesktop.ModemManager'
@bus_path ||= '/org/freedesktop/ModemManager'
args.each do |k,v|

0 comments on commit 4f3fc92

Please sign in to comment.