utils: new utils_check_for_single_value() method
It was being used in several places with different static implementations
This commit is contained in:
@@ -3792,24 +3792,6 @@ set_charset_done (MMAtSerialPort *port,
|
||||
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
|
||||
set_charset (MMModem *modem,
|
||||
MMModemCharset charset,
|
||||
@@ -3824,7 +3806,7 @@ set_charset (MMModem *modem,
|
||||
|
||||
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,
|
||||
MM_MODEM_ERROR_UNSUPPORTED_CHARSET,
|
||||
"Character set 0x%X not supported",
|
||||
|
@@ -21,6 +21,7 @@
|
||||
#include "mm-errors.h"
|
||||
#include "mm-callback-info.h"
|
||||
#include "mm-marshal.h"
|
||||
#include "mm-utils.h"
|
||||
|
||||
static void impl_gsm_modem_register (MMModemGsmNetwork *modem,
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
||||
impl_gsm_modem_set_band (MMModemGsmNetwork *modem,
|
||||
MMModemGsmBand band,
|
||||
@@ -511,7 +494,7 @@ impl_gsm_modem_set_network_mode (MMModemGsmNetwork *modem,
|
||||
MMModemDeprecatedMode old_mode,
|
||||
DBusGMethodInvocation *context)
|
||||
{
|
||||
if (!check_for_single_value (old_mode)) {
|
||||
if (!utils_check_for_single_value (old_mode)) {
|
||||
GError *error;
|
||||
|
||||
error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
|
||||
|
@@ -90,3 +90,20 @@ utils_bin2hexstr (const guint8 *bin, gsize len)
|
||||
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;
|
||||
}
|
||||
|
@@ -22,5 +22,7 @@ char *utils_hexstr2bin (const char *hex, gsize *out_len);
|
||||
|
||||
char *utils_bin2hexstr (const guint8 *bin, gsize len);
|
||||
|
||||
gboolean utils_check_for_single_value (guint32 value);
|
||||
|
||||
#endif /* MM_UTILS_H */
|
||||
|
||||
|
Reference in New Issue
Block a user