/* rygel-signal-handler.c generated by valac 0.15.1.36-84b2b, the Vala compiler
 * generated from rygel-signal-handler.vala, do not modify */

/*
 * Copyright (C) 2008,2010 Nokia Corporation.
 * Copyright (C) 2008 Zeeshan Ali (Khattak) <zeeshanak@gnome.org>.
 *
 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 *
 * This file is part of Rygel.
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Rygel 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser 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 <signal.h>
#include <string.h>


#define RYGEL_TYPE_SIGNAL_HANDLER (rygel_signal_handler_get_type ())
#define RYGEL_SIGNAL_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_SIGNAL_HANDLER, RygelSignalHandler))
#define RYGEL_SIGNAL_HANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_SIGNAL_HANDLER, RygelSignalHandlerClass))
#define RYGEL_IS_SIGNAL_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_SIGNAL_HANDLER))
#define RYGEL_IS_SIGNAL_HANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_SIGNAL_HANDLER))
#define RYGEL_SIGNAL_HANDLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_SIGNAL_HANDLER, RygelSignalHandlerClass))

typedef struct _RygelSignalHandler RygelSignalHandler;
typedef struct _RygelSignalHandlerClass RygelSignalHandlerClass;
typedef struct _RygelSignalHandlerPrivate RygelSignalHandlerPrivate;

#define RYGEL_TYPE_MAIN (rygel_main_get_type ())
#define RYGEL_MAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_MAIN, RygelMain))
#define RYGEL_MAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_MAIN, RygelMainClass))
#define RYGEL_IS_MAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_MAIN))
#define RYGEL_IS_MAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_MAIN))
#define RYGEL_MAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_MAIN, RygelMainClass))

typedef struct _RygelMain RygelMain;
typedef struct _RygelMainClass RygelMainClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _RygelSignalHandler {
	GObject parent_instance;
	RygelSignalHandlerPrivate * priv;
};

struct _RygelSignalHandlerClass {
	GObjectClass parent_class;
};


static gpointer rygel_signal_handler_parent_class = NULL;
static RygelMain* rygel_signal_handler_main;
static RygelMain* rygel_signal_handler_main = NULL;
static struct sigaction rygel_signal_handler_action;
static struct sigaction rygel_signal_handler_action = {0};

GType rygel_signal_handler_get_type (void) G_GNUC_CONST;
enum  {
	RYGEL_SIGNAL_HANDLER_DUMMY_PROPERTY
};
GType rygel_main_get_type (void) G_GNUC_CONST;
void rygel_signal_handler_setup (RygelMain* _main);
static void rygel_signal_handler_signal_handler (gint signum);
static void _rygel_signal_handler_signal_handler_sighandler_t (gint signal);
void rygel_signal_handler_cleanup (void);
static gboolean ___lambda16_ (void);
void rygel_main_restart (RygelMain* self);
static gboolean ____lambda16__gsource_func (gpointer self);
static gboolean ___lambda17_ (void);
void rygel_main_exit (RygelMain* self, gint exit_code);
static gboolean ____lambda17__gsource_func (gpointer self);
RygelSignalHandler* rygel_signal_handler_new (void);
RygelSignalHandler* rygel_signal_handler_construct (GType object_type);
static void rygel_signal_handler_finalize (GObject* obj);


static gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


static void _rygel_signal_handler_signal_handler_sighandler_t (gint signal) {
	rygel_signal_handler_signal_handler (signal);
}


void rygel_signal_handler_setup (RygelMain* _main) {
	RygelMain* _tmp0_;
	RygelMain* _tmp1_;
	struct sigaction _tmp2_;
	struct sigaction _tmp3_;
	struct sigaction _tmp4_;
	g_return_if_fail (_main != NULL);
	_tmp0_ = _main;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (rygel_signal_handler_main);
	rygel_signal_handler_main = _tmp1_;
	memset (&rygel_signal_handler_action, 0, sizeof (struct sigaction));
	rygel_signal_handler_action.sa_handler = _rygel_signal_handler_signal_handler_sighandler_t;
	_tmp2_ = rygel_signal_handler_action;
	sigaction (SIGINT, &_tmp2_, NULL);
	_tmp3_ = rygel_signal_handler_action;
	sigaction (SIGTERM, &_tmp3_, NULL);
	_tmp4_ = rygel_signal_handler_action;
	sigaction (SIGHUP, &_tmp4_, NULL);
}


void rygel_signal_handler_cleanup (void) {
	_g_object_unref0 (rygel_signal_handler_main);
	rygel_signal_handler_main = NULL;
}


static gboolean ___lambda16_ (void) {
	gboolean result = FALSE;
	RygelMain* _tmp0_;
	_tmp0_ = rygel_signal_handler_main;
	rygel_main_restart (_tmp0_);
	result = FALSE;
	return result;
}


static gboolean ____lambda16__gsource_func (gpointer self) {
	gboolean result;
	result = ___lambda16_ ();
	return result;
}


static gboolean ___lambda17_ (void) {
	gboolean result = FALSE;
	RygelMain* _tmp0_;
	_tmp0_ = rygel_signal_handler_main;
	if (_tmp0_ != NULL) {
		RygelMain* _tmp1_;
		_tmp1_ = rygel_signal_handler_main;
		rygel_main_exit (_tmp1_, 0);
	}
	result = FALSE;
	return result;
}


static gboolean ____lambda17__gsource_func (gpointer self) {
	gboolean result;
	result = ___lambda17_ ();
	return result;
}


static void rygel_signal_handler_signal_handler (gint signum) {
	RygelMain* _tmp0_;
	gint _tmp1_;
	_tmp0_ = rygel_signal_handler_main;
	if (_tmp0_ == NULL) {
		g_debug ("rygel-signal-handler.vala:52: Signal handler already called, ignoring");
		return;
	}
	_tmp1_ = signum;
	if (_tmp1_ == SIGHUP) {
		g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ____lambda16__gsource_func, NULL, NULL);
	} else {
		g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ____lambda17__gsource_func, NULL, NULL);
	}
}


RygelSignalHandler* rygel_signal_handler_construct (GType object_type) {
	RygelSignalHandler * self = NULL;
	self = (RygelSignalHandler*) g_object_new (object_type, NULL);
	return self;
}


RygelSignalHandler* rygel_signal_handler_new (void) {
	return rygel_signal_handler_construct (RYGEL_TYPE_SIGNAL_HANDLER);
}


static void rygel_signal_handler_class_init (RygelSignalHandlerClass * klass) {
	rygel_signal_handler_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = rygel_signal_handler_finalize;
}


static void rygel_signal_handler_instance_init (RygelSignalHandler * self) {
}


static void rygel_signal_handler_finalize (GObject* obj) {
	RygelSignalHandler * self;
	self = RYGEL_SIGNAL_HANDLER (obj);
	G_OBJECT_CLASS (rygel_signal_handler_parent_class)->finalize (obj);
}


/**
 * Handles Posix signals.
 */
GType rygel_signal_handler_get_type (void) {
	static volatile gsize rygel_signal_handler_type_id__volatile = 0;
	if (g_once_init_enter (&rygel_signal_handler_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RygelSignalHandlerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_signal_handler_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelSignalHandler), 0, (GInstanceInitFunc) rygel_signal_handler_instance_init, NULL };
		GType rygel_signal_handler_type_id;
		rygel_signal_handler_type_id = g_type_register_static (G_TYPE_OBJECT, "RygelSignalHandler", &g_define_type_info, 0);
		g_once_init_leave (&rygel_signal_handler_type_id__volatile, rygel_signal_handler_type_id);
	}
	return rygel_signal_handler_type_id__volatile;
}



