Class: ONVIF::Server

Inherits:
EM::HttpServer::Server
  • Object
show all
Defined in:
lib/ruby_onvif_client/server.rb

Instance Method Summary collapse

Constructor Details

#initialize(call_back) ⇒ Server

def post_init

super

end



9
10
11
12
# File 'lib/ruby_onvif_client/server.rb', line 9

def initialize call_back
    @call_back = call_back
    super
end

Instance Method Details

#http_request_errback(e) ⇒ Object



54
55
56
57
# File 'lib/ruby_onvif_client/server.rb', line 54

def http_request_errback e
    # printing the whole exception
    puts e.inspect
end

#parse_data(data) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ruby_onvif_client/server.rb', line 59

def parse_data data
    xml_doc = Nokogiri::XML(data)
    res = {}
    res[:topic] = xml_doc.xpath('//wsnt:Topic').first.content
    res[:time] = xml_doc.xpath('//tt:Message').first.attribute('UtcTime').value
    event_type = {}
    xml_doc.xpath('//tt:Source').each do |node|
        event_type[:name] = node.xpath('tt:SimpleItem').attribute('Name').value
        event_type[:value] = node.xpath('tt:SimpleItem').attribute('Value').value
    end
    res[:source] = event_type
    event_data = {}
    xml_doc.xpath('//tt:Data').each do |node|
        event_data[:name] = node.xpath('tt:SimpleItem').attribute('Name').value
        event_data[:value] = node.xpath('tt:SimpleItem').attribute('Value').value
    end
    res[:data] = event_data
    res[:host] = @http[:host] + @http_request_uri
    puts res
    # {:topic=>"tns1:VideoAnalytics/tnsn:MotionDetection", 
    #  :time=>"2013-08-01T17:01:33", 
    #  :source=>{:name=>"VideoSourceConfigurationToken", :value=>"profile_VideoSource_1"}, 
    #  :data=>{:name=>"MotionActive", :value=>"true"}, :host=>"192.168.16.251:8080/onvif_notify_server"}
    res
end

#process_http_requestObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ruby_onvif_client/server.rb', line 14

def process_http_request
    puts "############################ #{__LINE__}"
    puts  @http_request_method
    puts "############################ #{__LINE__}"
    puts  @http_request_uri
    puts "############################ #{__LINE__}"
    puts  @http_query_string
    puts "############################ #{__LINE__}"
    puts  @http_protocol
    puts "############################ #{__LINE__}"
    puts  @http_content
    puts "############################ #{__LINE__}"
    puts  @http[:cookie]
    puts "############################ #{__LINE__}"
    puts  @http[:content_type]
    puts "############################ #{__LINE__}"
    # you have all the http headers in this hash
    puts  @http.inspect
    puts "############################ #{__LINE__}"
    puts @http_if_none_match
    puts "############################ #{__LINE__}"
    puts @http_path_info
    puts "############################ #{__LINE__}"
    puts @http_if_none_match
    puts "############################ #{__LINE__}"
    puts @http_post_content
    puts "############################ #{__LINE__}"
    puts @http_headers
    puts "############################ #{__LINE__}"
    puts @http_bodys

    result = parse_data @http_content
    # response = EM::DelegatedHttpResponse.new(self)
    # response.status = 200
    # response.content_type 'text/html'
    # response.content = 'It works'
    # response.send_response
    @call_back.call result
end