1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
|
/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
/* Copyright (C) 2004-2005 Carlos Garnacho
*
* This program 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.
*
* 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.
*
* Authors: Carlos Garnacho Parro <carlosg@gnome.org>
*/
#include <glib-object.h>
#include "oobs-iface.h"
/**
* SECTION:oobs-iface
* @title: OobsIface
* @short_description: Base object for network interfaces
* @see_also: #OobsIfacesConfig, #OobsIfaceEthernet, #OobsIfaceIRLan,
* #OobsIfacePlip, #OobsIfacePPP, #OobsIfaceWireless
**/
#define OOBS_IFACE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), OOBS_TYPE_IFACE, OobsIfacePrivate))
typedef struct _OobsIfacePrivate OobsIfacePrivate;
struct _OobsIfacePrivate
{
gchar *dev;
gchar *file;
guint is_auto : 1;
guint is_enabled : 1;
guint explicitly_not_configured : 1;
};
static void oobs_iface_class_init (OobsIfaceClass *class);
static void oobs_iface_init (OobsIface *iface);
static void oobs_iface_finalize (GObject *object);
static void oobs_iface_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void oobs_iface_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
enum {
STATE_CHANGED,
LAST_SIGNAL
};
enum {
PROP_0,
PROP_AUTO,
PROP_ENABLED,
PROP_CONFIGURED,
PROP_DEV
};
static guint signals [LAST_SIGNAL] = { 0 };
G_DEFINE_ABSTRACT_TYPE (OobsIface, oobs_iface, G_TYPE_OBJECT);
static void
oobs_iface_class_init (OobsIfaceClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->set_property = oobs_iface_set_property;
object_class->get_property = oobs_iface_get_property;
object_class->finalize = oobs_iface_finalize;
g_object_class_install_property (object_class,
PROP_AUTO,
g_param_spec_boolean ("auto",
"Iface is auto",
"Whether the interface starts at boot time",
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_ENABLED,
g_param_spec_boolean ("active",
"Iface is active",
"Whether the interface is active",
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_CONFIGURED,
g_param_spec_boolean ("configured",
"Iface is configured",
"Whether the interface is fully configured",
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_DEV,
g_param_spec_string ("device",
"Iface device",
"Device name of the iface",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
signals [STATE_CHANGED] = g_signal_new ("state-changed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (OobsIfaceClass, state_changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
g_type_class_add_private (object_class,
sizeof (OobsIfacePrivate));
}
static void
oobs_iface_init (OobsIface *iface)
{
OobsIfacePrivate *priv;
g_return_if_fail (OOBS_IS_IFACE (iface));
priv = OOBS_IFACE_GET_PRIVATE (iface);
priv->dev = NULL;
priv->file = NULL;
priv->explicitly_not_configured = FALSE;
iface->_priv = priv;
}
static void
oobs_iface_finalize (GObject *object)
{
OobsIfacePrivate *priv;
g_return_if_fail (OOBS_IS_IFACE (object));
priv = OOBS_IFACE (object)->_priv;
if (priv)
{
g_free (priv->dev);
g_free (priv->file);
}
if (G_OBJECT_CLASS (oobs_iface_parent_class)->finalize)
(* G_OBJECT_CLASS (oobs_iface_parent_class)->finalize) (object);
}
static void
oobs_iface_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
OobsIfacePrivate *priv;
g_return_if_fail (OOBS_IS_IFACE (object));
priv = OOBS_IFACE (object)->_priv;
switch (prop_id)
{
case PROP_AUTO:
priv->is_auto = g_value_get_boolean (value);
break;
case PROP_ENABLED:
priv->is_enabled = g_value_get_boolean (value);
break;
case PROP_CONFIGURED:
oobs_iface_set_configured (OOBS_IFACE (object), g_value_get_boolean (value));
break;
case PROP_DEV:
priv->dev = g_value_dup_string (value);
break;
}
}
static void
oobs_iface_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
OobsIfacePrivate *priv;
g_return_if_fail (OOBS_IS_IFACE (object));
priv = OOBS_IFACE (object)->_priv;
switch (prop_id)
{
case PROP_AUTO:
g_value_set_boolean (value, priv->is_auto);
break;
case PROP_ENABLED:
g_value_set_boolean (value, priv->is_enabled);
break;
case PROP_CONFIGURED:
g_value_set_boolean (value, oobs_iface_get_configured (OOBS_IFACE (object)));
break;
case PROP_DEV:
g_value_set_string (value, priv->dev);
break;
}
}
/**
* oobs_iface_get_auto:
* @iface: An #OobsIface.
*
* Returns whether the interface is started automatically at boot time.
*
* Return Value: #TRUE if the interface starts during system boot.
**/
gboolean
oobs_iface_get_auto (OobsIface *iface)
{
OobsIfacePrivate *priv;
g_return_val_if_fail (OOBS_IS_IFACE (iface), FALSE);
priv = iface->_priv;
return priv->is_auto;
}
/**
* oobs_iface_set_auto:
* @iface: An #OobsIface.
* @is_auto: #TRUE to make the interface start at boot time.
*
* Sets whether the interface is started automatically at boot time.
**/
void
oobs_iface_set_auto (OobsIface *iface, gboolean is_auto)
{
g_return_if_fail (OOBS_IS_IFACE (iface));
g_object_set (G_OBJECT (iface), "auto", is_auto, NULL);
}
/**
* oobs_iface_get_active:
* @iface: An #OobsIface.
*
* Returns whether the interface is active.
*
* Return Value: #TRUE if the interface is active.
**/
gboolean
oobs_iface_get_active (OobsIface *iface)
{
OobsIfacePrivate *priv;
g_return_val_if_fail (OOBS_IS_IFACE (iface), FALSE);
priv = iface->_priv;
return priv->is_enabled;
}
/**
* oobs_iface_set_active:
* @iface: An #OobsIface.
* @is_active: #TRUE to enable the interface.
*
* Sets whether the interface is currently active.
**/
void
oobs_iface_set_active (OobsIface *iface, gboolean is_active)
{
g_return_if_fail (OOBS_IS_IFACE (iface));
g_object_set (G_OBJECT (iface), "active", is_active, NULL);
}
/**
* oobs_iface_get_device_name:
* @iface: An #OobsIface.
*
* Returns the device name for the interface.
*
* Return Value: A string containing the device name.
* This string must not be freed or modified.
**/
G_CONST_RETURN gchar*
oobs_iface_get_device_name (OobsIface *iface)
{
OobsIfacePrivate *priv;
g_return_val_if_fail (OOBS_IS_IFACE (iface), FALSE);
priv = iface->_priv;
return priv->dev;
}
/**
* oobs_iface_get_configured:
* @iface: An #OobsIface.
*
* Returns whether the interface has a valid (i.e.: complete)
* configuration and is explicitly marked as configured
* (see oobs_iface_set_configured ()).
*
* Return Value: #TRUE if its configuration is valid.
**/
gboolean
oobs_iface_get_configured (OobsIface *iface)
{
OobsIfacePrivate *priv;
g_return_val_if_fail (OOBS_IS_IFACE (iface), FALSE);
priv = iface->_priv;
if (priv->explicitly_not_configured)
return FALSE;
return (* OOBS_IFACE_GET_CLASS (iface)->is_configured) (iface);
}
/**
* oobs_iface_set_configured:
* @iface: An #OobsIface.
* @is_configured: #FALSE to explictitly mark the interface as not configured.
*
* If @is_configured is #FALSE, the function explicitly marks the interface
* as not configured. If @is_configured is #TRUE, the explicit mark will be
* removed, but the interface may still have an incomplete/invalid configuration.
**/
void
oobs_iface_set_configured (OobsIface *iface, gboolean is_configured)
{
OobsIfacePrivate *priv;
g_return_if_fail (OOBS_IS_IFACE (iface));
priv = iface->_priv;
priv->explicitly_not_configured = (is_configured == FALSE);
g_object_notify (G_OBJECT (iface), "configured");
}
/**
* oobs_iface_has_gateway:
* @iface: An #OobsIface.
*
* Returns whether the interface has a defined gateway.
*
* Return Value: #TRUE if the interface has a defined gateway.
**/
gboolean
oobs_iface_has_gateway (OobsIface *iface)
{
g_return_val_if_fail (OOBS_IS_IFACE (iface), FALSE);
if (OOBS_IFACE_GET_CLASS (iface)->has_gateway == NULL)
return FALSE;
return OOBS_IFACE_GET_CLASS (iface)->has_gateway (iface);
}
|