Module: PahoMqtt

Extended by:
PahoMqtt
Included in:
PahoMqtt
Defined in:
lib/paho_mqtt/sender.rb,
lib/paho-mqtt.rb,
lib/paho_mqtt/client.rb,
lib/paho_mqtt/packet.rb,
lib/paho_mqtt/handler.rb,
lib/paho_mqtt/version.rb,
lib/paho_mqtt/exception.rb,
lib/paho_mqtt/publisher.rb,
lib/paho_mqtt/ssl_helper.rb,
lib/paho_mqtt/subscriber.rb,
lib/paho_mqtt/packet/base.rb,
lib/paho_mqtt/packet/puback.rb,
lib/paho_mqtt/packet/pubrec.rb,
lib/paho_mqtt/packet/pubrel.rb,
lib/paho_mqtt/packet/suback.rb,
lib/paho_mqtt/packet/connack.rb,
lib/paho_mqtt/packet/connect.rb,
lib/paho_mqtt/packet/pingreq.rb,
lib/paho_mqtt/packet/pubcomp.rb,
lib/paho_mqtt/packet/publish.rb,
lib/paho_mqtt/packet/pingresp.rb,
lib/paho_mqtt/packet/unsuback.rb,
lib/paho_mqtt/packet/subscribe.rb,
lib/paho_mqtt/connection_helper.rb,
lib/paho_mqtt/packet/disconnect.rb,
lib/paho_mqtt/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,
  PahoMqtt::Packet::Connect,
  PahoMqtt::Packet::Connack,
  PahoMqtt::Packet::Publish,
  PahoMqtt::Packet::Puback,
  PahoMqtt::Packet::Pubrec,
  PahoMqtt::Packet::Pubrel,
  PahoMqtt::Packet::Pubcomp,
  PahoMqtt::Packet::Subscribe,
  PahoMqtt::Packet::Suback,
  PahoMqtt::Packet::Unsubscribe,
  PahoMqtt::Packet::Unsuback,
  PahoMqtt::Packet::Pingreq,
  PahoMqtt::Packet::Pingresp,
  PahoMqtt::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.12"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



23
24
25
# File 'lib/paho-mqtt.rb', line 23

def logger
  @logger
end

Instance Method Details

#check_topics(topics, filters) ⇒ Object



155
156
157
158
159
160
161
# File 'lib/paho-mqtt.rb', line 155

def check_topics(topics, filters)
  if topics.is_a?(String) && filters.is_a?(String)
  else
    @logger.error("Topics or Wildcards are not found as String.") if logger?
    raise ArgumentError
  end
end

#is_end?(topic_part, filter_part) ⇒ Boolean

Returns:

  • (Boolean)


147
148
149
# File 'lib/paho-mqtt.rb', line 147

def is_end?(topic_part, filter_part)
  topic_part.nil? || filter_part.nil?
end

#is_matching?(rc, topic_length, filter_length, index) ⇒ Boolean

Returns:

  • (Boolean)


151
152
153
# File 'lib/paho-mqtt.rb', line 151

def is_matching?(rc, topic_length, filter_length, index)
  rc || index == [topic_length, filter_length].max
end

#is_wildcard?(filter_part) ⇒ Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/paho-mqtt.rb', line 143

def is_wildcard?(filter_part)
  filter_part == '#'
end

#keep_running?(filter_part, topic_part) ⇒ Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/paho-mqtt.rb', line 139

def keep_running?(filter_part, topic_part)
  filter_part == topic_part || filter_part == '+'
end

#logger?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/paho-mqtt.rb', line 114

def logger?
  @logger.is_a?(Logger)
end

#match_filter(topics, filters) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/paho-mqtt.rb', line 118

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