Class: RSMP::AlarmCollector

Inherits:
Collector show all
Defined in:
lib/rsmp/collect/alarm_collector.rb

Overview

Class for waiting for specific command responses

Instance Attribute Summary

Attributes inherited from Collector

#condition, #error, #m_id, #messages, #status, #task

Instance Method Summary collapse

Methods inherited from Collector

#cancel, #cancelled?, #collect, #collect!, #collecting?, #complete, #describe, #describe_num_and_type, #describe_progress, #describe_types, #do_stop, #done?, #identifier, #incomplete, #ingoing?, #inspect, #keep, #log_complete, #log_incomplete, #log_start, #make_title, #ok!, #ok?, #outgoing?, #perform_match, #ready?, #receive, #receive_disconnect, #receive_error, #receive_schema_error, #reject_not_ack, #reset, #start, #timeout?, #use_task, #wait, #wait!

Methods included from Receiver

#accept_message?, #handle_message, #initialize_receiver, #receive, #receive_error, #reject_message?, #start_receiving, #stop_receiving

Methods included from Inspect

#inspect, #inspector

Constructor Details

#initialize(proxy, options = {}) ⇒ AlarmCollector

Returns a new instance of AlarmCollector.



4
5
6
7
8
9
10
# File 'lib/rsmp/collect/alarm_collector.rb', line 4

def initialize proxy,options={}
  @matcher = options[:matcher] || {}
  super proxy, options.merge(
    filter: RSMP::Filter.new(ingoing: true, outgoing: false, type: 'Alarm'),
    title:'alarm'
  )
end

Instance Method Details

#acceptable?(message) ⇒ Boolean

match alarm attributes

Returns:

  • (Boolean)


13
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
# File 'lib/rsmp/collect/alarm_collector.rb', line 13

def acceptable? message
  return false if super(message) == false

  # match fixed attributes
  %w{cId aCId aSp ack aS sS cat pri}.each do |key|
    want = @matcher[key]
    got = message.attribute(key)
    case want
    when Regexp
      return false if got !~ want
    when String
      return false if got != want
    end
  end

  # match rvs items
  if @matcher['rvs']
    matcher_rvs = @matcher['rvs']
    message_rvs = message.attributes['rvs']
    return false unless message_rvs
    return false unless matcher_rvs.all? do |matcher_item|
      return false unless message_rvs.any? do |message_item|
        next message_item['n'] == matcher_item['n'] && message_item['v'] == matcher_item['v']
      end
      next true
    end
  end
  true
end

#describe_matcherObject

return a string that describes what we’re collecting



44
45
46
# File 'lib/rsmp/collect/alarm_collector.rb', line 44

def describe_matcher
  "#{describe_num_and_type} #{ {component: @options[:component]}.merge(@matcher).compact }"
end