mqtt_priv.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * @file
  3. * MQTT client (private interface)
  4. */
  5. /*
  6. * Copyright (c) 2016 Erik Andersson
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without modification,
  10. * are permitted provided that the following conditions are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * 3. The name of the author may not be used to endorse or promote products
  18. * derived from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  21. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  22. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  23. * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  25. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  28. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  29. * OF SUCH DAMAGE.
  30. *
  31. * This file is part of the lwIP TCP/IP stack.
  32. *
  33. * Author: Erik Andersson
  34. *
  35. */
  36. #ifndef LWIP_HDR_APPS_MQTT_PRIV_H
  37. #define LWIP_HDR_APPS_MQTT_PRIV_H
  38. #include "lwip/apps/mqtt.h"
  39. #include "lwip/altcp.h"
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /** Pending request item, binds application callback to pending server requests */
  44. struct mqtt_request_t
  45. {
  46. /** Next item in list, NULL means this is the last in chain,
  47. next pointing at itself means request is unallocated */
  48. struct mqtt_request_t *next;
  49. /** Callback to upper layer */
  50. mqtt_request_cb_t cb;
  51. void *arg;
  52. /** MQTT packet identifier */
  53. u16_t pkt_id;
  54. /** Expire time relative to element before this */
  55. u16_t timeout_diff;
  56. };
  57. /** Ring buffer */
  58. struct mqtt_ringbuf_t {
  59. u16_t put;
  60. u16_t get;
  61. u8_t buf[MQTT_OUTPUT_RINGBUF_SIZE];
  62. };
  63. /** MQTT client */
  64. struct mqtt_client_s
  65. {
  66. /** Timers and timeouts */
  67. u16_t cyclic_tick;
  68. u16_t keep_alive;
  69. u16_t server_watchdog;
  70. /** Packet identifier generator*/
  71. u16_t pkt_id_seq;
  72. /** Packet identifier of pending incoming publish */
  73. u16_t inpub_pkt_id;
  74. /** Connection state */
  75. u8_t conn_state;
  76. struct altcp_pcb *conn;
  77. /** Connection callback */
  78. void *connect_arg;
  79. mqtt_connection_cb_t connect_cb;
  80. /** Pending requests to server */
  81. struct mqtt_request_t *pend_req_queue;
  82. struct mqtt_request_t req_list[MQTT_REQ_MAX_IN_FLIGHT];
  83. void *inpub_arg;
  84. /** Incoming data callback */
  85. mqtt_incoming_data_cb_t data_cb;
  86. mqtt_incoming_publish_cb_t pub_cb;
  87. /** Input */
  88. u32_t msg_idx;
  89. u8_t rx_buffer[MQTT_VAR_HEADER_BUFFER_LEN];
  90. /** Output ring-buffer */
  91. struct mqtt_ringbuf_t output;
  92. };
  93. #ifdef __cplusplus
  94. }
  95. #endif
  96. #endif /* LWIP_HDR_APPS_MQTT_PRIV_H */