[network-manager-applet/danw/slavetypes] connection-editor: use nm_utils_check_master_slave_compat()



commit b1b37ea86e8c0ce93752820023887a772f28f0bb
Author: Dan Winship <danw gnome org>
Date:   Mon Jan 27 11:52:48 2014 -0500

    connection-editor: use nm_utils_check_master_slave_compat()
    
    Use nm_utils_check_master_slave_compat() to determine what types can
    be slaves of other types, rather than hardcoding.

 src/connection-editor/page-bond.c   |   47 +++++++++++++++++------------
 src/connection-editor/page-bridge.c |    8 +----
 src/connection-editor/page-team.c   |   55 +++++++++++++++-------------------
 src/connection-editor/page-vlan.c   |   11 +++++--
 4 files changed, 61 insertions(+), 60 deletions(-)
---
diff --git a/src/connection-editor/page-bond.c b/src/connection-editor/page-bond.c
index 6974685..9d8e9ed 100644
--- a/src/connection-editor/page-bond.c
+++ b/src/connection-editor/page-bond.c
@@ -26,9 +26,9 @@
 
 #include <nm-setting-connection.h>
 #include <nm-setting-bond.h>
+#include <nm-utils.h>
 
 #include "page-bond.h"
-#include "page-ethernet.h"
 #include "page-infiniband.h"
 #include "nm-connection-editor.h"
 #include "new-connection.h"
@@ -40,8 +40,7 @@ G_DEFINE_TYPE (CEPageBond, ce_page_bond, CE_TYPE_PAGE_MASTER)
 typedef struct {
        NMSettingBond *setting;
 
-       GType slave_type;
-       PageNewConnectionFunc new_slave_func;
+       int slave_arptype;
 
        GtkWindow *toplevel;
 
@@ -109,10 +108,8 @@ connection_removed (CEPageMaster *master, NMConnection *connection)
        CEPageBond *self = CE_PAGE_BOND (master);
        CEPageBondPrivate *priv = CE_PAGE_BOND_GET_PRIVATE (self);
 
-       if (!ce_page_master_has_slaves (master)) {
-               priv->slave_type = G_TYPE_INVALID;
-               priv->new_slave_func = NULL;
-       }
+       if (!ce_page_master_has_slaves (master))
+               priv->slave_arptype = ARPHRD_VOID;
 }
 
 static void
@@ -121,15 +118,12 @@ connection_added (CEPageMaster *master, NMConnection *connection)
        CEPageBond *self = CE_PAGE_BOND (master);
        CEPageBondPrivate *priv = CE_PAGE_BOND_GET_PRIVATE (self);
 
-       /* A bit kludgy... */
        if (nm_connection_is_type (connection, NM_SETTING_INFINIBAND_SETTING_NAME)) {
-               priv->slave_type = NM_TYPE_SETTING_INFINIBAND;
-               priv->new_slave_func = infiniband_connection_new;
+               priv->slave_arptype = ARPHRD_INFINIBAND;
                gtk_combo_box_set_active (priv->mode, MODE_ACTIVE_BACKUP);
                gtk_widget_set_sensitive (GTK_WIDGET (priv->mode), FALSE);
        } else {
-               priv->slave_type = NM_TYPE_SETTING_WIRED;
-               priv->new_slave_func = ethernet_connection_new;
+               priv->slave_arptype = ARPHRD_ETHER;
                gtk_widget_set_sensitive (GTK_WIDGET (priv->mode), TRUE);
        }
 }
@@ -359,13 +353,22 @@ populate_ui (CEPageBond *self)
 }
 
 static gboolean
-connection_type_filter (GType type, gpointer user_data)
+connection_type_filter (GType type, gpointer self)
 {
-       if (type == NM_TYPE_SETTING_WIRED ||
-           type == NM_TYPE_SETTING_INFINIBAND)
-               return TRUE;
-       else
+       CEPageBondPrivate *priv = CE_PAGE_BOND_GET_PRIVATE (self);
+
+       if (!nm_utils_check_master_slave_compat (NM_TYPE_SETTING_BOND, type))
                return FALSE;
+
+       /* Can only have connections of a single arptype. Note that we don't
+        * need to check the reverse case here since we don't need to call
+        * new_connection_dialog() in the InfiniBand case.
+        */
+       if (   priv->slave_arptype == ARPHRD_ETHER
+           && type == NM_TYPE_SETTING_INFINIBAND)
+               return FALSE;
+
+       return TRUE;
 }
 
 static void
@@ -374,11 +377,11 @@ add_slave (CEPageMaster *master, NewConnectionResultFunc result_func)
        CEPageBond *self = CE_PAGE_BOND (master);
        CEPageBondPrivate *priv = CE_PAGE_BOND_GET_PRIVATE (self);
 
