Initializing the mqtt libraries with base files

This commit is contained in:
Jelani 2015-12-04 13:14:12 -08:00
Коммит b1f3d20567
17 изменённых файлов: 739 добавлений и 0 удалений

23
LICENSE Normal file
Просмотреть файл

@ -0,0 +1,23 @@
Microsoft Azure IoT SDKs
Copyright (c) Microsoft Corporation
All rights reserved.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the ""Software""), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

216
c/CMakeLists.txt Normal file
Просмотреть файл

@ -0,0 +1,216 @@
#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.0)
project(azure_mqtt)
include(ExternalProject)
#the following variables are project-wide and can be used with cmake-gui
option(skip_unittests "set skip_unittests to ON to skip unittests (default is OFF)[if possible, they are always build]" OFF)
option(compileOption_C "passes a string to the command line of the C compiler" OFF)
option(compileOption_CXX "passes a string to the command line of the C++ compiler" OFF)
#Use solution folders.
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Start of variables used during install
#set (INCLUDE_INSTALL_DIR include CACHE PATH "Include file directory")
if(WIN32)
get_filename_component(REPO_DIR ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY)
get_filename_component(REPO_DIR ${REPO_DIR} DIRECTORY)
set(SHARED_UTIL_INC_FOLDER ${REPO_DIR}/azure-c-shared-utility/c/inc)
set(SHARED_UTIL_SRC_FOLDER ${REPO_DIR}/azure-c-shared-utility/c/src)
set(SHARED_UTIL_LIB_DIR "$ENV{USERPROFILE}/shared-util_Win32")
set(MICROMOCK_UNITTEST_LIB_DIR "$ENV{USERPROFILE}/shared-util_Win32/testtools/micromock/")
set(CTEST_LIB_DIR "$ENV{USERPROFILE}/shared-util_Win32/testtools/ctest/")
else()
set(SHARED_UTIL_INC_FOLDER /usr/include/azuresharedutil)
set(SHARED_UTIL_LIB_DIR "/usr/lib")
#set(MICROMOCK_UNITTEST_LIB_DIR "$ENV{USERPROFILE}/shared-util_Win32/testtools/micromock/")
#set(CTEST_LIB_DIR "$ENV{USERPROFILE}/shared-util_Win32/testtools/ctest/")
endif(WIN32)
enable_testing()
#if any compiler has a command line switch called "OFF" then it will need special care
if(NOT "${compileOption_C}" STREQUAL "OFF")
set(CMAKE_C_FLAGS "${compileOption_C} ${CMAKE_C_FLAGS}")
endif()
if(NOT "${compileOption_CXX}" STREQUAL "OFF")
set(CMAKE_CXX_FLAGS "${compileOption_CXX} ${CMAKE_CXX_FLAGS}")
endif()
#this project uses several other projects that are build not by these CMakeFiles
#this project also targets several OSes
#this function takes care of three things:
#1. copying some shared libraries(.dll or .so) to the location of the output executable
macro(compileAsC99)
if (CMAKE_VERSION VERSION_LESS "3.1")
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
set (CMAKE_C_FLAGS "--std=c99 ${CMAKE_C_FLAGS}")
set (CMAKE_CXX_FLAGS "--std=c++11 ${CMAKE_CXX_FLAGS}")
endif()
else()
set (CMAKE_C_STANDARD 99)
set (CMAKE_CXX_STANDARD 11)
endif()
endmacro(compileAsC99)
macro(compileAsC11)
if (CMAKE_VERSION VERSION_LESS "3.1")
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
set (CMAKE_C_FLAGS "--std=c11 ${CMAKE_C_FLAGS}")
set (CMAKE_C_FLAGS "-D_POSIX_C_SOURCE=200112L ${CMAKE_C_FLAGS}")
set (CMAKE_CXX_FLAGS "--std=c++11 ${CMAKE_CXX_FLAGS}")
endif()
else()
set (CMAKE_C_STANDARD 11)
set (CMAKE_CXX_STANDARD 11)
endif()
endmacro(compileAsC11)
function(windows_unittests_add_dll whatIsBuilding)
link_directories(${whatIsBuilding}_dll ${MICROMOCK_UNITTEST_LIB_DIR} ${CTEST_LIB_DIR} ${SHARED_UTIL_LIB_DIR} $ENV{VCInstallDir}UnitTest/lib)
add_library(${whatIsBuilding}_dll SHARED
${${whatIsBuilding}_cpp_files}
${${whatIsBuilding}_h_files}
${${whatIsBuilding}_c_files}
)
#Add UnitTests to their own folder
set_target_properties(${whatIsBuilding}_dll
PROPERTIES
FOLDER "UnitTests")
target_include_directories(${whatIsBuilding}_dll PUBLIC ${sharedutil_include_directories} $ENV{VCInstallDir}UnitTest/include)
target_compile_definitions(${whatIsBuilding}_dll PUBLIC -DCPP_UNITTEST)
target_link_libraries(${whatIsBuilding}_dll micromock_cpp_unittest ctest ${ARGN})
endfunction()
function(windows_unittests_add_exe whatIsBuilding)
link_directories(${whatIsBuilding}_exe ${MICROMOCK_UNITTEST_LIB_DIR} ${CTEST_LIB_DIR} ${SHARED_UTIL_LIB_DIR} $ENV{VCInstallDir}UnitTest/lib)
add_executable(${whatIsBuilding}_exe
${${whatIsBuilding}_cpp_files}
${${whatIsBuilding}_h_files}
${${whatIsBuilding}_c_files}
${CMAKE_CURRENT_LIST_DIR}/main.c
)
#Add UnitTests to their own folder
set_target_properties(${whatIsBuilding}_exe
PROPERTIES
FOLDER "UnitTests")
target_compile_definitions(${whatIsBuilding}_exe PUBLIC -DUSE_CTEST)
target_include_directories(${whatIsBuilding}_exe PUBLIC ${sharedutil_include_directories})
target_link_libraries(${whatIsBuilding}_exe micromock_ctest ctest ${ARGN})
add_test(NAME ${whatIsBuilding} COMMAND ${whatIsBuilding}_exe)
endfunction()
function(windows_unittests_add_lib whatIsBuilding)
link_directories(${whatIsBuilding}_lib ${MICROMOCK_UNITTEST_LIB_DIR} ${CTEST_LIB_DIR} ${SHARED_UTIL_LIB_DIR} $ENV{VCInstallDir}UnitTest/lib)
add_library(${whatIsBuilding}_lib STATIC
${${whatIsBuilding}_cpp_files}
${${whatIsBuilding}_h_files}
${${whatIsBuilding}_c_files}
)
#Add UnitTests to their own folder
set_target_properties(${whatIsBuilding}_lib
PROPERTIES
FOLDER "UnitTests")
target_include_directories(${whatIsBuilding}_lib PUBLIC ${sharedutil_include_directories})
target_compile_definitions(${whatIsBuilding}_lib PUBLIC -DUSE_CTEST)
target_link_libraries(${whatIsBuilding}_lib micromock_cpp_unittest ctest ${ARGN})
endfunction()
function(build_test_artifacts whatIsBuilding use_gballoc)
#the first argument is what is building
#the second argument is whether the tests should be build with gballoc #defines or not
#the following arguments are a list of libraries to link with
if(${use_gballoc})
add_definitions(-DGB_MEASURE_MEMORY_FOR_THIS -DGB_DEBUG_ALLOC)
else()
endif()
#setting #defines
if(WIN32)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
else()
endif()
#setting includes
set(sharedutil_include_directories ${MICROMOCK_INC_FOLDER} ${TESTRUNNERSWITCHER_INC_FOLDER} ${CTEST_INC_FOLDER} ${SAL_INC_FOLDER} ${SHARED_UTIL_INC_FOLDER} ${SHARED_UTIL_SRC_FOLDER} ../)
if(WIN32)
else()
include_directories(${sharedutil_include_directories})
endif()
#setting output type
if(WIN32)
#to disable unittests tests for windows, we build the the same thing as "static library" so it is not picked up by visual studio
if(("${whatIsBuilding}" MATCHES ".*unittests.*") AND ${skip_unittests})
windows_unittests_add_lib(${whatIsBuilding} ${ARGN})
else()
windows_unittests_add_exe(${whatIsBuilding} ${ARGN})
windows_unittests_add_dll(${whatIsBuilding} ${ARGN})
endif()
else()
if(("${whatIsBuilding}" MATCHES ".*unittests.*") AND ${skip_unittests})
windows_unittests_add_lib(${whatIsBuilding} ${ARGN})
else()
windows_unittests_add_exe(${whatIsBuilding} ${ARGN})
endif()
endif()
endfunction(build_test_artifacts)
#Update_dependencies()
compileAsC11()
#these are the C source files
set(source_c_files
./src/mqtt_client.c
)
#these are the C headers
set(source_h_files
./inc/control_packet.h
./inc/mqtt_client.h
./inc/mqtt_codec.h
./inc/mqttconst.h
./inc/mqtt_message.h
./inc/data_byte_util.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
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})
IF(WIN32)
#windows needs this define
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
ENDIF(WIN32)
#this is the product (a library)
add_library(azuremqtt ${source_c_files} ${source_h_files})
add_subdirectory(samples)
#add_subdirectory(tests)
#target_link_libraries(azure_mqtt azure_c_shared_utility)

