Class: AwsIotDevice::MqttAdapter::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_iot_device/mqtt_adapter/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Client

On a MqttAdapter’s create, the client adapter is set as the previously define module adapter The client is then initialize with the client type of the third librairy of the adapter.



19
20
21
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 19

def initialize(*args)
  @adapter = MqttAdapter.adapter.new(*args)
end

Instance Attribute Details

#adapterObject

The method call by the shared client are implemented by the third party or the adapter module itself.



10
11
12
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 10

def adapter
  @adapter
end

#client_idObject (readonly)

Returns the value of attribute client_id.



5
6
7
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 5

def client_id
  @client_id
end

Instance Method Details

#add_callback_filter_topic(topic, callback = nil, &block) ⇒ Object



106
107
108
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 106

def add_callback_filter_topic(topic, callback=nil, &block)
  @adapter.add_callback_filter_topic(topic, callback, &block)
end

#connect(*args, &block) ⇒ Object

The following method represent the basics common MQTT actions. As possible, they should be implemented in the third party librairy If not, the adpater should implement them or throw and excpetion



30
31
32
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 30

def connect(*args, &block)
  @adapter.connect(*args, &block)
end

#connected?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 82

def connected?
  @adapter.connected?
end

#disconnect(send_msg = true) ⇒ Object



78
79
80
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 78

def disconnect(send_msg=true)
  @adapter.disconnect(send_msg)
end

#generate_client_idObject



74
75
76
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 74

def generate_client_id
  @adapter.generate_client_id
end

#get(topic = nil, &block) ⇒ Object



66
67
68
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 66

def get(topic=nil, &block)
  @adapter.get(topic, &block)
end

#get_packet(topic = nil, &block) ⇒ Object



70
71
72
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 70

def get_packet(topic=nil, &block)
  @adapter.get_packet(topic, &block)
end

#hostObject

The following attributes should exists in every MQTT third party librairy. They are necessary (or really usefull and common) for the establishement of the connection and/or the basic Mqtt actions. The setter directely change the third party client value when the getter remote the actual SharedClient instance’s attribute value



181
182
183
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 181

def host
  @adapter.host
end

#host=(host) ⇒ Object



185
186
187
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 185

def host=(host)
  @adapter.host = host
end

#loop_foreverObject



46
47
48
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 46

def loop_forever
  @adapter.loop_forever
end

#loop_miscObject



62
63
64
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 62

def loop_misc
  @adapter.loop_misc
end

#loop_readObject



54
55
56
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 54

def loop_read
  @adapter.loop_read
end

#loop_startObject



38
39
40
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 38

def loop_start
  @thread = @adapter.loop_start
end

#loop_stopObject



42
43
44
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 42

def loop_stop
  @adapter.loop_stop(@thread)
end

#loop_writeObject



58
59
60
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 58

def loop_write
  @adapter.loop_write
end

#mqtt_loopObject



50
51
52
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 50

def mqtt_loop
  @adapter.mqtt_loop
end

#on_connack(&block) ⇒ Object



146
147
148
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 146

def on_connack(&block)
  @adapter.on_connack(&block)
end

#on_connack=(callback) ⇒ Object



114
115
116
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 114

def on_connack=(callback)
  @adapter.on_connack = callback
end

#on_message(&block) ⇒ Object



174
175
176
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 174

def on_message(&block)
  @adapter.on_message(&block)
end

#on_message=(callback) ⇒ Object



142
143
144
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 142

def on_message=(callback)
  @adapter.on_message = callback
end

#on_puback(&block) ⇒ Object



158
159
160
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 158

def on_puback(&block)
  @adapter.on_puback(&block)
end

#on_puback=(callback) ⇒ Object



126
127
128
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 126

def on_puback=(callback)
  @adapter.on_puback = callback
end

#on_pubcomp(&block) ⇒ Object



170
171
172
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 170

def on_pubcomp(&block)
  @adapter.on_pubcomp(&block)
end

#on_pubcomp=(callback) ⇒ Object



138
139
140
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 138

def on_pubcomp=(callback)
  @adapter.on_pubcomp = callback
end

#on_pubrec(&block) ⇒ Object



162
163
164
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 162

def on_pubrec(&block)
  @adapter.on_pubrec(&block)
end

#on_pubrec=(callback) ⇒ Object



130
131
132
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 130

def on_pubrec=(callback)
  @adapter.on_pubrec = callback
end

#on_pubrel(&block) ⇒ Object



166
167
168
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 166

def on_pubrel(&block)
  @adapter.on_pubrel(&block)
end

#on_pubrel=(callback) ⇒ Object



134
135
136
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 134

def on_pubrel=(callback)
  @adapter.on_pubrel = callback
end

#on_suback(&block) ⇒ Object



150
151
152
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 150

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

#on_suback=(callback) ⇒ Object



118
119
120
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 118

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

#on_unsuback(&block) ⇒ Object



154
155
156
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 154

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

#on_unsuback=(callback) ⇒ Object



122
123
124
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 122

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

#portObject



189
190
191
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 189

def port
  @adapter.port
end

#port=(port) ⇒ Object



193
194
195
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 193

def port=(port)
  @adapter.port = port
end

#publish(topic, payload = '', retain = false, qos = 0) ⇒ Object



34
35
36
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 34

def publish(topic, payload='', retain=false, qos=0)
  @adapter.publish(topic, payload, retain, qos)
end

#remove_callback_filter_topic(topic) ⇒ Object



110
111
112
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 110

def remove_callback_filter_topic(topic)
  @adapter.remove_callback_filter_topic(topic)
end

#set_tls_ssl_context(ca_cert, cert = nil, key = nil) ⇒ Object



102
103
104
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 102

def set_tls_ssl_context(ca_cert, cert=nil, key=nil)
  @adapter.set_tls_ssl_context(ca_cert, cert, key)
end

#sslObject

Boolean for the encrypted mode (true = ssl/tls | false = no encryption)



198
199
200
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 198

def ssl
  @adapter.ssl
end

#ssl=(ssl) ⇒ Object



202
203
204
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 202

def ssl=(ssl)
  @adapter.ssl = ssl
end

#subscribe(topic, qos) ⇒ Object



86
87
88
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 86

def subscribe(topic, qos)
  @adapter.subscribe(topic, qos)
end

#subscribe_bunch(*topics) ⇒ Object



90
91
92
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 90

def subscribe_bunch(*topics)
  @adapter.subscribe_bunch(topics)
end

#unsubscribe(topic) ⇒ Object



94
95
96
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 94

def unsubscribe(topic)
  @adapter.unsubscribe(topic)
end

#unsubscribe_bunch(*topics) ⇒ Object



98
99
100
# File 'lib/aws_iot_device/mqtt_adapter/client.rb', line 98

def unsubscribe_bunch(*topics)
  @adapter.unsubscribe_bunch(topics)
end