/* main.c generated by valac 0.14.2, the Vala compiler
 * generated from main.vala, do not modify */

/*
 * Copyright (C) 2009-2011 Michael 'Mickey' Lauer <mlauer@vanille-media.de>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program 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 General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 */

#include <glib.h>
#include <glib-object.h>
#include <fsoframework.h>
#include <signal.h>
#include <fsobasics.h>
#include <stdlib.h>
#include <string.h>

#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL)))


extern GMainLoop* mainloop;
GMainLoop* mainloop = NULL;
extern FsoFrameworkSubsystem* subsystem;
FsoFrameworkSubsystem* subsystem = NULL;

void sighandler (gint signum);
static gboolean __lambda0_ (void);
static gboolean ___lambda0__gsource_func (gpointer self);
gint _vala_main (gchar** args, int args_length1);
static void _sighandler_sighandler_t (gint signal);


static gboolean __lambda0_ (void) {
	gboolean result = FALSE;
	FsoFrameworkSubsystem* _tmp0_;
	GMainLoop* _tmp1_;
	_tmp0_ = subsystem;
	fso_framework_subsystem_shutdown (_tmp0_);
	_tmp1_ = mainloop;
	g_main_loop_quit (_tmp1_);
	result = FALSE;
	return result;
}


static gboolean ___lambda0__gsource_func (gpointer self) {
	gboolean result;
	result = __lambda0_ ();
	return result;
}


void sighandler (gint signum) {
	gint _tmp0_;
	FsoFrameworkLogger* _tmp1_;
	gint _tmp2_;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_;
	_tmp0_ = signum;
	signal (_tmp0_, NULL);
	_tmp1_ = fso_framework_theLogger;
	_tmp2_ = signum;
	_tmp3_ = g_strdup_printf ("received signal -%d, exiting.", _tmp2_);
	_tmp4_ = _tmp3_;
	fso_framework_logger_info (_tmp1_, _tmp4_);
	_g_free0 (_tmp4_);
	g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ___lambda0__gsource_func, NULL, NULL);
}


static void _sighandler_sighandler_t (gint signal) {
	sighandler (signal);
}


gint _vala_main (gchar** args, int args_length1) {
	gint result = 0;
	gchar* _tmp0_ = NULL;
	gchar* bin;
	FsoFrameworkDBusSubsystem* _tmp1_;
	FsoFrameworkSubsystem* _tmp2_;
	FsoFrameworkSubsystem* _tmp3_;
	guint _tmp4_ = 0U;
	guint count;
	FsoFrameworkLogger* _tmp5_;
	guint _tmp6_;
	gchar* _tmp7_ = NULL;
	gchar* _tmp8_;
	guint _tmp9_;
	FsoFrameworkLogger* _tmp20_;
	const gchar* _tmp21_;
	gchar* _tmp22_ = NULL;
	gchar* _tmp23_;
	_tmp0_ = fso_framework_utility_programName ();
	bin = _tmp0_;
	_tmp1_ = fso_framework_dbus_subsystem_new ("fsogsm");
	_g_object_unref0 (subsystem);
	subsystem = (FsoFrameworkSubsystem*) _tmp1_;
	_tmp2_ = subsystem;
	fso_framework_subsystem_registerPlugins (_tmp2_);
	_tmp3_ = subsystem;
	_tmp4_ = fso_framework_subsystem_loadPlugins (_tmp3_);
	count = _tmp4_;
	_tmp5_ = fso_framework_theLogger;
	_tmp6_ = count;
	_tmp7_ = g_strdup_printf ("loaded %u plugins", _tmp6_);
	_tmp8_ = _tmp7_;
	fso_framework_logger_info (_tmp5_, _tmp8_);
	_g_free0 (_tmp8_);
	_tmp9_ = count;
	if (_tmp9_ > ((guint) 0)) {
		GMainLoop* _tmp10_;
		FsoFrameworkLogger* _tmp11_;
		const gchar* _tmp12_;
		gchar* _tmp13_ = NULL;
		gchar* _tmp14_;
		GMainLoop* _tmp15_;
		FsoFrameworkLogger* _tmp16_;
		const gchar* _tmp17_;
		gchar* _tmp18_ = NULL;
		gchar* _tmp19_;
		_tmp10_ = g_main_loop_new (NULL, FALSE);
		_g_main_loop_unref0 (mainloop);
		mainloop = _tmp10_;
		_tmp11_ = fso_framework_theLogger;
		_tmp12_ = bin;
		_tmp13_ = g_strdup_printf ("%s => mainloop", _tmp12_);
		_tmp14_ = _tmp13_;
		fso_framework_logger_info (_tmp11_, _tmp14_);
		_g_free0 (_tmp14_);
		signal (SIGINT, _sighandler_sighandler_t);
		signal (SIGTERM, _sighandler_sighandler_t);
		signal (SIGBUS, _sighandler_sighandler_t);
		signal (SIGSEGV, _sighandler_sighandler_t);
		_tmp15_ = mainloop;
		g_main_loop_run (_tmp15_);
		_tmp16_ = fso_framework_theLogger;
		_tmp17_ = bin;
		_tmp18_ = g_strdup_printf ("mainloop => %s", _tmp17_);
		_tmp19_ = _tmp18_;
		fso_framework_logger_info (_tmp16_, _tmp19_);
		_g_free0 (_tmp19_);
	}
	_tmp20_ = fso_framework_theLogger;
	_tmp21_ = bin;
	_tmp22_ = g_strdup_printf ("%s exit", _tmp21_);
	_tmp23_ = _tmp22_;
	fso_framework_logger_info (_tmp20_, _tmp23_);
	_g_free0 (_tmp23_);
	result = 0;
	_g_free0 (bin);
	return result;
}


int main (int argc, char ** argv) {
	g_type_init ();
	return _vala_main (argv, argc);
}



