Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Commit

Permalink
feat(mqtt): Use logger_helper in MQTT files
Browse files Browse the repository at this point in the history
  • Loading branch information
howjmay committed Aug 15, 2019
1 parent 0645641 commit 97a4687
Show file tree
Hide file tree
Showing 12 changed files with 448 additions and 112 deletions.
2 changes: 1 addition & 1 deletion accelerator/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern "C" {
#define TA_HOST "localhost"
#ifdef ENABLE_MQTT
#define MQTT_HOST "localhost"
#define TOPIC_ROOT "NB/root/topics"
#define TOPIC_ROOT "root/topics"
#endif
#define TA_PORT "8000"
#define TA_THREAD_COUNT 10
Expand Down
32 changes: 32 additions & 0 deletions accelerator/mqtt_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,31 @@
#include "connectivity/mqtt/duplex_utils.h"
#include "errors.h"

#define MQTT_INTERFACE_LOGGER "mqtt-interface"

static logger_id_t mqtt_logger_id;

int main(int argc, char *argv[]) {
status_t ret;
mosq_config_t cfg;
struct mosquitto *mosq = NULL;

// Initialize logger
logger_helper_init(LOGGER_DEBUG);
mqtt_logger_id = logger_helper_enable(MQTT_INTERFACE_LOGGER, LOGGER_DEBUG, true);

if (verbose_mode) {
mqtt_utils_logger_init();
mqtt_common_logger_init();
mqtt_callback_logger_init();
mqtt_pub_logger_init();
mqtt_sub_logger_init();
} else {
// Destroy logger when verbose mode is off
logger_helper_release(mqtt_logger_id);
logger_helper_destroy();
}

// Initialize `mosq` and `cfg`
// if we want to opertate this program under multi-threading, see https://github.com/eclipse/mosquitto/issues/450
ret = duplex_config_init(&mosq, &cfg);
Expand Down Expand Up @@ -43,5 +63,17 @@ int main(int argc, char *argv[]) {
mosquitto_destroy(mosq);
mosquitto_lib_cleanup();
mosq_config_free(&cfg);

if (verbose_mode) {
mqtt_utils_logger_release();
mqtt_common_logger_release();
mqtt_callback_logger_release();
mqtt_pub_logger_release();
mqtt_sub_logger_release();
logger_helper_release(mqtt_logger_id);
if (logger_helper_destroy() != RC_OK) {
return EXIT_FAILURE;
}
}
return ret;
}
Loading

0 comments on commit 97a4687

Please sign in to comment.