introspection,api: new 'Bearers' property in the Modem interface

https://bugzilla.gnome.org/show_bug.cgi?id=712276
This commit is contained in:
Aleksander Morgado
2013-11-21 10:50:49 +01:00
parent c21709b32e
commit 7f442b777c
5 changed files with 75 additions and 40 deletions
@@ -209,6 +209,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:
+16 -36
View File
@@ -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)
+23 -4
View File
@@ -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",
+1
View File
@@ -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"
+27
View File
@@ -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);