coreMQTT  v1.1.2
MQTT 3.1.1 Client Library
core_mqtt_state.h
Go to the documentation of this file.
1 /*
2  * coreMQTT v1.1.2
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
27 #ifndef CORE_MQTT_STATE_H
28 #define CORE_MQTT_STATE_H
29 
30 /* *INDENT-OFF* */
31 #ifdef __cplusplus
32  extern "C" {
33 #endif
34 /* *INDENT-ON* */
35 
36 #include "core_mqtt.h"
37 
43 #define MQTT_STATE_CURSOR_INITIALIZER ( ( size_t ) 0 )
44 
49 typedef size_t MQTTStateCursor_t;
50 
57 typedef enum MQTTStateOperation
58 {
59  MQTT_SEND,
60  MQTT_RECEIVE
61 } MQTTStateOperation_t;
80  uint16_t packetId,
81  MQTTQoS_t qos );
98 MQTTPublishState_t MQTT_CalculateStatePublish( MQTTStateOperation_t opType,
99  MQTTQoS_t qos );
121  uint16_t packetId,
122  MQTTStateOperation_t opType,
123  MQTTQoS_t qos,
124  MQTTPublishState_t * pNewState );
143  MQTTStateOperation_t opType,
144  MQTTQoS_t qos );
168  uint16_t packetId,
169  MQTTPubAckType_t packetType,
170  MQTTStateOperation_t opType,
171  MQTTPublishState_t * pNewState );
192 uint16_t MQTT_PubrelToResend( const MQTTContext_t * pMqttContext,
193  MQTTStateCursor_t * pCursor,
194  MQTTPublishState_t * pState );
263 /* @[declare_mqtt_publishtoresend] */
264 uint16_t MQTT_PublishToResend( const MQTTContext_t * pMqttContext,
265  MQTTStateCursor_t * pCursor );
266 /* @[declare_mqtt_publishtoresend] */
267 
281 const char * MQTT_State_strerror( MQTTPublishState_t state );
284 /* *INDENT-OFF* */
285 #ifdef __cplusplus
286  }
287 #endif
288 /* *INDENT-ON* */
289 
290 #endif /* ifndef CORE_MQTT_STATE_H */
MQTTPublishState_t
MQTTPublishState_t
The state of QoS 1 or QoS 2 MQTT publishes, used in the state engine.
Definition: core_mqtt.h:115
MQTT_PubrelToResend
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:989
MQTT_UpdateStatePublish
MQTTStatus_t MQTT_UpdateStatePublish(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:842
MQTT_PublishToResend
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:1025
MQTTStateCursor_t
size_t MQTTStateCursor_t
Cursor for iterating through state records.
Definition: core_mqtt_state.h:49
MQTT_ReserveState
MQTTStatus_t MQTT_ReserveState(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:784
MQTTPubAckType_t
MQTTPubAckType_t
Packet types used in acknowledging QoS 1 or QoS 2 publishes.
Definition: core_mqtt.h:134
MQTTStatus_t
MQTTStatus_t
Return codes from MQTT functions.
Definition: core_mqtt_serializer.h:97
MQTT_CalculateStatePublish
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:813
core_mqtt.h
User-facing functions of the MQTT 3.1.1 library.
MQTT_CalculateStateAck
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:620
MQTTContext_t
A struct representing an MQTT connection.
Definition: core_mqtt.h:169
MQTTQoS_t
MQTTQoS_t
MQTT Quality of Service values.
Definition: core_mqtt_serializer.h:116
MQTT_UpdateStateAck
MQTTStatus_t MQTT_UpdateStateAck(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:916
MQTT_State_strerror
const char * MQTT_State_strerror(MQTTPublishState_t state)
State to string conversion for state engine.
Definition: core_mqtt_state.c:1055