File:  [ELWIX - Embedded LightWeight unIX -] / mqtt / src / mqttd.c
Revision 1.1.1.1.2.5: download - view: text, annotated - select for diffs - revision graph
Wed Nov 30 00:12:30 2011 UTC (12 years, 7 months ago) by misho
Branches: mqtt1_0
Diff to: branchpoint 1.1.1.1: preferred, unified
finish server socket init part

    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: 	int sock, ret = 0;
   31: 
   32: 	strlcpy(szCfgName, DEFAULT_CONFIG, sizeof szCfgName);
   33: 	while ((ch = getopt(argc, argv, "hvc:")) != -1)
   34: 		switch (ch) {
   35: 			case 'c':
   36: 				strlcpy(szCfgName, optarg, sizeof szCfgName);
   37: 				break;
   38: 			case 'v':
   39: 				Verbose++;
   40: 				break;
   41: 			case 'h':
   42: 			default:
   43: 				Usage();
   44: 				return 1;
   45: 		}
   46: 	argc -= optind;
   47: 	argv += optind;
   48: 
   49: 	if (LoadConfig(szCfgName, &cfg)) {
   50: 		printf("Error:: can't load #%d - %s\n", cfg_GetErrno(), cfg_GetError());
   51: 		return 1;
   52: 	}
   53: 	for (i = 0; i < 3; i++)
   54: 		if (!mqttLoadRTLM(&cfg, i)) {
   55: 			printf("Error:: Can't load RTL module\n");
   56: 			while (i--)
   57: 				mqttUnloadRTLM(i);
   58: 			UnloadConfig(&cfg);
   59: 			return 2;
   60: 		}
   61: 	acc = call.OpenACC(&cfg);
   62: 	if (!acc) {
   63: 		ret = 3;
   64: 		goto end;
   65: 	}
   66: 	pub = call.OpenPUB(&cfg);
   67: 	if (!pub) {
   68: 		ret = 3;
   69: 		goto end;
   70: 	}
   71: 	logg = call.OpenLOG(&cfg);
   72: 	if (!logg) {
   73: 		ret = 3;
   74: 		goto end;
   75: 	}
   76: 
   77: 	if (mqttMkDir(&cfg)) {
   78: 		printf("Error:: in statedir #%d - %s\n", errno, strerror(errno));
   79: 		ret = 3;
   80: 		goto end;
   81: 	}
   82: 
   83: 	VERB(2) printf("Service is ready for start engine ...\n");
   84: 
   85: 	if ((sock = srv_Socket(&cfg)) == -1) {
   86: 		ret = 4;
   87: 		goto end;
   88: 	}
   89: 
   90: 	srv_Close(sock);
   91: end:
   92: 	call.CloseLOG(logg);
   93: 	call.ClosePUB(pub);
   94: 	call.CloseACC(acc);
   95: 	for (i = 0; i < 3; i++)
   96: 		mqttUnloadRTLM(i);
   97: 	UnloadConfig(&cfg);
   98: 	return ret;
   99: }

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