File:  [ELWIX - Embedded LightWeight unIX -] / mqtt / src / mqttd.c
Revision 1.1.1.1.2.4: download - view: text, annotated - select for diffs - revision graph
Tue Nov 29 23:31:57 2011 UTC (12 years, 7 months ago) by misho
Branches: mqtt1_0
Diff to: branchpoint 1.1.1.1: preferred, unified
add new files

    1: #include "global.h"
    2: #include "rtlm.h"
    3: #include "utils.h"
    4: 
    5: 
    6: sl_config cfg;
    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: }
   21: 
   22: 
   23: int
   24: main(int argc, char **argv)
   25: {
   26: 	char ch, szCfgName[MAXPATHLEN];
   27: 	register int i;
   28: 	sqlite3 *acc = NULL, *pub = NULL;
   29: 	FILE *logg = NULL;
   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: 	}
   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");
   76: 
   77: end:
   78: 	call.CloseLOG(logg);
   79: 	call.ClosePUB(pub);
   80: 	call.CloseACC(acc);
   81: 	for (i = 0; i < 3; i++)
   82: 		mqttUnloadRTLM(i);
   83: 	UnloadConfig(&cfg);
   84: 	return 0;
   85: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>