[PATCH 4/4] Have NMPolicy implement the new NMZonesInterface.



---
 include/NetworkManager.h |    3 +
 src/nm-policy.c          |  126 ++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 119 insertions(+), 10 deletions(-)

diff --git a/include/NetworkManager.h b/include/NetworkManager.h
index 17c3a11..dc403a4 100644
--- a/include/NetworkManager.h
+++ b/include/NetworkManager.h
@@ -62,6 +62,9 @@
 #define NM_DBUS_INTERFACE_SECRET_AGENT    NM_DBUS_INTERFACE ".SecretAgent"
 #define NM_DBUS_PATH_SECRET_AGENT         "/org/freedesktop/NetworkManager/SecretAgent"
 
+#define NM_DBUS_INTERFACE_ZONES           NM_DBUS_INTERFACE ".Zones"
+#define NM_DBUS_PATH_ZONES                NM_DBUS_PATH "/Zones"
+
 /**
  * NMState:
  * @NM_STATE_UNKNOWN: networking state is unknown
diff --git a/src/nm-policy.c b/src/nm-policy.c
index f84306a..5451418 100644
--- a/src/nm-policy.c
+++ b/src/nm-policy.c
@@ -47,6 +47,7 @@
 #include "nm-vpn-manager.h"
 #include "nm-policy-hostname.h"
 #include "nm-manager-auth.h"
+#include "nm-zones-interface.h"
 
 typedef struct {
 	gboolean disposed;
@@ -74,8 +75,11 @@ typedef struct {
 	char *cur_hostname;  /* hostname we want to assign */
 } NMPolicyPrivate;
 
+static void zones_interface_init (NMZonesInterface *zones_interface_class);
 
-G_DEFINE_TYPE (NMPolicy, nm_policy, G_TYPE_OBJECT)
+G_DEFINE_TYPE_EXTENDED (NMPolicy, nm_policy, G_TYPE_OBJECT, 0,
+						G_IMPLEMENT_INTERFACE (NM_TYPE_ZONES_INTERFACE,
+											   zones_interface_init))
 
 #define NM_POLICY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_POLICY, NMPolicyPrivate))
 
@@ -968,6 +972,72 @@ get_device_connection (NMDevice *device)
 }
 
 static void
