Class: RUPNP::CP::EventSubscriber
- Inherits:
-
EM::Connection
- Object
- EM::Connection
- RUPNP::CP::EventSubscriber
- Includes:
- LogMixin
- Defined in:
- lib/rupnp/cp/event_subscriber.rb
Overview
Event subscriber to an event’s service
Constant Summary
Constants included from LogMixin
Instance Attribute Summary collapse
-
#response ⇒ EM::Channel
readonly
Response from device.
Instance Method Summary collapse
-
#initialize(msg) ⇒ EventSubscriber
constructor
A new instance of EventSubscriber.
- #post_init ⇒ void
-
#receive_data(data) ⇒ void
Receive response from device and send it through #response.
Methods included from LogMixin
Constructor Details
#initialize(msg) ⇒ EventSubscriber
Returns a new instance of EventSubscriber.
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
#response ⇒ EM::Channel (readonly)
Response from device
10 11 12 |
# File 'lib/rupnp/cp/event_subscriber.rb', line 10 def response @response end |
Instance Method Details
#post_init ⇒ void
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
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 |