telit: minor coding style fixes

This commit is contained in:
Aleksander Morgado
2016-01-25 13:58:57 +01:00
parent 70b8ec1a88
commit 3911ea5a0f
3 changed files with 30 additions and 27 deletions

View File

@@ -104,7 +104,7 @@ modem_load_supported_bands (MMIfaceModem *self,
{ {
LoadSupportedBandsContext *ctx; LoadSupportedBandsContext *ctx;
ctx = g_slice_new0(LoadSupportedBandsContext); ctx = g_slice_new0 (LoadSupportedBandsContext);
ctx->self = g_object_ref (self); ctx->self = g_object_ref (self);
ctx->mm_modem_is_2g = mm_iface_modem_is_2g (ctx->self); ctx->mm_modem_is_2g = mm_iface_modem_is_2g (ctx->self);

View File

@@ -26,9 +26,6 @@
#include "mm-modem-helpers.h" #include "mm-modem-helpers.h"
#include "mm-modem-helpers-telit.h" #include "mm-modem-helpers-telit.h"
#define EMPTY_STRING ""
/*****************************************************************************/ /*****************************************************************************/
/* +CSIM response parser */ /* +CSIM response parser */
@@ -168,7 +165,7 @@ mm_telit_parse_supported_bands_response (const gchar *response,
end: end:
if (!ret && bands != NULL) if (!ret && bands != NULL)
g_array_free(bands, TRUE); g_array_free (bands, TRUE);
if(match_info) if(match_info)
g_match_info_free (match_info); g_match_info_free (match_info);
@@ -198,14 +195,14 @@ mm_telit_get_2g_mm_bands (GMatchInfo *match_info,
match_str = g_match_info_fetch_named (match_info, "Bands2G"); match_str = g_match_info_fetch_named (match_info, "Bands2G");
if (match_str == NULL || g_strcmp0(match_str, EMPTY_STRING) == 0) { if (match_str == NULL || match_str[0] == '\0') {
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Could not find 2G band flags from response"); "Could not find 2G band flags from response");
ret = FALSE; ret = FALSE;
goto end; goto end;
} }
flags = g_array_new (FALSE, FALSE, sizeof(guint)); flags = g_array_new (FALSE, FALSE, sizeof (guint));
if (!mm_telit_get_band_flags_from_string (match_str, &flags, error)) { if (!mm_telit_get_band_flags_from_string (match_str, &flags, error)) {
ret = FALSE; ret = FALSE;
@@ -213,7 +210,9 @@ mm_telit_get_2g_mm_bands (GMatchInfo *match_info,
} }
for (i = 0; i < flags->len; i++) { for (i = 0; i < flags->len; i++) {
guint flag = g_array_index (flags, guint, i); guint flag;
flag = g_array_index (flags, guint, i);
if (!mm_telit_update_band_array (flag, map, bands, error)) { if (!mm_telit_update_band_array (flag, map, bands, error)) {
ret = FALSE; ret = FALSE;
goto end; goto end;
@@ -265,17 +264,16 @@ mm_telit_get_3g_mm_bands (GMatchInfo *match_info,
{ BND_FLAG_UNKNOWN, {}}, { BND_FLAG_UNKNOWN, {}},
}; };
match_str = g_match_info_fetch_named (match_info, "Bands3G"); match_str = g_match_info_fetch_named (match_info, "Bands3G");
if (match_str == NULL || g_strcmp0(match_str, EMPTY_STRING) == 0) { if (match_str == NULL || match_str[0] == '\0') {
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Could not find 3G band flags from response"); "Could not find 3G band flags from response");
ret = FALSE; ret = FALSE;
goto end; goto end;
} }
flags = g_array_new (FALSE, FALSE, sizeof(guint)); flags = g_array_new (FALSE, FALSE, sizeof (guint));
if (!mm_telit_get_band_flags_from_string (match_str, &flags, error)) { if (!mm_telit_get_band_flags_from_string (match_str, &flags, error)) {
ret = FALSE; ret = FALSE;
@@ -283,7 +281,9 @@ mm_telit_get_3g_mm_bands (GMatchInfo *match_info,
} }
for (i = 0; i < flags->len; i++) { for (i = 0; i < flags->len; i++) {
guint flag = g_array_index (flags, guint, i); guint flag;
flag = g_array_index (flags, guint, i);
if (!mm_telit_update_band_array (flag, map, bands, error)) { if (!mm_telit_update_band_array (flag, map, bands, error)) {
ret = FALSE; ret = FALSE;
goto end; goto end;
@@ -311,12 +311,11 @@ mm_telit_get_4g_mm_bands(GMatchInfo *match_info,
gchar *match_str = NULL; gchar *match_str = NULL;
guint i; guint i;
guint max_value; guint max_value;
gchar **tokens; gchar **tokens;
match_str = g_match_info_fetch_named (match_info, "Bands4G"); match_str = g_match_info_fetch_named (match_info, "Bands4G");
if (match_str == NULL || g_strcmp0(match_str, EMPTY_STRING) == 0) { if (match_str == NULL || match_str[0] == '\0') {
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Could not find 4G band flags from response"); "Could not find 4G band flags from response");
ret = FALSE; ret = FALSE;
@@ -332,12 +331,12 @@ mm_telit_get_4g_mm_bands(GMatchInfo *match_info,
goto end; goto end;
} }
sscanf(tokens[1], "%d", &max_value); sscanf (tokens[1], "%d", &max_value);
for(i = 0; max_value > 0; i++) { for (i = 0; max_value > 0; i++) {
if (max_value % 2 != 0) { if (max_value % 2 != 0) {
band = MM_MODEM_BAND_EUTRAN_I + i; band = MM_MODEM_BAND_EUTRAN_I + i;
g_array_append_val(*bands, band); g_array_append_val (*bands, band);
} }
max_value = max_value >> 1; max_value = max_value >> 1;
} }
@@ -351,6 +350,7 @@ end:
return ret; return ret;
} }
gboolean gboolean
mm_telit_bands_contains (GArray *mm_bands, const MMModemBand mm_band) mm_telit_bands_contains (GArray *mm_bands, const MMModemBand mm_band)
{ {
@@ -403,7 +403,7 @@ mm_telit_get_band_flags_from_string (const gchar *flag_str,
guint flag; guint flag;
guint i; guint i;
if (g_strcmp0(flag_str, "") == 0) { if (flag_str == NULL || flag_str[0] == '\0') {
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"String is empty, no band flags to parse"); "String is empty, no band flags to parse");
return FALSE; return FALSE;
@@ -443,6 +443,3 @@ mm_telit_get_band_flags_from_string (const gchar *flag_str,
return TRUE; return TRUE;
} }

View File

@@ -26,7 +26,7 @@
#include "mm-modem-helpers-telit.h" #include "mm-modem-helpers-telit.h"
typedef struct { typedef struct {
gchar* response; gchar *response;
gint result; gint result;
} CSIMResponseTest; } CSIMResponseTest;
@@ -137,8 +137,11 @@ test_parse_band_flag_str (void) {
g_assert_true (res); g_assert_true (res);
for (j = 0; j < band_flag_test[i].band_flags_len; j++) { for (j = 0; j < band_flag_test[i].band_flags_len; j++) {
guint ref = band_flag_test[i].band_flags[j]; guint ref;
guint cur = g_array_index (band_flags, guint, j); guint cur;
ref = band_flag_test[i].band_flags[j];
cur = g_array_index (band_flags, guint, j);
g_assert_true (ref == cur); g_assert_true (ref == cur);
} }
@@ -221,12 +224,15 @@ test_parse_supported_bands_response (void) {
for (j = 0; j < supported_band_mapping_tests[i].mm_bands_len; j++) { for (j = 0; j < supported_band_mapping_tests[i].mm_bands_len; j++) {
MMModemBand ref = supported_band_mapping_tests[i].mm_bands[j]; MMModemBand ref;
MMModemBand cur = g_array_index (bands, MMModemBand, j); MMModemBand cur;
ref = supported_band_mapping_tests[i].mm_bands[j];
cur = g_array_index (bands, MMModemBand, j);
g_assert_cmpint (cur, ==, ref); g_assert_cmpint (cur, ==, ref);
} }
g_assert_cmpint(bands->len, ==, supported_band_mapping_tests[i].mm_bands_len); g_assert_cmpint (bands->len, ==, supported_band_mapping_tests[i].mm_bands_len);
g_array_free (bands, FALSE); g_array_free (bands, FALSE);
bands = NULL; bands = NULL;