Return to mqttd.c CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / mqtt / src |
1.1 misho 1: #include "global.h"
1.1.1.1.2.1 misho 2: #include "rtlm.h"
1.1.1.1.2.4! misho 3: #include "utils.h"
1.1.1.1.2.1 misho 4:
5:
6: sl_config cfg;
1.1.1.1.2.2 misho 7: extern char compiled[], compiledby[], compilehost[];
8: int Verbose;
9:
10:
11: static void
12: Usage(void)
13: {
14: printf( " -= MQTT Broker =- MQTT Service from ELWIX\n"
15: "=== %s@%s === Compiled: %s ===\n\n"
16: "\t-c <config>\tService config\n"
17: "\t-v\t\tVerbose (more -vvv, more verbose)\n"
18: "\t-h\t\tHelp! This screen\n\n",
19: compiledby, compilehost, compiled);
20: }
1.1 misho 21:
22:
23: int
24: main(int argc, char **argv)
25: {
1.1.1.1.2.2 misho 26: char ch, szCfgName[MAXPATHLEN];
1.1.1.1.2.3 misho 27: register int i;
28: sqlite3 *acc = NULL, *pub = NULL;
29: FILE *logg = NULL;
1.1.1.1.2.2 misho 30:
31: strlcpy(szCfgName, DEFAULT_CONFIG, sizeof szCfgName);
32: while ((ch = getopt(argc, argv, "hvc:")) != -1)
33: switch (ch) {
34: case 'c':
35: strlcpy(szCfgName, optarg, sizeof szCfgName);
36: break;
37: case 'v':
38: Verbose++;
39: break;
40: case 'h':
41: default:
42: Usage();
43: return 1;
44: }
45: argc -= optind;
46: argv += optind;
47:
48: if (LoadConfig(szCfgName, &cfg)) {
49: printf("Error:: can't load #%d - %s\n", cfg_GetErrno(), cfg_GetError());
50: return 1;
51: }
1.1.1.1.2.3 misho 52: for (i = 0; i < 3; i++)
53: if (!mqttLoadRTLM(&cfg, i)) {
54: printf("Error:: Can't load RTL module\n");
55: while (i--)
56: mqttUnloadRTLM(i);
57: UnloadConfig(&cfg);
58: return 2;
59: }
60: acc = call.OpenACC(&cfg);
61: if (!acc)
62: goto end;
63: pub = call.OpenPUB(&cfg);
64: if (!pub)
65: goto end;
66: logg = call.OpenLOG(&cfg);
67: if (!logg)
68: goto end;
69:
70: if (mqttMkDir(&cfg)) {
71: printf("Error:: in statedir #%d - %s\n", errno, strerror(errno));
72: goto end;
73: }
74:
75: VERB(2) printf("Service is ready for start engine ...\n");
1.1.1.1.2.2 misho 76:
1.1.1.1.2.3 misho 77: end:
78: call.CloseLOG(logg);
79: call.ClosePUB(pub);
80: call.CloseACC(acc);
81: for (i = 0; i < 3; i++)
82: mqttUnloadRTLM(i);
1.1.1.1.2.2 misho 83: UnloadConfig(&cfg);
1.1 misho 84: return 0;
85: }