Просмотреть файл

@ -0,0 +1,75 @@
# Mqtt_Client Requirements
##Overview
Mqtt_Client is the library that encapsulates the mqtt protocol
##Exposed API
```C
typedef struct MQTTCLIENT_DATA_INSTANCE_TAG* MQTTCLIENT_HANDLE;
#define MQTTCLIENT_ACTION_VALUES \
MQTTCLIENT_ON_CONNACT, \
MQTTCLIENT_ON_SUBSCRIBE, \
MQTTCLIENT_ON_DISCONNECT
DEFINE_ENUM(MQTTCLIENT_ACTION_RESULT, MQTTCLIENT_ACTION_VALUES);
typedef int(*ON_MQTT_OPERATION_CALLBACK)(MQTTCLIENT_ACTION_RESULT actionResult, void* context);
typedef void(*ON_MQTT_MESSAGE_RECV_CALLBACK)(MQTT_MESSAGE_HANDLE msgHandle, void* context);
extern MQTTCLIENT_HANDLE mqttclient_init(LOGGER_LOG logger, ON_MQTT_OPERATION_CALLBACK opCallback, ON_MQTT_MESSAGE_RECV_CALLBACK msgRecv, void* callCtx);
extern void mqttclient_deinit(MQTTCLIENT_HANDLE handle);
extern int mqttclient_connect(MQTTCLIENT_HANDLE handle, XIO_HANDLE ioHandle, MQTTCLIENT_OPTIONS* mqttOptions);
extern void mqttclient_disconnect(MQTTCLIENT_HANDLE handle);
extern int mqttclient_subscribe(MQTTCLIENT_HANDLE handle, BYTE packetId, const char* subscribeTopic, QOS_VALUE qosValue);
extern int mqttclient_unsubscribe(MQTTCLIENT_HANDLE handle, BYTE packetId, const char* unsubscribeTopic, QOS_VALUE qosValue);
extern int mqttclient_publish(MQTTCLIENT_HANDLE handle, MQTT_MESSAGE_HANDLE msgHandle);
extern void mqttclient_dowork(MQTTCLIENT_HANDLE handle);
```
##MqttClient_Init
```
extern MQTTCLIENT_HANDLE mqttclient_init(LOGGER_LOG logger, ON_MQTT_OPERATION_CALLBACK opCallback, ON_MQTT_MESSAGE_RECV_CALLBACK msgRecv, void* callCtx);
```
##MqttClient_Deinit
```
extern void mqttclient_deinit(MQTTCLIENT_HANDLE handle);
```
##mqttclient_connect
```
extern int mqttclient_connect(MQTTCLIENT_HANDLE handle, XIO_HANDLE ioHandle, MQTTCLIENT_OPTIONS* mqttOptions);
```
##mqttclient_disconnect
```
extern void mqttclient_disconnect(MQTTCLIENT_HANDLE handle);
```
##mqttclient_subscribe
```
extern int mqttclient_subscribe(MQTTCLIENT_HANDLE handle, BYTE packetId, const char* subscribeTopic, QOS_VALUE qosValue);
```
##mqttclient_unsubscribe
```
extern int mqttclient_unsubscribe(MQTTCLIENT_HANDLE handle, BYTE packetId, const char* unsubscribeTopic, QOS_VALUE qosValue);
```
##mqttclient_publish
```
extern int mqttclient_publish(MQTTCLIENT_HANDLE handle, MQTT_MESSAGE_HANDLE msgHandle);
```
##mqttclient_dowork
```
extern void mqttclient_dowork(MQTTCLIENT_HANDLE handle);
```

