Class: RUPNP::CP::EventServer

Inherits:
EM::HttpServer::Server
  • Object
show all
Includes:
LogMixin
Defined in:
lib/rupnp/cp/event_server.rb

Overview

Event server to receive events from services.

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(add_url_channel) ⇒ EventServer

Returns a new instance of EventServer.

Parameters:

  • add_url_channel (EM::Channel)

    channel for adding url



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rupnp/cp/event_server.rb', line 16

def initialize(add_url_channel)
  super

  @urls = []
  @add_url = add_url_channel

  @add_url.subscribe do |url|
    log :info, "add URL #{url} for eventing"
    @urls << url
  end
end

Instance Attribute Details

#add_urlEM::Channel (readonly)

Channel to add url for listening to

Returns:

  • (EM::Channel)


12
13
14
# File 'lib/rupnp/cp/event_server.rb', line 12

def add_url
  @add_url
end

Instance Method Details

#process_http_requestObject

Process a HTTP request received from a service/device



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

def process_http_request
  log :debug, 'EventServer: receive request'
  url, event = @urls.find { |a| a[0] == @http_request_uri }

  if event.is_a? EM::Channel
    if @http_request_method == 'NOTIFY'
      if @http[:nt] == 'upnp:event' and @http[:nts] == 'upnp:propchange'
        event << {
          :sid => @http[:sid],
          :seq => @http[:seq],
          :content => @http_content }
      else
        log :warn, 'EventServer: ' +
          "malformed NOTIFY event message:\n#@http_headers\n#@http_content"
      end
    else
      log :warn, "EventServer: unknown HTTP verb: #@http_request_method"
    end
  end
end