Class: RUPNP::ControlPoint
- Inherits:
-
Object
- Object
- RUPNP::ControlPoint
- Defined in:
- lib/rupnp/control_point.rb
Overview
Constant Summary collapse
- DEFAULT_RESPONSE_WAIT_TIME =
Default response wait time for searching devices. This is set to the maximum value from UPnP 1.1 specification.
5
Constants included from LogMixin
Instance Attribute Summary collapse
-
#devices ⇒ Array<CP::RemoteDevice>
readonly
Return remote devices controlled by this control point.
-
#event_port ⇒ Integer
readonly
Get event listening port.
Instance Method Summary collapse
-
#add_device(device) ⇒ void
Add a device to the control point.
-
#find_device_by_udn(udn) ⇒ Device?
Find a device from control point’s device list by its UDN.
-
#initialize(search_target, search_options = {}) ⇒ ControlPoint
constructor
A new instance of ControlPoint.
-
#search_only ⇒ void
Start a search for devices.
-
#start {|new_device_channel, bye_device_channel| ... } ⇒ void
Start control point.
-
#start_event_server(port = EVENT_SUB_DEFAULT_PORT) ⇒ void
Start event server for listening for device events.
-
#stop_event_server ⇒ void
Stop event server.
Methods included from Tools
#build_url, #snake_case, #urn_are_equivalent?, #usn2udn
Methods included from LogMixin
Constructor Details
#initialize(search_target, search_options = {}) ⇒ ControlPoint
Returns a new instance of ControlPoint.
39 40 41 42 43 44 45 46 47 |
# File 'lib/rupnp/control_point.rb', line 39 def initialize(search_target, ={}) @search_target = search_target @search_options = @search_options[:response_wait_time] ||= DEFAULT_RESPONSE_WAIT_TIME @devices = [] @new_device_channel = EM::Channel.new @bye_device_channel = EM::Channel.new end |
Instance Attribute Details
#devices ⇒ Array<CP::RemoteDevice> (readonly)
Return remote devices controlled by this control point
29 30 31 |
# File 'lib/rupnp/control_point.rb', line 29 def devices @devices end |
#event_port ⇒ Integer (readonly)
Get event listening port
26 27 28 |
# File 'lib/rupnp/control_point.rb', line 26 def event_port @event_port end |
Instance Method Details
#add_device(device) ⇒ void
This method returns an undefined value.
Add a device to the control point
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/rupnp/control_point.rb', line 92 def add_device(device) if has_already_device?(device) log :info, "Device already in database: #{device.udn}" existing_device = self.find_device_by_udn(device.udn) if existing_device.expiration < device.expiration log :info, 'update expiration time for device #{device.udn}' @devices.delete existing_device @devices << device end else log :info, "adding device #{device.udn}" @devices << device @new_device_channel << device end end |
#find_device_by_udn(udn) ⇒ Device?
Find a device from control point’s device list by its UDN
112 113 114 |
# File 'lib/rupnp/control_point.rb', line 112 def find_device_by_udn(udn) @devices.find { |d| d.udn == udn } end |
#search_only ⇒ void
This method returns an undefined value.
Start a search for devices. No listen for update is made.
Found devices are accessible through #devices.
66 67 68 69 70 |
# File 'lib/rupnp/control_point.rb', line 66 def search_only = @search_options.dup [:search_only] = true search_devices_and_listen @search_target, end |
#start {|new_device_channel, bye_device_channel| ... } ⇒ void
This method returns an undefined value.
Start control point. This methos starts a search for devices. Then, listening is performed for device notifications.
57 58 59 60 |
# File 'lib/rupnp/control_point.rb', line 57 def start search_devices_and_listen @search_target, @search_options yield @new_device_channel, @bye_device_channel if block_given? end |
#start_event_server(port = EVENT_SUB_DEFAULT_PORT) ⇒ void
This method returns an undefined value.
Start event server for listening for device events
75 76 77 78 |
# File 'lib/rupnp/control_point.rb', line 75 def start_event_server(port=EVENT_SUB_DEFAULT_PORT) @event_port ||= port @event_server ||= EM.start_server('0.0.0.0', port, CP::EventServer) end |
#stop_event_server ⇒ void
This method returns an undefined value.
Stop event server
83 84 85 86 87 |
# File 'lib/rupnp/control_point.rb', line 83 def stop_event_server @event_port = nil EM.stop_server @event_server @event_server = nil end |