<commit_before>/**
 * This file is part of Slideshow.
 * Copyright (C) 2008-2010 <NAME> <<EMAIL>>
 *
 * Slideshow is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * Slideshow is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Slideshow.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifdef HAVE_CONFIG_H
#	include "config.h"
#endif

#include "Kernel.h"
#include "ForegroundApp.h"

#ifdef BUILD_DAEMON
#	include "DaemonApp.h"
#endif /* BUILD_DAEMON */

#include "Log.h"
#include "Exceptions.h"
#include "module_loader.h"
#include "path.h"
#include <cstring>
#include <limits.h>
#include <portable/Time.h>
#include "backend/platform.h"

// for getcwd
#ifdef WIN32
#	include <direct.h>
#	define getcwd _getcwd
#	define PATH_MAX _MAX_PATH
#endif

int main( int argc, const char* argv[] ){
	try {

		// Default arguments
		Kernel::argument_set_t arguments = {
			Kernel::ForegroundMode, // mode
			Log::Info, 				// loglevel
			false,					// fullscreen
			false,					// have_password
			0, 						// collection_id
			800,					// width
			600,					// height
			3.0f,					// transition_time;
			5.0f,					// switch_time;
			NULL,					// connection_string
			NULL					// transition_string
		};

		// Parse the cli arguments, overriding the defaults
		if ( !Kernel::parse_arguments(arguments, argc, argv) ){
			throw exception("Failed to parse commandline arguments");
		}

		initTime();
		moduleloader_init(pluginpath());
		PlatformBackend::register_all();

		Log::initialize("slideshow.log");
		Log::set_level( (Log::Severity)arguments.loglevel );

		Kernel* application = NULL;
		PlatformBackend* backend = PlatformBackend::factory("sdl");

		switch ( arguments.mode ){
			case Kernel::ForegroundMode:
				application = new ForegroundApp(arguments, backend);
				break;
			case Kernel::DaemonMode: 
#ifdef BUILD_DAEMON
				application = new DaemonApp(arguments, backend); break;
#else /* BUILD_DAEMON */
				throw exception("DaemonMode is not supported on this platform.");
#endif /* BUILD_DAEMON */
			case Kernel::ListTransitionMode:
				Kernel::print_transitions();
				throw ExitException();
			default:
				throw exception("No valid mode. This should not happen, please report this to the maintainer. Modeid: %d\n", arguments.mode);
		}

		application->init();
		application->run();
		application->cleanup();

		delete application;

		moduleloader_cleanup();

		Log::deinitialize();

	} catch ( ExitException &e ){<commit_msg>throwing exception when failing to create a backend<commit_after>/**
 * This file is part of Slideshow.
 * Copyright (C) 2008-2010 <NAME> <<EMAIL>>
 *
 * Slideshow is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * Slideshow is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Slideshow.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifdef HAVE_CONFIG_H
#	include "config.h"
#endif

#include "Kernel.h"
#include "ForegroundApp.h"

#ifdef BUILD_DAEMON
#	include "DaemonApp.h"
#endif /* BUILD_DAEMON */

#include "Log.h"
#include "Exceptions.h"
#include "module_loader.h"
#include "path.h"
#include <cstring>
#include <limits.h>
#include <portable/Time.h>
#include "backend/platform.h"

// for getcwd
#ifdef WIN32
#	include <direct.h>
#	define getcwd _getcwd
#	define PATH_MAX _MAX_PATH
#endif

int main( int argc, const char* argv[] ){
	try {

		// Default arguments
		Kernel::argument_set_t arguments = {
			Kernel::ForegroundMode, // mode
			Log::Info, 				// loglevel
			false,					// fullscreen
			false,					// have_password
			0, 						// collection_id
			800,					// width
			600,					// height
			3.0f,					// transition_time;
			5.0f,					// switch_time;
			NULL,					// connection_string
			NULL					// transition_string
		};

		// Parse the cli arguments, overriding the defaults
		if ( !Kernel::parse_arguments(arguments, argc, argv) ){
			throw exception("Failed to parse commandline arguments");
		}

		initTime();
		moduleloader_init(pluginpath());
		PlatformBackend::register_all();

		Log::initialize("slideshow.log");
		Log::set_level( (Log::Severity)arguments.loglevel );

		Kernel* application = NULL;

		const char* backend_name = "sdl";
		PlatformBackend* backend = PlatformBackend::factory(backend_name);
		if ( !backend ){
			throw exception("Failed to create a backend named \"%s\"", backend_name);
		}

		switch ( arguments.mode ){
			case Kernel::ForegroundMode:
				application = new ForegroundApp(arguments, backend);
				break;
			case Kernel::DaemonMode: 
#ifdef BUILD_DAEMON
				application = new DaemonApp(arguments, backend); break;
#else /* BUILD_DAEMON */
				throw exception("DaemonMode is not supported on this platform.");
#endif /* BUILD_DAEMON */
			case Kernel::ListTransitionMode:
				Kernel::print_transitions();
				throw ExitException();
			default:
				throw exception("No valid mode. This should not happen, please report this to the maintainer. Modeid: %d\n", arguments.mode);
		}

		application->init();
		application->run();
		application->cleanup();

		delete application;

		moduleloader_cleanup();

		Log::deinitialize();

	} catch ( ExitException &e ){
{'fraction_non_alphanumeric': 0.11498664886515354, 'fraction_numerical': 0.007343124165554072, 'mean_word_length': 3.722616233254531, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6665323', 'n_tokens_mistral': 2097, 'n_tokens_neox': 1826, 'n_words': 584}