[PATCH 03/15] modem-manager: switch the `state' property from `NMModem' into just `connected'



We don't want to depend in the `NMModem' interface on an enumeration which is
very specific to the old ModemManager interface, so we'll just skip exposing it
and instead we'll just give a new boolean property which tells whether the modem
is connected or not (which was at the end the whole purpose of the `state'
property).
---
 src/modem-manager/nm-modem-cdma.c    |  2 +-
 src/modem-manager/nm-modem-generic.c | 16 ++++++++++++----
 src/modem-manager/nm-modem-generic.h | 15 +++++++++++++++
 src/modem-manager/nm-modem-gsm.c     |  2 +-
 src/modem-manager/nm-modem.c         | 37 +++++++++++++++---------------------
 src/modem-manager/nm-modem.h         | 28 ++++++---------------------
 src/nm-device-modem.c                |  6 +++---
 7 files changed, 53 insertions(+), 53 deletions(-)

diff --git a/src/modem-manager/nm-modem-cdma.c b/src/modem-manager/nm-modem-cdma.c
index 48176c6..00e506a 100644
--- a/src/modem-manager/nm-modem-cdma.c
+++ b/src/modem-manager/nm-modem-cdma.c
@@ -73,7 +73,7 @@ nm_modem_cdma_new (const char *path,
 	                                 NM_MODEM_PATH, path,
 	                                 NM_MODEM_IFACE, data_device,
 	                                 NM_MODEM_IP_METHOD, ip_method,
-	                                 NM_MODEM_STATE, state,
+	                                 NM_MODEM_CONNECTED, (state == NM_MODEM_STATE_CONNECTED),
 	                                 NULL);
 }
 
diff --git a/src/modem-manager/nm-modem-generic.c b/src/modem-manager/nm-modem-generic.c
index 33454da..3d1b700 100644
--- a/src/modem-manager/nm-modem-generic.c
+++ b/src/modem-manager/nm-modem-generic.c
@@ -42,6 +42,8 @@ typedef struct {
 	DBusGProxy *props_proxy;
 
 	DBusGProxyCall *call;
+
+	NMModemState state;
 } NMModemGenericPrivate;
 
 /*****************************************************************************/
@@ -335,10 +337,16 @@ modem_properties_changed (DBusGProxy *proxy,
 	value = g_hash_table_lookup (props, "State");
 	if (value && G_VALUE_HOLDS_UINT (value)) {
 		new_state = g_value_get_uint (value);
-		if (new_state != nm_modem_get_state (NM_MODEM (self))) {
-			g_object_set (self,
-			              NM_MODEM_STATE, new_state,
-			              NULL);
+		if (new_state != priv->state) {
+			if (new_state == NM_MODEM_STATE_CONNECTED)
+				g_object_set (self,
+				              NM_MODEM_CONNECTED, TRUE,
+				              NULL);
+			else if (priv->state == NM_MODEM_STATE_CONNECTED)
+				g_object_set (self,
+				              NM_MODEM_CONNECTED, FALSE,
+				              NULL);
+			priv->state = new_state;
 		}
 	}
 }
diff --git a/src/modem-manager/nm-modem-generic.h b/src/modem-manager/nm-modem-generic.h
index 5a9ee76..59866a1 100644
--- a/src/modem-manager/nm-modem-generic.h
+++ b/src/modem-manager/nm-modem-generic.h
@@ -35,6 +35,21 @@ G_BEGIN_DECLS
 #define NM_IS_MODEM_GENERIC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  NM_TYPE_MODEM_GENERIC))
 #define NM_MODEM_GENERIC_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  NM_TYPE_MODEM_GENERIC, NMModemGenericClass))
 
+typedef enum {
+    NM_MODEM_STATE_UNKNOWN = 0,
+    NM_MODEM_STATE_DISABLED = 10,
+    NM_MODEM_STATE_DISABLING = 20,
+    NM_MODEM_STATE_ENABLING = 30,
+    NM_MODEM_STATE_ENABLED = 40,
+    NM_MODEM_STATE_SEARCHING = 50,
+    NM_MODEM_STATE_REGISTERED = 60,
+    NM_MODEM_STATE_DISCONNECTING = 70,
+    NM_MODEM_STATE_CONNECTING = 80,
+    NM_MODEM_STATE_CONNECTED = 90,
+
+    NM_MODEM_STATE_LAST = NM_MODEM_STATE_CONNECTED
+} NMModemState;
+
 typedef struct {
 	NMModem parent;
 } NMModemGeneric;
diff --git a/src/modem-manager/nm-modem-gsm.c b/src/modem-manager/nm-modem-gsm.c
index 54bbe3c..b6854ca 100644
--- a/src/modem-manager/nm-modem-gsm.c
+++ b/src/modem-manager/nm-modem-gsm.c
@@ -115,7 +115,7 @@ nm_modem_gsm_new (const char *path,
 	                                 NM_MODEM_PATH, path,
 	                                 NM_MODEM_IFACE, data_device,
 	                                 NM_MODEM_IP_METHOD, ip_method,
-	                                 NM_MODEM_STATE, state,
+	                                 NM_MODEM_CONNECTED, (state == NM_MODEM_STATE_CONNECTED),
 	                                 NULL);
 }
 
diff --git a/src/modem-manager/nm-modem.c b/src/modem-manager/nm-modem.c
index 76567a8..3fa61eb 100644
--- a/src/modem-manager/nm-modem.c
+++ b/src/modem-manager/nm-modem.c
@@ -43,7 +43,7 @@ enum {
 	PROP_IP_METHOD,
 	PROP_IP_TIMEOUT,
 	PROP_ENABLED,
-	PROP_STATE,
+	PROP_CONNECTED,
 
 	LAST_PROP
 };
@@ -61,7 +61,7 @@ typedef struct {
 
 	gboolean mm_enabled;
 	guint32 mm_ip_timeout;
-	NMModemState state;
+	gboolean mm_connected;
 
 	/* PPP stats */
 	guint32 in_bytes;
@@ -102,14 +102,10 @@ nm_modem_set_mm_enabled (NMModem *self,
 		NM_MODEM_GET_CLASS (self)->set_mm_enabled (self, enabled);
 }
 
-/*****************************************************************************/
-
-NMModemState
-nm_modem_get_state (NMModem *self)
+gboolean
+nm_modem_get_mm_connected (NMModem *self)
 {
-	g_return_val_if_fail (NM_IS_MODEM (self), NM_MODEM_STATE_UNKNOWN);
-
-	return NM_MODEM_GET_PRIVATE (self)->state;
+	return NM_MODEM_GET_PRIVATE (self)->mm_connected;
 }
 
 /*****************************************************************************/
@@ -693,8 +689,8 @@ get_property (GObject *object, guint prop_id,
 	case PROP_ENABLED:
 		g_value_set_boolean (value, priv->mm_enabled);
 		break;
-	case PROP_STATE:
-		g_value_set_boolean (value, priv->state);
+	case PROP_CONNECTED:
+		g_value_set_boolean (value, priv->mm_connected);
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -718,7 +714,6 @@ set_property (GObject *object, guint prop_id,
 		priv->iface = g_value_dup_string (value);
 		break;
 	case PROP_IP_METHOD:
-		/* Construct only */
 		priv->ip_method = g_value_get_uint (value);
 		break;
 	case PROP_IP_TIMEOUT:
@@ -727,8 +722,8 @@ set_property (GObject *object, guint prop_id,
 	case PROP_ENABLED:
 		priv->mm_enabled = g_value_get_boolean (value);
 		break;
-	case PROP_STATE:
-		priv->state = g_value_get_uint (value);
+	case PROP_CONNECTED:
+		priv->mm_connected = g_value_get_boolean (value);
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -822,14 +817,12 @@ nm_modem_class_init (NMModemClass *klass)
 		                       G_PARAM_READWRITE));
 
 	g_object_class_install_property
-		(object_class, PROP_STATE,
-		 g_param_spec_uint (NM_MODEM_STATE,
-		                    "ModemManager modem state",
-		                    "ModemManager modem state",
-		                    NM_MODEM_STATE_UNKNOWN,
-		                    NM_MODEM_STATE_LAST,
-		                    NM_MODEM_STATE_UNKNOWN,
-		                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+		(object_class, PROP_CONNECTED,
+		 g_param_spec_boolean (NM_MODEM_CONNECTED,
+		                       "Connected",
+		                       "Connected",
+		                       TRUE,
+		                       G_PARAM_READWRITE));
 
 	/* Signals */
 
diff --git a/src/modem-manager/nm-modem.h b/src/modem-manager/nm-modem.h
index 91eec95..56f43c2 100644
--- a/src/modem-manager/nm-modem.h
+++ b/src/modem-manager/nm-modem.h
@@ -36,12 +36,12 @@ G_BEGIN_DECLS
 #define NM_IS_MODEM_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass),	NM_TYPE_MODEM))
 #define NM_MODEM_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS ((obj),	NM_TYPE_MODEM, NMModemClass))
 
-#define NM_MODEM_PATH      "path"
-#define NM_MODEM_IFACE     "iface"
-#define NM_MODEM_IP_METHOD "ip-method"
+#define NM_MODEM_PATH       "path"
+#define NM_MODEM_IFACE      "iface"
+#define NM_MODEM_IP_METHOD  "ip-method"
 #define NM_MODEM_IP_TIMEOUT "ip-timeout"
-#define NM_MODEM_ENABLED   "enabled"
-#define NM_MODEM_STATE     "state"
+#define NM_MODEM_ENABLED    "enabled"
+#define NM_MODEM_CONNECTED  "connected"
 
 #define NM_MODEM_PPP_STATS         "ppp-stats"
 #define NM_MODEM_PPP_FAILED        "ppp-failed"
@@ -50,22 +50,6 @@ G_BEGIN_DECLS
 #define NM_MODEM_AUTH_REQUESTED    "auth-requested"
 #define NM_MODEM_AUTH_RESULT       "auth-result"
 
-/* From ModemManager */
-typedef enum {
-    NM_MODEM_STATE_UNKNOWN = 0,
-    NM_MODEM_STATE_DISABLED = 10,
-    NM_MODEM_STATE_DISABLING = 20,
-    NM_MODEM_STATE_ENABLING = 30,
-    NM_MODEM_STATE_ENABLED = 40,
-    NM_MODEM_STATE_SEARCHING = 50,
-    NM_MODEM_STATE_REGISTERED = 60,
-    NM_MODEM_STATE_DISCONNECTING = 70,
-    NM_MODEM_STATE_CONNECTING = 80,
-    NM_MODEM_STATE_CONNECTED = 90,
-
-    NM_MODEM_STATE_LAST = NM_MODEM_STATE_CONNECTED
-} NMModemState;
-
 #define MM_MODEM_IP_METHOD_PPP    0
 #define MM_MODEM_IP_METHOD_STATIC 1
 #define MM_MODEM_IP_METHOD_DHCP   2
@@ -180,7 +164,7 @@ gboolean      nm_modem_get_mm_enabled (NMModem *self);
 
 void          nm_modem_set_mm_enabled (NMModem *self, gboolean enabled);
 
-NMModemState  nm_modem_get_state (NMModem *self);
+gboolean      nm_modem_get_mm_connected (NMModem *self);
 
 G_END_DECLS
 
diff --git a/src/nm-device-modem.c b/src/nm-device-modem.c
index 2ceed1f..c27934f 100644
--- a/src/nm-device-modem.c
+++ b/src/nm-device-modem.c
@@ -167,13 +167,13 @@ modem_enabled_cb (NMModem *modem, GParamSpec *pspec, gpointer user_data)
 }
 
 static void
-modem_state_cb (NMModem *modem, GParamSpec *pspec, gpointer user_data)
+modem_connected_cb (NMModem *modem, GParamSpec *pspec, gpointer user_data)
 {
 	NMDeviceModem *self = NM_DEVICE_MODEM (user_data);
 	NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (self);
 
 	if (   nm_device_get_state (NM_DEVICE (self)) == NM_DEVICE_STATE_ACTIVATED
-	    && nm_modem_get_state (priv->modem) != NM_MODEM_STATE_CONNECTED) {
+	    && !nm_modem_get_mm_connected (priv->modem)) {
 		/* Fail the device if the modem disconnects unexpectedly */
 		nm_device_state_changed (NM_DEVICE (self), NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER);
 	}
@@ -390,7 +390,7 @@ set_modem (NMDeviceModem *self, NMModem *modem)
 	g_signal_connect (modem, NM_MODEM_AUTH_REQUESTED, G_CALLBACK (modem_auth_requested), self);
 	g_signal_connect (modem, NM_MODEM_AUTH_RESULT, G_CALLBACK (modem_auth_result), self);
 	g_signal_connect (modem, "notify::" NM_MODEM_ENABLED, G_CALLBACK (modem_enabled_cb), self);
-	g_signal_connect (modem, "notify::" NM_MODEM_STATE, G_CALLBACK (modem_state_cb), self);
+	g_signal_connect (modem, "notify::" NM_MODEM_CONNECTED, G_CALLBACK (modem_connected_cb), self);
 }
 
 static void
-- 
1.7.11.7



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