Class: AwsIotDevice::MqttShadowClient::ShadowTopicManager

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_iot_device/mqtt_shadow_client/shadow_topic_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(mqtt_manager, shadow_name) ⇒ ShadowTopicManager

Returns a new instance of ShadowTopicManager.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_topic_manager.rb', line 7

def initialize(mqtt_manager, shadow_name)
  raise ArgumentError, "topic manager should be initialized with a mqtt_manager but was undefined" if mqtt_manager.nil?
  raise ArgumentError, "topic manager should be initialize with a mqtt mmanager but was undefined" if shadow_name.nil?

  @mqtt_manager = mqtt_manager
  @sub_unsub_mutex = Mutex.new()
  @topic = TopicBuilder.new(shadow_name)
  @timeout = mqtt_manager.mqtt_operation_timeout_s
end

Instance Method Details

#on_suback(&block) ⇒ Object



62
63
64
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_topic_manager.rb', line 62

def on_suback(&block)
  @mqtt_manager.on_suback(&block)
end

#on_suback=(callback) ⇒ Object



58
59
60
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_topic_manager.rb', line 58

def on_suback=(callback)
  @mqtt_manager.on_suback = callback
end

#on_unsuback(&block) ⇒ Object



70
71
72
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_topic_manager.rb', line 70

def on_unsuback(&block)
  @mqtt_manager.on_unsuback(&block)
end

#on_unsuback=(callback) ⇒ Object



66
67
68
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_topic_manager.rb', line 66

def on_unsuback=(callback)
  @mqtt_manager.on_unsuback = callback 
end

#paho_client?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_topic_manager.rb', line 54

def paho_client?
  @mqtt_manager.paho_client?
end

#retrieve_action(topic) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_topic_manager.rb', line 43

def retrieve_action(topic)
  res = nil
  ACTION_NAME.each do |action|
    if topic[0] == @topic.get_topic_accepted(action)
      res = action.to_sym
      break
    end
  end
  res
end

#shadow_topic_publish(action, payload) ⇒ Object



17
18
19
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_topic_manager.rb', line 17

def shadow_topic_publish(action, payload)
  @mqtt_manager.publish(@topic.get_topic_general(action), payload, false, 0)
end

#shadow_topic_subscribe(action, callback = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_topic_manager.rb', line 21

def shadow_topic_subscribe(action, callback=nil)
  @sub_unsub_mutex.synchronize() {
    @subacked = false
    if @topic.is_delta?(action)
      @mqtt_manager.subscribe(@topic.get_topic_delta, 0, callback)
    else
      @mqtt_manager.subscribe_bunch([@topic.get_topic_accepted(action), 1, callback], [@topic.get_topic_rejected(action), 1, callback])
    end
  }
end

#shadow_topic_unsubscribe(action) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_topic_manager.rb', line 32

def shadow_topic_unsubscribe(action)
  @sub_unsub_mutex.synchronize(){
    @unsubacked = false
    if @topic.is_delta?(action)
      @mqtt_manager.unsubscribe(@topic.get_topic_delta)
    else
      @mqtt_manager.unsubscribe_bunch(@topic.get_topic_accepted(action), @topic.get_topic_rejected(action))
    end
  }
end