41
c/inc/control_packet.h Normal file
Просмотреть файл

@ -0,0 +1,41 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#ifndef CONNECT_PACKET_H
#define CONNECT_PACKET_H
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include "xio.h"
#include "mqttconst.h"
#include "buffer_.h"
typedef int(*CTRL_PACKET_IO_SEND)(BUFFER_HANDLE handle, void* callContext);
extern int ctrlpacket_connect(CTRL_PACKET_IO_SEND ioSendFn, void* callContext, const MQTTCLIENT_OPTIONS* mqttOptions);
extern int ctrlpacket_disconnect(CTRL_PACKET_IO_SEND ioSendFn, void* callContext);
extern int ctrlpacket_publish(CTRL_PACKET_IO_SEND ioSendFn, void* callContext, QOS_VALUE qosValue, bool duplicateMsg, bool serverRetain, int packetId, const char* topicName, const unsigned char* msgBuffer);
extern int ctrlpacket_publishAck(CTRL_PACKET_IO_SEND ioSendFn, void* callContext, int packetId);
extern int ctrlpacket_publishRecieved(CTRL_PACKET_IO_SEND ioSendFn, void* callContext, int packetId);
extern int ctrlpacket_publishRelease(CTRL_PACKET_IO_SEND ioSendFn, void* callContext, int packetId);
extern int ctrlpacket_publishComplete(CTRL_PACKET_IO_SEND ioSendFn, void* callContext, int packetId);
extern int ctrlpacket_subscribe(CTRL_PACKET_IO_SEND ioSendFn, void* callContext, int packetId, const char* subscribeTopic, QOS_VALUE qosValue);
extern int ctrlpacket_unsubscribe(CTRL_PACKET_IO_SEND ioSendFn, void* callContext, int packetId, const char* unsubscribeTopic, QOS_VALUE qosValue);
extern int ctrlpacket_ping(CTRL_PACKET_IO_SEND ioSendFn, void* callContext);
extern CONTROL_PACKET_TYPE ctrlpacket_processControlPacketType(BYTE pktByte, int* flags);
extern int ctrlpacket_processVariableHeader(CONTROL_PACKET_TYPE type, BUFFER_HANDLE packetData);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif // CONNECT_PACKET_H

