From 0984a86f9243a8147b8f02882af6380ee5bff22e Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Tue, 29 Oct 2024 23:30:39 +0100 Subject: Bessere Namensgebung für Funktionen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.c | 28 ++++++++++++++++------------ src/mqtt.c | 18 +++++++++--------- 2 files changed, 25 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index 5bef36b..82e7606 100644 --- a/src/main.c +++ b/src/main.c @@ -7,6 +7,9 @@ // System #include +// Mosquitto +#include + // Project #include "config.h" #include "mqtt.h" @@ -15,10 +18,10 @@ # define UNUSED(x) (void) (x) #endif -static volatile bool terminate = false; // NOLINT +static volatile bool terminate; // NOLINT static void -handler(int signal) +signal_handler(int signal) { if ( signal == SIGINT ) { terminate = true; @@ -26,18 +29,19 @@ handler(int signal) } static void -cleanup(void) +cleanup_app(void) { mosquitto_lib_cleanup(); } static void -init(void) +init_app(void) { - (void) signal(SIGINT, handler); + terminate = false; + (void) signal(SIGINT, signal_handler); mosquitto_lib_init(); - (void) atexit(cleanup); + (void) atexit(cleanup_app); } static void @@ -53,13 +57,13 @@ callback(struct mosquitto *client, void *userdata, const struct mosquitto_messag int main(void) { - init(); + init_app(); - struct mosquitto *client = connect( - CLIENT_ID, + struct mosquitto *client = mqtt_connect( + CLIENTID, USERNAME, PASSWORD, - HOST, + HOSTNAME, PORT, callback, NULL); @@ -68,9 +72,9 @@ main(void) return EXIT_FAILURE; } - run(client, (const char *[]){ TOPIC, NULL }, &terminate); + mqtt_run(client, (const char *[]){ TOPIC, NULL }, &terminate); - shutdown(client); + mqtt_shutdown(client); return EXIT_SUCCESS; } diff --git a/src/mqtt.c b/src/mqtt.c index 50cfa6a..ce89b0b 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -9,13 +9,13 @@ #include "mqtt.h" struct mosquitto * -connect(const char *clientid, // NOLINT - const char *username, // NOLINT - const char *password, // NOLINT - const char *hostname, // NOLINT - int port, - void callback(struct mosquitto *, void *, const struct mosquitto_message *), - void *userdata) +mqtt_connect(const char *clientid, // NOLINT + const char *username, // 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); if ( client == NULL ) { @@ -43,7 +43,7 @@ connect(const char *clientid, // NOLINT } void -run(struct mosquitto *client, const char *topics[], const volatile bool *quit) +mqtt_run(struct mosquitto *client, const char *topics[], const volatile bool *quit) { for ( size_t idx = 0; topics[idx] != NULL; ++idx ) { mosquitto_subscribe(client, NULL, topics[idx], 0); @@ -62,7 +62,7 @@ run(struct mosquitto *client, const char *topics[], const volatile bool *quit) } void -shutdown(struct mosquitto *client) +mqtt_shutdown(struct mosquitto *client) { mosquitto_disconnect(client); mosquitto_destroy(client); -- cgit v1.3