107 lines
2.1 KiB
C++
107 lines
2.1 KiB
C++
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <getopt.h>
|
|
|
|
#include "logging.h"
|
|
#include "config.h"
|
|
#include "gamescanner.h"
|
|
#include "gameparser.h"
|
|
#include "hlswserver.h"
|
|
#include "timerservice.h"
|
|
#include "modulelist.h"
|
|
|
|
#include "mod_example.h"
|
|
|
|
#define DEFAULT_CONFIG "hlswmaster.conf"
|
|
#define DEFAULT_LOGFILE "hlswmaster.log"
|
|
|
|
static struct option opts[] = {
|
|
{"config", 1, 0, 'c'},
|
|
{"debug", 0, 0, 'd'},
|
|
{"help", 0, 0, 'h'},
|
|
{0, 0, 0, 0}
|
|
};
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
LogSystem::init(LOG_DEBUG, new StdErrLog());
|
|
|
|
int arg = 0, code = 0, debug = 0;
|
|
char *configfile = DEFAULT_CONFIG;
|
|
while (code != -1) {
|
|
code = getopt_long(argc, argv, "c:dh", opts, &arg);
|
|
|
|
switch (code) {
|
|
case 'c': /* config */
|
|
configfile = optarg;
|
|
break;
|
|
|
|
case 'd': /* debug */
|
|
debug = 1;
|
|
break;
|
|
|
|
case 'h': /* help */
|
|
printf("Usage: hlsw-master [options]\n"
|
|
"Options: \n"
|
|
" --config -c configfile use this configfile\n"
|
|
" --debug -d do not fork and log to stderr\n"
|
|
" --help -h this help\n"
|
|
"\n");
|
|
exit(0);
|
|
break;
|
|
|
|
case '?': /* error */
|
|
exit(-1);
|
|
break;
|
|
|
|
default: /* unknown / all options parsed */
|
|
break;
|
|
}
|
|
}
|
|
|
|
Config conf;
|
|
conf.parseFile(configfile);
|
|
|
|
// char* logfile = conf.getString("global", "logfile", DEFAULT_LOGFILE);
|
|
// int logprio = conf.getInteger("global", "logprio", LOG_NOTICE);
|
|
// LogSystem::init(logprio, new FileLog(logfile));
|
|
|
|
LogSystem::log(LOG_EVERYTIME, "hlswmaster-ng startup");
|
|
// conf.show();
|
|
|
|
ModuleList modList;
|
|
|
|
GameScanner scanner(conf, modList);
|
|
GameParser parser(conf, scanner, modList);
|
|
HlswServer server(conf, parser);
|
|
|
|
modList.reg(new ModExample(conf));
|
|
|
|
server.start();
|
|
parser.start();
|
|
scanner.start();
|
|
|
|
while (1) {
|
|
TimerService::checkTimers();
|
|
usleep(500000);
|
|
|
|
if (!scanner.isRunning()) {
|
|
LogSystem::log(LOG_CRIT, "Scanner aborted!");
|
|
break;
|
|
}
|
|
|
|
if (!parser.isRunning()) {
|
|
LogSystem::log(LOG_CRIT, "RecvParser aborted!");
|
|
break;
|
|
}
|
|
|
|
if (!server.isRunning()) {
|
|
LogSystem::log(LOG_CRIT, "HlswServer aborted!");
|
|
break;
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
}
|