2 * UDP Gateway utility startup scripts support
3 * Copyright (C) 2004 Jan Kratochvil <project-udpgate@jankratochvil.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; exactly version 2 of June 1991 is required
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <glib/gmessages.h>
24 #include "startup.h" /* self */
25 #include "startup-lsb.h"
26 #include "startup-chkconfig.h"
27 #include "startup-debian.h"
30 gboolean udpgate_startup_query(UdpgateStartup *udpgate_startup,gboolean *is_on)
32 g_return_val_if_fail(UDPGATE_IS_STARTUP(udpgate_startup),FALSE);
34 return (*UDPGATE_STARTUP_GET_CLASS(udpgate_startup)->query)(udpgate_startup,is_on);
37 gboolean udpgate_startup_on(UdpgateStartup *udpgate_startup)
41 g_return_val_if_fail(UDPGATE_IS_STARTUP(udpgate_startup),FALSE);
43 if (!udpgate_startup_query(udpgate_startup,&is_on))
48 if (!(*UDPGATE_STARTUP_GET_CLASS(udpgate_startup)->on)(udpgate_startup))
50 if (!udpgate_startup_query(udpgate_startup,&is_on))
53 g_warning(_("Error registering automatic program startup!"));
59 gboolean udpgate_startup_off(UdpgateStartup *udpgate_startup)
63 g_return_val_if_fail(UDPGATE_IS_STARTUP(udpgate_startup),FALSE);
65 if (!udpgate_startup_query(udpgate_startup,&is_on))
70 if (!(*UDPGATE_STARTUP_GET_CLASS(udpgate_startup)->off)(udpgate_startup))
72 if (!udpgate_startup_query(udpgate_startup,&is_on))
75 g_warning(_("Error removing program's system startup registrance!"));
81 UdpgateStartup *udpgate_startup_new(void)
83 const GType impl_type_array[]={
84 UDPGATE_TYPE_STARTUP_LSB,
85 UDPGATE_TYPE_STARTUP_CHKCONFIG,
86 UDPGATE_TYPE_STARTUP_DEBIAN,
88 const GType *impl_type_pointer;
90 for (impl_type_pointer = impl_type_array;
91 impl_type_pointer < impl_type_array + G_N_ELEMENTS(impl_type_array);
92 impl_type_pointer++) {
93 UdpgateStartup *udpgate_startup;
95 udpgate_startup=g_object_new(*impl_type_pointer,NULL);
96 g_assert(UDPGATE_IS_STARTUP(udpgate_startup));
97 if (UDPGATE_STARTUP_GET_CLASS(udpgate_startup)->init(udpgate_startup))
98 return udpgate_startup;
99 g_object_unref(udpgate_startup);
106 udpgate_startup_class_init (UdpgateStartupClass *class)
111 udpgate_startup_get_type(void)
113 static GType startup_type=0;
116 static const GTypeInfo startup_info={
117 sizeof(UdpgateStartupClass),
118 NULL, /* base_init */
119 NULL, /* base_finalize */
120 (GClassInitFunc)udpgate_startup_class_init,
121 NULL, /* class_finalize */
122 NULL, /* class_data */
123 sizeof(UdpgateStartup),
125 NULL, /* instance_init */
126 NULL, /* value_table */
129 startup_type=g_type_register_static(G_TYPE_OBJECT,"UdpgateStartup",
130 &startup_info,G_TYPE_FLAG_ABSTRACT);