module PahoMqtt

Copyright © 2016-2018 Pierre Goudet <p-goudet@ruby-dev.jp>

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

Copyright © 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>

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

Copyright © 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>

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

Copyright © 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>

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

Copyright © 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>

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

Copyright © 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>

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

Copyright © 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>

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

Copyright © 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>

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

Copyright © 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>

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

Copyright © 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>

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

Copyright © 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>

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

Copyright © 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>

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

Copyright © 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>

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

Copyright © 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>

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

Copyright © 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>

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

Copyright © 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>

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

Copyright © 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>

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

Copyright © 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>

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

Copyright © 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>

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

Copyright © 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>

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

Constants

CLIENT_ATTR_DEFAULTS
CONNACK_ERROR_MESSAGE
DEFAULT_PORT
DEFAULT_SSL_PORT

Default connection setup

LOOP_TEMPO
MAX_PUBACK
MAX_PUBCOMP
MAX_PUBREC
MAX_PUBREL
MAX_READ
MAX_SUBACK

MAX size of queue

MAX_UNSUBACK
MAX_WRITING
MQTT_CS_CONNECTED
MQTT_CS_DISCONNECT
MQTT_CS_NEW

Connection states values

MQTT_ERR_FAIL
MQTT_ERR_SUCCESS

Error values

PACKET_TYPES
SELECT_TIMEOUT
VERSION

Attributes

logger[RW]

Public Instance Methods

check_topics(topics, filters) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/paho-mqtt.rb, line 146
def is_wildcard?(filter_part)
  filter_part == '#'
end
keep_running?(filter_part, topic_part) click to toggle source
# File lib/paho-mqtt.rb, line 142
def keep_running?(filter_part, topic_part)
  filter_part == topic_part || filter_part == '+'
end
logger=(logger_path) click to toggle source
# File lib/paho-mqtt.rb, line 105
def logger=(logger_path)
  file           = File.open(logger_path, "a+")
  file.sync      = true
  log_file       = Logger.new(file)
  log_file.level = Logger::DEBUG
  @logger        = log_file
end
logger?() click to toggle source
# File lib/paho-mqtt.rb, line 117
def logger?
  @logger.is_a?(Logger)
end
match_filter(topics, filters) click to toggle source
# 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