Modify libbase's compilation configuration

Add the nng-mqtt switch to the compilation process of libbase
This commit is contained in:
gc87
2022-01-20 10:09:22 +08:00
committed by Parker Liu
parent b496073518
commit a9b3a2057b
2 changed files with 41 additions and 0 deletions
+12
View File
@@ -152,6 +152,14 @@ set(NEURON_BASE_SOURCES
src/utils/uuid4.c
src/config.c)
if(USE_NNG_MQTT)
message("-- USE_NNG_MQTT is defined")
add_definitions(-DUSE_NNG_MQTT)
set(NEURON_BASE_SOURCES
${NEURON_BASE_SOURCES}
src/connection/mqtt_nng_client.c)
endif()
set(NEURON_BASE_INCLUDE_DIRECTORIES include src)
add_library(neuron-base SHARED)
target_sources(neuron-base PRIVATE ${NEURON_BASE_SOURCES} ${NEURON_SRC_PARSE} ${NEURON_SRC_SCHEMA})
@@ -162,6 +170,10 @@ target_compile_definitions(neuron-base PRIVATE MQTT_USE_BIO)
target_link_libraries(neuron-base vector-static csptr jansson crypto ssl mqttc yaml jwt
${CMAKE_THREAD_LIBS_INIT})
if(USE_NNG_MQTT)
target_link_libraries(neuron-base mbedtls mbedx509 mbedcrypto nng)
endif()
#copy file for run and unit test
file(COPY ${CMAKE_SOURCE_DIR}/neuron.yaml DESTINATION ${CMAKE_BINARY_DIR})
file(COPY ${CMAKE_SOURCE_DIR}/plugin_param_schema.json DESTINATION ${CMAKE_BINARY_DIR})
+29
View File
@@ -18,41 +18,70 @@
**/
#include "connection/mqtt_client_intf.h"
#ifdef USE_NNG_MQTT
#include "mqtt_nng_client.h"
#else
#include "mqtt_c_client.h"
#endif
neu_err_code_e neu_mqtt_client_open(neu_mqtt_client_t * p_client,
const neu_mqtt_option_t *option,
void * context)
{
#ifdef USE_NNG_MQTT
return mqtt_nng_client_open((mqtt_nng_client_t **) p_client, option,
context);
#else
return mqtt_c_client_open((mqtt_c_client_t **) p_client, option, context);
#endif
}
neu_err_code_e neu_mqtt_client_is_connected(neu_mqtt_client_t client)
{
#ifdef USE_NNG_MQTT
return mqtt_nng_client_is_connected(client);
#else
return mqtt_c_client_is_connected(client);
#endif
}
neu_err_code_e neu_mqtt_client_subscribe(neu_mqtt_client_t client,
const char *topic, const int qos,
neu_subscribe_handle handle)
{
#ifdef USE_NNG_MQTT
return mqtt_nng_client_subscribe(client, topic, qos, handle);
#else
return mqtt_c_client_subscribe(client, topic, qos, handle);
#endif
}
neu_err_code_e neu_mqtt_client_unsubscribe(neu_mqtt_client_t client,
const char * topic)
{
#ifdef USE_NNG_MQTT
return mqtt_nng_client_unsubscribe(client, topic);
#else
return mqtt_c_client_unsubscribe(client, topic);
#endif
}
neu_err_code_e neu_mqtt_client_publish(neu_mqtt_client_t client,
const char *topic, int qos,
unsigned char *payload, size_t len)
{
#ifdef USE_NNG_MQTT
return mqtt_nng_client_publish(client, topic, qos, payload, len);
#else
return mqtt_c_client_publish(client, topic, qos, payload, len);
#endif
}
neu_err_code_e neu_mqtt_client_close(neu_mqtt_client_t client)
{
#ifdef USE_NNG_MQTT
return mqtt_nng_client_close(client);
#else
return mqtt_c_client_close(client);
#endif
}