
- All internal source files (except "examples", which are not internal) should include "config.h" first. As also all internal source files should include "nm-default.h", let "config.h" be included by "nm-default.h" and include "nm-default.h" as first in every source file. We already wanted to include "nm-default.h" before other headers because it might contains some fixes (like "nm-glib.h" compatibility) that is required first. - After including "nm-default.h", we optinally allow for including the corresponding header file for the source file at hand. The idea is to ensure that each header file is self contained. - Don't include "config.h" or "nm-default.h" in any header file (except "nm-sd-adapt.h"). Public headers anyway must not include these headers, and internal headers are never included after "nm-default.h", as of the first previous point. - Include all internal headers with quotes instead of angle brackets. In practice it doesn't matter, because in our public headers we must include other headers with angle brackets. As we use our public headers also to compile our interal source files, effectively the result must be the same. Still do it for consistency. - Except for <config.h> itself. Include it with angle brackets as suggested by https://www.gnu.org/software/autoconf/manual/autoconf.html#Configuration-Headers
124 lines
3.8 KiB
C
124 lines
3.8 KiB
C
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
|
/*
|
|
* This library 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 library 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 library; if not, write to the
|
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
* Boston, MA 02110-1301 USA.
|
|
*
|
|
* Copyright 2007 - 2008 Novell, Inc.
|
|
* Copyright 2007 - 2014 Red Hat, Inc.
|
|
*/
|
|
|
|
#include "nm-default.h"
|
|
|
|
#include "nm-simple-connection.h"
|
|
#include "nm-setting-private.h"
|
|
|
|
static void nm_simple_connection_interface_init (NMConnectionInterface *iface);
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (NMSimpleConnection, nm_simple_connection, G_TYPE_OBJECT,
|
|
G_IMPLEMENT_INTERFACE (NM_TYPE_CONNECTION, nm_simple_connection_interface_init);
|
|
)
|
|
|
|
static void
|
|
nm_simple_connection_init (NMSimpleConnection *self)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* nm_simple_connection_new:
|
|
*
|
|
* Creates a new #NMSimpleConnection object with no #NMSetting objects. An
|
|
* #NMSimpleConnection does not directly represent a D-Bus-exported connection,
|
|
* but might be used in the process of creating a new one.
|
|
*
|
|
* Returns: (transfer full): the new empty #NMConnection object
|
|
**/
|
|
NMConnection *
|
|
nm_simple_connection_new (void)
|
|
{
|
|
return (NMConnection *) g_object_new (NM_TYPE_SIMPLE_CONNECTION, NULL);
|
|
}
|
|
|
|
/**
|
|
* nm_simple_connection_new_from_dbus:
|
|
* @dict: a #GVariant of type %NM_VARIANT_TYPE_CONNECTION describing the connection
|
|
* @error: on unsuccessful return, an error
|
|
*
|
|
* Creates a new #NMSimpleConnection from a hash table describing the
|
|
* connection. See nm_connection_to_dbus() for a description of the expected
|
|
* hash table.
|
|
*
|
|
* Returns: (transfer full): the new #NMSimpleConnection object, populated with
|
|
* settings created from the values in the hash table, or %NULL if the
|
|
* connection failed to validate
|
|
**/
|
|
NMConnection *
|
|
nm_simple_connection_new_from_dbus (GVariant *dict, GError **error)
|
|
{
|
|
NMConnection *connection;
|
|
|
|
g_return_val_if_fail (dict != NULL, NULL);
|
|
g_return_val_if_fail (g_variant_is_of_type (dict, NM_VARIANT_TYPE_CONNECTION), NULL);
|
|
|
|
connection = nm_simple_connection_new ();
|
|
if ( !nm_connection_replace_settings (connection, dict, error)
|
|
|| !nm_connection_normalize (connection, NULL, NULL, error))
|
|
g_clear_object (&connection);
|
|
return connection;
|
|
}
|
|
|
|
/**
|
|
* nm_simple_connection_new_clone:
|
|
* @connection: the #NMConnection to clone
|
|
*
|
|
* Clones an #NMConnection as an #NMSimpleConnection.
|
|
*
|
|
* Returns: (transfer full): a new #NMConnection containing the same settings
|
|
* and properties as the source #NMConnection
|
|
**/
|
|
NMConnection *
|
|
nm_simple_connection_new_clone (NMConnection *connection)
|
|
{
|
|
NMConnection *clone;
|
|
|
|
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
|
|
|
|
clone = nm_simple_connection_new ();
|
|
nm_connection_set_path (clone, nm_connection_get_path (connection));
|
|
nm_connection_replace_settings_from_connection (clone, connection);
|
|
|
|
return clone;
|
|
}
|
|
|
|
static void
|
|
dispose (GObject *object)
|
|
{
|
|
nm_connection_clear_secrets (NM_CONNECTION (object));
|
|
|
|
G_OBJECT_CLASS (nm_simple_connection_parent_class)->dispose (object);
|
|
}
|
|
|
|
static void
|
|
nm_simple_connection_class_init (NMSimpleConnectionClass *simple_class)
|
|
{
|
|
GObjectClass *object_class = G_OBJECT_CLASS (simple_class);
|
|
|
|
object_class->dispose = dispose;
|
|
}
|
|
|
|
static void
|
|
nm_simple_connection_interface_init (NMConnectionInterface *iface)
|
|
{
|
|
}
|