Class: UPnP::ControlPoint::Service
- Includes:
- EventMachine::Deferrable, LogSwitch::Mixin
- Defined in:
- lib/upnp/control_point/service.rb
Overview
An object of this type functions as somewhat of a proxy to a UPnP device’s service. The object sort of defines itself when you call #fetch; it gets the description file from the device, parses it, populates its attributes (as accessors) and defines singleton methods from the list of actions that the service defines.
After the fetch is done, you can call Ruby methods on the service and expect a Ruby Hash back as a return value. The methods will look just the SOAP actions and will always return a Hash, where key/value pairs are converted from the SOAP response; values are converted to the according Ruby type based on <dataType> in the <serviceStateTable>.
Types map like:
* Integer
* ui1
* ui2
* ui4
* i1
* i2
* i4
* int
* Float
* r4
* r8
* number
* fixed.14.4
* float
* String
* char
* string
* uuid
* TrueClass
* 1
* true
* yes
* FalseClass
* 0
* false
* no
Instance Attribute Summary collapse
- #action_list ⇒ Array<Hash> readonly
-
#control_url ⇒ URI::HTTP
readonly
Control URL.
-
#description ⇒ Hash
readonly
The whole description…
-
#event_sub_url ⇒ URI::HTTP
readonly
Eventing URL.
-
#scpd_url ⇒ URI::HTTP
readonly
Service description URL.
-
#service_id ⇒ String
readonly
Service identifier, unique within this service’s devices.
-
#service_state_table ⇒ Object
readonly
Probably don’t need to keep this long-term; just adding for testing.
-
#service_type ⇒ String
readonly
UPnP service type, including URN.
- #spec_version ⇒ String readonly
- #xmlns ⇒ String readonly
Instance Method Summary collapse
-
#fetch ⇒ Object
Fetches the service description file, parses it, extracts attributes into accessors, and defines Ruby methods from SOAP actions.
-
#initialize(device_base_url, service_list_info) ⇒ Service
constructor
A new instance of Service.
Constructor Details
#initialize(device_base_url, service_list_info) ⇒ Service
Returns a new instance of Service.
110 111 112 113 114 115 116 |
# File 'lib/upnp/control_point/service.rb', line 110 def initialize(device_base_url, service_list_info) @service_list_info = service_list_info @action_list = [] @xmlns = "" extract_service_list_info(device_base_url) configure_savon end |
Instance Attribute Details
#action_list ⇒ Array<Hash> (readonly)
94 95 96 |
# File 'lib/upnp/control_point/service.rb', line 94 def action_list @action_list end |
#control_url ⇒ URI::HTTP (readonly)
Returns Control URL.
74 75 76 |
# File 'lib/upnp/control_point/service.rb', line 74 def control_url @control_url end |
#description ⇒ Hash (readonly)
Returns The whole description… just in case.
104 105 106 |
# File 'lib/upnp/control_point/service.rb', line 104 def description @description end |
#event_sub_url ⇒ URI::HTTP (readonly)
Returns Eventing URL.
77 78 79 |
# File 'lib/upnp/control_point/service.rb', line 77 def event_sub_url @event_sub_url end |
#scpd_url ⇒ URI::HTTP (readonly)
Returns Service description URL.
71 72 73 |
# File 'lib/upnp/control_point/service.rb', line 71 def scpd_url @scpd_url end |
#service_id ⇒ String (readonly)
Returns Service identifier, unique within this service’s devices.
68 69 70 |
# File 'lib/upnp/control_point/service.rb', line 68 def service_id @service_id end |
#service_state_table ⇒ Object (readonly)
Probably don’t need to keep this long-term; just adding for testing.
97 98 99 |
# File 'lib/upnp/control_point/service.rb', line 97 def service_state_table @service_state_table end |
#service_type ⇒ String (readonly)
Returns UPnP service type, including URN.
65 66 67 |
# File 'lib/upnp/control_point/service.rb', line 65 def service_type @service_type end |
#spec_version ⇒ String (readonly)
91 92 93 |
# File 'lib/upnp/control_point/service.rb', line 91 def spec_version @spec_version end |
#xmlns ⇒ String (readonly)
88 89 90 |
# File 'lib/upnp/control_point/service.rb', line 88 def xmlns @xmlns end |
Instance Method Details
#fetch ⇒ Object
Fetches the service description file, parses it, extracts attributes into accessors, and defines Ruby methods from SOAP actions. Since this is a long-ish process, this is done using EventMachine Deferrable behavior.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/upnp/control_point/service.rb', line 122 def fetch if @scpd_url.empty? log "NO SCPDURL to get the service description from. Returning." set_deferred_success self return end description_getter = EventMachine::DefaultDeferrable.new log "Fetching service description with #{description_getter.object_id}" get_description(@scpd_url, description_getter) description_getter.errback do msg = "Failed getting service description." log "#{msg}", :error # @todo Should this return self? or should it succeed? set_deferred_status(:failed, msg) if ControlPoint.raise_on_remote_error raise ControlPoint::Error, msg end end description_getter.callback do |description| log "Service description received for #{description_getter.object_id}." @description = description @xmlns = @description[:scpd][:@xmlns] extract_spec_version extract_service_state_table if @description[:scpd][:actionList] log "Defining methods from action_list using [#{description_getter.object_id}]" define_methods_from_actions(@description[:scpd][:actionList][:action]) end set_deferred_status(:succeeded, self) end end |