rsmp 0.4.0 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rsmp/collect/collector.rb +10 -3
- data/lib/rsmp/collect/matcher.rb +22 -15
- data/lib/rsmp/collect/message_queries.rb +3 -3
- data/lib/rsmp/collect/query.rb +10 -20
- data/lib/rsmp/tlc.rb +0 -1
- data/lib/rsmp/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b82a88e9cd80aeb3bf0bc89b774727155dc8c6418520493c34a852809eb29e94
|
4
|
+
data.tar.gz: 16cb2331281e470233ff28fcf6ac1e89124a88628d920f8f3d7e486b0a076b2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47d08d2fab1e0dd76dc5e988b3ee4e56a3110258402ffc9d1d8213ca7cbd889e94d08119100b785dfc5803dfd5f0618ac25c2597e1499cebd7fbd2db500614d5
|
7
|
+
data.tar.gz: 321f695677507a66fa03a81fc2bdc87350df51278e53e95bb6f75e5eeea180ea3e1503f0ee072aea425970d32e7a814a8a683cd33abdf7d832cd8c83e216ff97
|
data/Gemfile.lock
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module RSMP
|
2
2
|
|
3
|
-
# Collects ingoing and/or outgoing messages.
|
3
|
+
# Collects ingoing and/or outgoing messages from a notifier.
|
4
4
|
# Can filter by message type and wakes up the client once the desired number of messages has been collected.
|
5
5
|
class Collector < Listener
|
6
6
|
attr_reader :condition, :messages, :done
|
@@ -17,22 +17,29 @@ module RSMP
|
|
17
17
|
reset
|
18
18
|
end
|
19
19
|
|
20
|
+
# Inspect formatter that shows the message we have collected
|
20
21
|
def inspect
|
21
22
|
"#<#{self.class.name}:#{self.object_id}, #{inspector(:@messages)}>"
|
22
23
|
end
|
23
24
|
|
25
|
+
# Want ingoing messages?
|
24
26
|
def ingoing?
|
25
27
|
@ingoing == true
|
26
28
|
end
|
27
29
|
|
30
|
+
# Want outgoing messages?
|
28
31
|
def outgoing?
|
29
32
|
@outgoing == true
|
30
33
|
end
|
31
34
|
|
35
|
+
# Block until all messages have been collected
|
32
36
|
def wait
|
33
37
|
@condition.wait
|
34
38
|
end
|
35
39
|
|
40
|
+
# Collect message
|
41
|
+
# Will block until all messages have been collected,
|
42
|
+
# or we time out
|
36
43
|
def collect task, options={}, &block
|
37
44
|
@options.merge! options
|
38
45
|
@block = block
|
@@ -46,9 +53,9 @@ module RSMP
|
|
46
53
|
return @error if @error
|
47
54
|
self
|
48
55
|
rescue Async::TimeoutError
|
49
|
-
str = "
|
56
|
+
str = "#{@title.capitalize} collection"
|
50
57
|
str << " in response to #{options[:m_id]}" if options[:m_id]
|
51
|
-
str << " within #{@options[:timeout]}s"
|
58
|
+
str << " didn't complete within #{@options[:timeout]}s"
|
52
59
|
raise RSMP::TimeoutError.new str
|
53
60
|
end
|
54
61
|
|
data/lib/rsmp/collect/matcher.rb
CHANGED
@@ -35,10 +35,11 @@ module RSMP
|
|
35
35
|
class Matcher < Collector
|
36
36
|
attr_reader :queries
|
37
37
|
|
38
|
-
# Initialize with a list
|
38
|
+
# Initialize with a list of wanted statuses
|
39
39
|
def initialize proxy, want, options={}
|
40
40
|
super proxy, options.merge( ingoing: true, outgoing: false)
|
41
|
-
@queries = want.map { |
|
41
|
+
@queries = want.map { |item| build_query item }
|
42
|
+
@want = want
|
42
43
|
end
|
43
44
|
|
44
45
|
# Build a query object.
|
@@ -51,10 +52,15 @@ module RSMP
|
|
51
52
|
def query_result want
|
52
53
|
query = @queries.find { |q| q.want == want}
|
53
54
|
raise unless query
|
54
|
-
query.
|
55
|
+
query.got
|
55
56
|
end
|
56
57
|
|
57
|
-
#
|
58
|
+
# Get an array of the last item received for each query
|
59
|
+
def reached
|
60
|
+
@queries.map { |query| query.got }.compact
|
61
|
+
end
|
62
|
+
|
63
|
+
# get the first message. Useful when you only collect one mesage
|
58
64
|
def message
|
59
65
|
@queries.first.message
|
60
66
|
end
|
@@ -64,11 +70,6 @@ module RSMP
|
|
64
70
|
@queries.map { |query| query.message }.uniq
|
65
71
|
end
|
66
72
|
|
67
|
-
# Get items from results
|
68
|
-
def items
|
69
|
-
@queries.map { |query| query.item }.uniq
|
70
|
-
end
|
71
|
-
|
72
73
|
# Are there queries left to match?
|
73
74
|
def done?
|
74
75
|
@queries.all? { |query| query.done? }
|
@@ -77,24 +78,30 @@ module RSMP
|
|
77
78
|
# Get a simplified hash of queries, with values set to either true or false,
|
78
79
|
# indicating which queries have been matched.
|
79
80
|
def status
|
80
|
-
@queries.map { |query| [query.
|
81
|
+
@queries.map { |query| [query.want, query.done?] }.to_h
|
81
82
|
end
|
82
83
|
|
83
|
-
# Get a simply array of bools, showing which queries
|
84
|
+
# Get a simply array of bools, showing which queries have been matched.
|
84
85
|
def summary
|
85
86
|
@queries.map { |query| query.done? }
|
86
87
|
end
|
87
88
|
|
88
89
|
# Check if a messages matches our criteria.
|
89
|
-
#
|
90
|
-
# Breaks as soon as where done matching all queries
|
90
|
+
# Match each query against each item in the message
|
91
91
|
def check_match message
|
92
92
|
return unless match?(message)
|
93
93
|
@queries.each do |query| # look through queries
|
94
|
-
get_items(message).each do |item| # look through
|
95
|
-
|
94
|
+
get_items(message).each do |item| # look through items in message
|
95
|
+
matched = query.check_match(item,message)
|
96
|
+
if matched != nil
|
97
|
+
type = {true=>'match',false=>'mismatch'}[matched]
|
98
|
+
@proxy.log "#{@title.capitalize} #{message.m_id_short} collect #{type} #{query.want}, item #{item}", level: :debug
|
99
|
+
break
|
100
|
+
end
|
96
101
|
end
|
97
102
|
end
|
103
|
+
@proxy.log "#{@title.capitalize} collect reached #{summary}", level: :debug
|
98
104
|
end
|
105
|
+
|
99
106
|
end
|
100
107
|
end
|
@@ -23,9 +23,9 @@ module RSMP
|
|
23
23
|
return nil if @want['n'] && @want['n'] != item['n']
|
24
24
|
return false if @want['q'] && @want['q'] != item['q']
|
25
25
|
if @want['s'].is_a? Regexp
|
26
|
-
return false if
|
27
|
-
|
28
|
-
return false if
|
26
|
+
return false if item['s'] !~ @want['s']
|
27
|
+
elsif @want['s']
|
28
|
+
return false if item['s'] != @want['s']
|
29
29
|
end
|
30
30
|
true
|
31
31
|
end
|
data/lib/rsmp/collect/query.rb
CHANGED
@@ -2,43 +2,33 @@ module RSMP
|
|
2
2
|
|
3
3
|
# Class that matches a single status or command item
|
4
4
|
class Query
|
5
|
-
attr_reader :want, :
|
5
|
+
attr_reader :want, :got, :message
|
6
6
|
|
7
7
|
def initialize want
|
8
8
|
@want = want
|
9
|
-
@
|
9
|
+
@got = nil
|
10
10
|
@message = nil
|
11
11
|
@done = false
|
12
12
|
end
|
13
13
|
|
14
|
+
# Are we done, i.e. did the last checked item match?
|
14
15
|
def done?
|
15
16
|
@done
|
16
17
|
end
|
17
18
|
|
19
|
+
# Check an item and set @done to true if it matches
|
20
|
+
# Store the item and corresponding message if there's a positive or negative match
|
18
21
|
def check_match item, message
|
19
22
|
matched = match? item
|
20
|
-
if matched
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
forget
|
25
|
-
true
|
23
|
+
if matched != nil
|
24
|
+
@message = message
|
25
|
+
@got = item
|
26
|
+
@done = matched
|
26
27
|
end
|
28
|
+
matched
|
27
29
|
end
|
28
30
|
|
29
31
|
def match? item
|
30
32
|
end
|
31
|
-
|
32
|
-
# Mark a query as matched and store item and message
|
33
|
-
def keep message, item
|
34
|
-
@message = message
|
35
|
-
@item = item
|
36
|
-
@done = true
|
37
|
-
end
|
38
|
-
|
39
|
-
# Mark a query as not matched
|
40
|
-
def forget
|
41
|
-
@done = false
|
42
|
-
end
|
43
33
|
end
|
44
34
|
end
|
data/lib/rsmp/tlc.rb
CHANGED
@@ -293,7 +293,6 @@ module RSMP
|
|
293
293
|
def handle_s0002 status_code, status_name=nil
|
294
294
|
case status_name
|
295
295
|
when 'detectorlogicstatus'
|
296
|
-
RSMP::Tlc.make_status @detector_logics.each { |dl| p dl.value }
|
297
296
|
RSMP::Tlc.make_status @detector_logics.map { |dl| dl.value ? '1' : '0' }.join
|
298
297
|
end
|
299
298
|
end
|
data/lib/rsmp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsmp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emil Tin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|