mbm: port to use object logging

This commit is contained in:
Aleksander Morgado
2020-04-07 15:18:55 +02:00
parent 64ac1c19ff
commit 1edd4bb101
7 changed files with 50 additions and 55 deletions

View File

@@ -38,7 +38,7 @@
#include "mm-base-modem-at.h" #include "mm-base-modem-at.h"
#include "mm-broadband-bearer-mbm.h" #include "mm-broadband-bearer-mbm.h"
#include "mm-log.h" #include "mm-log-object.h"
#include "mm-modem-helpers.h" #include "mm-modem-helpers.h"
#include "mm-modem-helpers-mbm.h" #include "mm-modem-helpers-mbm.h"
#include "mm-daemon-enums-types.h" #include "mm-daemon-enums-types.h"
@@ -180,11 +180,10 @@ connect_poll_ready (MMBaseModem *modem,
const gchar *response; const gchar *response;
guint state; guint state;
task = self->priv->connect_pending; task = g_steal_pointer (&self->priv->connect_pending);
self->priv->connect_pending = NULL;
if (!task) { if (!task) {
mm_dbg ("Connection context was finished already by an unsolicited message"); mm_obj_dbg (self, "connection context was finished already by an unsolicited message");
/* Run _finish() to finalize the async call, even if we don't care /* Run _finish() to finalize the async call, even if we don't care
* the result */ * the result */
mm_base_modem_at_command_full_finish (modem, res, NULL); mm_base_modem_at_command_full_finish (modem, res, NULL);
@@ -219,8 +218,7 @@ connect_poll_cb (MMBroadbandBearerMbm *self)
GTask *task; GTask *task;
Dial3gppContext *ctx; Dial3gppContext *ctx;
task = self->priv->connect_pending; task = g_steal_pointer (&self->priv->connect_pending);
self->priv->connect_pending = NULL;
g_assert (task); g_assert (task);
ctx = g_task_get_task_data (task); ctx = g_task_get_task_data (task);
@@ -269,11 +267,10 @@ activate_ready (MMBaseModem *modem,
/* Try to recover the connection context. If none found, it means the /* Try to recover the connection context. If none found, it means the
* context was already completed and we have nothing else to do. */ * context was already completed and we have nothing else to do. */
task = self->priv->connect_pending; task = g_steal_pointer (&self->priv->connect_pending);
self->priv->connect_pending = NULL;
if (!task) { if (!task) {
mm_dbg ("Connection context was finished already by an unsolicited message"); mm_obj_dbg (self, "connection context was finished already by an unsolicited message");
/* Run _finish() to finalize the async call, even if we don't care /* Run _finish() to finalize the async call, even if we don't care
* the result */ * the result */
mm_base_modem_at_command_full_finish (modem, res, NULL); mm_base_modem_at_command_full_finish (modem, res, NULL);
@@ -391,7 +388,7 @@ authenticate (GTask *task)
return; return;
} }
mm_dbg ("Authentication not needed"); mm_obj_dbg (self, "authentication not needed");
activate (task); activate (task);
} }
@@ -602,11 +599,8 @@ process_pending_disconnect_attempt (MMBroadbandBearerMbm *self,
DisconnectContext *ctx; DisconnectContext *ctx;
/* Recover disconnection task */ /* Recover disconnection task */
task = self->priv->disconnect_pending; task = g_steal_pointer (&self->priv->disconnect_pending);
self->priv->disconnect_pending = NULL; ctx = g_task_get_task_data (task);
g_assert (task != NULL);
ctx = g_task_get_task_data (task);
if (ctx->poll_id) { if (ctx->poll_id) {
g_source_remove (ctx->poll_id); g_source_remove (ctx->poll_id);
@@ -615,7 +609,7 @@ process_pending_disconnect_attempt (MMBroadbandBearerMbm *self,
/* Received 'DISCONNECTED' during a disconnection attempt? */ /* Received 'DISCONNECTED' during a disconnection attempt? */
if (status == MM_BEARER_CONNECTION_STATUS_DISCONNECTED) { if (status == MM_BEARER_CONNECTION_STATUS_DISCONNECTED) {
mm_dbg ("Connection disconnect indicated by an unsolicited message"); mm_obj_dbg (self, "connection disconnect indicated by an unsolicited message");
g_task_return_boolean (task, TRUE); g_task_return_boolean (task, TRUE);
} else { } else {
/* Otherwise, report error */ /* Otherwise, report error */
@@ -638,11 +632,10 @@ disconnect_poll_ready (MMBaseModem *modem,
const gchar *response; const gchar *response;
guint state; guint state;
task = self->priv->disconnect_pending; task = g_steal_pointer (&self->priv->disconnect_pending);
self->priv->disconnect_pending = NULL;
if (!task) { if (!task) {
mm_dbg ("Disconnection context was finished already by an unsolicited message"); mm_obj_dbg (self, "disconnection context was finished already by an unsolicited message");
/* Run _finish() to finalize the async call, even if we don't care /* Run _finish() to finalize the async call, even if we don't care
* the result */ * the result */
mm_base_modem_at_command_full_finish (modem, res, NULL); mm_base_modem_at_command_full_finish (modem, res, NULL);
@@ -722,8 +715,7 @@ disconnect_enap_ready (MMBaseModem *modem,
GTask *task; GTask *task;
GError *error = NULL; GError *error = NULL;
task = self->priv->disconnect_pending; task = g_steal_pointer (&self->priv->disconnect_pending);
self->priv->disconnect_pending = NULL;
/* Try to recover the disconnection context. If none found, it means the /* Try to recover the disconnection context. If none found, it means the
* context was already completed and we have nothing else to do. */ * context was already completed and we have nothing else to do. */
@@ -737,7 +729,7 @@ disconnect_enap_ready (MMBaseModem *modem,
/* Ignore errors for now */ /* Ignore errors for now */
mm_base_modem_at_command_full_finish (modem, res, &error); mm_base_modem_at_command_full_finish (modem, res, &error);
if (error) { if (error) {
mm_dbg ("Disconnection failed (not fatal): %s", error->message); mm_obj_dbg (self, "disconnection failed (not fatal): %s", error->message);
g_error_free (error); g_error_free (error);
} }
@@ -815,8 +807,8 @@ report_connection_status (MMBaseBearer *_self,
return; return;
} }
mm_dbg ("Received spontaneous E2NAP (%s)", mm_obj_dbg (self, "received spontaneous E2NAP (%s)",
mm_bearer_connection_status_get_string (status)); mm_bearer_connection_status_get_string (status));
/* Received a random 'DISCONNECTED'...*/ /* Received a random 'DISCONNECTED'...*/
if (status == MM_BEARER_CONNECTION_STATUS_DISCONNECTED || if (status == MM_BEARER_CONNECTION_STATUS_DISCONNECTED ||

View File

@@ -31,7 +31,7 @@
#include <ctype.h> #include <ctype.h>
#include "ModemManager.h" #include "ModemManager.h"
#include "mm-log.h" #include "mm-log-object.h"
#include "mm-bearer-list.h" #include "mm-bearer-list.h"
#include "mm-errors-types.h" #include "mm-errors-types.h"
#include "mm-modem-helpers.h" #include "mm-modem-helpers.h"
@@ -115,7 +115,7 @@ modem_create_bearer (MMIfaceModem *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
mm_dbg ("Creating MBM bearer..."); mm_obj_dbg (self, "creating MBM bearer...");
mm_broadband_bearer_mbm_new (MM_BROADBAND_MODEM_MBM (self), mm_broadband_bearer_mbm_new (MM_BROADBAND_MODEM_MBM (self),
properties, properties,
NULL, /* cancellable */ NULL, /* cancellable */
@@ -196,7 +196,7 @@ load_supported_modes_finish (MMIfaceModem *_self,
if (!response) if (!response)
return FALSE; return FALSE;
if (!mm_mbm_parse_cfun_test (response, &mask, error)) if (!mm_mbm_parse_cfun_test (response, self, &mask, error))
return FALSE; return FALSE;
/* Build list of combinations */ /* Build list of combinations */
@@ -448,7 +448,7 @@ emrdy_ready (MMBaseModem *self,
if (g_error_matches (error, if (g_error_matches (error,
MM_SERIAL_ERROR, MM_SERIAL_ERROR,
MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) MM_SERIAL_ERROR_RESPONSE_TIMEOUT))
mm_warn ("timed out waiting for EMRDY response."); mm_obj_warn (self, "timed out waiting for EMRDY response");
else else
MM_BROADBAND_MODEM_MBM (self)->priv->have_emrdy = TRUE; MM_BROADBAND_MODEM_MBM (self)->priv->have_emrdy = TRUE;
g_error_free (error); g_error_free (error);
@@ -635,7 +635,7 @@ factory_reset (MMIfaceModem *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
mm_dbg ("Ignoring factory reset code: '%s'", code); mm_obj_dbg (self, "ignoring user-provided factory reset code: '%s'", code);
mm_base_modem_at_sequence (MM_BASE_MODEM (self), mm_base_modem_at_sequence (MM_BASE_MODEM (self),
factory_reset_sequence, factory_reset_sequence,
@@ -695,7 +695,6 @@ load_unlock_retries (MMIfaceModem *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
mm_dbg ("loading unlock retries (mbm)...");
mm_base_modem_at_command (MM_BASE_MODEM (self), mm_base_modem_at_command (MM_BASE_MODEM (self),
"*EPIN?", "*EPIN?",
10, 10,
@@ -734,19 +733,19 @@ e2nap_received (MMPortSerialAt *port,
switch (state) { switch (state) {
case MBM_E2NAP_DISCONNECTED: case MBM_E2NAP_DISCONNECTED:
mm_dbg ("disconnected"); mm_obj_dbg (self, "disconnected");
ctx.status = MM_BEARER_CONNECTION_STATUS_DISCONNECTED; ctx.status = MM_BEARER_CONNECTION_STATUS_DISCONNECTED;
break; break;
case MBM_E2NAP_CONNECTED: case MBM_E2NAP_CONNECTED:
mm_dbg ("connected"); mm_obj_dbg (self, "connected");
ctx.status = MM_BEARER_CONNECTION_STATUS_CONNECTED; ctx.status = MM_BEARER_CONNECTION_STATUS_CONNECTED;
break; break;
case MBM_E2NAP_CONNECTING: case MBM_E2NAP_CONNECTING:
mm_dbg ("connecting"); mm_obj_dbg (self, "connecting");
break; break;
default: default:
/* Should not happen */ /* Should not happen */
mm_dbg ("unhandled E2NAP state %d", state); mm_obj_dbg (self, "unhandled E2NAP state %d", state);
} }
/* If unknown status, don't try to report anything */ /* If unknown status, don't try to report anything */

View File

@@ -169,21 +169,22 @@ done:
#define CFUN_TAG "+CFUN:" #define CFUN_TAG "+CFUN:"
static void static void
add_supported_mode (guint32 *mask, add_supported_mode (guint mode,
guint mode) gpointer log_object,
guint32 *mask)
{ {
g_assert (mask); g_assert (mask);
if (mode >= 32) if (mode >= 32)
mm_warn ("Ignored unexpected mode in +CFUN match: %d", mode); mm_obj_warn (log_object, "ignored unexpected mode in +CFUN match: %d", mode);
else else
*mask |= (1 << mode); *mask |= (1 << mode);
} }
gboolean gboolean
mm_mbm_parse_cfun_test (const gchar *response, mm_mbm_parse_cfun_test (const gchar *response,
guint32 *supported_mask, gpointer log_object,
GError **error) guint32 *supported_mask,
GError **error)
{ {
gchar **groups; gchar **groups;
guint32 mask = 0; guint32 mask = 0;
@@ -236,20 +237,20 @@ mm_mbm_parse_cfun_test (const gchar *response,
last_str = separator + 1; last_str = separator + 1;
if (!mm_get_uint_from_str (first_str, &first)) if (!mm_get_uint_from_str (first_str, &first))
mm_warn ("Couldn't match range start: '%s'", first_str); mm_obj_warn (log_object, "couldn't match range start: '%s'", first_str);
else if (!mm_get_uint_from_str (last_str, &last)) else if (!mm_get_uint_from_str (last_str, &last))
mm_warn ("Couldn't match range stop: '%s'", last_str); mm_obj_warn (log_object, "couldn't match range stop: '%s'", last_str);
else if (first >= last) else if (first >= last)
mm_warn ("Couldn't match range: wrong first '%s' and last '%s' items", first_str, last_str); mm_obj_warn (log_object, "couldn't match range: wrong first '%s' and last '%s' items", first_str, last_str);
else { else {
for (mode = first; mode <= last; mode++) for (mode = first; mode <= last; mode++)
add_supported_mode (&mask, mode); add_supported_mode (mode, log_object, &mask);
} }
} else { } else {
if (!mm_get_uint_from_str (supported_modes[i], &mode)) if (!mm_get_uint_from_str (supported_modes[i], &mode))
mm_warn ("Couldn't match mode: '%s'", supported_modes[i]); mm_obj_warn (log_object, "couldn't match mode: '%s'", supported_modes[i]);
else else
add_supported_mode (&mask, mode); add_supported_mode (mode, log_object, &mask);
} }
} }

View File

@@ -34,9 +34,10 @@ typedef enum {
/* AT+CFUN=? test parser /* AT+CFUN=? test parser
* Returns a bitmask, bit index set for the supported modes reported */ * Returns a bitmask, bit index set for the supported modes reported */
gboolean mm_mbm_parse_cfun_test (const gchar *response, gboolean mm_mbm_parse_cfun_test (const gchar *response,
guint32 *supported_mask, gpointer log_object,
GError **error); guint32 *supported_mask,
GError **error);
/* AT+CFUN? response parsers */ /* AT+CFUN? response parsers */
gboolean mm_mbm_parse_cfun_query_power_state (const gchar *response, gboolean mm_mbm_parse_cfun_query_power_state (const gchar *response,

View File

@@ -23,7 +23,7 @@
#define _LIBMM_INSIDE_MM #define _LIBMM_INSIDE_MM
#include <libmm-glib.h> #include <libmm-glib.h>
#include "mm-log.h" #include "mm-log-object.h"
#include "mm-plugin-mbm.h" #include "mm-plugin-mbm.h"
#include "mm-broadband-modem-mbm.h" #include "mm-broadband-modem-mbm.h"
@@ -49,7 +49,7 @@ create_modem (MMPlugin *self,
{ {
#if defined WITH_MBIM #if defined WITH_MBIM
if (mm_port_probe_list_has_mbim_port (probes)) { if (mm_port_probe_list_has_mbim_port (probes)) {
mm_dbg ("MBIM-powered Ericsson modem found..."); mm_obj_dbg (self, "MBIM-powered Ericsson modem found...");
return MM_BASE_MODEM (mm_broadband_modem_mbim_new (uid, return MM_BASE_MODEM (mm_broadband_modem_mbim_new (uid,
drivers, drivers,
mm_plugin_get_name (self), mm_plugin_get_name (self),

View File

@@ -24,7 +24,7 @@
#define _LIBMM_INSIDE_MM #define _LIBMM_INSIDE_MM
#include <libmm-glib.h> #include <libmm-glib.h>
#include "mm-log.h" #include "mm-log-object.h"
#include "mm-base-modem-at.h" #include "mm-base-modem-at.h"
#include "mm-sim-mbm.h" #include "mm-sim-mbm.h"
@@ -93,9 +93,11 @@ cpin_query_cb (GTask *task)
static void static void
wait_for_unlocked_status (GTask *task) wait_for_unlocked_status (GTask *task)
{ {
MMSimMbm *self;
SendPinPukContext *ctx; SendPinPukContext *ctx;
ctx = g_task_get_task_data (task); self = g_task_get_source_object (task);
ctx = g_task_get_task_data (task);
/* Oops... :/ */ /* Oops... :/ */
if (ctx->retries == 0) { if (ctx->retries == 0) {
@@ -109,7 +111,7 @@ wait_for_unlocked_status (GTask *task)
/* Check status */ /* Check status */
ctx->retries--; ctx->retries--;
mm_dbg ("Scheduling lock state check..."); mm_obj_dbg (self, "scheduling lock state check...");
g_timeout_add_seconds (1, (GSourceFunc)cpin_query_cb, task); g_timeout_add_seconds (1, (GSourceFunc)cpin_query_cb, task);
} }

View File

@@ -179,7 +179,7 @@ test_cfun_test (void)
gboolean success; gboolean success;
GError *error = NULL; GError *error = NULL;
success = mm_mbm_parse_cfun_test (cfun_tests[i].str, &mask, &error); success = mm_mbm_parse_cfun_test (cfun_tests[i].str, NULL, &mask, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (success); g_assert (success);
g_assert_cmpuint (mask, ==, cfun_tests[i].expected_mask); g_assert_cmpuint (mask, ==, cfun_tests[i].expected_mask);