Class: MQTT::Subscriptions::ValueTrackerSubscription
Instance Attribute Summary collapse
Attributes inherited from Subscription
#qos, #topic, #topic_split
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ValueTrackerSubscription.
50
51
52
53
54
55
56
57
|
# File 'lib/mqtt/subscription_classes.rb', line 50
def initialize(topic, qos = 1)
raise ArgumentError, "Tracking of topic wildcards is prohibited! Topic: #{topic}" if topic =~ /[#\+]/
super(topic, qos);
@value = nil;
@callbackList = Array.new();
end
|
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
48
49
50
|
# File 'lib/mqtt/subscription_classes.rb', line 48
def value
@value
end
|
Instance Method Details
#attach(callback) ⇒ Object
69
70
71
72
73
|
# File 'lib/mqtt/subscription_classes.rb', line 69
def attach(callback)
@callbackList << callback;
callback.call(@value, nil) if(@value);
return callback;
end
|
#detach(callback) ⇒ Object
74
75
76
|
# File 'lib/mqtt/subscription_classes.rb', line 74
def detach(callback)
@callbackList.delete callback;
end
|
#offer(_topicList, data) ⇒ Object
59
60
61
62
63
64
65
66
67
|
# File 'lib/mqtt/subscription_classes.rb', line 59
def offer(_topicList, data)
return if data == @value;
oldValue = @value;
@value = data;
@callbackList.each do |cb|
cb.call(data, oldValue);
end
end
|