/*
** SellaNMS
** $Id: daemon.cxx,v 1.7 2005/05/22 00:20:33 sella Exp $
** Copyright (c) 2001-2005 Digital Genesis Software, LLC. All Rights Reserved.
** Released under the GPL Version 2 License.
** http://www.digitalgenesis.com
*/

static char rcsid[] = "$Id: daemon.cxx,v 1.7 2005/05/22 00:20:33 sella Exp $";

#include "daemon.h"
#include "gui.h"
#include <signal.h>

void sighandler(int sig) {
	switch (sig) {
		case SIGUSR1:
			LMSG("Caught SIGUSR1 - daemon");
			break;

		case SIGUSR2:
			LMSG("Caught SIGUSR2 - daemon");
			break;

		default:
			LMSG("Caught unknown signal - daemon");
	}
}

bool start() {
	Gui *gui = NULL;

	/* Install Signal Handlers */
	if (signal(SIGUSR1, &sighandler) == SIG_ERR) {
		LMSG("Failed to install signal handler for SIGUSR1.");
	}
	if (signal(SIGUSR2, &sighandler) == SIG_ERR) {
		LMSG("Failed to install signal handler for SIGUSR2.");
	}

	if ((gui = new Gui()) != NULL) {
		if (gui->readConfig() == SUCCESS) {
			gui->execute();
		}

		SAFE_DELETE(gui);
	} else {
		LMSG("failed to allocate memory for Gui().");
	}
}

const char* getName() {
	return "guid";
}

const char* getConfigPath() {
	return "output gui";
}

const char* getProcTitle() {
	return "guid <out>";
}

const char* getDefaultConfigFile() {
	return DEFAULT_CONFIG_FILE;
}

const char* getDefaultPidFile() {
	return DEFAULT_PID_FILE;
}

const char* getDefaultStatFile() {
	return DEFAULT_STAT_FILE;
}

int getDefaultNiceness() {
	return DEFAULT_NICENESS;
}

/*
** Local Variables:
** c-basic-offset: 3
** tab-width: 3
** End:
** vim600: fdm=marker
** vim: noet ts=3 sw=3
*/
