diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2013-11-15 19:06:58 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2013-11-21 10:50:49 +0100 |
commit | 7f442b777c6fe7fd71f4f9022121752dabad5cdd (patch) | |
tree | d77ebb9ffa37c6abb549c85806b30bc4e1a73045 | |
parent | c21709b32e1af46f1764888a03b21fd747db7da1 (diff) | |
download | ModemManager-7f442b777c6fe7fd71f4f9022121752dabad5cdd.tar.gz |
introspection,api: new 'Bearers' property in the Modem interface
https://bugzilla.gnome.org/show_bug.cgi?id=712276
-rw-r--r-- | introspection/org.freedesktop.ModemManager1.Modem.xml | 8 | ||||
-rw-r--r-- | libmm-glib/mm-modem.c | 52 | ||||
-rw-r--r-- | src/mm-bearer-list.c | 27 | ||||
-rw-r--r-- | src/mm-bearer-list.h | 1 | ||||
-rw-r--r-- | src/mm-iface-modem.c | 27 |
5 files changed, 75 insertions, 40 deletions
diff --git a/introspection/org.freedesktop.ModemManager1.Modem.xml b/introspection/org.freedesktop.ModemManager1.Modem.xml index b264ab418..a5a236c5d 100644 --- a/introspection/org.freedesktop.ModemManager1.Modem.xml +++ b/introspection/org.freedesktop.ModemManager1.Modem.xml @@ -210,6 +210,14 @@ <property name="Sim" type="o" access="read" /> <!-- + Bearers: + + The list of bearer object paths (EPS Bearers, PDP Contexts, or + CDMA2000 Packet Data Sessions). + --> + <property name="Bearers" type="ao" access="read" /> + + <!-- SupportedCapabilities: List of <link linkend="MMModemCapability">MMModemCapability</link> diff --git a/libmm-glib/mm-modem.c b/libmm-glib/mm-modem.c index 780fd6d2a..c1dee3ace 100644 --- a/libmm-glib/mm-modem.c +++ b/libmm-glib/mm-modem.c @@ -1721,7 +1721,7 @@ bearer_object_list_free (GList *list) static void list_bearers_context_complete_and_free (ListBearersContext *ctx) { - g_simple_async_result_complete (ctx->result); + g_simple_async_result_complete_in_idle (ctx->result); g_strfreev (ctx->bearer_paths); bearer_object_list_free (ctx->bearer_objects); @@ -1816,32 +1816,6 @@ create_next_bearer (ListBearersContext *ctx) NULL); } -static void -modem_list_bearers_ready (MMModem *self, - GAsyncResult *res, - ListBearersContext *ctx) -{ - GError *error = NULL; - - mm_gdbus_modem_call_list_bearers_finish (MM_GDBUS_MODEM (self), &ctx->bearer_paths, res, &error); - if (error) { - g_simple_async_result_take_error (ctx->result, error); - list_bearers_context_complete_and_free (ctx); - return; - } - - /* If no bearers, just end here. */ - if (!ctx->bearer_paths || !ctx->bearer_paths[0]) { - g_simple_async_result_set_op_res_gpointer (ctx->result, NULL, NULL); - list_bearers_context_complete_and_free (ctx); - return; - } - - /* Got list of paths. If at least one found, start creating objects for each */ - ctx->i = 0; - create_next_bearer (ctx); -} - /** * mm_modem_list_bearers: * @self: A #MMModem. @@ -1875,10 +1849,19 @@ mm_modem_list_bearers (MMModem *self, if (cancellable) ctx->cancellable = g_object_ref (cancellable); - mm_gdbus_modem_call_list_bearers (MM_GDBUS_MODEM (self), - cancellable, - (GAsyncReadyCallback)modem_list_bearers_ready, - ctx); + /* Read from the property, skip List() */ + ctx->bearer_paths = mm_gdbus_modem_dup_bearers (MM_GDBUS_MODEM (self)); + + /* If no bearers, just end here. */ + if (!ctx->bearer_paths || !ctx->bearer_paths[0]) { + g_simple_async_result_set_op_res_gpointer (ctx->result, NULL, NULL); + list_bearers_context_complete_and_free (ctx); + return; + } + + /* Got list of paths. If at least one found, start creating objects for each */ + ctx->i = 0; + create_next_bearer (ctx); } /** @@ -1905,11 +1888,8 @@ mm_modem_list_bearers_sync (MMModem *self, g_return_val_if_fail (MM_IS_MODEM (self), NULL); - if (!mm_gdbus_modem_call_list_bearers_sync (MM_GDBUS_MODEM (self), - &bearer_paths, - cancellable, - error)) - return NULL; + /* Read from the property, skip List() */ + bearer_paths = mm_gdbus_modem_dup_bearers (MM_GDBUS_MODEM (self)); /* Only non-empty lists are returned */ if (!bearer_paths) diff --git a/src/mm-bearer-list.c b/src/mm-bearer-list.c index 43ccf8f7c..278cebab9 100644 --- a/src/mm-bearer-list.c +++ b/src/mm-bearer-list.c @@ -33,6 +33,7 @@ G_DEFINE_TYPE (MMBearerList, mm_bearer_list, G_TYPE_OBJECT); enum { PROP_0, + PROP_NUM_BEARERS, PROP_MAX_BEARERS, PROP_MAX_ACTIVE_BEARERS, PROP_LAST @@ -91,8 +92,9 @@ mm_bearer_list_add_bearer (MMBearerList *self, } /* Keep our own reference */ - self->priv->bearers = g_list_prepend (self->priv->bearers, - g_object_ref (bearer)); + self->priv->bearers = g_list_prepend (self->priv->bearers, g_object_ref (bearer)); + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_NUM_BEARERS]); + return TRUE; } @@ -115,8 +117,8 @@ mm_bearer_list_delete_bearer (MMBearerList *self, for (l = self->priv->bearers; l; l = g_list_next (l)) { if (g_str_equal (path, mm_bearer_get_path (MM_BEARER (l->data)))) { g_object_unref (l->data); - self->priv->bearers = - g_list_delete_link (self->priv->bearers, l); + self->priv->bearers = g_list_delete_link (self->priv->bearers, l); + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_NUM_BEARERS]); return TRUE; } } @@ -137,6 +139,7 @@ mm_bearer_list_delete_all_bearers (MMBearerList *self) g_list_free_full (self->priv->bearers, (GDestroyNotify) g_object_unref); self->priv->bearers = NULL; + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_NUM_BEARERS]); } GStrv @@ -288,6 +291,9 @@ set_property (GObject *object, MMBearerList *self = MM_BEARER_LIST (object); switch (prop_id) { + case PROP_NUM_BEARERS: + g_assert_not_reached (); + break; case PROP_MAX_BEARERS: self->priv->max_bearers = g_value_get_uint (value); break; @@ -309,6 +315,9 @@ get_property (GObject *object, MMBearerList *self = MM_BEARER_LIST (object); switch (prop_id) { + case PROP_NUM_BEARERS: + g_value_set_uint (value, g_list_length (self->priv->bearers)); + break; case PROP_MAX_BEARERS: g_value_set_uint (value, self->priv->max_bearers); break; @@ -352,6 +361,16 @@ mm_bearer_list_class_init (MMBearerListClass *klass) object_class->set_property = set_property; object_class->dispose = dispose; + properties[PROP_NUM_BEARERS] = + g_param_spec_uint (MM_BEARER_LIST_NUM_BEARERS, + "Number of bearers", + "Current number of bearers in the list", + 0, + G_MAXUINT, + 0, + G_PARAM_READABLE); + g_object_class_install_property (object_class, PROP_NUM_BEARERS, properties[PROP_NUM_BEARERS]); + properties[PROP_MAX_BEARERS] = g_param_spec_uint (MM_BEARER_LIST_MAX_BEARERS, "Max bearers", diff --git a/src/mm-bearer-list.h b/src/mm-bearer-list.h index 7cd03946d..292e3d521 100644 --- a/src/mm-bearer-list.h +++ b/src/mm-bearer-list.h @@ -30,6 +30,7 @@ #define MM_IS_BEARER_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_BEARER_LIST)) #define MM_BEARER_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BEARER_LIST, MMBearerListClass)) +#define MM_BEARER_LIST_NUM_BEARERS "num-bearers" #define MM_BEARER_LIST_MAX_BEARERS "max-bearers" #define MM_BEARER_LIST_MAX_ACTIVE_BEARERS "max-active-bearers" diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 0a3f096a1..838e8ec26 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -347,6 +347,29 @@ internal_load_unlock_required (MMIfaceModem *self, /*****************************************************************************/ +static void +bearer_list_updated (MMBearerList *bearer_list, + GParamSpec *pspec, + MMIfaceModem *self) +{ + MmGdbusModem *skeleton; + gchar **paths; + + g_object_get (self, + MM_IFACE_MODEM_DBUS_SKELETON, &skeleton, + NULL); + if (!skeleton) + return; + + paths = mm_bearer_list_get_paths (bearer_list); + mm_gdbus_modem_set_bearers (skeleton, (const gchar *const *)paths); + g_strfreev (paths); + + g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (skeleton)); +} + +/*****************************************************************************/ + static MMModemState get_current_consolidated_state (MMIfaceModem *self, MMModemState modem_state); typedef struct { @@ -4209,6 +4232,10 @@ interface_initialization_step (InitializationContext *ctx) /* Create new default list */ list = mm_bearer_list_new (n, n); + g_signal_connect (list, + "notify::" MM_BEARER_LIST_NUM_BEARERS, + G_CALLBACK (bearer_list_updated), + ctx->self); g_object_set (ctx->self, MM_IFACE_MODEM_BEARER_LIST, list, NULL); |