Class: RUPNP::CP::EventSubscriber

Inherits:
EM::Connection
  • Object
show all
Includes:
LogMixin
Defined in:
lib/rupnp/cp/event_subscriber.rb

Overview

Event subscriber to an event’s service

Author:

  • Sylvain Daubert

Constant Summary

Constants included from LogMixin

LogMixin::LOG_LEVEL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LogMixin

#log

Constructor Details

#initialize(msg) ⇒ EventSubscriber

Returns a new instance of EventSubscriber.

Parameters:

  • msg (String)

    message to send for subscribing



14
15
16
17
# File 'lib/rupnp/cp/event_subscriber.rb', line 14

def initialize(msg)
  @msg = msg
  @response = EM::Channel.new
end

Instance Attribute Details

#responseEM::Channel (readonly)

Response from device

Returns:

  • (EM::Channel)


10
11
12
# File 'lib/rupnp/cp/event_subscriber.rb', line 10

def response
  @response
end

Instance Method Details

#post_initvoid

This method returns an undefined value.



20
21
22
23
# File 'lib/rupnp/cp/event_subscriber.rb', line 20

def post_init
  log :debug, "send event subscribe request:\n#@msg"
  send_data @msg
end

#receive_data(data) ⇒ void

This method returns an undefined value.

Receive response from device and send it through #response

Parameters:

  • data (String)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rupnp/cp/event_subscriber.rb', line 28

def receive_data(data)
  log :debug, "receive data from subscribe event action:\n#{data}"
  resp = {}
  io = StringIO.new(data)

  status = io.readline
  status =~ /HTTP\/1\.1 (\d+) (.+)/
  resp[:status] = $2
  resp[:status_code] = $1

  io.each_line do |line|
    if line =~ /(\w+):\s*(.*)/
      resp[$1.downcase.to_sym] = $2.chomp
    end
  end

  @response << resp
end