wavecom: port to use g_autoptr() setup
This commit is contained in:
@@ -217,7 +217,7 @@ load_current_modes_finish (MMIfaceModem *self,
|
|||||||
MMModemMode *preferred,
|
MMModemMode *preferred,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
LoadCurrentModesResult *result;
|
g_autofree LoadCurrentModesResult *result = NULL;
|
||||||
|
|
||||||
result = g_task_propagate_pointer (G_TASK (res), error);
|
result = g_task_propagate_pointer (G_TASK (res), error);
|
||||||
if (!result)
|
if (!result)
|
||||||
@@ -225,7 +225,6 @@ load_current_modes_finish (MMIfaceModem *self,
|
|||||||
|
|
||||||
*allowed = result->allowed;
|
*allowed = result->allowed;
|
||||||
*preferred = result->preferred;
|
*preferred = result->preferred;
|
||||||
g_free (result);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,11 +233,11 @@ wwsm_read_ready (MMBaseModem *self,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GTask *task)
|
GTask *task)
|
||||||
{
|
{
|
||||||
GRegex *r;
|
g_autoptr(GRegex) r = NULL;
|
||||||
GMatchInfo *match_info = NULL;
|
g_autoptr(GMatchInfo) match_info = NULL;
|
||||||
LoadCurrentModesResult *result;
|
g_autofree LoadCurrentModesResult *result = NULL;
|
||||||
const gchar *response;
|
const gchar *response;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
|
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
|
||||||
if (!response) {
|
if (!response) {
|
||||||
@@ -305,19 +304,15 @@ wwsm_read_ready (MMBaseModem *self,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result->allowed == MM_MODEM_MODE_NONE) {
|
if (result->allowed == MM_MODEM_MODE_NONE)
|
||||||
g_task_return_new_error (task,
|
g_task_return_new_error (task,
|
||||||
MM_CORE_ERROR,
|
MM_CORE_ERROR,
|
||||||
MM_CORE_ERROR_FAILED,
|
MM_CORE_ERROR_FAILED,
|
||||||
"Unknown wireless data service reply: '%s'",
|
"Unknown wireless data service reply: '%s'",
|
||||||
response);
|
response);
|
||||||
g_free (result);
|
else
|
||||||
} else
|
g_task_return_pointer (task, g_steal_pointer (&result), g_free);
|
||||||
g_task_return_pointer (task, result, g_free);
|
|
||||||
g_object_unref (task);
|
g_object_unref (task);
|
||||||
|
|
||||||
g_regex_unref (r);
|
|
||||||
g_match_info_free (match_info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -325,9 +320,9 @@ current_ms_class_ready (MMBaseModem *self,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GTask *task)
|
GTask *task)
|
||||||
{
|
{
|
||||||
LoadCurrentModesResult *result;
|
g_autofree LoadCurrentModesResult *result = NULL;
|
||||||
const gchar *response;
|
const gchar *response;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
response = mm_base_modem_at_command_finish (self, res, &error);
|
response = mm_base_modem_at_command_finish (self, res, &error);
|
||||||
if (!response) {
|
if (!response) {
|
||||||
@@ -376,15 +371,14 @@ current_ms_class_ready (MMBaseModem *self,
|
|||||||
result->preferred = MM_MODEM_MODE_NONE;
|
result->preferred = MM_MODEM_MODE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result->allowed == MM_MODEM_MODE_NONE) {
|
if (result->allowed == MM_MODEM_MODE_NONE)
|
||||||
g_task_return_new_error (task,
|
g_task_return_new_error (task,
|
||||||
MM_CORE_ERROR,
|
MM_CORE_ERROR,
|
||||||
MM_CORE_ERROR_FAILED,
|
MM_CORE_ERROR_FAILED,
|
||||||
"Unknown mobile station class: '%s'",
|
"Unknown mobile station class: '%s'",
|
||||||
response);
|
response);
|
||||||
g_free (result);
|
else
|
||||||
} else
|
g_task_return_pointer (task, g_steal_pointer (&result), g_free);
|
||||||
g_task_return_pointer (task, result, g_free);
|
|
||||||
g_object_unref (task);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -524,8 +518,8 @@ set_current_modes (MMIfaceModem *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx->cgclass_command) {
|
if (!ctx->cgclass_command) {
|
||||||
gchar *allowed_str;
|
g_autofree gchar *allowed_str = NULL;
|
||||||
gchar *preferred_str;
|
g_autofree gchar *preferred_str = NULL;
|
||||||
|
|
||||||
allowed_str = mm_modem_mode_build_string_from_mask (allowed);
|
allowed_str = mm_modem_mode_build_string_from_mask (allowed);
|
||||||
preferred_str = mm_modem_mode_build_string_from_mask (preferred);
|
preferred_str = mm_modem_mode_build_string_from_mask (preferred);
|
||||||
@@ -536,8 +530,6 @@ set_current_modes (MMIfaceModem *self,
|
|||||||
"supported by the modem.",
|
"supported by the modem.",
|
||||||
allowed_str, preferred_str);
|
allowed_str, preferred_str);
|
||||||
g_object_unref (task);
|
g_object_unref (task);
|
||||||
g_free (allowed_str);
|
|
||||||
g_free (preferred_str);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -768,11 +760,10 @@ set_bands_3g (GTask *task,
|
|||||||
GArray *bands_array)
|
GArray *bands_array)
|
||||||
{
|
{
|
||||||
MMBroadbandModemWavecom *self;
|
MMBroadbandModemWavecom *self;
|
||||||
GArray *bands_array_final;
|
|
||||||
guint wavecom_band = 0;
|
guint wavecom_band = 0;
|
||||||
guint i;
|
guint i;
|
||||||
gchar *bands_string;
|
g_autoptr(GArray) bands_array_final = NULL;
|
||||||
gchar *cmd;
|
g_autofree gchar *cmd = NULL;
|
||||||
|
|
||||||
self = g_task_get_source_object (task);
|
self = g_task_get_source_object (task);
|
||||||
|
|
||||||
@@ -799,18 +790,16 @@ set_bands_3g (GTask *task,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bands_string = mm_common_build_bands_string ((MMModemBand *)(gpointer)bands_array_final->data,
|
|
||||||
bands_array_final->len);
|
|
||||||
g_array_unref (bands_array_final);
|
|
||||||
|
|
||||||
if (wavecom_band == 0) {
|
if (wavecom_band == 0) {
|
||||||
|
g_autofree gchar *bands_string = NULL;
|
||||||
|
|
||||||
|
bands_string = mm_common_build_bands_string ((MMModemBand *)(gpointer)bands_array_final->data, bands_array_final->len);
|
||||||
g_task_return_new_error (task,
|
g_task_return_new_error (task,
|
||||||
MM_CORE_ERROR,
|
MM_CORE_ERROR,
|
||||||
MM_CORE_ERROR_UNSUPPORTED,
|
MM_CORE_ERROR_UNSUPPORTED,
|
||||||
"The given band combination is not supported: '%s'",
|
"The given band combination is not supported: '%s'",
|
||||||
bands_string);
|
bands_string);
|
||||||
g_object_unref (task);
|
g_object_unref (task);
|
||||||
g_free (bands_string);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -821,8 +810,6 @@ set_bands_3g (GTask *task,
|
|||||||
FALSE,
|
FALSE,
|
||||||
(GAsyncReadyCallback)wmbs_set_ready,
|
(GAsyncReadyCallback)wmbs_set_ready,
|
||||||
task);
|
task);
|
||||||
g_free (cmd);
|
|
||||||
g_free (bands_string);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -830,11 +817,10 @@ set_bands_2g (GTask *task,
|
|||||||
GArray *bands_array)
|
GArray *bands_array)
|
||||||
{
|
{
|
||||||
MMBroadbandModemWavecom *self;
|
MMBroadbandModemWavecom *self;
|
||||||
GArray *bands_array_final;
|
|
||||||
gchar wavecom_band = '\0';
|
gchar wavecom_band = '\0';
|
||||||
guint i;
|
guint i;
|
||||||
gchar *bands_string;
|
g_autofree gchar *cmd = NULL;
|
||||||
gchar *cmd;
|
g_autoptr(GArray) bands_array_final = NULL;
|
||||||
|
|
||||||
self = g_task_get_source_object (task);
|
self = g_task_get_source_object (task);
|
||||||
|
|
||||||
@@ -859,7 +845,7 @@ set_bands_2g (GTask *task,
|
|||||||
bands_array_final = g_array_ref (bands_array);
|
bands_array_final = g_array_ref (bands_array);
|
||||||
|
|
||||||
for (i = 0; wavecom_band == '\0' && i < G_N_ELEMENTS (bands_2g); i++) {
|
for (i = 0; wavecom_band == '\0' && i < G_N_ELEMENTS (bands_2g); i++) {
|
||||||
GArray *supported_combination;
|
g_autoptr(GArray) supported_combination = NULL;
|
||||||
|
|
||||||
supported_combination = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), bands_2g[i].n_mm_bands);
|
supported_combination = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), bands_2g[i].n_mm_bands);
|
||||||
g_array_append_vals (supported_combination, bands_2g[i].mm_bands, bands_2g[i].n_mm_bands);
|
g_array_append_vals (supported_combination, bands_2g[i].mm_bands, bands_2g[i].n_mm_bands);
|
||||||
@@ -867,22 +853,18 @@ set_bands_2g (GTask *task,
|
|||||||
/* Check if the given array is exactly one of the supported combinations */
|
/* Check if the given array is exactly one of the supported combinations */
|
||||||
if (mm_common_bands_garray_cmp (bands_array_final, supported_combination))
|
if (mm_common_bands_garray_cmp (bands_array_final, supported_combination))
|
||||||
wavecom_band = bands_2g[i].wavecom_band;
|
wavecom_band = bands_2g[i].wavecom_band;
|
||||||
|
|
||||||
g_array_unref (supported_combination);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bands_string = mm_common_build_bands_string ((MMModemBand *)(gpointer)bands_array_final->data,
|
|
||||||
bands_array_final->len);
|
|
||||||
g_array_unref (bands_array_final);
|
|
||||||
|
|
||||||
if (wavecom_band == '\0') {
|
if (wavecom_band == '\0') {
|
||||||
|
g_autofree gchar *bands_string = NULL;
|
||||||
|
|
||||||
|
bands_string = mm_common_build_bands_string ((MMModemBand *)(gpointer)bands_array_final->data, bands_array_final->len);
|
||||||
g_task_return_new_error (task,
|
g_task_return_new_error (task,
|
||||||
MM_CORE_ERROR,
|
MM_CORE_ERROR,
|
||||||
MM_CORE_ERROR_UNSUPPORTED,
|
MM_CORE_ERROR_UNSUPPORTED,
|
||||||
"The given band combination is not supported: '%s'",
|
"The given band combination is not supported: '%s'",
|
||||||
bands_string);
|
bands_string);
|
||||||
g_object_unref (task);
|
g_object_unref (task);
|
||||||
g_free (bands_string);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -893,9 +875,6 @@ set_bands_2g (GTask *task,
|
|||||||
FALSE,
|
FALSE,
|
||||||
(GAsyncReadyCallback)wmbs_set_ready,
|
(GAsyncReadyCallback)wmbs_set_ready,
|
||||||
task);
|
task);
|
||||||
|
|
||||||
g_free (cmd);
|
|
||||||
g_free (bands_string);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -1041,9 +1020,8 @@ static gboolean
|
|||||||
parse_network_registration_mode (const gchar *reply,
|
parse_network_registration_mode (const gchar *reply,
|
||||||
guint *mode)
|
guint *mode)
|
||||||
{
|
{
|
||||||
GRegex *r;
|
g_autoptr(GRegex) r = NULL;
|
||||||
GMatchInfo *match_info;
|
g_autoptr(GMatchInfo) match_info = NULL;
|
||||||
gboolean parsed = FALSE;
|
|
||||||
|
|
||||||
g_assert (mode != NULL);
|
g_assert (mode != NULL);
|
||||||
|
|
||||||
@@ -1054,14 +1032,8 @@ parse_network_registration_mode (const gchar *reply,
|
|||||||
g_assert (r != NULL);
|
g_assert (r != NULL);
|
||||||
|
|
||||||
g_regex_match (r, reply, 0, &match_info);
|
g_regex_match (r, reply, 0, &match_info);
|
||||||
if (g_match_info_matches (match_info) &&
|
|
||||||
mm_get_uint_from_match_info (match_info, 1, mode))
|
|
||||||
parsed = TRUE;
|
|
||||||
|
|
||||||
g_match_info_free (match_info);
|
return (g_match_info_matches (match_info) && mm_get_uint_from_match_info (match_info, 1, mode));
|
||||||
g_regex_unref (r);
|
|
||||||
|
|
||||||
return parsed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -1074,14 +1046,18 @@ cops_ready (MMBaseModem *self,
|
|||||||
guint mode;
|
guint mode;
|
||||||
|
|
||||||
response = mm_base_modem_at_command_finish (self, res, &error);
|
response = mm_base_modem_at_command_finish (self, res, &error);
|
||||||
if (!response)
|
if (!response) {
|
||||||
goto out;
|
g_task_return_error (task, error);
|
||||||
|
g_object_unref (task);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!parse_network_registration_mode (response, &mode)) {
|
if (!parse_network_registration_mode (response, &mode)) {
|
||||||
error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
||||||
"Couldn't parse current network registration mode: '%s'",
|
"Couldn't parse current network registration mode: '%s'",
|
||||||
response);
|
response);
|
||||||
goto out;
|
g_object_unref (task);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the modem is not configured for automatic registration, run parent */
|
/* If the modem is not configured for automatic registration, run parent */
|
||||||
@@ -1091,12 +1067,7 @@ cops_ready (MMBaseModem *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
mm_obj_dbg (self, "device is already in automatic registration mode, not requesting it again");
|
mm_obj_dbg (self, "device is already in automatic registration mode, not requesting it again");
|
||||||
|
g_task_return_boolean (task, TRUE);
|
||||||
out:
|
|
||||||
if (error)
|
|
||||||
g_task_return_error (task, error);
|
|
||||||
else
|
|
||||||
g_task_return_boolean (task, TRUE);
|
|
||||||
g_object_unref (task);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user