// ==============================================
// Zboard Config Utility
// Copyright (C) 2007 Matt Razza
// ----------------------------------------------
// This file contains the main loop
// ==============================================

// Standard Includes
#include "zboard-inc.h"

// Starts the zboard management system
void startSystem()
{
	// Create vars
	int iLoop;
	std::string sData = "", oldData = "", currentConfig = "", mapPath = "/usr/share/zboard-config/maps/";
	settingMan setting("/usr/share/zboard-config/zboard.conf");
	
	// Loop for ever
	while (true)
	{
		// Reset to defaults
		iLoop = 1;
		sData = "";
		currentConfig = "";
		
		sData = setting.getSettingNameByID(iLoop); //Start loop off
		
		// Loop until End of File
		while (sData != "ZINVALIDZ")
		{
			// Is the app running
			if (linuxProcInfo::isRunning(sData))
			{
				currentConfig = setting.getSetting(sData); //Get setting file
				break;
			}
			
			// Continue loop
			iLoop++;
			sData = setting.getSettingNameByID(iLoop);
		}
		
		// If no app found, set default config
		if (currentConfig == "")
			currentConfig = setting.getSetting("DEFAULT");
		
		// Update Needed?
		if (currentConfig != oldData)
		{
			mapInterface::bindNewFile(mapPath + currentConfig);
			oldData = currentConfig;
		}
		
		sleep(5); // Wait 5 seconds before we scan again
	}
}
