Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatible with NEWEST marco-utils-c #171

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#Copyright (c) Microsoft. All rights reserved.
#Licensed under the MIT license. See LICENSE file in the project root for full license information.

cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.12.0)

if (TARGET umqtt)
RETURN()
Expand All @@ -14,6 +14,10 @@ FILE(READ ${CMAKE_CURRENT_LIST_DIR}/version.txt UMQTT_VERSION)
set(GENERIC_LIB_VERSION ${UMQTT_VERSION})
string(SUBSTRING ${UMQTT_VERSION} 0 1 GENERIC_LIB_SOVERSION)

# Set C and C++ standards
set(CMAKE_C_STANDARD 23)
set(CMAKE_CXX_STANDARD 23)

#the following variables are project-wide and can be used with cmake-gui
option(run_unittests "set run_unittests to ON to run unittests (default is OFF)" OFF)
option(run_e2e_tests "set run_e2e_tests to ON to run e2e tests (default is OFF)" OFF)
Expand Down Expand Up @@ -114,7 +118,7 @@ set(source_h_files
./inc/azure_umqtt_c/mqtt_message.h
)

#the following "set" statetement exports across the project a global variable called COMMON_INC_FOLDER that expands to whatever needs to included when using COMMON library
#the following "set" statement exports across the project a global variable called COMMON_INC_FOLDER that expands to whatever needs to included when using COMMON library
set(MQTT_INC_FOLDER ${CMAKE_CURRENT_LIST_DIR}/inc CACHE INTERNAL "this is what needs to be included if using sharedLib lib" FORCE)
set(MQTT_SRC_FOLDER ${CMAKE_CURRENT_LIST_DIR}/src CACHE INTERNAL "this is what needs to be included when doing include sources" FORCE)
include_directories(${MQTT_INC_FOLDER} ${SHARED_UTIL_INC_FOLDER} ${UMOCK_C_INC_FOLDER} ${MACRO_UTILS_INC_FOLDER})
Expand Down
85 changes: 58 additions & 27 deletions inc/azure_umqtt_c/mqttconst.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,66 @@ extern "C" {
#include <stdint.h>
#endif /* __cplusplus */

// Define CONTROL_PACKET_TYPE without numeric constants
#define CONTROL_PACKET_TYPE_VALUES \
CONNECT_TYPE, 0x10, \
CONNACK_TYPE, 0x20, \
PUBLISH_TYPE, 0x30, \
PUBACK_TYPE, 0x40, \
PUBREC_TYPE, 0x50, \
PUBREL_TYPE, 0x60, \
PUBCOMP_TYPE, 0x70, \
SUBSCRIBE_TYPE, 0x80, \
SUBACK_TYPE, 0x90, \
UNSUBSCRIBE_TYPE, 0xA0, \
UNSUBACK_TYPE, 0xB0, \
PINGREQ_TYPE, 0xC0, \
PINGRESP_TYPE, 0xD0, \
DISCONNECT_TYPE, 0xE0, \
PACKET_TYPE_ERROR, 0xE1, /* 0xE1 was assigned because ENUM_2 needs it */ \
UNKNOWN_TYPE, 0xE2, /* 0xE2 was assigned because ENUM_2 needs it */ \
PACKET_INVALID1_TYPE, 0x00, \
PACKET_INVALID2_TYPE, 0xF0

MU_DEFINE_ENUM_2(CONTROL_PACKET_TYPE, CONTROL_PACKET_TYPE_VALUES)

CONNECT_TYPE, \
CONNACK_TYPE, \
PUBLISH_TYPE, \
PUBACK_TYPE, \
PUBREC_TYPE, \
PUBREL_TYPE, \
PUBCOMP_TYPE, \
SUBSCRIBE_TYPE, \
SUBACK_TYPE, \
UNSUBSCRIBE_TYPE, \
UNSUBACK_TYPE, \
PINGREQ_TYPE, \
PINGRESP_TYPE, \
DISCONNECT_TYPE, \
PACKET_TYPE_ERROR, \
UNKNOWN_TYPE, \
PACKET_INVALID1_TYPE, \
PACKET_INVALID2_TYPE

MU_DEFINE_ENUM(CONTROL_PACKET_TYPE, CONTROL_PACKET_TYPE_VALUES)

// Define QOS_VALUE without numeric constants
#define QOS_VALUE_VALUES \
DELIVER_AT_MOST_ONCE, 0x00, \
DELIVER_AT_LEAST_ONCE, 0x01, \
DELIVER_EXACTLY_ONCE, 0x02, \
DELIVER_FAILURE, 0x80

MU_DEFINE_ENUM_2(QOS_VALUE, QOS_VALUE_VALUES)
DELIVER_AT_MOST_ONCE, \
DELIVER_AT_LEAST_ONCE, \
DELIVER_EXACTLY_ONCE, \
DELIVER_FAILURE

MU_DEFINE_ENUM(QOS_VALUE, QOS_VALUE_VALUES)

// Map enum values to numeric constants
static const int CONTROL_PACKET_TYPE_NUMERIC_VALUES[] = {
[CONNECT_TYPE] = 0x10,
[CONNACK_TYPE] = 0x20,
[PUBLISH_TYPE] = 0x30,
[PUBACK_TYPE] = 0x40,
[PUBREC_TYPE] = 0x50,
[PUBREL_TYPE] = 0x60,
[PUBCOMP_TYPE] = 0x70,
[SUBSCRIBE_TYPE] = 0x80,
[SUBACK_TYPE] = 0x90,
[UNSUBSCRIBE_TYPE] = 0xA0,
[UNSUBACK_TYPE] = 0xB0,
[PINGREQ_TYPE] = 0xC0,
[PINGRESP_TYPE] = 0xD0,
[DISCONNECT_TYPE] = 0xE0,
[PACKET_TYPE_ERROR] = 0xE1,
[UNKNOWN_TYPE] = 0xE2,
[PACKET_INVALID1_TYPE] = 0x00,
[PACKET_INVALID2_TYPE] = 0xF0
};

static const int QOS_VALUE_NUMERIC_VALUES[] = {
[DELIVER_AT_MOST_ONCE] = 0x00,
[DELIVER_AT_LEAST_ONCE] = 0x01,
[DELIVER_EXACTLY_ONCE] = 0x02,
[DELIVER_FAILURE] = 0x80
};

typedef struct APP_PAYLOAD_TAG
{
Expand Down
4 changes: 2 additions & 2 deletions src/mqtt_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
static const char* const TRUE_CONST = "true";
static const char* const FALSE_CONST = "false";

MU_DEFINE_ENUM_STRINGS_2(QOS_VALUE, QOS_VALUE_VALUES);
MU_DEFINE_ENUM_STRINGS(QOS_VALUE, QOS_VALUE_VALUES);

#define MQTT_STATUS_INITIAL_STATUS 0x0000
#define MQTT_STATUS_CLIENT_CONNECTED 0x0001
Expand Down Expand Up @@ -710,7 +710,7 @@ static void ProcessPublishMessage(MQTT_CLIENT* mqtt_client, uint8_t* initialPos,
if (is_trace_enabled(mqtt_client))
{
trace_log = STRING_construct_sprintf("PUBLISH | IS_DUP: %s | RETAIN: %d | QOS: %s | TOPIC_NAME: %s", isDuplicateMsg ? TRUE_CONST : FALSE_CONST,
isRetainMsg ? 1 : 0, MU_ENUM_TO_STRING_2(QOS_VALUE, qosValue), topicName);
isRetainMsg ? 1 : 0, MU_ENUM_TO_STRING(QOS_VALUE, qosValue), topicName);
}
#endif
uint16_t packetId = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/mqtt_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ int mqtt_codec_bytesReceived(MQTTCODEC_HANDLE handle, const unsigned char* buffe
break;

case PUBLISH_TYPE:
case CONTROL_PACKET_TYPE_INVALID:
// case CONTROL_PACKET_TYPE_INVALID:
case PACKET_TYPE_ERROR:
case UNKNOWN_TYPE:
break;
Expand Down
2 changes: 1 addition & 1 deletion tests/mqtt_client_ut/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#Copyright (c) Microsoft. All rights reserved.
#Licensed under the MIT license. See LICENSE file in the project root for full license information.

cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.12.0)

set(theseTestsName mqtt_client_ut)

Expand Down
4 changes: 2 additions & 2 deletions tests/mqtt_client_ut/mqtt_client_ut.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ extern "C"
}
#endif

TEST_DEFINE_ENUM_2_TYPE(QOS_VALUE, QOS_VALUE_VALUES);
IMPLEMENT_UMOCK_C_ENUM_2_TYPE(QOS_VALUE, QOS_VALUE_VALUES);
TEST_DEFINE_ENUM_TYPE(QOS_VALUE, QOS_VALUE_VALUES);
IMPLEMENT_UMOCK_C_ENUM_TYPE(QOS_VALUE, QOS_VALUE_VALUES);

static const char* TEST_USERNAME = "testuser";
static const char* TEST_PASSWORD = "testpassword";
Expand Down
6 changes: 3 additions & 3 deletions tests/mqtt_codec_ut/mqtt_codec_ut.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ STRING_HANDLE STRING_construct_sprintf(const char* format, ...)
}
#endif

