mirror of
https://github.com/espressif/esp-mqtt.git
synced 2025-07-29 18:28:24 +02:00
Reduce the includes used in all files.
- To reduce the dependencies to the minimal the number of includes was reduced.
This commit is contained in:
committed by
Euripedes Rocha
parent
fd2d04e687
commit
87fcce72c9
@ -11,7 +11,6 @@
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "esp_err.h"
|
||||
|
||||
#include "esp_event.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -20,8 +19,8 @@ extern "C" {
|
||||
|
||||
#ifndef ESP_EVENT_DECLARE_BASE
|
||||
// Define event loop types if macros not available
|
||||
typedef void * esp_event_loop_handle_t;
|
||||
typedef void * esp_event_handler_t;
|
||||
typedef void *esp_event_loop_handle_t;
|
||||
typedef void *esp_event_handler_t;
|
||||
#endif
|
||||
|
||||
typedef struct esp_mqtt_client *esp_mqtt_client_handle_t;
|
||||
@ -190,7 +189,7 @@ typedef struct {
|
||||
size_t client_key_len; /*!< Length of the buffer pointed to by client_key_pem. May be 0 for null-terminated pem */
|
||||
esp_mqtt_transport_t transport; /*!< overrides URI transport */
|
||||
int refresh_connection_after_ms; /*!< Refresh connection after this value (in milliseconds) */
|
||||
const struct psk_key_hint* psk_hint_key; /*!< Pointer to PSK struct defined in esp_tls.h to enable PSK authentication (as alternative to certificate verification). If not NULL and server/client certificates are NULL, PSK is enabled */
|
||||
const struct psk_key_hint *psk_hint_key; /*!< Pointer to PSK struct defined in esp_tls.h to enable PSK authentication (as alternative to certificate verification). If not NULL and server/client certificates are NULL, PSK is enabled */
|
||||
bool use_global_ca_store; /*!< Use a global ca_store for all the connections in which this bool is set. */
|
||||
int reconnect_timeout_ms; /*!< Reconnect to the broker after this value in miliseconds if auto reconnect is not disabled (defaults to 10s) */
|
||||
const char **alpn_protos; /*!< NULL-terminated list of supported application protocols to be used for ALPN */
|
||||
@ -383,7 +382,7 @@ esp_err_t esp_mqtt_set_config(esp_mqtt_client_handle_t client, const esp_mqtt_cl
|
||||
* @return ESP_ERR_NO_MEM if failed to allocate
|
||||
* ESP_OK on success
|
||||
*/
|
||||
esp_err_t esp_mqtt_client_register_event(esp_mqtt_client_handle_t client, esp_mqtt_event_id_t event, esp_event_handler_t event_handler, void* event_handler_arg);
|
||||
esp_err_t esp_mqtt_client_register_event(esp_mqtt_client_handle_t client, esp_mqtt_event_id_t event, esp_event_handler_t event_handler, void *event_handler_arg);
|
||||
|
||||
/**
|
||||
* @brief Get outbox size
|
||||
|
@ -6,6 +6,7 @@
|
||||
#ifndef _MQTT_OUTOBX_H_
|
||||
#define _MQTT_OUTOBX_H_
|
||||
#include "platform.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -7,21 +7,9 @@
|
||||
#define _ESP_PLATFORM_H__
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/event_groups.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/netdb.h"
|
||||
#include "lwip/dns.h"
|
||||
|
||||
#include "sys/queue.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_system.h"
|
||||
#include <sys/time.h>
|
||||
|
||||
char *platform_create_id_string(void);
|
||||
int platform_random(int max);
|
||||
|
@ -5,8 +5,6 @@
|
||||
#include "esp_log.h"
|
||||
|
||||
#ifndef CONFIG_MQTT_CUSTOM_OUTBOX
|
||||
|
||||
|
||||
static const char *TAG = "OUTBOX";
|
||||
|
||||
typedef struct outbox_item {
|
||||
@ -151,7 +149,7 @@ esp_err_t outbox_set_tick(outbox_handle_t outbox, int msg_id, outbox_tick_t tick
|
||||
item->tick = tick;
|
||||
return ESP_OK;
|
||||
}
|
||||
return ESP_FAIL;
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t outbox_delete_msgtype(outbox_handle_t outbox, int msg_type)
|
||||
|
@ -1,9 +1,11 @@
|
||||
#include "platform.h"
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include "esp_system.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_system.h"
|
||||
#include <sys/time.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
static const char *TAG = "PLATFORM";
|
||||
|
||||
|
@ -1,13 +1,19 @@
|
||||
#include <stdio.h>
|
||||
#include "platform.h"
|
||||
|
||||
#include "esp_event.h"
|
||||
#include "mqtt_client.h"
|
||||
#include "mqtt_msg.h"
|
||||
#include "esp_transport.h"
|
||||
#include "esp_transport_tcp.h"
|
||||
#include "esp_transport_ssl.h"
|
||||
#include "esp_transport_ws.h"
|
||||
#include "esp_log.h"
|
||||
#include "mqtt_outbox.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mqtt_supported_features.h"
|
||||
|
||||
/* using uri parser */
|
||||
@ -112,9 +118,9 @@ struct esp_mqtt_client {
|
||||
TaskHandle_t task_handle;
|
||||
};
|
||||
|
||||
const static int STOPPED_BIT = BIT0;
|
||||
const static int RECONNECT_BIT = BIT1;
|
||||
const static int DISCONNECT_BIT = BIT2;
|
||||
const static int STOPPED_BIT = (1 << 0);
|
||||
const static int RECONNECT_BIT = (1 << 1);
|
||||
const static int DISCONNECT_BIT = (1 << 2);
|
||||
|
||||
static esp_err_t esp_mqtt_dispatch_event(esp_mqtt_client_handle_t client);
|
||||
static esp_err_t esp_mqtt_dispatch_event_with_msgid(esp_mqtt_client_handle_t client);
|
||||
@ -313,7 +319,7 @@ static bool set_if_config(char const *const new_config, char **old_config)
|
||||
if (new_config) {
|
||||
free(*old_config);
|
||||
*old_config = strdup(new_config);
|
||||
if(*old_config == NULL) {
|
||||
if (*old_config == NULL) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -903,7 +909,7 @@ static esp_err_t deliver_publish(esp_mqtt_client_handle_t client)
|
||||
ESP_LOGE(TAG, "%s: mqtt_get_publish_topic() failed", __func__);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
ESP_LOGD(TAG, "%s: msg_topic_len=%u", __func__, msg_topic_len);
|
||||
ESP_LOGD(TAG, "%s: msg_topic_len=%zu", __func__, msg_topic_len);
|
||||
|
||||
// get payload
|
||||
msg_data = mqtt_get_publish_data(msg_buf, &msg_data_len);
|
||||
@ -917,7 +923,7 @@ static esp_err_t deliver_publish(esp_mqtt_client_handle_t client)
|
||||
client->event.total_data_len = msg_data_len + msg_total_len - msg_read_len;
|
||||
|
||||
post_data_event:
|
||||
ESP_LOGD(TAG, "Get data len= %d, topic len=%d, total_data: %d offset: %d", msg_data_len, msg_topic_len,
|
||||
ESP_LOGD(TAG, "Get data len= %zu, topic len=%zu, total_data: %d offset: %zu", msg_data_len, msg_topic_len,
|
||||
client->event.total_data_len, msg_data_offset);
|
||||
client->event.event_id = MQTT_EVENT_DATA;
|
||||
client->event.data = msg_data_len > 0 ? msg_data : NULL;
|
||||
@ -938,7 +944,7 @@ post_data_event:
|
||||
msg_total_len - msg_read_len > buf_len ? buf_len : msg_total_len - msg_read_len,
|
||||
client->config->network_timeout_ms);
|
||||
if (msg_data_len <= 0) {
|
||||
ESP_LOGE(TAG, "Read error or timeout: len_read=%d, errno=%d", msg_data_len, errno);
|
||||
ESP_LOGE(TAG, "Read error or timeout: len_read=%zu, errno=%d", msg_data_len, errno);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
msg_read_len += msg_data_len;
|
||||
@ -1065,7 +1071,7 @@ static int mqtt_message_receive(esp_mqtt_client_handle_t client, int read_poll_t
|
||||
} while ((client->mqtt_state.in_buffer_read_len < 6) && (*(buf - 1) & 0x80));
|
||||
}
|
||||
total_len = mqtt_get_total_length(client->mqtt_state.in_buffer, client->mqtt_state.in_buffer_read_len, &fixed_header_len);
|
||||
ESP_LOGD(TAG, "%s: total message length: %d (already read: %u)", __func__, total_len, client->mqtt_state.in_buffer_read_len);
|
||||
ESP_LOGD(TAG, "%s: total message length: %d (already read: %zu)", __func__, total_len, client->mqtt_state.in_buffer_read_len);
|
||||
client->mqtt_state.message_length = total_len;
|
||||
if (client->mqtt_state.in_buffer_length < total_len) {
|
||||
if (mqtt_get_type(client->mqtt_state.in_buffer) == MQTT_MSG_TYPE_PUBLISH) {
|
||||
@ -1087,7 +1093,7 @@ static int mqtt_message_receive(esp_mqtt_client_handle_t client, int read_poll_t
|
||||
client->mqtt_state.in_buffer_read_len += read_len;
|
||||
buf += read_len;
|
||||
if (client->mqtt_state.in_buffer_read_len < fixed_header_len + 2) {
|
||||
ESP_LOGD(TAG, "%s: transport_read(): message reading left in progress :: total message length: %d (already read: %u)",
|
||||
ESP_LOGD(TAG, "%s: transport_read(): message reading left in progress :: total message length: %d (already read: %zu)",
|
||||
__func__, total_len, client->mqtt_state.in_buffer_read_len);
|
||||
return 0;
|
||||
}
|
||||
@ -1122,12 +1128,12 @@ static int mqtt_message_receive(esp_mqtt_client_handle_t client, int read_poll_t
|
||||
}
|
||||
client->mqtt_state.in_buffer_read_len += read_len;
|
||||
if (client->mqtt_state.in_buffer_read_len < total_len) {
|
||||
ESP_LOGD(TAG, "%s: transport_read(): message reading left in progress :: total message length: %d (already read: %u)",
|
||||
ESP_LOGD(TAG, "%s: transport_read(): message reading left in progress :: total message length: %d (already read: %zu)",
|
||||
__func__, total_len, client->mqtt_state.in_buffer_read_len);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
ESP_LOGD(TAG, "%s: transport_read():%d %d", __func__, client->mqtt_state.in_buffer_read_len, client->mqtt_state.message_length);
|
||||
ESP_LOGD(TAG, "%s: transport_read():%zu %zu", __func__, client->mqtt_state.in_buffer_read_len, client->mqtt_state.message_length);
|
||||
return 1;
|
||||
err:
|
||||
esp_mqtt_client_dispatch_transport_error(client);
|
||||
@ -1174,7 +1180,7 @@ static esp_err_t mqtt_process_receive(esp_mqtt_client_handle_t client)
|
||||
}
|
||||
break;
|
||||
case MQTT_MSG_TYPE_PUBLISH:
|
||||
ESP_LOGD(TAG, "deliver_publish, message_length_read=%d, message_length=%d", client->mqtt_state.in_buffer_read_len, client->mqtt_state.message_length);
|
||||
ESP_LOGD(TAG, "deliver_publish, message_length_read=%zu, message_length=%zu", client->mqtt_state.in_buffer_read_len, client->mqtt_state.message_length);
|
||||
if (deliver_publish(client) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to deliver publish message id=%d", msg_id);
|
||||
return ESP_FAIL;
|
||||
@ -1265,10 +1271,10 @@ static esp_err_t mqtt_resend_queued(esp_mqtt_client_handle_t client, outbox_item
|
||||
|
||||
// check if it was QoS-0 publish message
|
||||
if (client->mqtt_state.pending_msg_type == MQTT_MSG_TYPE_PUBLISH && client->mqtt_state.pending_publish_qos == 0) {
|
||||
// delete all qos0 publish messages once we process them
|
||||
if (outbox_delete_item(client->outbox, item) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to remove queued qos0 message from the outbox");
|
||||
}
|
||||
// delete all qos0 publish messages once we process them
|
||||
if (outbox_delete_item(client->outbox, item) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to remove queued qos0 message from the outbox");
|
||||
}
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
@ -1627,7 +1633,7 @@ int esp_mqtt_client_unsubscribe(esp_mqtt_client_handle_t client, const char *top
|
||||
}
|
||||
|
||||
static inline int mqtt_client_enqueue_priv(esp_mqtt_client_handle_t client, const char *topic, const char *data,
|
||||
int len, int qos, int retain, bool store)
|
||||
int len, int qos, int retain, bool store)
|
||||
{
|
||||
uint16_t pending_msg_id = 0;
|
||||
|
||||
@ -1641,9 +1647,9 @@ static inline int mqtt_client_enqueue_priv(esp_mqtt_client_handle_t client, cons
|
||||
}
|
||||
|
||||
mqtt_message_t *publish_msg = mqtt_msg_publish(&client->mqtt_state.mqtt_connection,
|
||||
topic, data, len,
|
||||
qos, retain,
|
||||
&pending_msg_id);
|
||||
topic, data, len,
|
||||
qos, retain,
|
||||
&pending_msg_id);
|
||||
|
||||
if (publish_msg->length == 0) {
|
||||
ESP_LOGE(TAG, "Publish message cannot be created");
|
||||
|
Reference in New Issue
Block a user