api, dbus, bearer: Add ReloadStatsSupported bearer dbus property

This property means that the current bearer can reload stats and read TX
and RX bytes transmitted.

The property is initiliazed as soon as the bearer is connected.

Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
This commit is contained in:
Frederic Martinsons
2021-10-15 08:27:42 +02:00
committed by Aleksander Morgado
parent 07c4e95ac9
commit 9fc3d15d29
4 changed files with 66 additions and 18 deletions

View File

@@ -378,6 +378,15 @@
-->
<property name="Stats" type="a{sv}" access="read" />
<!--
ReloadStatsSupported:
Indicates whether or not the bearer support getting rx and tx bytes statistics.
Since: 1.20
-->
<property name="ReloadStatsSupported" type="b" access="read" />
<!--
IpTimeout:

View File

@@ -171,6 +171,27 @@ mm_bearer_get_connected (MMBearer *self)
/*****************************************************************************/
/**
* mm_bearer_get_reload_stats_supported:
* @self: A #MMBearer.
*
* Checks whether or not the #MMBearer supporting stats reload (to have
* RX and TX bytes of the ongoing connection).
*
* Returns: %TRUE if the #MMBearer supports these stats, #FALSE otherwise.
*
* Since: 1.20
*/
gboolean
mm_bearer_get_reload_stats_supported (MMBearer *self)
{
g_return_val_if_fail (MM_IS_BEARER (self), FALSE);
return mm_gdbus_bearer_get_reload_stats_supported (MM_GDBUS_BEARER (self));
}
/*****************************************************************************/
/**
* mm_bearer_get_suspended:
* @self: A #MMBearer.

View File

@@ -76,6 +76,8 @@ gchar *mm_bearer_dup_interface (MMBearer *self);
gboolean mm_bearer_get_connected (MMBearer *self);
gboolean mm_bearer_get_reload_stats_supported (MMBearer *self);
gboolean mm_bearer_get_suspended (MMBearer *self);
gboolean mm_bearer_get_multiplexed (MMBearer *self);

View File

@@ -125,7 +125,7 @@ struct _MMBaseBearerPrivate {
/* Timer to measure the duration of the connection */
GTimer *duration_timer;
/* Flag to specify whether reloading stats is supported or not */
gboolean reload_stats_unsupported;
gboolean reload_stats_supported;
};
/*****************************************************************************/
@@ -389,6 +389,25 @@ bearer_stats_stop (MMBaseBearer *self)
}
}
static void
reload_stats_supported_ready (MMBaseBearer *self,
GAsyncResult *res)
{
GError *error = NULL;
guint64 rx_bytes = 0;
guint64 tx_bytes = 0;
MM_BASE_BEARER_GET_CLASS (self)->reload_stats_finish (self, &rx_bytes, &tx_bytes, res, &error);
if (!error) {
mm_obj_info (self, "reloading stats is supported by the device");
self->priv->reload_stats_supported = TRUE;
mm_gdbus_bearer_set_reload_stats_supported (MM_GDBUS_BEARER (self), self->priv->reload_stats_supported);
} else {
mm_obj_info (self, "reloading stats is not supported by the device");
g_clear_error (&error);
}
}
static void
reload_stats_ready (MMBaseBearer *self,
GAsyncResult *res)
@@ -398,22 +417,11 @@ reload_stats_ready (MMBaseBearer *self,
guint64 tx_bytes = 0;
if (!MM_BASE_BEARER_GET_CLASS (self)->reload_stats_finish (self, &rx_bytes, &tx_bytes, res, &error)) {
/* If reloading stats fails, warn about it and don't update anything */
if (!g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED)) {
mm_obj_warn (self, "reloading stats failed: %s", error->message);
g_error_free (error);
return;
}
/* If we're being told that reloading stats is unsupported, just ignore
* the error and update oly the duration timer. */
mm_obj_dbg (self, "reloading stats is unsupported by the device");
self->priv->reload_stats_unsupported = TRUE;
rx_bytes = 0;
tx_bytes = 0;
g_error_free (error);
}
/* We only update stats if they were retrieved properly */
bearer_set_ongoing_interface_stats (self,
(guint32) g_timer_elapsed (self->priv->duration_timer, NULL),
@@ -429,9 +437,7 @@ stats_update_cb (MMBaseBearer *self)
return G_SOURCE_CONTINUE;
/* If the implementation knows how to update stat values, run it */
if (!self->priv->reload_stats_unsupported &&
MM_BASE_BEARER_GET_CLASS (self)->reload_stats &&
MM_BASE_BEARER_GET_CLASS (self)->reload_stats_finish) {
if (self->priv->reload_stats_supported) {
MM_BASE_BEARER_GET_CLASS (self)->reload_stats (
self,
(GAsyncReadyCallback)reload_stats_ready,
@@ -538,7 +544,7 @@ bearer_update_status (MMBaseBearer *self,
"connection #%u finished: duration %us",
mm_bearer_stats_get_attempts (self->priv->stats),
mm_bearer_stats_get_duration (self->priv->stats));
if (!self->priv->reload_stats_unsupported)
if (self->priv->reload_stats_supported)
g_string_append_printf (report,
", tx: %" G_GUINT64_FORMAT " bytes, rx: %" G_GUINT64_FORMAT " bytes",
mm_bearer_stats_get_tx_bytes (self->priv->stats),
@@ -583,6 +589,15 @@ bearer_update_status_connected (MMBaseBearer *self,
self->priv->status = MM_BEARER_STATUS_CONNECTED;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_STATUS]);
/* Check that reload statistics is supported by the device */
if (MM_BASE_BEARER_GET_CLASS (self)->reload_stats &&
MM_BASE_BEARER_GET_CLASS (self)->reload_stats_finish) {
MM_BASE_BEARER_GET_CLASS (self)->reload_stats (
self,
(GAsyncReadyCallback)reload_stats_supported_ready,
NULL);
}
/* Start statistics */
bearer_stats_start (self, uplink_speed, downlink_speed);
@@ -1773,6 +1788,7 @@ mm_base_bearer_init (MMBaseBearer *self)
self->priv->status = MM_BEARER_STATUS_DISCONNECTED;
self->priv->reason_3gpp = CONNECTION_FORBIDDEN_REASON_NONE;
self->priv->reason_cdma = CONNECTION_FORBIDDEN_REASON_NONE;
self->priv->reload_stats_supported = FALSE;
self->priv->stats = mm_bearer_stats_new ();
/* Set defaults */