Cosmetic: Fixed error message.
[udpgate.git] / src / startup.c
1 /* $Id$
2  * UDP Gateway utility startup scripts support
3  * Copyright (C) 2004 Jan Kratochvil <project-udpgate@jankratochvil.net>
4  * 
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
8  * 
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.
13  * 
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
17  */
18
19
20 #include "config.h"
21
22 #include <glib/gmessages.h>
23
24 #include "startup.h"    /* self */
25 #include "startup-lsb.h"
26 #include "startup-chkconfig.h"
27 #include "startup-debian.h"
28
29
30 gboolean udpgate_startup_query(UdpgateStartup *udpgate_startup,gboolean *is_on)
31 {
32         g_return_val_if_fail(UDPGATE_IS_STARTUP(udpgate_startup),FALSE);
33
34         return (*UDPGATE_STARTUP_GET_CLASS(udpgate_startup)->query)(udpgate_startup,is_on);
35 }
36
37 gboolean udpgate_startup_on(UdpgateStartup *udpgate_startup)
38 {
39 gboolean is_on;
40
41         g_return_val_if_fail(UDPGATE_IS_STARTUP(udpgate_startup),FALSE);
42
43         if (!udpgate_startup_query(udpgate_startup,&is_on))
44                 return FALSE;
45         if (is_on==TRUE)
46                 return TRUE;
47
48         return (*UDPGATE_STARTUP_GET_CLASS(udpgate_startup)->on)(udpgate_startup);
49 }
50
51 gboolean udpgate_startup_off(UdpgateStartup *udpgate_startup)
52 {
53 gboolean is_on;
54
55         g_return_val_if_fail(UDPGATE_IS_STARTUP(udpgate_startup),FALSE);
56
57         if (!udpgate_startup_query(udpgate_startup,&is_on))
58                 return FALSE;
59         if (is_on==FALSE)
60                 return TRUE;
61
62         return (*UDPGATE_STARTUP_GET_CLASS(udpgate_startup)->off)(udpgate_startup);
63 }
64
65 UdpgateStartup *udpgate_startup_new(void)
66 {
67         const GType impl_type_array[]={
68                 UDPGATE_TYPE_STARTUP_LSB,
69                 UDPGATE_TYPE_STARTUP_CHKCONFIG,
70                 UDPGATE_TYPE_STARTUP_DEBIAN,
71                 };
72         const GType *impl_type_pointer;
73
74         for (impl_type_pointer = impl_type_array;
75              impl_type_pointer < impl_type_array + G_N_ELEMENTS(impl_type_array);
76              impl_type_pointer++) {
77                 UdpgateStartup *udpgate_startup;
78                 
79                 udpgate_startup=g_object_new(*impl_type_pointer,NULL);
80                 g_assert(UDPGATE_IS_STARTUP(udpgate_startup));
81                 if (UDPGATE_STARTUP_GET_CLASS(udpgate_startup)->init(udpgate_startup))
82                         return udpgate_startup;
83                 g_object_unref(udpgate_startup);
84         }
85
86         return NULL;
87 }
88
89 static void
90 udpgate_startup_class_init (UdpgateStartupClass *class)
91 {
92 }
93
94 GType
95 udpgate_startup_get_type(void)
96 {
97   static GType startup_type=0;
98
99   if (!startup_type) {
100                 static const GTypeInfo startup_info={
101                         sizeof(UdpgateStartupClass),
102                         NULL,           /* base_init */
103                         NULL,           /* base_finalize */
104                         (GClassInitFunc)udpgate_startup_class_init,
105                         NULL,           /* class_finalize */
106                         NULL,           /* class_data */
107                         sizeof(UdpgateStartup),
108                         0,              /* n_preallocs */
109                         NULL,           /* instance_init */
110                         NULL,           /* value_table */
111       };
112
113                 startup_type=g_type_register_static(G_TYPE_OBJECT,"UdpgateStartup",
114                                  &startup_info,G_TYPE_FLAG_ABSTRACT);
115     }
116
117   return startup_type;
118 }