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

Returns a new instance of RemoteDevice.

Parameters:



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

Returns:

  • (Integer)


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

Returns:

  • (String)


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

Returns:

  • (nil, Integer)


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

Returns:



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

Returns:

  • (String)


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

def date
  @date
end

#devicesArray<Device> (readonly)

List of embedded devices

Returns:

  • (Array<Device>)


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

def devices
  @devices
end

#expirationTime (readonly)

Expiration time for the advertisement

Returns:

  • (Time)


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

def expiration
  @expiration
end

#extString (readonly)

Returns:

  • (String)


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

def ext
  @ext
end

#friendly_nameString (readonly)

Short description for end users

Returns:

  • (String)


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

Returns:

  • (Array<OpenStruct>)


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

Returns:

  • (String)


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

def location
  @location
end

#manufacturerString (readonly)

Manufacturer’s name

Returns:

  • (String)


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

def manufacturer
  @manufacturer
end

#manufacturer_urlString (readonly)

Web site for manufacturer

Returns:

  • (String)


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

Returns:

  • (String)


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

def model_description
  @model_description
end

#model_nameString (readonly)

Model name

Returns:

  • (String)


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

def model_name
  @model_name
end

#model_numberString (readonly)

Model number

Returns:

  • (String)


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

Returns:

  • (String)


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

Returns:

  • (String)


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

def presentation_url
  @presentation_url
end

#serial_umberString (readonly)

Serial number

Returns:

  • (String)


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

def serial_umber
  @serial_umber
end

#serverString (readonly)

Get SERVER string

Returns:

  • (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

Returns:

  • (Array<Service>)


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

def services
  @services
end

#stString (readonly)

Get search target.

Returns:

  • (String)


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

def st
  @st
end

#typeString (readonly)

Device type

Returns:

  • (String)


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

def type
  @type
end

#udnString (readonly)

Unique Device Name

Returns:

  • (String)


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

def udn
  @udn
end

#upcString (readonly)

Universal Product Code

Returns:

  • (String)


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

Returns:

  • (String)


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

Returns:

  • (String)


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

def url_base
  @url_base
end

#usnString (readonly)

Get Unique Service Name

Returns:

  • (String)


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

def usn
  @usn
end

#xmlnsString (readonly)

XML namespace for device description

Returns:

  • (String)


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
# File 'lib/rupnp/cp/remote_device.rb', line 120

def fetch
  upnp_minor_ver = @notification['server'].match(/UPnP\/1\.(\d)/)[1].to_i
  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
  elsif upnp_minor_ver > 0
    fail self, 'no BOOTID.UPNP.ORG field. Message discarded.'
    return
  end
  @config_id = @notification['configid.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
    next
  end

  extract_from_ssdp_notification description_getter

  description_getter.callback do |description|
    @description = description
  if bad_description?
      fail self, "Bad description returned: #@description"
      next
    else
      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
end

#update(notification) ⇒ void

This method returns an undefined value.

Update a device from a ssdp:update notification

Parameters:

  • notification (String)


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

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