version 1.1, 2011/11/07 08:47:16
|
version 1.1.1.1.2.3, 2011/11/29 23:23:31
|
Line 1
|
Line 1
|
#include "global.h" |
#include "global.h" |
|
#include "rtlm.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 <config>\tService config\n" |
|
"\t-v\t\tVerbose (more -vvv, more verbose)\n" |
|
"\t-h\t\tHelp! This screen\n\n", |
|
compiledby, compilehost, compiled); |
|
} |
|
|
|
|
int |
int |
main(int argc, char **argv) |
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; |
return 0; |
} |
} |