28
c/inc/data_byte_util.h Normal file
Просмотреть файл

@ -0,0 +1,28 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#ifndef DATA_BYTE_UTIL_H
#define DATA_BYTE_UTIL_H
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include "mqttconst.h"
extern BYTE byteutil_readByte(BYTE** buffer);
extern int byteutil_readInt(BYTE** buffer);
extern char* byteutil_readUTF(BYTE** buffer);
extern void byteutil_writeByte(char** buffer, char value);
extern void byteutil_writeInt(char** buffer, int value);
extern void byteutil_writeUTF(char** buffer, const char* stringData, size_t len);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif // DATA_BYTE_UTIL_H

47
c/inc/mqtt_client.h Normal file
Просмотреть файл

@ -0,0 +1,47 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#ifndef MQTTCLIENT_H
#define MQTTCLIENT_H
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
#include "xio.h"
#include "mqttconst.h"
#include "iot_logging.h"
#include "macro_utils.h"
#include "mqtt_message.h"
#include "list.h"
typedef struct MQTTCLIENT_DATA_INSTANCE_TAG* MQTTCLIENT_HANDLE;
#define MQTTCLIENT_ACTION_VALUES \
MQTTCLIENT_ON_CONNACT, \
MQTTCLIENT_ON_SUBSCRIBE, \
MQTTCLIENT_ON_DISCONNECT
DEFINE_ENUM(MQTTCLIENT_ACTION_RESULT, MQTTCLIENT_ACTION_VALUES);
typedef int(*ON_MQTT_OPERATION_CALLBACK)(MQTTCLIENT_ACTION_RESULT actionResult, void* context);
typedef void(*ON_MQTT_MESSAGE_RECV_CALLBACK)(MQTT_MESSAGE_HANDLE msgHandle, void* context);
extern MQTTCLIENT_HANDLE mqttclient_init(LOGGER_LOG logger, ON_MQTT_OPERATION_CALLBACK opCallback, ON_MQTT_MESSAGE_RECV_CALLBACK msgRecv, void* callCtx);
extern void mqttclient_deinit(MQTTCLIENT_HANDLE handle);
extern int mqttclient_connect(MQTTCLIENT_HANDLE handle, XIO_HANDLE ioHandle, MQTTCLIENT_OPTIONS* mqttOptions);
extern void mqttclient_disconnect(MQTTCLIENT_HANDLE handle);
extern int mqttclient_subscribe(MQTTCLIENT_HANDLE handle, BYTE packetId, const char* subscribeTopic, QOS_VALUE qosValue);
extern int mqttclient_unsubscribe(MQTTCLIENT_HANDLE handle, BYTE packetId, const char* unsubscribeTopic, QOS_VALUE qosValue);
extern int mqttclient_publish(MQTTCLIENT_HANDLE handle, MQTT_MESSAGE_HANDLE msgHandle);
extern void mqttclient_dowork(MQTTCLIENT_HANDLE handle);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // MQTTCLIENT_H

