#include "global.h" #include "rtlm.h" #include "utils.h" sl_config cfg; extern char compiled[], compiledby[], compilehost[]; int Verbose; static void Usage(void) { printf( " -= MQTT Broker =- MQTT Service from ELWIX\n" "=== %s@%s === Compiled: %s ===\n\n" "\t-c \tService config\n" "\t-v\t\tVerbose (more -vvv, more verbose)\n" "\t-h\t\tHelp! This screen\n\n", compiledby, compilehost, compiled); } int main(int argc, char **argv) { char ch, szCfgName[MAXPATHLEN]; register int i; sqlite3 *acc = NULL, *pub = NULL; FILE *logg = NULL; strlcpy(szCfgName, DEFAULT_CONFIG, sizeof szCfgName); while ((ch = getopt(argc, argv, "hvc:")) != -1) switch (ch) { case 'c': strlcpy(szCfgName, optarg, sizeof szCfgName); break; case 'v': Verbose++; break; case 'h': default: Usage(); return 1; } argc -= optind; argv += optind; if (LoadConfig(szCfgName, &cfg)) { printf("Error:: can't load #%d - %s\n", cfg_GetErrno(), cfg_GetError()); return 1; } for (i = 0; i < 3; i++) if (!mqttLoadRTLM(&cfg, i)) { printf("Error:: Can't load RTL module\n"); while (i--) mqttUnloadRTLM(i); UnloadConfig(&cfg); return 2; } acc = call.OpenACC(&cfg); if (!acc) goto end; pub = call.OpenPUB(&cfg); if (!pub) goto end; logg = call.OpenLOG(&cfg); if (!logg) goto end; if (mqttMkDir(&cfg)) { printf("Error:: in statedir #%d - %s\n", errno, strerror(errno)); goto end; } VERB(2) printf("Service is ready for start engine ...\n"); end: call.CloseLOG(logg); call.ClosePUB(pub); call.CloseACC(acc); for (i = 0; i < 3; i++) mqttUnloadRTLM(i); UnloadConfig(&cfg); return 0; }