summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2024-11-04 16:42:24 +0100
committerThomas Schmucker <ts@its1.de>2024-11-04 16:42:24 +0100
commite2e32a1410331f2c478d61b3ecd0a0baf4aec511 (patch)
tree0be98671f9a15bdf4b719f14ad497290b872b760 /src
parentd2a40e5f9e17c32f081b7d6ffe719cf82407ba51 (diff)
downloaduse-mosquitto-e2e32a1410331f2c478d61b3ecd0a0baf4aec511.tar.gz
use-mosquitto-e2e32a1410331f2c478d61b3ecd0a0baf4aec511.tar.bz2
use-mosquitto-e2e32a1410331f2c478d61b3ecd0a0baf4aec511.zip
Verschiebe die Hauptlogik von 'publish.c' in eine eigene Funktion
Diffstat (limited to 'src')
-rw-r--r--src/publish.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/publish.c b/src/publish.c
index 98cab76..28a9c3a 100644
--- a/src/publish.c
+++ b/src/publish.c
@@ -1,5 +1,4 @@
1// Standard C 1// Standard C
2#include <signal.h>
3#include <stdbool.h> 2#include <stdbool.h>
4#include <stdio.h> 3#include <stdio.h>
5#include <stdlib.h> 4#include <stdlib.h>
@@ -38,28 +37,14 @@ application_init(void)
38 (void) atexit(application_cleanup); 37 (void) atexit(application_cleanup);
39} 38}
40 39
41int 40static void
42main(void) 41application_run(struct mosquitto *client)
43{ 42{
44 application_init(); 43 char command[MAX_COMMAND_LENGTH];
45
46 struct mosquitto *client = mqtt_connect(
47 NULL,
48 USERNAME,
49 PASSWORD,
50 HOSTNAME,
51 PORT,
52 NULL);
53 44
54 if ( !client ) {
55 return EXIT_FAILURE;
56 }
57
58 // logic
59 for ( bool quit = false; !quit; ) { 45 for ( bool quit = false; !quit; ) {
60 printf("> "); 46 printf("> ");
61 47
62 char command[MAX_COMMAND_LENGTH];
63 if ( fgets(command, sizeof command, stdin) == NULL ) { 48 if ( fgets(command, sizeof command, stdin) == NULL ) {
64 quit = true; 49 quit = true;
65 continue; 50 continue;
@@ -95,6 +80,26 @@ main(void)
95 (void) fprintf(stderr, "unknown command: '%s'\n", command); 80 (void) fprintf(stderr, "unknown command: '%s'\n", command);
96 } 81 }
97 } 82 }
83}
84
85int
86main(void)
87{
88 application_init();
89
90 struct mosquitto *client = mqtt_connect(
91 NULL,
92 USERNAME,
93 PASSWORD,
94 HOSTNAME,
95 PORT,
96 NULL);
97
98 if ( !client ) {
99 return EXIT_FAILURE;
100 }
101
102 application_run(client);
98 103
99 mqtt_shutdown(client); 104 mqtt_shutdown(client);
100 105