31
c/inc/mqtt_codec.h Normal file
Просмотреть файл

@ -0,0 +1,31 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#ifndef MQTT_CODEC_H
#define MQTT_CODEC_H
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include "xio.h"
#include "mqttconst.h"
#include "buffer_.h"
typedef struct MQTTCODEC_INSTANCE_TAG* MQTTCODEC_HANDLE;
typedef void(*ON_PACKET_COMPLETE_CALLBACK)(void* context, CONTROL_PACKET_TYPE packet, int flags, BUFFER_HANDLE headerData);
extern MQTTCODEC_HANDLE mqttcodec_init(ON_PACKET_COMPLETE_CALLBACK packetComplete, void* callContext);
extern void mqttcodec_deinit(MQTTCODEC_HANDLE handle);
extern int mqttcodec_bytesReceived(MQTTCODEC_HANDLE handle, const void* buffer, size_t size);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif // MQTT_CODEC_H

37
c/inc/mqtt_message.h Normal file
Просмотреть файл

@ -0,0 +1,37 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#ifndef MQTT_MESSAGE_H
#define MQTT_MESSAGE_H
#include "macro_utils.h"
#include "map.h"
#ifdef __cplusplus
#include <cstddef>
extern "C"
{
#else
#include <stddef.h>
#endif
#include "mqttconst.h"
typedef void* MQTT_MESSAGE_HANDLE;
extern MQTT_MESSAGE_HANDLE mqttmsg_createMessage(BYTE packetId, const char* topicName, QOS_VALUE qosValue, const BYTE* appMsg, bool duplicateMsg, bool retainMsg);
extern void mqttmsg_destroyMessage(MQTT_MESSAGE_HANDLE handle);
extern MQTT_MESSAGE_HANDLE mqttmsg_clone(MQTT_MESSAGE_HANDLE handle);
extern BYTE mqttmsg_getPacketId(MQTT_MESSAGE_HANDLE handle);
extern const char* mqttmsg_getTopicName(MQTT_MESSAGE_HANDLE handle);
extern QOS_VALUE mqttmsg_getQosType(MQTT_MESSAGE_HANDLE handle);
extern bool mqttmsg_isDuplicateMsg(MQTT_MESSAGE_HANDLE handle);
extern bool mqttmsg_isRetained(MQTT_MESSAGE_HANDLE handle);
extern const BYTE* mqttmsg_applicationMsg(MQTT_MESSAGE_HANDLE handle);
#ifdef __cplusplus
}
#endif
#endif // MQTT_MESSAGE_H

