broadband-modem,iface-modem: move bearer counting to interface and generalize
Allow counting more kinds of bearers than just multiplexed ones. Signed-off-by: Dan Williams <dan@ioncontrol.co>
This commit is contained in:
@@ -1458,10 +1458,11 @@ load_settings_from_bearer (MMBearerMbim *self,
|
||||
guint max_multiplexed_bearers;
|
||||
const gchar *data_port_driver;
|
||||
|
||||
if (!mm_broadband_modem_get_active_multiplexed_bearers (MM_BROADBAND_MODEM (ctx->modem),
|
||||
¤t_multiplexed_bearers,
|
||||
&max_multiplexed_bearers,
|
||||
error))
|
||||
if (!mm_iface_modem_count_bearers (MM_IFACE_MODEM (ctx->modem),
|
||||
MM_IFACE_MODEM_COUNT_BEARERS_FLAG_MULTIPLEXED,
|
||||
¤t_multiplexed_bearers,
|
||||
&max_multiplexed_bearers,
|
||||
error))
|
||||
return FALSE;
|
||||
|
||||
/* Check multiplex support in the kernel and the device */
|
||||
|
||||
+5
-4
@@ -2424,10 +2424,11 @@ load_settings_from_bearer (MMBearerQmi *self,
|
||||
guint max_multiplexed_bearers;
|
||||
gboolean multiplex_supported = TRUE;
|
||||
|
||||
if (!mm_broadband_modem_get_active_multiplexed_bearers (MM_BROADBAND_MODEM (ctx->modem),
|
||||
¤t_multiplexed_bearers,
|
||||
&max_multiplexed_bearers,
|
||||
error))
|
||||
if (!mm_iface_modem_count_bearers (MM_IFACE_MODEM (ctx->modem),
|
||||
MM_IFACE_MODEM_COUNT_BEARERS_FLAG_MULTIPLEXED,
|
||||
¤t_multiplexed_bearers,
|
||||
&max_multiplexed_bearers,
|
||||
error))
|
||||
return FALSE;
|
||||
|
||||
/* Check multiplex support in the kernel and the device */
|
||||
|
||||
@@ -13799,52 +13799,6 @@ mm_broadband_modem_get_current_charset (MMBroadbandModem *self)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
bearer_count_multiplexed_connected (MMBaseBearer *bearer,
|
||||
guint *count)
|
||||
{
|
||||
/* The Multiplexed property is only set if connected, so it's enough to check
|
||||
* that one to see if we're connected and multiplexed */
|
||||
if (mm_gdbus_bearer_get_multiplexed (MM_GDBUS_BEARER (bearer)))
|
||||
*count += 1;
|
||||
}
|
||||
|
||||
gboolean
|
||||
mm_broadband_modem_get_active_multiplexed_bearers (MMBroadbandModem *self,
|
||||
guint *out_current,
|
||||
guint *out_max,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(MMBearerList) list = NULL;
|
||||
guint max;
|
||||
guint count = 0;
|
||||
|
||||
g_object_get (self,
|
||||
MM_IFACE_MODEM_BEARER_LIST, &list,
|
||||
NULL);
|
||||
|
||||
if (!list) {
|
||||
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Bearer list unavailable");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
max = mm_bearer_list_get_max_active_multiplexed (list);
|
||||
|
||||
mm_bearer_list_foreach (list,
|
||||
(MMBearerListForeachFunc)bearer_count_multiplexed_connected,
|
||||
&count);
|
||||
g_assert (!(!max && count));
|
||||
|
||||
if (out_max)
|
||||
*out_max = max;
|
||||
if (out_current)
|
||||
*out_current = count;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
gchar *
|
||||
mm_broadband_modem_create_device_identifier (MMBroadbandModem *self,
|
||||
const gchar *ati,
|
||||
|
||||
@@ -143,12 +143,6 @@ gboolean mm_broadband_modem_sim_hot_swap_ports_context_init (MMBroadbandModem
|
||||
GError **error);
|
||||
void mm_broadband_modem_sim_hot_swap_ports_context_reset (MMBroadbandModem *self);
|
||||
|
||||
/* Helper to manage multiplexed bearers */
|
||||
gboolean mm_broadband_modem_get_active_multiplexed_bearers (MMBroadbandModem *self,
|
||||
guint *out_current,
|
||||
guint *out_max,
|
||||
GError **error);
|
||||
|
||||
/* Helper to manage initial EPS bearer */
|
||||
gint mm_broadband_modem_get_initial_eps_bearer_cid (MMBroadbandModem *self);
|
||||
|
||||
|
||||
@@ -6720,6 +6720,74 @@ mm_iface_modem_get_current_modes (MMIfaceModem *self,
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
const MMIfaceModemCountBearersFlags flags;
|
||||
guint count;
|
||||
} CountBearersContext;
|
||||
|
||||
static void
|
||||
bearer_count (MMBaseBearer *bearer,
|
||||
CountBearersContext *ctx)
|
||||
{
|
||||
MMBearerStatus status;
|
||||
|
||||
status = mm_base_bearer_get_status (MM_BASE_BEARER (bearer));
|
||||
|
||||
if (ctx->flags & MM_IFACE_MODEM_COUNT_BEARERS_FLAG_MULTIPLEXED) {
|
||||
/* The Multiplexed property is only set if connected, so it's enough to check
|
||||
* that one to see if we're connected and multiplexed */
|
||||
if (mm_gdbus_bearer_get_multiplexed (MM_GDBUS_BEARER (bearer)))
|
||||
ctx->count++;
|
||||
} else if (ctx->flags & MM_IFACE_MODEM_COUNT_BEARERS_FLAG_CONNECTED) {
|
||||
if (status == MM_BEARER_STATUS_CONNECTED)
|
||||
ctx->count++;
|
||||
} else if (ctx->flags & MM_IFACE_MODEM_COUNT_BEARERS_FLAG_ACTIVE) {
|
||||
if (status >= MM_BEARER_STATUS_CONNECTING)
|
||||
ctx->count++;
|
||||
} else
|
||||
ctx->count++;
|
||||
}
|
||||
|
||||
gboolean
|
||||
mm_iface_modem_count_bearers (MMIfaceModem *self,
|
||||
MMIfaceModemCountBearersFlags flags,
|
||||
guint *out_current,
|
||||
guint *out_max,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(MMBearerList) list = NULL;
|
||||
guint max = 0;
|
||||
CountBearersContext ctx = {
|
||||
.flags = flags,
|
||||
.count = 0,
|
||||
};
|
||||
|
||||
g_object_get (self,
|
||||
MM_IFACE_MODEM_BEARER_LIST, &list,
|
||||
NULL);
|
||||
if (!list) {
|
||||
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Bearer list unavailable");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (flags & MM_IFACE_MODEM_COUNT_BEARERS_FLAG_MULTIPLEXED)
|
||||
max = mm_bearer_list_get_max_active_multiplexed (list);
|
||||
else
|
||||
max = mm_bearer_list_get_max_active (list);
|
||||
|
||||
mm_bearer_list_foreach (list, (MMBearerListForeachFunc)bearer_count, &ctx);
|
||||
g_assert (max >= ctx.count);
|
||||
|
||||
if (out_max)
|
||||
*out_max = max;
|
||||
if (out_current)
|
||||
*out_current = ctx.count;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
mm_iface_modem_default_init (MMIfaceModemInterface *iface)
|
||||
{
|
||||
|
||||
@@ -620,4 +620,19 @@ void mm_iface_modem_modify_sim (MMIfaceModem *self,
|
||||
|
||||
void mm_iface_modem_process_sim_event (MMIfaceModem *self);
|
||||
|
||||
typedef enum {
|
||||
/* Connecting or connected bearers */
|
||||
MM_IFACE_MODEM_COUNT_BEARERS_FLAG_ACTIVE = 0x1,
|
||||
/* Fully connected bearers */
|
||||
MM_IFACE_MODEM_COUNT_BEARERS_FLAG_CONNECTED = 0x2,
|
||||
/* Multiplexed implies connected */
|
||||
MM_IFACE_MODEM_COUNT_BEARERS_FLAG_MULTIPLEXED = 0x4,
|
||||
} MMIfaceModemCountBearersFlags;
|
||||
|
||||
gboolean mm_iface_modem_count_bearers (MMIfaceModem *self,
|
||||
MMIfaceModemCountBearersFlags flags,
|
||||
guint *out_current,
|
||||
guint *out_max,
|
||||
GError **error);
|
||||
|
||||
#endif /* MM_IFACE_MODEM_H */
|
||||
|
||||
Reference in New Issue
Block a user