/* $Id$ * UDP Gateway utility startup scripts support * Copyright (C) 2004 Jan Kratochvil * * 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; exactly version 2 of June 1991 is required * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" #include #include "startup.h" /* self */ #include "startup-lsb.h" #include "startup-chkconfig.h" #include "startup-debian.h" gboolean udpgate_startup_query(UdpgateStartup *udpgate_startup,gboolean *is_on) { g_return_val_if_fail(UDPGATE_IS_STARTUP(udpgate_startup),FALSE); return (*UDPGATE_STARTUP_GET_CLASS(udpgate_startup)->query)(udpgate_startup,is_on); } gboolean udpgate_startup_on(UdpgateStartup *udpgate_startup) { gboolean is_on; g_return_val_if_fail(UDPGATE_IS_STARTUP(udpgate_startup),FALSE); if (!udpgate_startup_query(udpgate_startup,&is_on)) return FALSE; if (is_on==TRUE) return TRUE; if (!(*UDPGATE_STARTUP_GET_CLASS(udpgate_startup)->on)(udpgate_startup)) return FALSE; if (!udpgate_startup_query(udpgate_startup,&is_on)) return FALSE; if (is_on!=TRUE) { g_warning(_("Error registering automatic program startup!")); return FALSE; } return TRUE; } gboolean udpgate_startup_off(UdpgateStartup *udpgate_startup) { gboolean is_on; g_return_val_if_fail(UDPGATE_IS_STARTUP(udpgate_startup),FALSE); if (!udpgate_startup_query(udpgate_startup,&is_on)) return FALSE; if (is_on==FALSE) return TRUE; if (!(*UDPGATE_STARTUP_GET_CLASS(udpgate_startup)->off)(udpgate_startup)) return FALSE; if (!udpgate_startup_query(udpgate_startup,&is_on)) return FALSE; if (is_on!=FALSE) { g_warning(_("Error removing program's system startup registrance!")); return FALSE; } return TRUE; } UdpgateStartup *udpgate_startup_new(void) { const GType impl_type_array[]={ UDPGATE_TYPE_STARTUP_LSB, UDPGATE_TYPE_STARTUP_CHKCONFIG, UDPGATE_TYPE_STARTUP_DEBIAN, }; const GType *impl_type_pointer; for (impl_type_pointer = impl_type_array; impl_type_pointer < impl_type_array + G_N_ELEMENTS(impl_type_array); impl_type_pointer++) { UdpgateStartup *udpgate_startup; udpgate_startup=g_object_new(*impl_type_pointer,NULL); g_assert(UDPGATE_IS_STARTUP(udpgate_startup)); if (UDPGATE_STARTUP_GET_CLASS(udpgate_startup)->init(udpgate_startup)) return udpgate_startup; g_object_unref(udpgate_startup); } return NULL; } static void udpgate_startup_class_init (UdpgateStartupClass *class) { } GType udpgate_startup_get_type(void) { static GType startup_type=0; if (!startup_type) { static const GTypeInfo startup_info={ sizeof(UdpgateStartupClass), NULL, /* base_init */ NULL, /* base_finalize */ (GClassInitFunc)udpgate_startup_class_init, NULL, /* class_finalize */ NULL, /* class_data */ sizeof(UdpgateStartup), 0, /* n_preallocs */ NULL, /* instance_init */ NULL, /* value_table */ }; startup_type=g_type_register_static(G_TYPE_OBJECT,"UdpgateStartup", &startup_info,G_TYPE_FLAG_ABSTRACT); } return startup_type; }