#include "collectd.h"
-#include "common.h"
#include "plugin.h"
+#include "utils/common/common.h"
#include "utils_complain.h"
#include <mosquitto.h>
* Data types
*/
struct mqtt_client_conf {
- _Bool publish;
+ bool publish;
char *name;
struct mosquitto *mosq;
- _Bool connected;
+ bool connected;
char *host;
int port;
/* For publishing */
char *topic_prefix;
- _Bool store_rates;
- _Bool retain;
+ bool store_rates;
+ bool retain;
/* For subscribing */
pthread_t thread;
- _Bool loop;
+ bool loop;
char *topic;
- _Bool clean_session;
+ bool clean_session;
c_complain_t complaint_cantpublish;
pthread_mutex_t lock;
};
typedef struct mqtt_client_conf mqtt_client_conf_t;
-static mqtt_client_conf_t **subscribers = NULL;
-static size_t subscribers_num = 0;
+static mqtt_client_conf_t **subscribers;
+static size_t subscribers_num;
/*
* Functions
if (conf->connected)
(void)mosquitto_disconnect(conf->mosq);
- conf->connected = 0;
+ conf->connected = false;
(void)mosquitto_destroy(conf->mosq);
sfree(conf->host);
return -1;
}
- conf->connected = 1;
+ conf->connected = true;
c_release(LOG_INFO, &conf->complaint_cantpublish,
"mqtt plugin: successfully reconnected to broker \"%s:%d\"",
}
}
- conf->connected = 1;
+ conf->connected = true;
return 0;
} /* mqtt_connect */
/* max_packets = */ 100);
#endif
if (status == MOSQ_ERR_CONN_LOST) {
- conf->connected = 0;
+ conf->connected = false;
continue;
} else if (status != MOSQ_ERR_SUCCESS) {
ERROR("mqtt plugin: mosquitto_loop failed: %s",
mosquitto_strerror(status));
mosquitto_destroy(conf->mosq);
conf->mosq = NULL;
- conf->connected = 0;
+ conf->connected = false;
continue;
}
/* Mark our connection "down" regardless of the error as a safety
* measure; we will try to reconnect the next time we have to publish a
* message */
- conf->connected = 0;
+ conf->connected = false;
mosquitto_disconnect(conf->mosq);
pthread_mutex_unlock(&conf->lock);
ERROR("mqtt plugin: calloc failed.");
return -1;
}
- conf->publish = 1;
+ conf->publish = true;
conf->name = NULL;
status = cf_util_get_string(ci, &conf->name);
conf->client_id = NULL;
conf->qos = 0;
conf->topic_prefix = strdup(MQTT_DEFAULT_TOPIC_PREFIX);
- conf->store_rates = 1;
+ conf->store_rates = true;
status = pthread_mutex_init(&conf->lock, NULL);
if (status != 0) {
}
snprintf(cb_name, sizeof(cb_name), "mqtt/%s", conf->name);
- plugin_register_write(cb_name, mqtt_write, &(user_data_t){
- .data = conf,
- });
+ plugin_register_write(cb_name, mqtt_write,
+ &(user_data_t){
+ .data = conf,
+ });
return 0;
} /* mqtt_config_publisher */
ERROR("mqtt plugin: calloc failed.");
return -1;
}
- conf->publish = 0;
+ conf->publish = false;
conf->name = NULL;
status = cf_util_get_string(ci, &conf->name);
conf->client_id = NULL;
conf->qos = 2;
conf->topic = strdup(MQTT_DEFAULT_TOPIC);
- conf->clean_session = 1;
+ conf->clean_session = true;
status = pthread_mutex_init(&conf->lock, NULL);
if (status != 0) {