iface-modem: move state update context to iface-specific private context
Avoid keeping separate per-operation contexts, it doesn't make sense. Just have one single Private context for the whole interface where we can add support for all operations performed by the interface.
This commit is contained in:
@@ -42,16 +42,50 @@
|
|||||||
#define SIGNAL_CHECK_INITIAL_TIMEOUT_SEC 3
|
#define SIGNAL_CHECK_INITIAL_TIMEOUT_SEC 3
|
||||||
#define SIGNAL_CHECK_TIMEOUT_SEC 30
|
#define SIGNAL_CHECK_TIMEOUT_SEC 30
|
||||||
|
|
||||||
#define STATE_UPDATE_CONTEXT_TAG "state-update-context-tag"
|
|
||||||
#define SIGNAL_QUALITY_UPDATE_CONTEXT_TAG "signal-quality-update-context-tag"
|
#define SIGNAL_QUALITY_UPDATE_CONTEXT_TAG "signal-quality-update-context-tag"
|
||||||
#define SIGNAL_CHECK_CONTEXT_TAG "signal-check-context-tag"
|
#define SIGNAL_CHECK_CONTEXT_TAG "signal-check-context-tag"
|
||||||
#define RESTART_INITIALIZE_IDLE_TAG "restart-initialize-tag"
|
#define RESTART_INITIALIZE_IDLE_TAG "restart-initialize-tag"
|
||||||
|
|
||||||
static GQuark state_update_context_quark;
|
|
||||||
static GQuark signal_quality_update_context_quark;
|
static GQuark signal_quality_update_context_quark;
|
||||||
static GQuark signal_check_context_quark;
|
static GQuark signal_check_context_quark;
|
||||||
static GQuark restart_initialize_idle_quark;
|
static GQuark restart_initialize_idle_quark;
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Private data context */
|
||||||
|
|
||||||
|
#define PRIVATE_TAG "modem-private-tag"
|
||||||
|
static GQuark private_quark;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
/* Subsystem specific states */
|
||||||
|
GArray *subsystem_states;
|
||||||
|
} Private;
|
||||||
|
|
||||||
|
static void
|
||||||
|
private_free (Private *priv)
|
||||||
|
{
|
||||||
|
if (priv->subsystem_states)
|
||||||
|
g_array_unref (priv->subsystem_states);
|
||||||
|
g_slice_free (Private, priv);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Private *
|
||||||
|
get_private (MMIfaceModem *self)
|
||||||
|
{
|
||||||
|
Private *priv;
|
||||||
|
|
||||||
|
if (G_UNLIKELY (!private_quark))
|
||||||
|
private_quark = g_quark_from_static_string (PRIVATE_TAG);
|
||||||
|
|
||||||
|
priv = g_object_get_qdata (G_OBJECT (self), private_quark);
|
||||||
|
if (!priv) {
|
||||||
|
priv = g_slice_new0 (Private);
|
||||||
|
g_object_set_qdata_full (G_OBJECT (self), private_quark, priv, (GDestroyNotify)private_free);
|
||||||
|
}
|
||||||
|
|
||||||
|
return priv;
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
@@ -1987,20 +2021,11 @@ typedef struct {
|
|||||||
} SubsystemState;
|
} SubsystemState;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
subsystem_state_array_free (GArray *array)
|
subsystem_state_clear (SubsystemState *s)
|
||||||
{
|
{
|
||||||
guint i;
|
|
||||||
|
|
||||||
for (i = 0; i < array->len; i++) {
|
|
||||||
SubsystemState *s;
|
|
||||||
|
|
||||||
s = &g_array_index (array, SubsystemState, i);
|
|
||||||
g_free (s->subsystem);
|
g_free (s->subsystem);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_array_free (array, TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
static MMModemState
|
static MMModemState
|
||||||
get_consolidated_subsystem_state (MMIfaceModem *self)
|
get_consolidated_subsystem_state (MMIfaceModem *self)
|
||||||
{
|
{
|
||||||
@@ -2008,26 +2033,21 @@ get_consolidated_subsystem_state (MMIfaceModem *self)
|
|||||||
* use the old modem state as initial state, as that would disallow reporting
|
* use the old modem state as initial state, as that would disallow reporting
|
||||||
* e.g. ENABLED if the old state was REGISTERED (as ENABLED < REGISTERED). */
|
* e.g. ENABLED if the old state was REGISTERED (as ENABLED < REGISTERED). */
|
||||||
MMModemState consolidated = MM_MODEM_STATE_ENABLED;
|
MMModemState consolidated = MM_MODEM_STATE_ENABLED;
|
||||||
GArray *subsystem_states;
|
Private *priv;
|
||||||
|
|
||||||
if (G_UNLIKELY (!state_update_context_quark))
|
priv = get_private (self);
|
||||||
state_update_context_quark = (g_quark_from_static_string (
|
|
||||||
STATE_UPDATE_CONTEXT_TAG));
|
|
||||||
|
|
||||||
subsystem_states = g_object_get_qdata (G_OBJECT (self),
|
|
||||||
state_update_context_quark);
|
|
||||||
|
|
||||||
/* Build consolidated state, expected fixes are:
|
/* Build consolidated state, expected fixes are:
|
||||||
* - Enabled (meaning unregistered) --> Searching|Registered
|
* - Enabled (meaning unregistered) --> Searching|Registered
|
||||||
* - Searching --> Registered
|
* - Searching --> Registered
|
||||||
*/
|
*/
|
||||||
if (subsystem_states) {
|
if (priv->subsystem_states) {
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
for (i = 0; i < subsystem_states->len; i++) {
|
for (i = 0; i < priv->subsystem_states->len; i++) {
|
||||||
SubsystemState *s;
|
SubsystemState *s;
|
||||||
|
|
||||||
s = &g_array_index (subsystem_states, SubsystemState, i);
|
s = &g_array_index (priv->subsystem_states, SubsystemState, i);
|
||||||
if (s->state > consolidated)
|
if (s->state > consolidated)
|
||||||
consolidated = s->state;
|
consolidated = s->state;
|
||||||
}
|
}
|
||||||
@@ -2043,7 +2063,9 @@ get_updated_consolidated_state (MMIfaceModem *self,
|
|||||||
MMModemState subsystem_state)
|
MMModemState subsystem_state)
|
||||||
{
|
{
|
||||||
guint i;
|
guint i;
|
||||||
GArray *subsystem_states;
|
Private *priv;
|
||||||
|
|
||||||
|
priv = get_private (self);
|
||||||
|
|
||||||
/* Reported subsystem states will be REGISTRATION-related. This means
|
/* Reported subsystem states will be REGISTRATION-related. This means
|
||||||
* that we would only expect a subset of the states being reported for
|
* that we would only expect a subset of the states being reported for
|
||||||
@@ -2052,28 +2074,16 @@ get_updated_consolidated_state (MMIfaceModem *self,
|
|||||||
subsystem_state == MM_MODEM_STATE_SEARCHING ||
|
subsystem_state == MM_MODEM_STATE_SEARCHING ||
|
||||||
subsystem_state == MM_MODEM_STATE_REGISTERED);
|
subsystem_state == MM_MODEM_STATE_REGISTERED);
|
||||||
|
|
||||||
if (G_UNLIKELY (!state_update_context_quark))
|
if (!priv->subsystem_states) {
|
||||||
state_update_context_quark = (g_quark_from_static_string (
|
priv->subsystem_states = g_array_sized_new (FALSE, FALSE, sizeof (SubsystemState), 2);
|
||||||
STATE_UPDATE_CONTEXT_TAG));
|
g_array_set_clear_func (priv->subsystem_states, (GDestroyNotify)subsystem_state_clear);
|
||||||
|
|
||||||
subsystem_states = g_object_get_qdata (G_OBJECT (self),
|
|
||||||
state_update_context_quark);
|
|
||||||
if (!subsystem_states) {
|
|
||||||
subsystem_states = g_array_sized_new (FALSE,
|
|
||||||
FALSE,
|
|
||||||
sizeof (SubsystemState),
|
|
||||||
2);
|
|
||||||
g_object_set_qdata_full (G_OBJECT (self),
|
|
||||||
state_update_context_quark,
|
|
||||||
subsystem_states,
|
|
||||||
(GDestroyNotify)subsystem_state_array_free);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Store new subsystem state */
|
/* Store new subsystem state */
|
||||||
for (i = 0; i < subsystem_states->len; i++) {
|
for (i = 0; i < priv->subsystem_states->len; i++) {
|
||||||
SubsystemState *s;
|
SubsystemState *s;
|
||||||
|
|
||||||
s = &g_array_index (subsystem_states, SubsystemState, i);
|
s = &g_array_index (priv->subsystem_states, SubsystemState, i);
|
||||||
if (g_str_equal (s->subsystem, subsystem)) {
|
if (g_str_equal (s->subsystem, subsystem)) {
|
||||||
s->state = subsystem_state;
|
s->state = subsystem_state;
|
||||||
break;
|
break;
|
||||||
@@ -2081,13 +2091,13 @@ get_updated_consolidated_state (MMIfaceModem *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* If not found, insert new element */
|
/* If not found, insert new element */
|
||||||
if (i == subsystem_states->len) {
|
if (i == priv->subsystem_states->len) {
|
||||||
SubsystemState s;
|
SubsystemState s;
|
||||||
|
|
||||||
mm_obj_dbg (self, "will start keeping track of state for subsystem '%s'", subsystem);
|
mm_obj_dbg (self, "will start keeping track of state for subsystem '%s'", subsystem);
|
||||||
s.subsystem = g_strdup (subsystem);
|
s.subsystem = g_strdup (subsystem);
|
||||||
s.state = subsystem_state;
|
s.state = subsystem_state;
|
||||||
g_array_append_val (subsystem_states, s);
|
g_array_append_val (priv->subsystem_states, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
return get_consolidated_subsystem_state (self);
|
return get_consolidated_subsystem_state (self);
|
||||||
|
Reference in New Issue
Block a user