MqttSettings.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. Copyright (c) 2013, 2014 Paolo Patierno
  3. All rights reserved. This program and the accompanying materials
  4. are made available under the terms of the Eclipse Public License v1.0
  5. and Eclipse Distribution License v1.0 which accompany this distribution.
  6. The Eclipse Public License is available at
  7. http://www.eclipse.org/legal/epl-v10.html
  8. and the Eclipse Distribution License is available at
  9. http://www.eclipse.org/org/documents/edl-v10.php.
  10. Contributors:
  11. Paolo Patierno - initial API and implementation and/or initial documentation
  12. */
  13. namespace uPLibrary.Networking.M2Mqtt
  14. {
  15. /// <summary>
  16. /// Settings class for the MQTT broker
  17. /// </summary>
  18. public class MqttSettings
  19. {
  20. // default port for MQTT protocol
  21. public const int MQTT_BROKER_DEFAULT_PORT = 1883;
  22. public const int MQTT_BROKER_DEFAULT_SSL_PORT = 8883;
  23. // default timeout on receiving from client
  24. public const int MQTT_DEFAULT_TIMEOUT = 5000;
  25. // max publish, subscribe and unsubscribe retry for QoS Level 1 or 2
  26. public const int MQTT_ATTEMPTS_RETRY = 3;
  27. // delay for retry publish, subscribe and unsubscribe for QoS Level 1 or 2
  28. public const int MQTT_DELAY_RETRY = 10000;
  29. // broker need to receive the first message (CONNECT)
  30. // within a reasonable amount of time after TCP/IP connection
  31. public const int MQTT_CONNECT_TIMEOUT = 5000;
  32. /// <summary>
  33. /// Listening connection port
  34. /// </summary>
  35. public int Port { get; internal set; }
  36. /// <summary>
  37. /// Listening connection SSL port
  38. /// </summary>
  39. public int SslPort { get; internal set; }
  40. /// <summary>
  41. /// Timeout on client connection (before receiving CONNECT message)
  42. /// </summary>
  43. public int TimeoutOnConnection { get; internal set; }
  44. /// <summary>
  45. /// Timeout on receiving
  46. /// </summary>
  47. public int TimeoutOnReceiving { get; internal set; }
  48. /// <summary>
  49. /// Attempts on retry
  50. /// </summary>
  51. public int AttemptsOnRetry { get; internal set; }
  52. /// <summary>
  53. /// Delay on retry
  54. /// </summary>
  55. public int DelayOnRetry { get; internal set; }
  56. /// <summary>
  57. /// Singleton instance of settings
  58. /// </summary>
  59. public static MqttSettings Instance
  60. {
  61. get
  62. {
  63. if (instance == null)
  64. instance = new MqttSettings();
  65. return instance;
  66. }
  67. }
  68. // singleton instance
  69. private static MqttSettings instance;
  70. /// <summary>
  71. /// Constructor
  72. /// </summary>
  73. private MqttSettings()
  74. {
  75. this.Port = MQTT_BROKER_DEFAULT_PORT;
  76. this.SslPort = MQTT_BROKER_DEFAULT_SSL_PORT;
  77. this.TimeoutOnReceiving = MQTT_DEFAULT_TIMEOUT;
  78. this.AttemptsOnRetry = MQTT_ATTEMPTS_RETRY;
  79. this.DelayOnRetry = MQTT_DELAY_RETRY;
  80. this.TimeoutOnConnection = MQTT_CONNECT_TIMEOUT;
  81. }
  82. }
  83. }