68
c/inc/mqttconst.h Normal file
Просмотреть файл

@ -0,0 +1,68 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#ifndef MQTTCONST_H
#define MQTTCONST_H
#include "crt_abstractions.h"
typedef unsigned char BYTE;
typedef enum CONTROL_PACKET_TYPE_TAG
{
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,
UNKNOWN_TYPE
} CONTROL_PACKET_TYPE;
typedef enum QOS_VALUE_TAG
{
DELIVER_AT_MOST_ONCE = 0x00,
DELIVER_AT_LEAST_ONCE = 0x01,
DELIVER_EXACTLY_ONCE = 0x02
} QOS_VALUE;
typedef struct MQTTCLIENT_OPTIONS_TAG
{
const char* clientId;
const char* willTopic;
const char* willMessage;
const char* username;
const char* password;
int keepAliveInterval;
bool messageRetain;
bool useCleanSession;
QOS_VALUE qualityOfServiceValue;
} MQTTCLIENT_OPTIONS;
typedef enum CONNECT_RETURN_CODE_TAG
{
CONNECTION_ACCEPTED = 0x00,
CONN_REFUSED_UNACCEPTABLE_VERSION = 0x01,
CONN_REFUSED_ID_REJECTED = 0x02,
CONN_REFUSED_SERVER_UNAVAIL = 0x03,
CONN_REFUSED_BAD_USERNAME_PASSWORD = 0x04,
CONN_REFUSED_NOT_AUTHORIZED = 0x05,
CONN_REFUSED_UNKNOWN
} CONNECT_RETURN_CODE;
typedef struct CONNECT_ACK_TAG
{
bool isSessionPresent;
CONNECT_RETURN_CODE returnCode;
} CONNECT_ACK;
#endif // MQTTCONST_H

16
c/samples/CMakeLists.txt Normal file
Просмотреть файл

@ -0,0 +1,16 @@
#Copyright (c) Microsoft. All rights reserved.
#Licensed under the MIT license. See LICENSE file in the project root for full license information.
#this is CMakeLists.txt for samples. There's noithig here, except redirections to
#individual protocol samples
function(add_sample_directory whatIsBuilding)
add_subdirectory(${whatIsBuilding})
set_target_properties(${whatIsBuilding}
PROPERTIES
FOLDER "Samples")
endfunction()
add_sample_directory(mqtt_client_sample)

Просмотреть файл

