modem-helpers: port device identifier to use object logging and autoptr

This commit is contained in:
Aleksander Morgado
2020-04-03 15:34:42 +02:00
parent b682d7ec67
commit fd1464cff0
4 changed files with 18 additions and 20 deletions

View File

@@ -11760,6 +11760,7 @@ mm_broadband_modem_create_device_identifier (MMBroadbandModem *self,
return (mm_create_device_identifier ( return (mm_create_device_identifier (
mm_base_modem_get_vendor_id (MM_BASE_MODEM (self)), mm_base_modem_get_vendor_id (MM_BASE_MODEM (self)),
mm_base_modem_get_product_id (MM_BASE_MODEM (self)), mm_base_modem_get_product_id (MM_BASE_MODEM (self)),
self,
ati, ati,
ati1, ati1,
mm_gdbus_modem_get_equipment_identifier ( mm_gdbus_modem_get_equipment_identifier (

View File

@@ -31,7 +31,7 @@
#include "mm-sms-part.h" #include "mm-sms-part.h"
#include "mm-modem-helpers.h" #include "mm-modem-helpers.h"
#include "mm-helper-enums-types.h" #include "mm-helper-enums-types.h"
#include "mm-log.h" #include "mm-log-object.h"
/*****************************************************************************/ /*****************************************************************************/
@@ -256,6 +256,7 @@ mm_find_bit_set (gulong number)
gchar * gchar *
mm_create_device_identifier (guint vid, mm_create_device_identifier (guint vid,
guint pid, guint pid,
gpointer log_object,
const gchar *ati, const gchar *ati,
const gchar *ati1, const gchar *ati1,
const gchar *gsn, const gchar *gsn,
@@ -263,9 +264,11 @@ mm_create_device_identifier (guint vid,
const gchar *model, const gchar *model,
const gchar *manf) const gchar *manf)
{ {
GString *devid, *msg = NULL; g_autoptr(GString) devid = NULL;
GChecksum *sum; g_autoptr(GString) msg = NULL;
gchar *p, *ret = NULL; g_autoptr(GChecksum) sum = NULL;
const gchar *ret;
gchar *p = NULL;
gchar str_vid[10], str_pid[10]; gchar str_vid[10], str_pid[10];
/* Build up the device identifier */ /* Build up the device identifier */
@@ -286,14 +289,11 @@ mm_create_device_identifier (guint vid,
if (manf) if (manf)
g_string_append (devid, manf); g_string_append (devid, manf);
if (!strlen (devid->str)) { if (!strlen (devid->str))
g_string_free (devid, TRUE);
return NULL; return NULL;
}
p = devid->str; p = devid->str;
msg = g_string_sized_new (strlen (devid->str) + 17); msg = g_string_sized_new (strlen (devid->str) + 17);
sum = g_checksum_new (G_CHECKSUM_SHA1); sum = g_checksum_new (G_CHECKSUM_SHA1);
if (vid) { if (vid) {
@@ -315,15 +315,10 @@ mm_create_device_identifier (guint vid,
} }
p++; p++;
} }
ret = g_strdup (g_checksum_get_string (sum));
g_checksum_free (sum);
mm_dbg ("Device ID source '%s'", msg->str); ret = g_checksum_get_string (sum);
mm_dbg ("Device ID '%s'", ret); mm_obj_dbg (log_object, "device identifier built: %s -> %s", msg->str, ret);
g_string_free (msg, TRUE); return g_strdup (ret);
g_string_free (devid, TRUE);
return ret;
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@@ -61,6 +61,7 @@ guint mm_find_bit_set (gulong number);
gchar *mm_create_device_identifier (guint vid, gchar *mm_create_device_identifier (guint vid,
guint pid, guint pid,
gpointer log_object,
const gchar *ati, const gchar *ati,
const gchar *ati1, const gchar *ati1,
const gchar *gsn, const gchar *gsn,

View File

@@ -1911,6 +1911,7 @@ test_devid_item (void *f, gpointer d)
g_debug ("%s... ", item->desc); g_debug ("%s... ", item->desc);
devid = mm_create_device_identifier (item->vid, devid = mm_create_device_identifier (item->vid,
item->pid, item->pid,
NULL,
item->ati, item->ati,
item->ati1, item->ati1,
item->gsn, item->gsn,