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/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, Handler, LowVersionException, PacketException, ProtocolViolation, Publisher, ReadingException, Sender, Subscriber, WritingException

Constant Summary collapse

DEFAULT_SSL_PORT =

Default connection setup

8883
DEFAULT_PORT =
1883
SELECT_TIMEOUT =
0
LOOP_TEMPO =
0.005
RECONNECT_RETRY_TIME =
3
RECONNECT_RETRY_TEMPO =
5
MAX_READ =

MAX size of queue

10
MAX_PUBACK =
20
MAX_PUBREC =
20
MAX_PUBREL =
20
MAX_PUBCOMP =
20
MAX_WRITING =
MAX_PUBACK + MAX_PUBREC + MAX_PUBREL  + MAX_PUBCOMP
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.5"

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



158
159
160
161
162
163
164
# File 'lib/paho-mqtt.rb', line 158

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)


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

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)


154
155
156
# File 'lib/paho-mqtt.rb', line 154

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

#is_wildcard?(filter_part) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#keep_running?(filter_part, topic_part) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#logger?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/paho-mqtt.rb', line 117

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

#match_filter(topics, filters) ⇒ Object



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

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