utils: new utils_check_for_single_value() method

It was being used in several places with different static implementations
This commit is contained in:
Aleksander Morgado
2011-04-28 12:38:03 +02:00
parent a0c902bdb5
commit db7c11768a
4 changed files with 24 additions and 40 deletions

View File

@@ -3792,24 +3792,6 @@ set_charset_done (MMAtSerialPort *port,
mm_at_serial_port_queue_command (port, "+CSCS?", 3, set_get_charset_done, info); mm_at_serial_port_queue_command (port, "+CSCS?", 3, set_get_charset_done, info);
} }
static gboolean
check_for_single_value (guint32 value)
{
gboolean found = FALSE;
guint32 i;
for (i = 1; i <= 32; i++) {
if (value & 0x1) {
if (found)
return FALSE; /* More than one bit set */
found = TRUE;
}
value >>= 1;
}
return TRUE;
}
static void static void
set_charset (MMModem *modem, set_charset (MMModem *modem,
MMModemCharset charset, MMModemCharset charset,
@@ -3824,7 +3806,7 @@ set_charset (MMModem *modem,
info = mm_callback_info_new (modem, callback, user_data); info = mm_callback_info_new (modem, callback, user_data);
if (!(priv->charsets & charset) || !check_for_single_value (charset)) { if (!(priv->charsets & charset) || !utils_check_for_single_value (charset)) {
info->error = g_error_new (MM_MODEM_ERROR, info->error = g_error_new (MM_MODEM_ERROR,
MM_MODEM_ERROR_UNSUPPORTED_CHARSET, MM_MODEM_ERROR_UNSUPPORTED_CHARSET,
"Character set 0x%X not supported", "Character set 0x%X not supported",

View File

@@ -21,6 +21,7 @@
#include "mm-errors.h" #include "mm-errors.h"
#include "mm-callback-info.h" #include "mm-callback-info.h"
#include "mm-marshal.h" #include "mm-marshal.h"
#include "mm-utils.h"
static void impl_gsm_modem_register (MMModemGsmNetwork *modem, static void impl_gsm_modem_register (MMModemGsmNetwork *modem,
const char *network_id, const char *network_id,
@@ -473,24 +474,6 @@ impl_gsm_modem_get_signal_quality (MMModemGsmNetwork *modem,
mm_modem_gsm_network_get_signal_quality (modem, uint_call_done, context); mm_modem_gsm_network_get_signal_quality (modem, uint_call_done, context);
} }
static gboolean
check_for_single_value (guint32 value)
{
gboolean found = FALSE;
guint32 i;
for (i = 1; i <= 32; i++) {
if (value & 0x1) {
if (found)
return FALSE; /* More than one bit set */
found = TRUE;
}
value >>= 1;
}
return TRUE;
}
static void static void
impl_gsm_modem_set_band (MMModemGsmNetwork *modem, impl_gsm_modem_set_band (MMModemGsmNetwork *modem,
MMModemGsmBand band, MMModemGsmBand band,
@@ -511,7 +494,7 @@ impl_gsm_modem_set_network_mode (MMModemGsmNetwork *modem,
MMModemDeprecatedMode old_mode, MMModemDeprecatedMode old_mode,
DBusGMethodInvocation *context) DBusGMethodInvocation *context)
{ {
if (!check_for_single_value (old_mode)) { if (!utils_check_for_single_value (old_mode)) {
GError *error; GError *error;
error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED, error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,

View File

@@ -90,3 +90,20 @@ utils_bin2hexstr (const guint8 *bin, gsize len)
return g_string_free (ret, FALSE); return g_string_free (ret, FALSE);
} }
gboolean
utils_check_for_single_value (guint32 value)
{
gboolean found = FALSE;
guint32 i;
for (i = 1; i <= 32; i++) {
if (value & 0x1) {
if (found)
return FALSE; /* More than one bit set */
found = TRUE;
}
value >>= 1;
}
return TRUE;
}

View File

@@ -22,5 +22,7 @@ char *utils_hexstr2bin (const char *hex, gsize *out_len);
char *utils_bin2hexstr (const guint8 *bin, gsize len); char *utils_bin2hexstr (const guint8 *bin, gsize len);
gboolean utils_check_for_single_value (guint32 value);
#endif /* MM_UTILS_H */ #endif /* MM_UTILS_H */