coreMQTT v2.1.1
MQTT 3.1.1 Client Library
core_mqtt_state.h
Go to the documentation of this file.
1/*
2 * coreMQTT v2.1.1
3 * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *
5 * SPDX-License-Identifier: MIT
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
29#ifndef CORE_MQTT_STATE_H
30#define CORE_MQTT_STATE_H
31
32/* *INDENT-OFF* */
33#ifdef __cplusplus
34 extern "C" {
35#endif
36/* *INDENT-ON* */
37
38#include "core_mqtt.h"
39
45#define MQTT_STATE_CURSOR_INITIALIZER ( ( size_t ) 0 )
46
51typedef size_t MQTTStateCursor_t;
52
59typedef enum MQTTStateOperation
60{
61 MQTT_SEND,
62 MQTT_RECEIVE
63} MQTTStateOperation_t;
81MQTTStatus_t MQTT_ReserveState( const MQTTContext_t * pMqttContext,
82 uint16_t packetId,
83 MQTTQoS_t qos );
100MQTTPublishState_t MQTT_CalculateStatePublish( MQTTStateOperation_t opType,
101 MQTTQoS_t qos );
123 uint16_t packetId,
124 MQTTStateOperation_t opType,
125 MQTTQoS_t qos,
126 MQTTPublishState_t * pNewState );
144 uint16_t packetId );
163 MQTTStateOperation_t opType,
164 MQTTQoS_t qos );
188 uint16_t packetId,
189 MQTTPubAckType_t packetType,
190 MQTTStateOperation_t opType,
191 MQTTPublishState_t * pNewState );
212uint16_t MQTT_PubrelToResend( const MQTTContext_t * pMqttContext,
213 MQTTStateCursor_t * pCursor,
214 MQTTPublishState_t * pState );
283/* @[declare_mqtt_publishtoresend] */
284uint16_t MQTT_PublishToResend( const MQTTContext_t * pMqttContext,
285 MQTTStateCursor_t * pCursor );
286/* @[declare_mqtt_publishtoresend] */
287
301const char * MQTT_State_strerror( MQTTPublishState_t state );
304/* *INDENT-OFF* */
305#ifdef __cplusplus
306 }
307#endif
308/* *INDENT-ON* */
309
310#endif /* ifndef CORE_MQTT_STATE_H */
User-facing functions of the MQTT 3.1.1 library.
MQTTStatus_t MQTT_UpdateStateAck(const MQTTContext_t *pMqttContext, uint16_t packetId, MQTTPubAckType_t packetType, MQTTStateOperation_t opType, MQTTPublishState_t *pNewState)
Update the state record for an ACKed publish.
Definition: core_mqtt_state.c:1007
MQTTPublishState_t MQTT_CalculateStateAck(MQTTPubAckType_t packetType, MQTTStateOperation_t opType, MQTTQoS_t qos)
Calculate the state from a PUBACK, PUBREC, PUBREL, or PUBCOMP.
Definition: core_mqtt_state.c:659
MQTTStatus_t MQTT_ReserveState(const MQTTContext_t *pMqttContext, uint16_t packetId, MQTTQoS_t qos)
Reserve an entry for an outgoing QoS 1 or Qos 2 publish.
Definition: core_mqtt_state.c:827
const char * MQTT_State_strerror(MQTTPublishState_t state)
State to string conversion for state engine.
Definition: core_mqtt_state.c:1155
MQTTPublishState_t MQTT_CalculateStatePublish(MQTTStateOperation_t opType, MQTTQoS_t qos)
Calculate the new state for a publish from its qos and operation type.
Definition: core_mqtt_state.c:856
MQTTStatus_t MQTT_UpdateStatePublish(const MQTTContext_t *pMqttContext, uint16_t packetId, MQTTStateOperation_t opType, MQTTQoS_t qos, MQTTPublishState_t *pNewState)
Update the state record for a PUBLISH packet.
Definition: core_mqtt_state.c:885
uint16_t MQTT_PubrelToResend(const MQTTContext_t *pMqttContext, MQTTStateCursor_t *pCursor, MQTTPublishState_t *pState)
Get the packet ID of next pending PUBREL ack to be resent.
Definition: core_mqtt_state.c:1089
MQTTStatus_t MQTT_RemoveStateRecord(const MQTTContext_t *pMqttContext, uint16_t packetId)
Remove the state record for a PUBLISH packet.
Definition: core_mqtt_state.c:959
uint16_t MQTT_PublishToResend(const MQTTContext_t *pMqttContext, MQTTStateCursor_t *pCursor)
Get the packet ID of next pending publish to be resent.
Definition: core_mqtt_state.c:1125
size_t MQTTStateCursor_t
Cursor for iterating through state records.
Definition: core_mqtt_state.h:51
MQTTPublishState_t
The state of QoS 1 or QoS 2 MQTT publishes, used in the state engine.
Definition: core_mqtt.h:108
MQTTPubAckType_t
Packet types used in acknowledging QoS 1 or QoS 2 publishes.
Definition: core_mqtt.h:127
MQTTStatus_t
Return codes from MQTT functions.
Definition: core_mqtt_serializer.h:99
MQTTQoS_t
MQTT Quality of Service values.
Definition: core_mqtt_serializer.h:121
A struct representing an MQTT connection.
Definition: core_mqtt.h:162