Class: RUPNP::CP::RemoteDevice

Inherits:
Base
  • Object
show all
Defined in:
lib/rupnp/cp/remote_device.rb

Overview

A device is a UPnP service provider.

Author:

  • Sylvain Daubert.

Constant Summary collapse

DEFAULT_MAX_AGE =

Number of seconds the advertisement is valid. Used when ssdp:update advertisement is received but no previuous ssdp:alive was received.

600

Constants inherited from Base

Base::HTTP_COMMON_CONFIG

Constants included from LogMixin

LogMixin::LOG_LEVEL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#get_description, #inspect

Methods included from LogMixin

#log

Methods included from Tools

#build_url, #snake_case, #urn_are_equivalent?, #usn2udn

Constructor Details

#initialize(control_point, notification) ⇒ RemoteDevice



108
109
110
111
112
113
114
115
116
# File 'lib/rupnp/cp/remote_device.rb', line 108

def initialize(control_point, notification)
  super()
  @control_point = control_point
  @notification = notification

  @icons = []
  @services = []
  @devices = []
end

Instance Attribute Details

#boot_idInteger (readonly)

BOOTID.UPNP.ORG field value



45
46
47
# File 'lib/rupnp/cp/remote_device.rb', line 45

def boot_id
  @boot_id
end

#cache_controlString (readonly)

Contains max-age directive used to specify advertisement validity



39
40
41
# File 'lib/rupnp/cp/remote_device.rb', line 39

def cache_control
  @cache_control
end

#config_idnil, Integer (readonly)

CONFIGID.UPNP.ORG field value



48
49
50
# File 'lib/rupnp/cp/remote_device.rb', line 48

def config_id
  @config_id
end

#control_pointControlPoint (readonly)

Get control point which controls this device



18
19
20
# File 'lib/rupnp/cp/remote_device.rb', line 18

def control_point
  @control_point
end

#dateString (readonly)

Date when response was generated



36
37
38
# File 'lib/rupnp/cp/remote_device.rb', line 36

def date
  @date
end

#devicesArray<Device> (readonly)

List of embedded devices



103
104
105
# File 'lib/rupnp/cp/remote_device.rb', line 103

def devices
  @devices
end

#expirationTime (readonly)

Expiration time for the advertisement



42
43
44
# File 'lib/rupnp/cp/remote_device.rb', line 42

def expiration
  @expiration
end

#extString (readonly)



33
34
35
# File 'lib/rupnp/cp/remote_device.rb', line 33

def ext
  @ext
end

#friendly_nameString (readonly)

Short description for end users



64
65
66
# File 'lib/rupnp/cp/remote_device.rb', line 64

def friendly_name
  @friendly_name
end

#iconsArray<OpenStruct> (readonly)

Array of icons to depict device in control point UI



97
98
99
# File 'lib/rupnp/cp/remote_device.rb', line 97

def icons
  @icons
end

#locationString (readonly)

URL to the UPnP description of the root device



31
32
33
# File 'lib/rupnp/cp/remote_device.rb', line 31

def location
  @location
end

#manufacturerString (readonly)

Manufacturer’s name



67
68
69
# File 'lib/rupnp/cp/remote_device.rb', line 67

def manufacturer
  @manufacturer
end

#manufacturer_urlString (readonly)

Web site for manufacturer



70
71
72
# File 'lib/rupnp/cp/remote_device.rb', line 70

def manufacturer_url
  @manufacturer_url
end

#model_descriptionString (readonly)

Long decription for end user



73
74
75
# File 'lib/rupnp/cp/remote_device.rb', line 73

def model_description
  @model_description
end

#model_nameString (readonly)

Model name



76
77
78
# File 'lib/rupnp/cp/remote_device.rb', line 76

def model_name
  @model_name
end

#model_numberString (readonly)

Model number



79
80
81
# File 'lib/rupnp/cp/remote_device.rb', line 79

def model_number
  @model_number