-       if (priv->new_slave_func) {
+       if (priv->slave_arptype == ARPHRD_INFINIBAND) {
                new_connection_of_type (priv->toplevel,
                                        NULL,
                                        CE_PAGE (self)->settings,
-                                       priv->new_slave_func,
+                                       infiniband_connection_new,
                                        result_func,
                                        master);
        } else {
@@ -548,7 +551,11 @@ validate (CEPage *page, NMConnection *connection, GError **error)
 static void
 ce_page_bond_init (CEPageBond *self)
 {
-       CE_PAGE_MASTER (self)->aggregating = TRUE;
+       CEPageBondPrivate *priv = CE_PAGE_BOND_GET_PRIVATE (self);
+       CEPageMaster *master = CE_PAGE_MASTER (self);
+
+       priv->slave_arptype = ARPHRD_VOID;
+       master->aggregating = TRUE;
 }
 
 static void
diff --git a/src/connection-editor/page-bridge.c b/src/connection-editor/page-bridge.c
index 2f119de..bf67652 100644
--- a/src/connection-editor/page-bridge.c
+++ b/src/connection-editor/page-bridge.c
@@ -26,6 +26,7 @@
 
 #include <nm-setting-connection.h>
 #include <nm-setting-bridge.h>
+#include <nm-utils.h>
 
 #include "page-bridge.h"
 #include "nm-connection-editor.h"
@@ -161,12 +162,7 @@ create_connection (CEPageMaster *master, NMConnection *connection)
 static gboolean
 connection_type_filter (GType type, gpointer user_data)
 {
-       if (type == NM_TYPE_SETTING_WIRED ||
-           type == NM_TYPE_SETTING_WIRELESS ||
-               type == NM_TYPE_SETTING_VLAN)
-               return TRUE;
-       else
-               return FALSE;
+       return nm_utils_check_master_slave_compat (NM_TYPE_SETTING_BRIDGE, type);
 }
 
 static void
diff --git a/src/connection-editor/page-team.c b/src/connection-editor/page-team.c
index 1c79a76..f5aa0a4 100644
--- a/src/connection-editor/page-team.c
+++ b/src/connection-editor/page-team.c
@@ -25,12 +25,10 @@
 
 #include <nm-setting-connection.h>
 #include <nm-setting-team.h>
+#include <nm-utils.h>
 
 #include "page-team.h"
-#include "page-ethernet.h"
-#include "page-wifi.h"
 #include "page-infiniband.h"
-#include "page-vlan.h"
 #include "nm-connection-editor.h"
 #include "new-connection.h"
 
@@ -41,7 +39,7 @@ G_DEFINE_TYPE (CEPageTeam, ce_page_team, CE_TYPE_PAGE_MASTER)
 typedef struct {
        NMSettingTeam *setting;
 
-       GType slave_type;
+       int slave_arptype;
 
        GtkWindow *toplevel;
 
@@ -148,7 +146,7 @@ connection_removed (CEPageMaster *master, NMConnection *connection)
        CEPageTeamPrivate *priv = CE_PAGE_TEAM_GET_PRIVATE (self);
 
        if (!ce_page_master_has_slaves (master))
-               priv->slave_type = G_TYPE_INVALID;
+               priv->slave_arptype = ARPHRD_VOID;
 }
 
 static void
@@ -157,15 +155,10 @@ connection_added (CEPageMaster *master, NMConnection *connection)
        CEPageTeam *self = CE_PAGE_TEAM (master);
        CEPageTeamPrivate *priv = CE_PAGE_TEAM_GET_PRIVATE (self);
 
-       /* A bit kludgy... */
        if (nm_connection_is_type (connection, NM_SETTING_INFINIBAND_SETTING_NAME))
-               priv->slave_type = NM_TYPE_SETTING_INFINIBAND;
-       else if (nm_connection_is_type (connection, NM_SETTING_WIRED_SETTING_NAME))
-               priv->slave_type = NM_TYPE_SETTING_WIRED;
-       else if (nm_connection_is_type (connection, NM_SETTING_WIRELESS_SETTING_NAME))
-               priv->slave_type = NM_TYPE_SETTING_WIRELESS;
+               priv->slave_arptype = ARPHRD_INFINIBAND;
        else
-               priv->slave_type = NM_TYPE_SETTING_VLAN;
+               priv->slave_arptype = ARPHRD_ETHER;
 }
 
 static void
@@ -181,26 +174,22 @@ create_connection (CEPageMaster *master, NMConnection *connection)
 }
 
 static gboolean