MU_DEFINE_ENUM_STRINGS_2(CONTROL_PACKET_TYPE, CONTROL_PACKET_TYPE_VALUES);
TEST_DEFINE_ENUM_2_TYPE(CONTROL_PACKET_TYPE, CONTROL_PACKET_TYPE_VALUES);
IMPLEMENT_UMOCK_C_ENUM_2_TYPE(CONTROL_PACKET_TYPE, CONTROL_PACKET_TYPE_VALUES);
MU_DEFINE_ENUM_STRINGS(CONTROL_PACKET_TYPE, CONTROL_PACKET_TYPE_VALUES);
TEST_DEFINE_ENUM_TYPE(CONTROL_PACKET_TYPE, CONTROL_PACKET_TYPE_VALUES);
IMPLEMENT_UMOCK_C_ENUM_TYPE(CONTROL_PACKET_TYPE, CONTROL_PACKET_TYPE_VALUES);

static void SetupMqttLibOptions(MQTT_CLIENT_OPTIONS* options, const char* clientId,
const char* willMsg,
Expand Down
6 changes: 3 additions & 3 deletions tests/mqtt_message_ut/mqtt_message_ut.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ typedef struct TEST_COMPLETE_DATA_INSTANCE_TAG
size_t Length;
} TEST_COMPLETE_DATA_INSTANCE;

MU_DEFINE_ENUM_STRINGS_2(QOS_VALUE, QOS_VALUE_VALUES);
TEST_DEFINE_ENUM_2_TYPE(QOS_VALUE, QOS_VALUE_VALUES);
IMPLEMENT_UMOCK_C_ENUM_2_TYPE(QOS_VALUE, QOS_VALUE_VALUES);
MU_DEFINE_ENUM_STRINGS(QOS_VALUE, QOS_VALUE_VALUES);
TEST_DEFINE_ENUM_TYPE(QOS_VALUE, QOS_VALUE_VALUES);
IMPLEMENT_UMOCK_C_ENUM_TYPE(QOS_VALUE, QOS_VALUE_VALUES);

TEST_MUTEX_HANDLE test_serialize_mutex;

Expand Down