+device_signal_zone (NMPolicy *self,
+             NMDevice *device,
+             NMConnection *connection,
+             NMDeviceState new_state)
+{
+	NMSettingConnection *setting_connection = nm_connection_get_setting_connection (connection);
+	const char * zone_name = nm_setting_connection_get_zone (setting_connection);
+	const char * ip_iface = nm_device_get_ip_iface (device);
+
+	if (!ip_iface || !zone_name) {
+		nm_log_warn (LOGD_CORE, "couldn't determine IP interface (%p) or Zone (%p)!",
+		             ip_iface, setting_connection, zone_name);
+		return;
+	}
+
+	if (new_state == NM_DEVICE_STATE_ACTIVATED) {
+		g_signal_emit_by_name(self,
+				NM_ZONES_INTERFACE_CONNECTION_ADDED, ip_iface, zone_name);
+
+		nm_log_dbg (LOGD_DEVICE, "(%s): added to zone '%s'",
+					ip_iface,
+					zone_name);
+	} else if (new_state == NM_DEVICE_STATE_DISCONNECTED) {
+		g_signal_emit_by_name(self,
+				NM_ZONES_INTERFACE_CONNECTION_REMOVED, ip_iface, zone_name);
+
+		nm_log_dbg (LOGD_DEVICE, "(%s): removed from zone '%s'",
+					ip_iface,
+					zone_name);
+	}
+}
+
+static void
+device_ip_iface_changed (NMDevice *device,
+                         GParamSpec *pspec,
+                         gpointer user_data)
+{
+	NMConnection *connection = get_device_connection (device);
+	NMSettingConnection *setting_connection = nm_connection_get_setting_connection (connection);
+	const char * zone_name = nm_setting_connection_get_zone (setting_connection);
+	const char * ip_iface = nm_device_get_ip_iface (device);
+
+	if (!ip_iface || !zone_name) {
+		nm_log_warn (LOGD_CORE, "couldn't determine IP interface (%p) or Zone (%p)!",
+		             ip_iface, setting_connection, zone_name);
+		return;
+	}
+
+	g_signal_emit_by_name(self,
+			NM_ZONES_INTERFACE_CONNECTION_ADDED, ip_iface, zone_name);
+
+	nm_log_dbg (LOGD_DEVICE, "(%s): added to zone '%s'",
+				ip_iface,
+				zone_name);
+
+}
+
+static void
+device_ip_config_changed (NMDevice *device,
+                          GParamSpec *pspec,
+                          gpointer user_data)
+{
+	update_routing_and_dns ((NMPolicy *) user_data, TRUE);
+}
+
+static void
 device_state_changed (NMDevice *device,
                       NMDeviceState new_state,
                       NMDeviceState old_state,
@@ -1028,6 +1098,8 @@ device_state_changed (NMDevice *device,
 			 * settings service when the next connection is made.
 			 */
 			nm_connection_clear_secrets (connection);
+
+			device_signal_zone (self, device, connection, new_state);
 		}
 
 		update_routing_and_dns (self, FALSE);
@@ -1045,6 +1117,8 @@ device_state_changed (NMDevice *device,
 		/* Device is now available for auto-activation */
 		update_routing_and_dns (self, FALSE);
 		schedule_activate_check (self, device, 0);
+
+		device_signal_zone (self, device, connection, new_state);
 		break;
 	default:
 		break;
@@ -1052,14 +1126,6 @@ device_state_changed (NMDevice *device,
 }
 
 static void
-device_ip_config_changed (NMDevice *device,
-                          GParamSpec *pspec,
-                          gpointer user_data)
-{
-	update_routing_and_dns ((NMPolicy *) user_data, TRUE);
-}
-
-static void
 wireless_networks_changed (NMDeviceWifi *device, NMAccessPoint *ap, gpointer user_data)
 {
 	schedule_activate_check ((NMPolicy *) user_data, NM_DEVICE (device), 0);
@@ -1099,6 +1165,7 @@ device_added (NMManager *manager, NMDevice *device, gpointer user_data)
 	_connect_device_signal (self, device, "state-changed", device_state_changed);
 	_connect_device_signal (self, device, "notify::" NM_DEVICE_INTERFACE_IP4_CONFIG, device_ip_config_changed);
 	_connect_device_signal (self, device, "notify::" NM_DEVICE_INTERFACE_IP6_CONFIG, device_ip_config_changed);
+	_connect_device_signal (self, device, "notify::" NM_DEVICE_INTERFACE_IP_IFACE, device_ip_iface_changed);
 
 	if (NM_IS_DEVICE_WIFI (device)) {
 		_connect_device_signal (self, device, "access-point-added", wireless_networks_changed);
@@ -1276,6 +1343,7 @@ nm_policy_new (NMManager *manager,
 {
 	NMPolicy *self;
 	NMPolicyPrivate *priv;
+	NMDBusManager *dbus_mgr;
 	static gboolean initialized = FALSE;
 	gulong id;
 	char hostname[HOST_NAME_MAX + 2];
@@ -1330,15 +1398,53 @@ nm_policy_new (NMManager *manager,
 	/* Initialize connections' auto-retries */
 	reset_retries_all (priv->settings, NULL);
 
+	dbus_mgr = nm_dbus_manager_get ();
+	dbus_g_connection_register_g_object (nm_dbus_manager_get_connection (dbus_mgr),
+	                                     NM_DBUS_PATH_ZONES,
+	                                     G_OBJECT (self));
+
 	initialized = TRUE;
 	return self;
 }
 
 static void
+zones_interface_init (NMZonesInterface *zones_interface_class)
+{
+
+}
+
+static void
+policy_connection_added (NMPolicy *self,
+						 char *iface_name,
+						 char *zone_name,
+						 gpointer user_data)
+{
+	nm_log_dbg (LOGD_DEVICE, "policy_connection_added_callback: (%s): added to zone '%s'",
+				            iface_name,
+				            zone_name);
+
+}
+
+static void
+policy_connection_removed (NMPolicy *self,
+						 char *iface_name,
+						 char *zone_name,
+						 gpointer user_data)
+{
+	nm_log_dbg (LOGD_DEVICE, "policy_connection_removed_callback: (%s): removed from zone '%s'",
+				            iface_name,
+				            zone_name);
+
+}
+
+static void
 nm_policy_init (NMPolicy *self)
 {
 	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	priv->disposed = FALSE;
+
+	g_signal_connect (self, NM_ZONES_INTERFACE_CONNECTION_ADDED, G_CALLBACK (policy_connection_added), NULL);
+	g_signal_connect (self, NM_ZONES_INTERFACE_CONNECTION_REMOVED, G_CALLBACK (policy_connection_removed), NULL);
 }
 
 static void
@@ -1414,5 +1520,5 @@ nm_policy_class_init (NMPolicyClass *class)
 	/* virtual methods */
 	object_class->dispose = dispose;
 	object_class->finalize = finalize;
-
 }
+
-- 
1.7.6



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