![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
test
aws-iot/src/aws_iot_mqtt_client.cpp@0:cd5404401c2f, 2017-04-12 (annotated)
- Committer:
- peyo
- Date:
- Wed Apr 12 14:07:09 2017 +0200
- Revision:
- 0:cd5404401c2f
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
peyo |
0:cd5404401c2f | 1 | /* |
peyo |
0:cd5404401c2f | 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
peyo |
0:cd5404401c2f | 3 | * |
peyo |
0:cd5404401c2f | 4 | * Licensed under the Apache License, Version 2.0 (the "License"). |
peyo |
0:cd5404401c2f | 5 | * You may not use this file except in compliance with the License. |
peyo |
0:cd5404401c2f | 6 | * A copy of the License is located at |
peyo |
0:cd5404401c2f | 7 | * |
peyo |
0:cd5404401c2f | 8 | * http://aws.amazon.com/apache2.0 |
peyo |
0:cd5404401c2f | 9 | * |
peyo |
0:cd5404401c2f | 10 | * or in the "license" file accompanying this file. This file is distributed |
peyo |
0:cd5404401c2f | 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
peyo |
0:cd5404401c2f | 12 | * express or implied. See the License for the specific language governing |
peyo |
0:cd5404401c2f | 13 | * permissions and limitations under the License. |
peyo |
0:cd5404401c2f | 14 | */ |
peyo |
0:cd5404401c2f | 15 | |
peyo |
0:cd5404401c2f | 16 | // Based on Eclipse Paho. |
peyo |
0:cd5404401c2f | 17 | /******************************************************************************* |
peyo |
0:cd5404401c2f | 18 | * Copyright (c) 2014 IBM Corp. |
peyo |
0:cd5404401c2f | 19 | * |
peyo |
0:cd5404401c2f | 20 | * All rights reserved. This program and the accompanying materials |
peyo |
0:cd5404401c2f | 21 | * are made available under the terms of the Eclipse Public License v1.0 |
peyo |
0:cd5404401c2f | 22 | * and Eclipse Distribution License v1.0 which accompany this distribution. |
peyo |
0:cd5404401c2f | 23 | * |
peyo |
0:cd5404401c2f | 24 | * The Eclipse Public License is available at |
peyo |
0:cd5404401c2f | 25 | * http://www.eclipse.org/legal/epl-v10.html |
peyo |
0:cd5404401c2f | 26 | * and the Eclipse Distribution License is available at |
peyo |
0:cd5404401c2f | 27 | * http://www.eclipse.org/org/documents/edl-v10.php. |
peyo |
0:cd5404401c2f | 28 | * |
peyo |
0:cd5404401c2f | 29 | * Contributors: |
peyo |
0:cd5404401c2f | 30 | * Allan Stockdill-Mander/Ian Craggs - initial API and implementation and/or initial documentation |
peyo |
0:cd5404401c2f | 31 | *******************************************************************************/ |
peyo |
0:cd5404401c2f | 32 | |
peyo |
0:cd5404401c2f | 33 | /** |
peyo |
0:cd5404401c2f | 34 | * @file aws_iot_mqtt_client.c |
peyo |
0:cd5404401c2f | 35 | * @brief MQTT client API definitions |
peyo |
0:cd5404401c2f | 36 | */ |
peyo |
0:cd5404401c2f | 37 | |
peyo |
0:cd5404401c2f | 38 | #ifdef __cplusplus |
peyo |
0:cd5404401c2f | 39 | extern "C" { |
peyo |
0:cd5404401c2f | 40 | #endif |
peyo |
0:cd5404401c2f | 41 | |
peyo |
0:cd5404401c2f | 42 | #include "aws_iot_log.h" |
peyo |
0:cd5404401c2f | 43 | #include "aws_iot_mqtt_client_interface.h" |
peyo |
0:cd5404401c2f | 44 | |
peyo |
0:cd5404401c2f | 45 | #ifdef _ENABLE_THREAD_SUPPORT_ |
peyo |
0:cd5404401c2f | 46 | #include "threads_interface.h" |
peyo |
0:cd5404401c2f | 47 | #endif |
peyo |
0:cd5404401c2f | 48 | |
peyo |
0:cd5404401c2f | 49 | const IoT_Client_Init_Params iotClientInitParamsDefault = IoT_Client_Init_Params_initializer; |
peyo |
0:cd5404401c2f | 50 | const IoT_MQTT_Will_Options iotMqttWillOptionsDefault = IoT_MQTT_Will_Options_Initializer; |
peyo |
0:cd5404401c2f | 51 | const IoT_Client_Connect_Params iotClientConnectParamsDefault = IoT_Client_Connect_Params_initializer; |
peyo |
0:cd5404401c2f | 52 | |
peyo |
0:cd5404401c2f | 53 | ClientState aws_iot_mqtt_get_client_state(AWS_IoT_Client *pClient) { |
peyo |
0:cd5404401c2f | 54 | FUNC_ENTRY; |
peyo |
0:cd5404401c2f | 55 | if(NULL == pClient) { |
peyo |
0:cd5404401c2f | 56 | return CLIENT_STATE_INVALID; |
peyo |
0:cd5404401c2f | 57 | } |
peyo |
0:cd5404401c2f | 58 | |
peyo |
0:cd5404401c2f | 59 | FUNC_EXIT_RC(pClient->clientStatus.clientState); |
peyo |
0:cd5404401c2f | 60 | } |
peyo |
0:cd5404401c2f | 61 | |
peyo |
0:cd5404401c2f | 62 | #ifdef _ENABLE_THREAD_SUPPORT_ |
peyo |
0:cd5404401c2f | 63 | IoT_Error_t aws_iot_mqtt_client_lock_mutex(AWS_IoT_Client *pClient, IoT_Mutex_t *pMutex) { |
peyo |
0:cd5404401c2f | 64 | FUNC_ENTRY; |
peyo |
0:cd5404401c2f | 65 | IoT_Error_t threadRc = FAILURE; |
peyo |
0:cd5404401c2f | 66 | |
peyo |
0:cd5404401c2f | 67 | if(NULL == pClient || NULL == pMutex){ |
peyo |
0:cd5404401c2f | 68 | FUNC_EXIT_RC(NULL_VALUE_ERROR); |
peyo |
0:cd5404401c2f | 69 | } |
peyo |
0:cd5404401c2f | 70 | |
peyo |
0:cd5404401c2f | 71 | if(false == pClient->clientData.isBlockOnThreadLockEnabled) { |
peyo |
0:cd5404401c2f | 72 | threadRc = aws_iot_thread_mutex_trylock(pMutex); |
peyo |
0:cd5404401c2f | 73 | } else { |
peyo |
0:cd5404401c2f | 74 | threadRc = aws_iot_thread_mutex_lock(pMutex); |
peyo |
0:cd5404401c2f | 75 | /* Should never return Error because the above request blocks until lock is obtained */ |
peyo |
0:cd5404401c2f | 76 | } |
peyo |
0:cd5404401c2f | 77 | |
peyo |
0:cd5404401c2f | 78 | if(SUCCESS != threadRc) { |
peyo |
0:cd5404401c2f | 79 | FUNC_EXIT_RC(threadRc); |
peyo |
0:cd5404401c2f | 80 | } |
peyo |
0:cd5404401c2f | 81 | |
peyo |
0:cd5404401c2f | 82 | FUNC_EXIT_RC(SUCCESS); |
peyo |
0:cd5404401c2f | 83 | } |
peyo |
0:cd5404401c2f | 84 | |
peyo |
0:cd5404401c2f | 85 | IoT_Error_t aws_iot_mqtt_client_unlock_mutex(AWS_IoT_Client *pClient, IoT_Mutex_t *pMutex) { |
peyo |
0:cd5404401c2f | 86 | if(NULL == pClient || NULL == pMutex) { |
peyo |
0:cd5404401c2f | 87 | return NULL_VALUE_ERROR; |
peyo |
0:cd5404401c2f | 88 | } |
peyo |
0:cd5404401c2f | 89 | IOT_UNUSED(pClient); |
peyo |
0:cd5404401c2f | 90 | return aws_iot_thread_mutex_unlock(pMutex); |
peyo |
0:cd5404401c2f | 91 | } |
peyo |
0:cd5404401c2f | 92 | #endif |
peyo |
0:cd5404401c2f | 93 | |
peyo |
0:cd5404401c2f | 94 | IoT_Error_t aws_iot_mqtt_set_client_state(AWS_IoT_Client *pClient, ClientState expectedCurrentState, |
peyo |
0:cd5404401c2f | 95 | ClientState newState) { |
peyo |
0:cd5404401c2f | 96 | IoT_Error_t rc; |
peyo |
0:cd5404401c2f | 97 | #ifdef _ENABLE_THREAD_SUPPORT_ |
peyo |
0:cd5404401c2f | 98 | IoT_Error_t threadRc = FAILURE; |
peyo |
0:cd5404401c2f | 99 | #endif |
peyo |
0:cd5404401c2f | 100 | |
peyo |
0:cd5404401c2f | 101 | FUNC_ENTRY; |
peyo |
0:cd5404401c2f | 102 | if(NULL == pClient) { |
peyo |
0:cd5404401c2f | 103 | FUNC_EXIT_RC(NULL_VALUE_ERROR); |
peyo |
0:cd5404401c2f | 104 | } |
peyo |
0:cd5404401c2f | 105 | |
peyo |
0:cd5404401c2f | 106 | #ifdef _ENABLE_THREAD_SUPPORT_ |
peyo |
0:cd5404401c2f | 107 | rc = aws_iot_mqtt_client_lock_mutex(pClient, &(pClient->clientData.state_change_mutex)); |
peyo |
0:cd5404401c2f | 108 | if(SUCCESS != rc) { |
peyo |
0:cd5404401c2f | 109 | return rc; |
peyo |
0:cd5404401c2f | 110 | } |
peyo |
0:cd5404401c2f | 111 | #endif |
peyo |
0:cd5404401c2f | 112 | if(expectedCurrentState == aws_iot_mqtt_get_client_state(pClient)) { |
peyo |
0:cd5404401c2f | 113 | pClient->clientStatus.clientState = newState; |
peyo |
0:cd5404401c2f | 114 | rc = SUCCESS; |
peyo |
0:cd5404401c2f | 115 | } else { |
peyo |
0:cd5404401c2f | 116 | rc = MQTT_UNEXPECTED_CLIENT_STATE_ERROR; |
peyo |
0:cd5404401c2f | 117 | } |
peyo |
0:cd5404401c2f | 118 | |
peyo |
0:cd5404401c2f | 119 | #ifdef _ENABLE_THREAD_SUPPORT_ |
peyo |
0:cd5404401c2f | 120 | threadRc = aws_iot_mqtt_client_unlock_mutex(pClient, &(pClient->clientData.state_change_mutex)); |
peyo |
0:cd5404401c2f | 121 | if(SUCCESS == rc && SUCCESS != threadRc) { |
peyo |
0:cd5404401c2f | 122 | rc = threadRc; |
peyo |
0:cd5404401c2f | 123 | } |
peyo |
0:cd5404401c2f | 124 | #endif |
peyo |
0:cd5404401c2f | 125 | |
peyo |
0:cd5404401c2f | 126 | FUNC_EXIT_RC(rc); |
peyo |
0:cd5404401c2f | 127 | } |
peyo |
0:cd5404401c2f | 128 | |
peyo |
0:cd5404401c2f | 129 | IoT_Error_t aws_iot_mqtt_set_connect_params(AWS_IoT_Client *pClient, IoT_Client_Connect_Params *pNewConnectParams) { |
peyo |
0:cd5404401c2f | 130 | FUNC_ENTRY; |
peyo |
0:cd5404401c2f | 131 | if(NULL == pClient || NULL == pNewConnectParams) { |
peyo |
0:cd5404401c2f | 132 | FUNC_EXIT_RC(NULL_VALUE_ERROR); |
peyo |
0:cd5404401c2f | 133 | } |
peyo |
0:cd5404401c2f | 134 | |
peyo |
0:cd5404401c2f | 135 | pClient->clientData.options.isWillMsgPresent = pNewConnectParams->isWillMsgPresent; |
peyo |
0:cd5404401c2f | 136 | pClient->clientData.options.MQTTVersion = pNewConnectParams->MQTTVersion; |
peyo |
0:cd5404401c2f | 137 | pClient->clientData.options.pClientID = pNewConnectParams->pClientID; |
peyo |
0:cd5404401c2f | 138 | pClient->clientData.options.clientIDLen = pNewConnectParams->clientIDLen; |
peyo |
0:cd5404401c2f | 139 | pClient->clientData.options.pUsername = pNewConnectParams->pUsername; |
peyo |
0:cd5404401c2f | 140 | pClient->clientData.options.usernameLen = pNewConnectParams->usernameLen; |
peyo |
0:cd5404401c2f | 141 | pClient->clientData.options.pPassword = pNewConnectParams->pUsername; |
peyo |
0:cd5404401c2f | 142 | pClient->clientData.options.passwordLen = pNewConnectParams->passwordLen; |
peyo |
0:cd5404401c2f | 143 | pClient->clientData.options.will.pTopicName = pNewConnectParams->will.pTopicName; |
peyo |
0:cd5404401c2f | 144 | pClient->clientData.options.will.topicNameLen = pNewConnectParams->will.topicNameLen; |
peyo |
0:cd5404401c2f | 145 | pClient->clientData.options.will.pMessage = pNewConnectParams->will.pMessage; |
peyo |
0:cd5404401c2f | 146 | pClient->clientData.options.will.msgLen = pNewConnectParams->will.msgLen; |
peyo |
0:cd5404401c2f | 147 | pClient->clientData.options.will.qos = pNewConnectParams->will.qos; |
peyo |
0:cd5404401c2f | 148 | pClient->clientData.options.will.isRetained = pNewConnectParams->will.isRetained; |
peyo |
0:cd5404401c2f | 149 | pClient->clientData.options.keepAliveIntervalInSec = pNewConnectParams->keepAliveIntervalInSec; |
peyo |
0:cd5404401c2f | 150 | pClient->clientData.options.isCleanSession = pNewConnectParams->isCleanSession; |
peyo |
0:cd5404401c2f | 151 | |
peyo |
0:cd5404401c2f | 152 | FUNC_EXIT_RC(SUCCESS); |
peyo |
0:cd5404401c2f | 153 | } |
peyo |
0:cd5404401c2f | 154 | |
peyo |
0:cd5404401c2f | 155 | IoT_Error_t aws_iot_mqtt_init(AWS_IoT_Client *pClient, IoT_Client_Init_Params *pInitParams) { |
peyo |
0:cd5404401c2f | 156 | uint32_t i; |
peyo |
0:cd5404401c2f | 157 | IoT_Error_t rc; |
peyo |
0:cd5404401c2f | 158 | IoT_Client_Connect_Params default_options = IoT_Client_Connect_Params_initializer; |
peyo |
0:cd5404401c2f | 159 | |
peyo |
0:cd5404401c2f | 160 | FUNC_ENTRY; |
peyo |
0:cd5404401c2f | 161 | |
peyo |
0:cd5404401c2f | 162 | if(NULL == pClient || NULL == pInitParams || NULL == pInitParams->pHostURL || 0 == pInitParams->port /*|| |
peyo |
0:cd5404401c2f | 163 | NULL == pInitParams->pRootCALocation || NULL == pInitParams->pDevicePrivateKeyLocation || |
peyo |
0:cd5404401c2f | 164 | NULL == pInitParams->pDeviceCertLocation*/) { |
peyo |
0:cd5404401c2f | 165 | FUNC_EXIT_RC(NULL_VALUE_ERROR); |
peyo |
0:cd5404401c2f | 166 | } |
peyo |
0:cd5404401c2f | 167 | |
peyo |
0:cd5404401c2f | 168 | for(i = 0; i < AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS; ++i) { |
peyo |
0:cd5404401c2f | 169 | pClient->clientData.messageHandlers[i].topicName = NULL; |
peyo |
0:cd5404401c2f | 170 | pClient->clientData.messageHandlers[i].pApplicationHandler = NULL; |
peyo |
0:cd5404401c2f | 171 | pClient->clientData.messageHandlers[i].pApplicationHandlerData = NULL; |
peyo |
0:cd5404401c2f | 172 | pClient->clientData.messageHandlers[i].qos = QOS0; |
peyo |
0:cd5404401c2f | 173 | } |
peyo |
0:cd5404401c2f | 174 | |
peyo |
0:cd5404401c2f | 175 | pClient->clientData.packetTimeoutMs = pInitParams->mqttPacketTimeout_ms; |
peyo |
0:cd5404401c2f | 176 | pClient->clientData.commandTimeoutMs = pInitParams->mqttCommandTimeout_ms; |
peyo |
0:cd5404401c2f | 177 | pClient->clientData.writeBufSize = AWS_IOT_MQTT_TX_BUF_LEN; |
peyo |
0:cd5404401c2f | 178 | pClient->clientData.readBufSize = AWS_IOT_MQTT_RX_BUF_LEN; |
peyo |
0:cd5404401c2f | 179 | pClient->clientData.counterNetworkDisconnected = 0; |
peyo |
0:cd5404401c2f | 180 | pClient->clientData.disconnectHandler = pInitParams->disconnectHandler; |
peyo |
0:cd5404401c2f | 181 | pClient->clientData.disconnectHandlerData = pInitParams->disconnectHandlerData; |
peyo |
0:cd5404401c2f | 182 | pClient->clientData.nextPacketId = 1; |
peyo |
0:cd5404401c2f | 183 | |
peyo |
0:cd5404401c2f | 184 | /* Initialize default connection options */ |
peyo |
0:cd5404401c2f | 185 | rc = aws_iot_mqtt_set_connect_params(pClient, &default_options); |
peyo |
0:cd5404401c2f | 186 | if(SUCCESS != rc) { |
peyo |
0:cd5404401c2f | 187 | FUNC_EXIT_RC(rc); |
peyo |
0:cd5404401c2f | 188 | } |
peyo |
0:cd5404401c2f | 189 | |
peyo |
0:cd5404401c2f | 190 | #ifdef _ENABLE_THREAD_SUPPORT_ |
peyo |
0:cd5404401c2f | 191 | pClient->clientData.isBlockOnThreadLockEnabled = pInitParams->isBlockOnThreadLockEnabled; |
peyo |
0:cd5404401c2f | 192 | rc = aws_iot_thread_mutex_init(&(pClient->clientData.state_change_mutex)); |
peyo |
0:cd5404401c2f | 193 | if(SUCCESS != rc) { |
peyo |
0:cd5404401c2f | 194 | FUNC_EXIT_RC(rc); |
peyo |
0:cd5404401c2f | 195 | } |
peyo |
0:cd5404401c2f | 196 | rc = aws_iot_thread_mutex_init(&(pClient->clientData.tls_read_mutex)); |
peyo |
0:cd5404401c2f | 197 | if(SUCCESS != rc) { |
peyo |
0:cd5404401c2f | 198 | FUNC_EXIT_RC(rc); |
peyo |
0:cd5404401c2f | 199 | } |
peyo |
0:cd5404401c2f | 200 | rc = aws_iot_thread_mutex_init(&(pClient->clientData.tls_write_mutex)); |
peyo |
0:cd5404401c2f | 201 | if(SUCCESS != rc) { |
peyo |
0:cd5404401c2f | 202 | FUNC_EXIT_RC(rc); |
peyo |
0:cd5404401c2f | 203 | } |
peyo |
0:cd5404401c2f | 204 | #endif |
peyo |
0:cd5404401c2f | 205 | |
peyo |
0:cd5404401c2f | 206 | pClient->clientStatus.isPingOutstanding = 0; |
peyo |
0:cd5404401c2f | 207 | pClient->clientStatus.isAutoReconnectEnabled = pInitParams->enableAutoReconnect; |
peyo |
0:cd5404401c2f | 208 | |
peyo |
0:cd5404401c2f | 209 | rc = iot_tls_init(&(pClient->networkStack), pInitParams->pRootCALocation, pInitParams->pDeviceCertLocation, |
peyo |
0:cd5404401c2f | 210 | pInitParams->pDevicePrivateKeyLocation, pInitParams->pHostURL, pInitParams->port, |
peyo |
0:cd5404401c2f | 211 | pInitParams->tlsHandshakeTimeout_ms, pInitParams->isSSLHostnameVerify); |
peyo |
0:cd5404401c2f | 212 | |
peyo |
0:cd5404401c2f | 213 | if(SUCCESS != rc) { |
peyo |
0:cd5404401c2f | 214 | pClient->clientStatus.clientState = CLIENT_STATE_INVALID; |
peyo |
0:cd5404401c2f | 215 | FUNC_EXIT_RC(rc); |
peyo |
0:cd5404401c2f | 216 | } |
peyo |
0:cd5404401c2f | 217 | |
peyo |
0:cd5404401c2f | 218 | init_timer(&(pClient->pingTimer)); |
peyo |
0:cd5404401c2f | 219 | init_timer(&(pClient->reconnectDelayTimer)); |
peyo |
0:cd5404401c2f | 220 | |
peyo |
0:cd5404401c2f | 221 | pClient->clientStatus.clientState = CLIENT_STATE_INITIALIZED; |
peyo |
0:cd5404401c2f | 222 | |
peyo |
0:cd5404401c2f | 223 | FUNC_EXIT_RC(SUCCESS); |
peyo |
0:cd5404401c2f | 224 | } |
peyo |
0:cd5404401c2f | 225 | |
peyo |
0:cd5404401c2f | 226 | uint16_t aws_iot_mqtt_get_next_packet_id(AWS_IoT_Client *pClient) { |
peyo |
0:cd5404401c2f | 227 | return pClient->clientData.nextPacketId = (uint16_t) ((MAX_PACKET_ID == pClient->clientData.nextPacketId) ? 1 : ( |
peyo |
0:cd5404401c2f | 228 | pClient->clientData.nextPacketId + 1)); |
peyo |
0:cd5404401c2f | 229 | } |
peyo |
0:cd5404401c2f | 230 | |
peyo |
0:cd5404401c2f | 231 | bool aws_iot_mqtt_is_client_connected(AWS_IoT_Client *pClient) { |
peyo |
0:cd5404401c2f | 232 | bool isConnected; |
peyo |
0:cd5404401c2f | 233 | |
peyo |
0:cd5404401c2f | 234 | FUNC_ENTRY; |
peyo |
0:cd5404401c2f | 235 | |
peyo |
0:cd5404401c2f | 236 | if(NULL == pClient) { |
peyo |
0:cd5404401c2f | 237 | IOT_WARN(" Client is null! "); |
peyo |
0:cd5404401c2f | 238 | FUNC_EXIT_RC(false); |
peyo |
0:cd5404401c2f | 239 | } |
peyo |
0:cd5404401c2f | 240 | |
peyo |
0:cd5404401c2f | 241 | switch(pClient->clientStatus.clientState) { |
peyo |
0:cd5404401c2f | 242 | case CLIENT_STATE_INVALID: |
peyo |
0:cd5404401c2f | 243 | case CLIENT_STATE_INITIALIZED: |
peyo |
0:cd5404401c2f | 244 | case CLIENT_STATE_CONNECTING: |
peyo |
0:cd5404401c2f | 245 | isConnected = false; |
peyo |
0:cd5404401c2f | 246 | break; |
peyo |
0:cd5404401c2f | 247 | case CLIENT_STATE_CONNECTED_IDLE: |
peyo |
0:cd5404401c2f | 248 | case CLIENT_STATE_CONNECTED_YIELD_IN_PROGRESS: |
peyo |
0:cd5404401c2f | 249 | case CLIENT_STATE_CONNECTED_PUBLISH_IN_PROGRESS: |
peyo |
0:cd5404401c2f | 250 | case CLIENT_STATE_CONNECTED_SUBSCRIBE_IN_PROGRESS: |
peyo |
0:cd5404401c2f | 251 | case CLIENT_STATE_CONNECTED_UNSUBSCRIBE_IN_PROGRESS: |
peyo |
0:cd5404401c2f | 252 | case CLIENT_STATE_CONNECTED_RESUBSCRIBE_IN_PROGRESS: |
peyo |
0:cd5404401c2f | 253 | case CLIENT_STATE_CONNECTED_WAIT_FOR_CB_RETURN: |
peyo |
0:cd5404401c2f | 254 | isConnected = true; |
peyo |
0:cd5404401c2f | 255 | break; |
peyo |
0:cd5404401c2f | 256 | case CLIENT_STATE_DISCONNECTING: |
peyo |
0:cd5404401c2f | 257 | case CLIENT_STATE_DISCONNECTED_ERROR: |
peyo |
0:cd5404401c2f | 258 | case CLIENT_STATE_DISCONNECTED_MANUALLY: |
peyo |
0:cd5404401c2f | 259 | case CLIENT_STATE_PENDING_RECONNECT: |
peyo |
0:cd5404401c2f | 260 | default: |
peyo |
0:cd5404401c2f | 261 | isConnected = false; |
peyo |
0:cd5404401c2f | 262 | break; |
peyo |
0:cd5404401c2f | 263 | } |
peyo |
0:cd5404401c2f | 264 | |
peyo |
0:cd5404401c2f | 265 | FUNC_EXIT_RC(isConnected); |
peyo |
0:cd5404401c2f | 266 | } |
peyo |
0:cd5404401c2f | 267 | |
peyo |
0:cd5404401c2f | 268 | bool aws_iot_is_autoreconnect_enabled(AWS_IoT_Client *pClient) { |
peyo |
0:cd5404401c2f | 269 | FUNC_ENTRY; |
peyo |
0:cd5404401c2f | 270 | if(NULL == pClient) { |
peyo |
0:cd5404401c2f | 271 | IOT_WARN(" Client is null! "); |
peyo |
0:cd5404401c2f | 272 | FUNC_EXIT_RC(false); |
peyo |
0:cd5404401c2f | 273 | } |
peyo |
0:cd5404401c2f | 274 | |
peyo |
0:cd5404401c2f | 275 | FUNC_EXIT_RC(pClient->clientStatus.isAutoReconnectEnabled); |
peyo |
0:cd5404401c2f | 276 | } |
peyo |
0:cd5404401c2f | 277 | |
peyo |
0:cd5404401c2f | 278 | IoT_Error_t aws_iot_mqtt_autoreconnect_set_status(AWS_IoT_Client *pClient, bool newStatus) { |
peyo |
0:cd5404401c2f | 279 | FUNC_ENTRY; |
peyo |
0:cd5404401c2f | 280 | if(NULL == pClient) { |
peyo |
0:cd5404401c2f | 281 | FUNC_EXIT_RC(NULL_VALUE_ERROR); |
peyo |
0:cd5404401c2f | 282 | } |
peyo |
0:cd5404401c2f | 283 | pClient->clientStatus.isAutoReconnectEnabled = newStatus; |
peyo |
0:cd5404401c2f | 284 | FUNC_EXIT_RC(SUCCESS); |
peyo |
0:cd5404401c2f | 285 | } |
peyo |
0:cd5404401c2f | 286 | |
peyo |
0:cd5404401c2f | 287 | IoT_Error_t aws_iot_mqtt_set_disconnect_handler(AWS_IoT_Client *pClient, iot_disconnect_handler pDisconnectHandler, |
peyo |
0:cd5404401c2f | 288 | void *pDisconnectHandlerData) { |
peyo |
0:cd5404401c2f | 289 | FUNC_ENTRY; |
peyo |
0:cd5404401c2f | 290 | if(NULL == pClient || NULL == pDisconnectHandler) { |
peyo |
0:cd5404401c2f | 291 | FUNC_EXIT_RC(NULL_VALUE_ERROR); |
peyo |
0:cd5404401c2f | 292 | } |
peyo |
0:cd5404401c2f | 293 | |
peyo |
0:cd5404401c2f | 294 | pClient->clientData.disconnectHandler = pDisconnectHandler; |
peyo |
0:cd5404401c2f | 295 | pClient->clientData.disconnectHandlerData = pDisconnectHandlerData; |
peyo |
0:cd5404401c2f | 296 | FUNC_EXIT_RC(SUCCESS); |
peyo |
0:cd5404401c2f | 297 | } |
peyo |
0:cd5404401c2f | 298 | |
peyo |
0:cd5404401c2f | 299 | uint32_t aws_iot_mqtt_get_network_disconnected_count(AWS_IoT_Client *pClient) { |
peyo |
0:cd5404401c2f | 300 | return pClient->clientData.counterNetworkDisconnected; |
peyo |
0:cd5404401c2f | 301 | } |
peyo |
0:cd5404401c2f | 302 | |
peyo |
0:cd5404401c2f | 303 | void aws_iot_mqtt_reset_network_disconnected_count(AWS_IoT_Client *pClient) { |
peyo |
0:cd5404401c2f | 304 | pClient->clientData.counterNetworkDisconnected = 0; |
peyo |
0:cd5404401c2f | 305 | } |
peyo |
0:cd5404401c2f | 306 | |
peyo |
0:cd5404401c2f | 307 | #ifdef __cplusplus |
peyo |
0:cd5404401c2f | 308 | } |
peyo |
0:cd5404401c2f | 309 | #endif |
peyo |
0:cd5404401c2f | 310 |