@ -0,0 +1,52 @@
#Copyright (c) Microsoft. All rights reserved.
#Licensed under the MIT license. See LICENSE file in the project root for full license information.
#this is CMakeLists.txt for mqtt_client_sample
compileAsC11()
set(mqtt_client_sample_c_files
mqtt_client_sample.c
)
if(WIN32)
set(mqtt_client_sample_c_files ${mqtt_client_sample_c_files} ./windows/main.c)
else()
set(mqtt_client_sample_c_files ${mqtt_client_sample_c_files} ./linux/main.c)
endif()
set(mqtt_client_sample_h_files
mqtt_client_sample.h
)
IF(WIN32)
#windows needs this define
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-DGB_MEASURE_MEMORY_FOR_THIS -DGB_DEBUG_ALLOC)
ENDIF(WIN32)
include_directories(.)
add_executable(mqtt_client_sample ${mqtt_client_sample_c_files} ${mqtt_client_sample_h_files})
if(WIN32)
target_link_libraries(mqtt_client_sample
azuremqtt
${SHARED_UTIL_LIB_DIR}/Debug/aziotsharedutil.lib
secur32
ws2_32)
if(${tls_openssl})
target_link_libraries(mqtt_client_sample $ENV{OpenSSLDir}/lib/ssleay32.lib $ENV{OpenSSLDir}/lib/libeay32.lib)
file(COPY $ENV{OpenSSLDir}/bin/libeay32.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Debug)
file(COPY $ENV{OpenSSLDir}/bin/ssleay32.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Debug)
endif()
else()
target_link_libraries(mqtt_client_sample
pthread
azuremqtt
aziotsharedutil)
#if(${tls_openssl})
target_link_libraries(mqtt_client_sample ssl crypto)
#endif()
endif()

Просмотреть файл

@ -0,0 +1,10 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include "mqtt_client_sample.h"
int main(void)
{
mqtt_client_sample_run();
return 0;
}

Просмотреть файл

@ -0,0 +1,53 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include "mqtt_client_sample.h"
#include "mqtt_client.h"
#include "socketio.h"
#include <stdarg.h>
#include <stdio.h>
#ifdef _CRT_DBG_MAP_ALLOC
#include <crtdbg.h>
#endif // _CRT_DBG_MAP_ALLOC
static const char* HOSTNAME = "test.mosquitto.org";
static unsigned int sent_messages = 0;
#define PORT_NUM_UNENCRYPTED 1883
#define PORT_NUM_ENCRYPTED 8883
#define PORT_NUM_ENCRYPTED_CERT 8884
#define DEFAULT_MSG_TO_SEND 1
static void PrintLogFunction(unsigned int options, char* format, ...)
{
va_list args;
va_start(args, format);
(void)vprintf(format, args);
va_end(args);
if (options & LOG_LINE)
{
(void)printf("\r\n");
}
}
static void OnRecvCallback(MQTT_MESSAGE_HANDLE msgHandle, void* context)
{
}
static int OnOperationComplete(MQTTCLIENT_ACTION_RESULT actionResult, void* context)
{
return 0;
}
void mqtt_client_sample_run()
{
#ifdef _CRT_DBG_MAP_ALLOC
_CrtDumpMemoryLeaks();
#endif
}

Просмотреть файл

@ -0,0 +1,17 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#ifndef MQTT_CLIENT_SAMPLE_H
#define MQTT_CLIENT_SAMPLE_H
#ifdef __cplusplus
extern "C" {
#endif
void mqtt_client_sample_run(void);
#ifdef __cplusplus
}
#endif
#endif // MQTT_CLIENT_SAMPLE_H

Просмотреть файл

@ -0,0 +1,10 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include "mqtt_client_sample.h"
int main(void)
{
mqtt_client_sample_run();
return 0;
}

13
c/src/mqtt_client.c Normal file
Просмотреть файл

@ -0,0 +1,13 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include <stdlib.h>
#ifdef _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#endif
#include "mqtt_client.h"
#include "mqtt_codec.h"
#include "control_packet.h"
#include "data_byte_util.h"

2
readme.md Normal file
Просмотреть файл

@ -0,0 +1,2 @@
# Microsoft Azure MQTT