end

#model_urlString (readonly)

Web site for model



82
83
84
# File 'lib/rupnp/cp/remote_device.rb', line 82

def model_url
  @model_url
end

#presentation_urlString (readonly)

URL to presentation for device



94
95
96
# File 'lib/rupnp/cp/remote_device.rb', line 94

def presentation_url
  @presentation_url
end

#serial_umberString (readonly)

Serial number



85
86
87
# File 'lib/rupnp/cp/remote_device.rb', line 85

def serial_umber
  @serial_umber
end

#serverString (readonly)

Get SERVER string



28
29
30
# File 'lib/rupnp/cp/remote_device.rb', line 28

def server
  @server
end

#servicesArray<Service> (readonly)

List of device’s services



100
101
102
# File 'lib/rupnp/cp/remote_device.rb', line 100

def services
  @services
end

#stString (readonly)

Get search target.



22
23
24
# File 'lib/rupnp/cp/remote_device.rb', line 22

def st
  @st
end

#typeString (readonly)

Device type



61
62
63
# File 'lib/rupnp/cp/remote_device.rb', line 61

def type
  @type
end

#udnString (readonly)

Unique Device Name



88
89
90
# File 'lib/rupnp/cp/remote_device.rb', line 88

def udn
  @udn
end

#upcString (readonly)

Universal Product Code



91
92
93
# File 'lib/rupnp/cp/remote_device.rb', line 91

def upc
  @upc
end

#upnp_versionString (readonly)

UPnP version used by the device



52
53
54
# File 'lib/rupnp/cp/remote_device.rb', line 52

def upnp_version
  @upnp_version
end

#url_baseString (readonly)

URL base for device access



58
59
60
# File 'lib/rupnp/cp/remote_device.rb', line 58

def url_base
  @url_base
end

#usnString (readonly)

Get Unique Service Name



25
26
27
# File 'lib/rupnp/cp/remote_device.rb', line 25

def usn
  @usn
end

#xmlnsString (readonly)

XML namespace for device description



55
56
57
# File 'lib/rupnp/cp/remote_device.rb', line 55

def xmlns
  @xmlns
end

Instance Method Details

#fetchvoid

This method returns an undefined value.

Get device from its description



120
121
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
159
160
161
162
163
164
165
166
# File 'lib/rupnp/cp/remote_device.rb', line 120

def fetch
  if @notification['nextbootid.upnp.org']
    @boot_id = @notification['nextbootid.upnp.org'].to_i
  elsif @notification['bootid.upnp.org']
    @boot_id = @notification['bootid.upnp.org'].to_i
  else
    fail self, 'no BOOTID.UPNP.ORG field. Message discarded.'
  end
  @config_id = @notification['confgid.upnp.org']
  @config_id = @config_id.to_i if @config_id

  description_getter = EM::DefaultDeferrable.new

  description_getter.errback do
    msg = "Failed getting description"
    log :error, "Fetching device: #{msg}"
    fail self, msg
  end

  extract_from_ssdp_notification description_getter

  description_getter.callback do |description|
    @description = description
    unless description
      fail self, 'Blank description returned'
      next
    end

    if bad_description?
      fail self, "Bad description returned: #@description"
      next
    end

    extract_url_base
    extract_device_info
    extract_icons

    @services_extracted = @devices_extracted = false
    extract_services
    extract_devices

    tick_loop = EM.tick_loop do
      :stop if @services_extracted and @devices_extracted
    end
    tick_loop.on_stop { succeed self }
  end
end

#update(notification) ⇒ void

This method returns an undefined value.

Update a device from a ssdp:update notification



171
172
173
174
175
176
177
# File 'lib/rupnp/cp/remote_device.rb', line 171

def update(notification)
  update_expiration notification
  @boot_id = notification['nextbootid.upnp.org'].to_i
  if notification['configid.upnp.org']
    @config_id = notification['configid.upnp.org'].to_i
  end
end