From 9e339087e328d445f38173401f77502297a638f4 Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Mon, 4 Nov 2024 16:18:20 +0100 Subject: Verschiebe callback-handling nach 'mqtt_run' --- src/mqtt.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/mqtt.c') diff --git a/src/mqtt.c b/src/mqtt.c index 32e2ea9..34e7ee8 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -14,7 +14,6 @@ mqtt_connect(const char *clientid, // NOLINT const char *password, // NOLINT const char *hostname, // NOLINT int port, - void callback(struct mosquitto *, void *, const struct mosquitto_message *), void *userdata) { struct mosquitto *client = mosquitto_new(clientid, true, userdata); @@ -30,10 +29,6 @@ mqtt_connect(const char *clientid, // NOLINT return NULL; } - if ( callback ) { - mosquitto_message_callback_set(client, callback); - } - err = mosquitto_connect(client, hostname, port, KEEPALIVE); if ( err != MOSQ_ERR_SUCCESS ) { (void) fprintf(stderr, "error: %s\n", mosquitto_strerror(err)); @@ -45,8 +40,15 @@ mqtt_connect(const char *clientid, // NOLINT } void -mqtt_run(struct mosquitto *client, const char *topics[], const volatile bool *quit) +mqtt_run(struct mosquitto *client, + const char *topics[], + void callback(struct mosquitto *, void *, const struct mosquitto_message *), + const volatile bool *quit) { + if ( callback ) { + mosquitto_message_callback_set(client, callback); + } + int *mid = NULL; for ( size_t idx = 0; topics[idx] != NULL; ++idx ) { -- cgit v1.3