Commit 9a9c2f4f authored by Dan Winship's avatar Dan Winship
Browse files

Make NMConnection an interface, and NMRemoteConnection an NMObject (bgo #734746)

parents c81fb49a 0fdd71fe
......@@ -156,7 +156,7 @@ parse_main (GKeyFile *kf,
if (id == NULL)
return FALSE;
connection = nm_connection_new ();
connection = nm_simple_connection_new ();
g_assert (connection);
s_con = (NMSettingConnection *) nm_setting_connection_new ();
g_assert (s_con);
......
......@@ -5252,7 +5252,7 @@ do_connection_add (NmCli *nmc, int argc, char **argv)
}
/* Create a new connection object */
connection = nm_connection_new ();
connection = nm_simple_connection_new ();
/* Build up the 'connection' setting */
s_con = (NMSettingConnection *) nm_setting_connection_new ();
......@@ -7889,7 +7889,7 @@ do_connection_edit (NmCli *nmc, int argc, char **argv)
/* Duplicate the connection and use that so that we need not
* differentiate existing vs. new later
*/
connection = nm_connection_duplicate (found_con);
connection = nm_simple_connection_new_clone (found_con);
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
......@@ -7926,7 +7926,7 @@ do_connection_edit (NmCli *nmc, int argc, char **argv)
g_free (tmp_str);
/* Create a new connection object */
connection = nm_connection_new ();
connection = nm_simple_connection_new ();
/* Build up the 'connection' setting */
s_con = (NMSettingConnection *) nm_setting_connection_new ();
......
......@@ -2256,7 +2256,7 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv)
/* If there are some connection data from user, create a connection and
* fill them into proper settings. */
if (con_name || private || bssid2_arr || password)
connection = nm_connection_new ();
connection = nm_simple_connection_new ();
if (con_name || private) {
s_con = (NMSettingConnection *) nm_setting_connection_new ();
......@@ -2291,7 +2291,7 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv)
if (password) {
if (!connection)
connection = nm_connection_new ();
connection = nm_simple_connection_new ();
s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
nm_connection_add_setting (connection, NM_SETTING (s_wsec));
......
......@@ -1539,7 +1539,7 @@ nmc_setting_new_for_name (const char *name)
NMSetting *setting = NULL;
if (name) {
stype = nm_connection_lookup_setting_type (name);
stype = nm_setting_lookup_type (name);
if (stype != G_TYPE_INVALID) {
setting = g_object_new (stype, NULL);
g_warn_if_fail (NM_IS_SETTING (setting));
......@@ -7225,7 +7225,7 @@ setting_details (NMSetting *setting, NmCli *nmc, const char *one_prop)
g_return_val_if_fail (NM_IS_SETTING (setting), FALSE);
while (iter->sname) {
if (nm_connection_lookup_setting_type (iter->sname) == G_OBJECT_TYPE (setting))
if (nm_setting_lookup_type (iter->sname) == G_OBJECT_TYPE (setting))
return iter->func (setting, nmc, one_prop);
iter++;
}
......
......@@ -329,7 +329,7 @@ nm_editor_utils_create_connection (GType type,
master_s_con = nm_connection_get_setting_connection (master);
master_setting_type = nm_setting_connection_get_connection_type (master_s_con);
master_uuid = nm_setting_connection_get_uuid (master_s_con);
master_type = nm_connection_lookup_setting_type (master_setting_type);
master_type = nm_setting_lookup_type (master_setting_type);
}
types = nm_editor_utils_get_connection_type_list ();
......@@ -345,7 +345,7 @@ nm_editor_utils_create_connection (GType type,
return NULL;
}
connection = nm_connection_new ();
connection = nm_simple_connection_new ();
s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
nm_connection_add_setting (connection, NM_SETTING (s_con));
......@@ -401,7 +401,7 @@ nm_editor_utils_get_connection_type_data (NMConnection *conn)
g_return_val_if_fail (s_con != NULL, NULL);
conn_type = nm_setting_connection_get_connection_type (s_con);
conn_gtype = nm_connection_lookup_setting_type (conn_type);
conn_gtype = nm_setting_lookup_type (conn_type);
g_return_val_if_fail (conn_gtype != G_TYPE_INVALID, NULL);
types = nm_editor_utils_get_connection_type_list ();
......
......@@ -183,7 +183,7 @@ build_edit_connection (NMConnection *orig_connection)
const char *setting_name;
NmtSyncOp op;
edit_connection = nm_connection_duplicate (orig_connection);
edit_connection = nm_simple_connection_new_clone (orig_connection);
if (!NM_IS_REMOTE_CONNECTION (orig_connection))
return edit_connection;
......
......@@ -46,7 +46,7 @@ add_connection (DBusGProxy *proxy, const char *con_name)
GError *error = NULL;
/* Create a new connection object */
connection = (NMConnection *) nm_connection_new ();
connection = (NMConnection *) nm_simple_connection_new ();
/* Build up the 'connection' Setting */
s_con = (NMSettingConnection *) nm_setting_connection_new ();
......
......@@ -62,7 +62,7 @@ add_connection (NMRemoteSettings *settings, GMainLoop *loop, const char *con_nam
gboolean success;
/* Create a new connection object */
connection = nm_connection_new ();
connection = nm_simple_connection_new ();
/* Build up the 'connection' Setting */
s_con = (NMSettingConnection *) nm_setting_connection_new ();
......
......@@ -66,7 +66,7 @@ print_connection (DBusGConnection *bus, const char *path)
/* Using the raw configuration, create an NMConnection object for it. This
* step also verifies that the data we got from NetworkManager are valid. */
connection = nm_connection_new_from_hash (hash, &error);
connection = nm_simple_connection_new_from_hash (hash, &error);
if (!connection) {
g_warning ("Received invalid connection data: %s", error->message);
g_error_free (error);
......
......@@ -680,7 +680,7 @@ nmtst_ip6_config_clone (NMIP6Config *config)
#endif
#ifdef __NM_CONNECTION_H__
#ifdef __NM_SIMPLE_CONNECTION_H__
inline static NMConnection *
nmtst_create_minimal_connection (const char *id, const char *uuid, const char *type, NMSettingConnection **out_s_con)
......@@ -698,7 +698,7 @@ nmtst_create_minimal_connection (const char *id, const char *uuid, const char *t
uuid = uuid_free = nm_utils_uuid_generate ();
if (type) {
GType type_g = nm_connection_lookup_setting_type (type);
GType type_g = nm_setting_lookup_type (type);
g_assert (type_g != G_TYPE_INVALID);
......@@ -706,7 +706,7 @@ nmtst_create_minimal_connection (const char *id, const char *uuid, const char *t
g_assert (NM_IS_SETTING (s_base));
}
con = nm_connection_new ();
con = nm_simple_connection_new ();
s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
g_object_set (s_con,
......
......@@ -37,6 +37,7 @@ libnm_core_headers = \
$(core)/nm-setting-wireless-security.h \
$(core)/nm-setting-wireless.h \
$(core)/nm-setting.h \
$(core)/nm-simple-connection.h \
$(core)/nm-utils.h \
$(core)/nm-vpn-dbus-interface.h
......@@ -78,6 +79,7 @@ libnm_core_sources = \
$(core)/nm-setting-wireless-security.c \
$(core)/nm-setting-wireless.c \
$(core)/nm-setting.c \
$(core)/nm-simple-connection.c \
$(core)/nm-utils.c \
$(core)/nm-value-transforms.c
......@@ -92,22 +92,18 @@ nm_connection_error_quark (void)
}
typedef struct {
NMConnection *self;
GHashTable *settings;
/* D-Bus path of the connection, if any */
char *path;
} NMConnectionPrivate;
#define NM_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_CONNECTION, NMConnectionPrivate))
static NMConnectionPrivate *nm_connection_get_private (NMConnection *connection);
#define NM_CONNECTION_GET_PRIVATE(o) (nm_connection_get_private ((NMConnection *)o))
G_DEFINE_TYPE (NMConnection, nm_connection, G_TYPE_OBJECT)
enum {
PROP_0,
PROP_PATH,
LAST_PROP
};
G_DEFINE_INTERFACE (NMConnection, nm_connection, G_TYPE_OBJECT)
enum {
SECRETS_UPDATED,
......@@ -124,58 +120,6 @@ static NMSettingVerifyResult _nm_connection_verify (NMConnection *connection, GE
/*************************************************************/
/**
* nm_connection_lookup_setting_type:
* @name: a setting name
*
* Returns the #GType of the setting's class for a given setting name.
*
* Returns: the #GType of the setting's class
**/
GType
nm_connection_lookup_setting_type (const char *name)
{
return _nm_setting_lookup_setting_type (name);
}
/**
* nm_connection_lookup_setting_type_by_quark:
* @error_quark: a setting error quark
*
* Returns the #GType of the setting's class for a given setting error quark.
* Useful for figuring out which setting a returned error is for.
*
* Returns: the #GType of the setting's class
**/
GType
nm_connection_lookup_setting_type_by_quark (GQuark error_quark)
{
return _nm_setting_lookup_setting_type_by_quark (error_quark);
}
/**
* nm_connection_create_setting:
* @name: a setting name
*
* Create a new #NMSetting object of the desired type, given a setting name.
*
* Returns: (transfer full): the new setting object, or %NULL if the setting name was unknown
**/
NMSetting *
nm_connection_create_setting (const char *name)
{
GType type;
NMSetting *setting = NULL;
g_return_val_if_fail (name != NULL, NULL);
type = nm_connection_lookup_setting_type (name);
if (type)
setting = (NMSetting *) g_object_new (type, NULL);
return setting;
}
static void
setting_changed_cb (NMSetting *setting,
GParamSpec *pspec,
......@@ -282,7 +226,7 @@ nm_connection_get_setting_by_name (NMConnection *connection, const char *name)
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
g_return_val_if_fail (name != NULL, NULL);
type = nm_connection_lookup_setting_type (name);
type = nm_setting_lookup_type (name);
return type ? nm_connection_get_setting (connection, type) : NULL;
}
......@@ -350,7 +294,7 @@ hash_to_connection (NMConnection *connection, GHashTable *new, GError **error)
g_hash_table_iter_init (&iter, new);
while (g_hash_table_iter_next (&iter, (gpointer) &setting_name, (gpointer) &setting_hash)) {
GType type = nm_connection_lookup_setting_type (setting_name);
GType type = nm_setting_lookup_type (setting_name);
if (type) {
NMSetting *setting = nm_setting_new_from_hash (type, setting_hash);
......@@ -987,7 +931,7 @@ nm_connection_update_secrets (NMConnection *connection,
*/
g_hash_table_iter_init (&iter, secrets);
while (g_hash_table_iter_next (&iter, (gpointer) &key, NULL)) {
if (_nm_setting_lookup_setting_type (key) != G_TYPE_INVALID) {
if (nm_setting_lookup_type (key) != G_TYPE_INVALID) {
/* @secrets looks like a hashed connection */
hashed_connection = TRUE;
break;
......@@ -1420,78 +1364,6 @@ nm_connection_get_virtual_iface_name (NMConnection *connection)
return nm_setting_get_virtual_iface_name (base);
}
/**
* nm_connection_new:
*
* Creates a new #NMConnection object with no #NMSetting objects.
*
* Returns: the new empty #NMConnection object
**/
NMConnection *
nm_connection_new (void)
{
return (NMConnection *) g_object_new (NM_TYPE_CONNECTION, NULL);
}
/**
* nm_connection_new_from_hash:
* @hash: (element-type utf8 GLib.HashTable): the #GHashTable describing
* the connection
* @error: on unsuccessful return, an error
*
* Creates a new #NMConnection from a hash table describing the connection. See
* nm_connection_to_hash() for a description of the expected hash table.
*
* Returns: the new #NMConnection object, populated with settings created
* from the values in the hash table, or %NULL if the connection failed to
* validate
**/
NMConnection *
nm_connection_new_from_hash (GHashTable *hash, GError **error)
{
NMConnection *connection;
g_return_val_if_fail (hash != NULL, NULL);
if (!validate_permissions_type (hash, error))
return NULL;
connection = nm_connection_new ();
if (!hash_to_connection (connection, hash, error)) {
g_object_unref (connection);
return NULL;
}
return connection;
}
/**
* nm_connection_duplicate:
* @connection: the #NMConnection to duplicate
*
* Duplicates a #NMConnection.
*
* Returns: (transfer full): a new #NMConnection containing the same settings and properties
* as the source #NMConnection
**/
NMConnection *
nm_connection_duplicate (NMConnection *connection)
{
NMConnection *dup;
GHashTableIter iter;
NMSetting *setting;
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
dup = nm_connection_new ();
nm_connection_set_path (dup, nm_connection_get_path (connection));
g_hash_table_iter_init (&iter, NM_CONNECTION_GET_PRIVATE (connection)->settings);
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &setting))
nm_connection_add_setting (dup, nm_setting_duplicate (setting));
return dup;
}
/**
* nm_connection_get_uuid:
* @connection: the #NMConnection
......@@ -2017,103 +1889,41 @@ nm_connection_get_setting_vlan (NMConnection *connection)
/*************************************************************/
static void
nm_connection_init (NMConnection *connection)
{
NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (connection);
priv->settings = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref);
}
static void
dispose (GObject *object)
nm_connection_private_free (NMConnectionPrivate *priv)
{
NMConnection *self = NM_CONNECTION (object);
NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (self);
NMConnection *self = priv->self;
GHashTableIter iter;
NMSetting *setting;
g_hash_table_iter_init (&iter, priv->settings);
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &setting)) {
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &setting))
g_signal_handlers_disconnect_by_func (setting, setting_changed_cb, self);
g_hash_table_iter_remove (&iter);
}
g_hash_table_destroy (priv->settings);
G_OBJECT_CLASS (nm_connection_parent_class)->dispose (object);
g_slice_free (NMConnectionPrivate, priv);
}
static void
finalize (GObject *object)
static NMConnectionPrivate *
nm_connection_get_private (NMConnection *connection)
{
NMConnection *connection = NM_CONNECTION (object);
NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (connection);
g_hash_table_destroy (priv->settings);
g_free (priv->path);
NMConnectionPrivate *priv;
G_OBJECT_CLASS (nm_connection_parent_class)->finalize (object);
}
priv = g_object_get_data (G_OBJECT (connection), "NMConnectionPrivate");
if (!priv) {
priv = g_slice_new0 (NMConnectionPrivate);
g_object_set_data_full (G_OBJECT (connection), "NMConnectionPrivate",
priv, (GDestroyNotify) nm_connection_private_free);
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMConnection *connection = NM_CONNECTION (object);
switch (prop_id) {
case PROP_PATH:
nm_connection_set_path (connection, g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
priv->self = connection;
priv->settings = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref);
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMConnection *connection = NM_CONNECTION (object);
switch (prop_id) {
case PROP_PATH:
g_value_set_string (value, nm_connection_get_path (connection));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
return priv;
}
static void
nm_connection_class_init (NMConnectionClass *klass)
nm_connection_default_init (NMConnectionInterface *iface)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (NMConnectionPrivate));
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->dispose = dispose;
object_class->finalize = finalize;
/* Properties */
/**
* NMConnection:path:
*
* The connection's D-Bus path, used only by the calling process as a record
* of the D-Bus path of the connection as provided by a settings service.
**/
g_object_class_install_property
(object_class, PROP_PATH,
g_param_spec_string (NM_CONNECTION_PATH, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
/* Signals */
/**
......@@ -2127,9 +1937,9 @@ nm_connection_class_init (NMConnectionClass *klass)
*/
signals[SECRETS_UPDATED] =
g_signal_new (NM_CONNECTION_SECRETS_UPDATED,
G_OBJECT_CLASS_TYPE (object_class),
NM_TYPE_CONNECTION,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMConnectionClass, secrets_updated),
G_STRUCT_OFFSET (NMConnectionInterface, secrets_updated),
NULL, NULL,
g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE, 1,
......@@ -2144,9 +1954,10 @@ nm_connection_class_init (NMConnectionClass *klass)
*/
signals[SECRETS_CLEARED] =
g_signal_new (NM_CONNECTION_SECRETS_CLEARED,
G_OBJECT_CLASS_TYPE (object_class),
NM_TYPE_CONNECTION,
G_SIGNAL_RUN_FIRST,
0, NULL, NULL,
G_STRUCT_OFFSET (NMConnectionInterface, secrets_cleared),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
......@@ -2160,9 +1971,10 @@ nm_connection_class_init (NMConnectionClass *klass)
*/
signals[CHANGED] =
g_signal_new (NM_CONNECTION_CHANGED,
G_OBJECT_CLASS_TYPE (object_class),
NM_TYPE_CONNECTION,
G_SIGNAL_RUN_FIRST,
0, NULL, NULL,
G_STRUCT_OFFSET (NMConnectionInterface, changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
}
......@@ -60,21 +60,16 @@
G_BEGIN_DECLS
#define NM_TYPE_CONNECTION (nm_connection_get_type ())
#define NM_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CONNECTION, NMConnection))
#define NM_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_CONNECTION, NMConnectionClass))
#define NM_IS_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_CONNECTION))
#define NM_IS_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_CONNECTION))
#define NM_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_CONNECTION, NMConnectionClass))
#define NM_TYPE_CONNECTION (nm_connection_get_type ())
#define NM_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CONNECTION, NMConnection))
#define NM_IS_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_CONNECTION))
#define NM_CONNECTION_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), NM_TYPE_CONNECTION, NMConnectionClass))
/* Signals */
#define NM_CONNECTION_SECRETS_UPDATED "secrets-updated"
#define NM_CONNECTION_SECRETS_CLEARED "secrets-cleared"
#define NM_CONNECTION_CHANGED "changed"
/* Properties */
#define NM_CONNECTION_PATH "path"
/**
* NMConnectionError:
* @NM_CONNECTION_ERROR_UNKNOWN: unknown or unclassified error
......@@ -115,33 +110,24 @@ GQuark nm_connection_error_quark (void);
/**
* NMConnection:
*
* The NMConnection struct contains only private data.
* It should only be accessed through the functions described below.
* NMConnection is the interface implemented by #NMRemoteConnection on the
* client side, and #NMSettingsConnection on the daemon side.
*/
typedef struct {
GObject parent;
} NMConnection;
typedef struct _NMConnection NMConnection;
typedef struct {
GObjectClass parent;
GTypeInterface parent;
/* Signals */
void (*secrets_updated) (NMConnection *connection, const char * setting);
void (*secrets_updated) (NMConnection *connection,
const char *setting);
void (*secrets_cleared) (NMConnection *connection);
void (*changed) (NMConnection *connection);
/*< private >*/
gpointer padding[8];
} NMConnectionClass;
} NMConnectionInterface;
GType nm_connection_get_type (void);
NMConnection *nm_connection_new (void);
NMConnection *nm_connection_new_from_hash (GHashTable *hash, GError **error);
NMConnection *nm_connection_duplicate (NMConnection *connection);
NMSetting *nm_connection_create_setting (const char *name);
void nm_connection_add_setting (NMConnection *connection,
NMSetting *setting);
......@@ -211,10 +197,6 @@ GHashTable *nm_connection_to_hash (NMConnection *connection,
void nm_connection_dump (NMConnection *connection);
GType nm_connection_lookup_setting_type (const char *name);
GType nm_connection_lookup_setting_type_by_quark (GQuark error_quark);
/* Helpers */
const char * nm_connection_get_uuid (NMConnection *connection);
const char * nm_connection_get_id (NMConnection *connection);
......
......@@ -56,8 +56,6 @@ void _nm_register_setting (const char *name,
gboolean _nm_setting_is_base_type (NMSetting *setting);
gboolean _nm_setting_type_is_base_type (GType type);