iface-modem: improve logging of user request to run AT command

This commit is contained in:
Aleksander Morgado
2022-09-12 11:49:27 +00:00
parent ac28a6a1c0
commit aed53fe30a

View File

@@ -985,11 +985,11 @@ handle_create_bearer (MmGdbusModem *skeleton,
/*****************************************************************************/ /*****************************************************************************/
typedef struct { typedef struct {
MmGdbusModem *skeleton; MmGdbusModem *skeleton;
GDBusMethodInvocation *invocation; GDBusMethodInvocation *invocation;
MMIfaceModem *self; MMIfaceModem *self;
gchar *cmd; gchar *cmd;
guint timeout; guint timeout;
} HandleCommandContext; } HandleCommandContext;
static void static void
@@ -999,31 +999,32 @@ handle_command_context_free (HandleCommandContext *ctx)
g_object_unref (ctx->invocation); g_object_unref (ctx->invocation);
g_object_unref (ctx->self); g_object_unref (ctx->self);
g_free (ctx->cmd); g_free (ctx->cmd);
g_free (ctx); g_slice_free (HandleCommandContext, ctx);
} }
static void static void
command_ready (MMIfaceModem *self, command_ready (MMIfaceModem *self,
GAsyncResult *res, GAsyncResult *res,
HandleCommandContext *ctx) HandleCommandContext *ctx)
{ {
GError *error = NULL; GError *error = NULL;
const gchar *result; const gchar *result;
result = MM_IFACE_MODEM_GET_INTERFACE (self)->command_finish (self, result = MM_IFACE_MODEM_GET_INTERFACE (self)->command_finish (self, res, &error);
res, if (error) {
&error); mm_obj_dbg (self, "failed running AT command '%s': %s", ctx->cmd, error->message);
if (error)
g_dbus_method_invocation_take_error (ctx->invocation, error); g_dbus_method_invocation_take_error (ctx->invocation, error);
else } else {
mm_obj_dbg (self, "AT command '%s' run: %s", ctx->cmd, result);
mm_gdbus_modem_complete_command (ctx->skeleton, ctx->invocation, result); mm_gdbus_modem_complete_command (ctx->skeleton, ctx->invocation, result);
}
handle_command_context_free (ctx); handle_command_context_free (ctx);
} }
static void static void
handle_command_auth_ready (MMBaseModem *self, handle_command_auth_ready (MMBaseModem *self,
GAsyncResult *res, GAsyncResult *res,
HandleCommandContext *ctx) HandleCommandContext *ctx)
{ {
GError *error = NULL; GError *error = NULL;
@@ -1037,28 +1038,22 @@ handle_command_auth_ready (MMBaseModem *self,
#if ! defined WITH_AT_COMMAND_VIA_DBUS #if ! defined WITH_AT_COMMAND_VIA_DBUS
/* If we are not in Debug mode, report an error */ /* If we are not in Debug mode, report an error */
if (!mm_context_get_debug ()) { if (!mm_context_get_debug ()) {
g_dbus_method_invocation_return_error (ctx->invocation, g_dbus_method_invocation_return_error (ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_UNAUTHORIZED,
MM_CORE_ERROR, "Operation only allowed in debug mode");
MM_CORE_ERROR_UNAUTHORIZED,
"Cannot send AT command to modem: "
"operation only allowed in debug mode");
handle_command_context_free (ctx); handle_command_context_free (ctx);
return; return;
} }
#endif #endif
/* If command is not implemented, report an error */ /* If command is not implemented, report an error */
if (!MM_IFACE_MODEM_GET_INTERFACE (self)->command || if (!MM_IFACE_MODEM_GET_INTERFACE (self)->command || !MM_IFACE_MODEM_GET_INTERFACE (self)->command_finish) {
!MM_IFACE_MODEM_GET_INTERFACE (self)->command_finish) { g_dbus_method_invocation_return_error (ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED,
g_dbus_method_invocation_return_error (ctx->invocation, "Operation not supported");
MM_CORE_ERROR,
MM_CORE_ERROR_UNSUPPORTED,
"Cannot send AT command to modem: "
"operation not supported");
handle_command_context_free (ctx); handle_command_context_free (ctx);
return; return;
} }
mm_obj_dbg (self, "processing user request to run AT command '%s'...", ctx->cmd);
MM_IFACE_MODEM_GET_INTERFACE (self)->command (ctx->self, MM_IFACE_MODEM_GET_INTERFACE (self)->command (ctx->self,
ctx->cmd, ctx->cmd,
ctx->timeout, ctx->timeout,
@@ -1067,15 +1062,15 @@ handle_command_auth_ready (MMBaseModem *self,
} }
static gboolean static gboolean
handle_command (MmGdbusModem *skeleton, handle_command (MmGdbusModem *skeleton,
GDBusMethodInvocation *invocation, GDBusMethodInvocation *invocation,
const gchar *cmd, const gchar *cmd,
guint timeout, guint timeout,
MMIfaceModem *self) MMIfaceModem *self)
{ {
HandleCommandContext *ctx; HandleCommandContext *ctx;
ctx = g_new (HandleCommandContext, 1); ctx = g_slice_new0 (HandleCommandContext);
ctx->skeleton = g_object_ref (skeleton); ctx->skeleton = g_object_ref (skeleton);
ctx->invocation = g_object_ref (invocation); ctx->invocation = g_object_ref (invocation);
ctx->self = g_object_ref (self); ctx->self = g_object_ref (self);