-connection_type_filter_all (GType type, gpointer user_data)
+connection_type_filter (GType type, gpointer self)
 {
-       if (type == NM_TYPE_SETTING_WIRED ||
-           type == NM_TYPE_SETTING_WIRELESS ||
-           type == NM_TYPE_SETTING_VLAN ||
-           type == NM_TYPE_SETTING_INFINIBAND)
-               return TRUE;
-       else
+       CEPageTeamPrivate *priv = CE_PAGE_TEAM_GET_PRIVATE (self);
+
+       if (!nm_utils_check_master_slave_compat (NM_TYPE_SETTING_TEAM, type))
                return FALSE;
-}
 
-static gboolean
-connection_type_filter_eth (GType type, gpointer user_data)
-{
-       if (type == NM_TYPE_SETTING_WIRED ||
-           type == NM_TYPE_SETTING_WIRELESS ||
-           type == NM_TYPE_SETTING_VLAN)
-               return TRUE;
-       else
+       /* Can only have connections of a single arptype. Note that we don't
+        * need to check the reverse case here since we don't need to call
+        * new_connection_dialog() in the InfiniBand case.
+        */
+       if (   priv->slave_arptype == ARPHRD_ETHER
+           && type == NM_TYPE_SETTING_INFINIBAND)
                return FALSE;
+
+       return TRUE;
 }
 
 static void
@@ -209,7 +198,7 @@ add_slave (CEPageMaster *master, NewConnectionResultFunc result_func)
        CEPageTeam *self = CE_PAGE_TEAM (master);
        CEPageTeamPrivate *priv = CE_PAGE_TEAM_GET_PRIVATE (self);
 
-       if (priv->slave_type == NM_TYPE_SETTING_INFINIBAND) {
+       if (priv->slave_arptype == ARPHRD_INFINIBAND) {
                new_connection_of_type (priv->toplevel,
                                        NULL,
                                        CE_PAGE (self)->settings,
@@ -219,7 +208,7 @@ add_slave (CEPageMaster *master, NewConnectionResultFunc result_func)
        } else {
                new_connection_dialog (priv->toplevel,
                                       CE_PAGE (self)->settings,
-                                      priv->slave_type == G_TYPE_INVALID ? connection_type_filter_all : 
connection_type_filter_eth,
+                                      connection_type_filter,
                                       result_func,
                                       master);
        }
@@ -314,7 +303,11 @@ validate (CEPage *page, NMConnection *connection, GError **error)
 static void
 ce_page_team_init (CEPageTeam *self)
 {
-       CE_PAGE_MASTER (self)->aggregating = TRUE;
+       CEPageTeamPrivate *priv = CE_PAGE_TEAM_GET_PRIVATE (self);
+       CEPageMaster *master = CE_PAGE_MASTER (self);
+
+       priv->slave_arptype = ARPHRD_VOID;
+       master->aggregating = TRUE;
 }
 
 static void
diff --git a/src/connection-editor/page-vlan.c b/src/connection-editor/page-vlan.c
index ff13387..ed63c41 100644
--- a/src/connection-editor/page-vlan.c
+++ b/src/connection-editor/page-vlan.c
@@ -249,8 +249,8 @@ get_vlan_devices (CEPageVlan *self)
        for (i = 0; devices_array && (i < devices_array->len); i++) {
                device = devices_array->pdata[i];
 
-               /* FIXME: this supported-device-types logic belongs in NM somewhere. */
-               if (!NM_IS_DEVICE_ETHERNET (device))
+               if (!nm_utils_check_master_slave_compat (NM_TYPE_SETTING_VLAN,
+                                                        nm_device_get_setting_type (device)))
                        continue;
 
                devices = g_slist_prepend (devices, device);
@@ -272,7 +272,7 @@ build_vlan_parent_list (CEPageVlan *self, GSList *devices)
 
        parents = g_ptr_array_new ();
 
-       /* Devices with no L2 configuration can spawn VLANs directly. At the
+       /* Devices with no interesting L2 configuration can spawn VLANs directly. At the
         * moment, this means just Ethernet.
         */
        for (d_iter = devices; d_iter; d_iter = d_iter->next) {
@@ -297,10 +297,15 @@ build_vlan_parent_list (CEPageVlan *self, GSList *devices)
        for (c_iter = connections; c_iter; c_iter = c_iter->next) {
                NMConnection *candidate = c_iter->data;
                NMSettingConnection *s_con = nm_connection_get_setting_connection (candidate);
+               GType connection_gtype;
 
                if (nm_setting_connection_get_master (s_con))
                        continue;
 
+               connection_gtype = nm_connection_lookup_setting_type 
(nm_setting_connection_get_connection_type (s_con));
+               if (!nm_utils_check_master_slave_compat (NM_TYPE_SETTING_VLAN, connection_gtype))
+                       continue;
+
                for (d_iter = devices; d_iter; d_iter = d_iter->next) {
                        device = d_iter->data;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]