Module: MqttRails
- Extended by:
- MqttRails
- Included in:
- MqttRails
- Defined in:
- lib/mqtt_rails/sender.rb,
lib/mqtt-rails.rb,
lib/mqtt_rails/client.rb,
lib/mqtt_rails/packet.rb,
lib/mqtt_rails/handler.rb,
lib/mqtt_rails/version.rb,
lib/mqtt_rails/exception.rb,
lib/mqtt_rails/publisher.rb,
lib/mqtt_rails/ssl_helper.rb,
lib/mqtt_rails/subscriber.rb,
lib/mqtt_rails/packet/base.rb,
lib/mqtt_rails/packet/puback.rb,
lib/mqtt_rails/packet/pubrec.rb,
lib/mqtt_rails/packet/pubrel.rb,
lib/mqtt_rails/packet/suback.rb,
lib/mqtt_rails/packet/connack.rb,
lib/mqtt_rails/packet/connect.rb,
lib/mqtt_rails/packet/pingreq.rb,
lib/mqtt_rails/packet/pubcomp.rb,
lib/mqtt_rails/packet/publish.rb,
lib/mqtt_rails/packet/pingresp.rb,
lib/mqtt_rails/packet/unsuback.rb,
lib/mqtt_rails/packet/subscribe.rb,
lib/mqtt_rails/connection_helper.rb,
lib/mqtt_rails/packet/disconnect.rb,
lib/mqtt_rails/packet/unsubscribe.rb
Overview
Copyright © 2016-2017 Pierre Goudet <[email protected]>
All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 and Eclipse Distribution License v1.0 which accompany this distribution.
The Eclipse Public License is available at
https://eclipse.org/org/documents/epl-v10.php.
and the Eclipse Distribution License is available at
https://eclipse.org/org/documents/edl-v10.php.
Contributors:
Pierre Goudet - initial committer
Defined Under Namespace
Modules: Packet, SSLHelper Classes: Client, ConnectionHelper, Exception, FullQueueException, FullWritingException, Handler, LowVersionException, NotSupportedEncryptionException, PacketException, PacketFormatException, ProtocolVersionException, ProtocolViolation, Publisher, ReadingException, Sender, Subscriber, WritingException
Constant Summary collapse
- MAX_PACKET_ID =
65535
- DEFAULT_SSL_PORT =
Default connection setup
8883
- DEFAULT_PORT =
1883
- SELECT_TIMEOUT =
0.002
- MAX_SUBACK =
MAX size of queue
10
- MAX_UNSUBACK =
10
- MAX_PUBLISH =
1000
- MAX_QUEUE =
1000
- MQTT_CS_NEW =
Connection states values
0
- MQTT_CS_CONNECTED =
1
- MQTT_CS_DISCONNECT =
2
- MQTT_ERR_SUCCESS =
Error values
0
- MQTT_ERR_FAIL =
1
- PACKET_TYPES =
[ nil, MqttRails::Packet::Connect, MqttRails::Packet::Connack, MqttRails::Packet::Publish, MqttRails::Packet::Puback, MqttRails::Packet::Pubrec, MqttRails::Packet::Pubrel, MqttRails::Packet::Pubcomp, MqttRails::Packet::Subscribe, MqttRails::Packet::Suback, MqttRails::Packet::Unsubscribe, MqttRails::Packet::Unsuback, MqttRails::Packet::Pingreq, MqttRails::Packet::Pingresp, MqttRails::Packet::Disconnect, nil ]
- CONNACK_ERROR_MESSAGE =
{ 0x02 => "Client Identifier is correct but not allowed by remote server.", 0x03 => "Connection established but MQTT service unvailable on remote server.", 0x04 => "User name or user password is malformed.", 0x05 => "Client is not authorized to connect to the server." }
- CLIENT_ATTR_DEFAULTS =
{ :host => "", :port => nil, :mqtt_version => '3.1.1', :clean_session => true, :persistent => false, :blocking => false, :client_id => nil, :username => nil, :password => nil, :ssl => false, :will_topic => nil, :will_payload => nil, :will_qos => 0, :will_retain => false, :keep_alive => 60, :ack_timeout => 5, :on_connack => nil, :on_suback => nil, :on_unsuback => nil, :on_puback => nil, :on_pubrel => nil, :on_pubrec => nil, :on_pubcomp => nil, :on_message => nil, }
- VERSION =
"1.0"
Instance Method Summary collapse
- #check_topics(topics, filters) ⇒ Object
- #is_end?(topic_part, filter_part) ⇒ Boolean
- #is_matching?(rc, topic_length, filter_length, index) ⇒ Boolean
- #is_wildcard?(filter_part) ⇒ Boolean
- #keep_running?(filter_part, topic_part) ⇒ Boolean
- #match_filter(topics, filters) ⇒ Object
Instance Method Details
#check_topics(topics, filters) ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/mqtt-rails.rb', line 137 def check_topics(topics, filters) if topics.is_a?(String) && filters.is_a?(String) else Rails.logger.error("Topics or Wildcards are not found as String.") raise ArgumentError end end |
#is_end?(topic_part, filter_part) ⇒ Boolean
129 130 131 |
# File 'lib/mqtt-rails.rb', line 129 def is_end?(topic_part, filter_part) topic_part.nil? || filter_part.nil? end |
#is_matching?(rc, topic_length, filter_length, index) ⇒ Boolean
133 134 135 |
# File 'lib/mqtt-rails.rb', line 133 def is_matching?(rc, topic_length, filter_length, index) rc || index == [topic_length, filter_length].max end |
#is_wildcard?(filter_part) ⇒ Boolean
125 126 127 |
# File 'lib/mqtt-rails.rb', line 125 def is_wildcard?(filter_part) filter_part == '#' end |
#keep_running?(filter_part, topic_part) ⇒ Boolean
121 122 123 |
# File 'lib/mqtt-rails.rb', line 121 def keep_running?(filter_part, topic_part) filter_part == topic_part || filter_part == '+' end |
#match_filter(topics, filters) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/mqtt-rails.rb', line 100 def match_filter(topics, filters) check_topics(topics, filters) index = 0 rc = false topic = topics.split('/') filter = filters.split('/') while index < [topic.length, filter.length].max do if is_end?(topic[index], filter[index]) break elsif is_wildcard?(filter[index]) rc = index == (filter.length - 1) break elsif keep_running?(filter[index], topic[index]) index = index + 1 else break end end is_matching?(rc, topic.length, filter.length, index) end |