diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2020-03-28 16:14:22 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2020-04-08 16:35:08 +0200 |
commit | 850d302d24a7c0bdf58b1a0a38a2ef04a5bc862d (patch) | |
tree | 18fe44c2edc120d40795486075dff7fdfe2e9ed2 | |
parent | 3a2466a3638390260a6149f15f81f3129371d7fd (diff) |
ports: port to object logging
-rw-r--r-- | src/mm-port-mbim.c | 43 | ||||
-rw-r--r-- | src/mm-port-qmi.c | 53 | ||||
-rw-r--r-- | src/mm-port-serial-at.c | 13 | ||||
-rw-r--r-- | src/mm-port-serial-gps.c | 11 | ||||
-rw-r--r-- | src/mm-port-serial-qcdm.c | 11 | ||||
-rw-r--r-- | src/mm-port-serial.c | 118 | ||||
-rw-r--r-- | src/mm-port-serial.h | 8 | ||||
-rw-r--r-- | src/mm-port.c | 32 |
8 files changed, 144 insertions, 145 deletions
diff --git a/src/mm-port-mbim.c b/src/mm-port-mbim.c index 1778e783..8e848e4d 100644 --- a/src/mm-port-mbim.c +++ b/src/mm-port-mbim.c @@ -26,7 +26,7 @@ #include <mm-errors-types.h> #include "mm-port-mbim.h" -#include "mm-log.h" +#include "mm-log-object.h" G_DEFINE_TYPE (MMPortMbim, mm_port_mbim, MM_TYPE_PORT) @@ -176,18 +176,14 @@ qmi_device_open_ready (QmiDevice *dev, self = g_task_get_source_object (task); if (!qmi_device_open_finish (dev, res, &error)) { - mm_dbg ("[%s] error: couldn't open QmiDevice: %s", - mm_port_get_device (MM_PORT (self)), - error->message); + mm_obj_dbg (self, "error: couldn't open QmiDevice: %s", error->message); g_error_free (error); g_clear_object (&self->priv->qmi_device); /* Ignore error and complete */ - mm_info ("[%s] MBIM device is not QMI capable", - mm_port_get_device (MM_PORT (self))); + mm_obj_info (self, "MBIM device is not QMI capable"); self->priv->qmi_supported = FALSE; } else { - mm_info ("[%s] MBIM device is QMI capable", - mm_port_get_device (MM_PORT (self))); + mm_obj_info (self, "MBIM device is QMI capable"); } self->priv->in_progress = FALSE; @@ -207,13 +203,10 @@ qmi_device_new_ready (GObject *unused, self->priv->qmi_device = qmi_device_new_finish (res, &error); if (!self->priv->qmi_device) { - mm_dbg ("[%s] error: couldn't create QmiDevice: %s", - mm_port_get_device (MM_PORT (self)), - error->message); + mm_obj_dbg (self, "error: couldn't create QmiDevice: %s", error->message); g_error_free (error); /* Ignore error and complete */ - mm_info ("[%s] MBIM device is not QMI capable", - mm_port_get_device (MM_PORT (self))); + mm_obj_info (self, "MBIM device is not QMI capable"); self->priv->qmi_supported = FALSE; self->priv->in_progress = FALSE; g_task_return_boolean (task, TRUE); @@ -222,8 +215,7 @@ qmi_device_new_ready (GObject *unused, } /* Try to open using QMI over MBIM */ - mm_dbg ("[%s] trying to open QMI over MBIM device...", - mm_port_get_device (MM_PORT (self))); + mm_obj_dbg (self, "trying to open QMI over MBIM device..."); qmi_device_open (self->priv->qmi_device, (QMI_DEVICE_OPEN_FLAGS_PROXY | QMI_DEVICE_OPEN_FLAGS_MBIM | @@ -272,7 +264,7 @@ mbim_query_device_services_ready (MbimDevice *device, mbim_device_service_element_array_free (device_services); } else { /* Ignore error */ - mm_dbg ("Couldn't query device services, will attempt QMI open anyway: %s", error->message); + mm_obj_dbg (self, "Couldn't query device services, will attempt QMI open anyway: %s", error->message); g_error_free (error); } @@ -283,8 +275,7 @@ mbim_query_device_services_ready (MbimDevice *device, file = G_FILE (g_task_get_task_data (task)); if (!file || !self->priv->qmi_supported) { - mm_info ("[%s] MBIM device is not QMI capable", - mm_port_get_device (MM_PORT (self))); + mm_obj_info (self, "MBIM device is not QMI capable"); self->priv->in_progress = FALSE; g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -292,8 +283,7 @@ mbim_query_device_services_ready (MbimDevice *device, } /* Attempt to create and open the QMI device */ - mm_dbg ("[%s] checking if QMI over MBIM is supported", - mm_port_get_device (MM_PORT (self))); + mm_obj_dbg (self, "checking if QMI over MBIM is supported..."); qmi_device_new (file, g_task_get_cancellable (task), (GAsyncReadyCallback) qmi_device_new_ready, @@ -338,8 +328,7 @@ mbim_device_open_ready (MbimDevice *mbim_device, return; } - mm_dbg ("[%s] MBIM device is now open", - mm_port_get_device (MM_PORT (self))); + mm_obj_dbg (self, "MBIM device is now open"); #if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED if (self->priv->qmi_supported) { @@ -507,10 +496,13 @@ qmi_device_close_ready (QmiDevice *qmi_device, GAsyncResult *res, GTask *task) { - GError *error = NULL; + GError *error = NULL; + MMPortMbim *self; + + self = g_task_get_source_object (task); if (!qmi_device_close_finish (qmi_device, res, &error)) { - mm_warn ("Couldn't properly close QMI device: %s", error->message); + mm_obj_warn (self, "Couldn't properly close QMI device: %s", error->message); g_error_free (error); } @@ -561,7 +553,8 @@ mm_port_mbim_close (MMPortMbim *self, for (l = self->priv->qmi_clients; l; l = g_list_next (l)) { QmiClient *qmi_client = QMI_CLIENT (l->data); - mm_dbg ("Releasing client for service '%s'...", qmi_service_get_string (qmi_client_get_service (qmi_client))); + mm_obj_dbg (self, "Releasing client for service '%s'...", + qmi_service_get_string (qmi_client_get_service (qmi_client))); qmi_device_release_client (self->priv->qmi_device, qmi_client, QMI_DEVICE_RELEASE_CLIENT_FLAGS_RELEASE_CID, diff --git a/src/mm-port-qmi.c b/src/mm-port-qmi.c index 75d3ee48..98dd8c44 100644 --- a/src/mm-port-qmi.c +++ b/src/mm-port-qmi.c @@ -22,7 +22,7 @@ #include <mm-errors-types.h> #include "mm-port-qmi.h" -#include "mm-log.h" +#include "mm-log-object.h" G_DEFINE_TYPE (MMPortQmi, mm_port_qmi, MM_TYPE_PORT) @@ -254,10 +254,13 @@ qmi_device_close_on_error_ready (QmiDevice *qmi_device, GAsyncResult *res, GTask *task) { - GError *error = NULL; + MMPortQmi *self; + GError *error = NULL; + + self = g_task_get_source_object (task); if (!qmi_device_close_finish (qmi_device, res, &error)) { - mm_warn ("Couldn't close QMI device after failed open sequence: %s", error->message); + mm_obj_warn (self, "Couldn't close QMI device after failed open sequence: %s", error->message); g_error_free (error); } @@ -285,12 +288,14 @@ qmi_device_close_to_reopen_ready (QmiDevice *qmi_device, GAsyncResult *res, GTask *task) { + MMPortQmi *self; PortOpenContext *ctx; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); if (!qmi_device_close_finish (qmi_device, res, &ctx->error)) { - mm_warn ("Couldn't close QMI device to reopen it"); + mm_obj_warn (self, "Couldn't close QMI device to reopen it"); ctx->step = PORT_OPEN_STEP_LAST; } else ctx->step++; @@ -302,10 +307,12 @@ get_data_format_ready (QmiClientWda *client, GAsyncResult *res, GTask *task) { + MMPortQmi *self; PortOpenContext *ctx; QmiMessageWdaGetDataFormatOutput *output; g_autoptr(GError) error = NULL; + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); output = qmi_client_wda_get_data_format_finish (client, res, NULL); if (!output || @@ -316,7 +323,7 @@ get_data_format_ready (QmiClientWda *client, * When this happens, assume the device supports only raw-ip and be done * with it. */ if (error && g_error_matches (error, QMI_PROTOCOL_ERROR, QMI_PROTOCOL_ERROR_MISSING_ARGUMENT)) { - mm_dbg ("Querying data format failed: '%s', assuming raw-ip is only supported", error->message); + mm_obj_dbg (self, "Querying data format failed: '%s', assuming raw-ip is only supported", error->message); ctx->llp = QMI_WDA_LINK_LAYER_PROTOCOL_RAW_IP; ctx->step++; } else { @@ -406,12 +413,12 @@ port_open_step (GTask *task) ctx = g_task_get_task_data (task); switch (ctx->step) { case PORT_OPEN_STEP_FIRST: - mm_dbg ("Opening QMI device..."); + mm_obj_dbg (self, "Opening QMI device..."); ctx->step++; /* Fall through */ case PORT_OPEN_STEP_CHECK_OPENING: - mm_dbg ("Checking if QMI device already opening..."); + mm_obj_dbg (self, "Checking if QMI device already opening..."); if (self->priv->in_progress) { g_task_return_new_error (task, MM_CORE_ERROR, @@ -424,7 +431,7 @@ port_open_step (GTask *task) /* Fall through */ case PORT_OPEN_STEP_CHECK_ALREADY_OPEN: - mm_dbg ("Checking if QMI device already open..."); + mm_obj_dbg (self, "Checking if QMI device already open..."); if (self->priv->qmi_device) { g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -445,7 +452,7 @@ port_open_step (GTask *task) * that all callbacks go through the LAST step for completing. */ self->priv->in_progress = TRUE; - mm_dbg ("Creating QMI device..."); + mm_obj_dbg (self, "Creating QMI device..."); qmi_device_new (file, g_task_get_cancellable (task), (GAsyncReadyCallback) qmi_device_new_ready, @@ -458,7 +465,7 @@ port_open_step (GTask *task) case PORT_OPEN_STEP_OPEN_WITHOUT_DATA_FORMAT: /* Now open the QMI device without any data format CTL flag */ - mm_dbg ("Opening device without data format update..."); + mm_obj_dbg (self, "Opening device without data format update..."); qmi_device_open (ctx->device, (QMI_DEVICE_OPEN_FLAGS_VERSION_INFO | QMI_DEVICE_OPEN_FLAGS_PROXY), @@ -469,7 +476,7 @@ port_open_step (GTask *task) return; case PORT_OPEN_STEP_GET_KERNEL_DATA_FORMAT: - mm_dbg ("Querying kernel data format..."); + mm_obj_dbg (self, "Querying kernel data format..."); /* Try to gather expected data format from the sysfs file */ ctx->kernel_data_format = qmi_device_get_expected_data_format (ctx->device, NULL); /* If data format cannot be retrieved, we fallback to 802.3 via CTL */ @@ -483,7 +490,7 @@ port_open_step (GTask *task) case PORT_OPEN_STEP_ALLOCATE_WDA_CLIENT: /* Allocate WDA client */ - mm_dbg ("Allocating WDA client..."); + mm_obj_dbg (self, "Allocating WDA client..."); qmi_device_allocate_client (ctx->device, QMI_SERVICE_WDA, QMI_CID_NONE, @@ -496,7 +503,7 @@ port_open_step (GTask *task) case PORT_OPEN_STEP_GET_WDA_DATA_FORMAT: /* If we have WDA client, query current data format */ g_assert (ctx->wda); - mm_dbg ("Querying device data format..."); + mm_obj_dbg (self, "Querying device data format..."); qmi_client_wda_get_data_format (QMI_CLIENT_WDA (ctx->wda), NULL, 10, @@ -508,9 +515,9 @@ port_open_step (GTask *task) case PORT_OPEN_STEP_CHECK_DATA_FORMAT: /* We now have the WDA data format and the kernel data format, if they're * equal, we're done */ - mm_dbg ("Checking data format: kernel %s, device %s", - qmi_device_expected_data_format_get_string (ctx->kernel_data_format), - qmi_wda_link_layer_protocol_get_string (ctx->llp)); + mm_obj_dbg (self, "Checking data format: kernel %s, device %s", + qmi_device_expected_data_format_get_string (ctx->kernel_data_format), + qmi_wda_link_layer_protocol_get_string (ctx->llp)); if (ctx->kernel_data_format == QMI_DEVICE_EXPECTED_DATA_FORMAT_802_3 && ctx->llp == QMI_WDA_LINK_LAYER_PROTOCOL_802_3) { @@ -533,7 +540,7 @@ port_open_step (GTask *task) case PORT_OPEN_STEP_SET_KERNEL_DATA_FORMAT: /* Update the data format to be expected by the kernel */ - mm_dbg ("Updating kernel data format: %s", qmi_wda_link_layer_protocol_get_string (ctx->llp)); + mm_obj_dbg (self, "Updating kernel data format: %s", qmi_wda_link_layer_protocol_get_string (ctx->llp)); if (ctx->llp == QMI_WDA_LINK_LAYER_PROTOCOL_802_3) { ctx->kernel_data_format = QMI_DEVICE_EXPECTED_DATA_FORMAT_802_3; self->priv->llp_is_raw_ip = FALSE; @@ -552,7 +559,7 @@ port_open_step (GTask *task) return; case PORT_OPEN_STEP_CLOSE_BEFORE_OPEN_WITH_DATA_FORMAT: - mm_dbg ("Closing device to reopen it right away..."); + mm_obj_dbg (self, "Closing device to reopen it right away..."); qmi_device_close_async (ctx->device, 5, g_task_get_cancellable (task), @@ -562,7 +569,7 @@ port_open_step (GTask *task) case PORT_OPEN_STEP_OPEN_WITH_DATA_FORMAT: /* Need to reopen setting 802.3 using CTL */ - mm_dbg ("Reopening device with data format..."); + mm_obj_dbg (self, "Reopening device with data format..."); qmi_device_open (ctx->device, (QMI_DEVICE_OPEN_FLAGS_VERSION_INFO | QMI_DEVICE_OPEN_FLAGS_PROXY | @@ -576,7 +583,7 @@ port_open_step (GTask *task) case PORT_OPEN_STEP_LAST: if (ctx->error) { - mm_dbg ("QMI port open operation failed: %s", ctx->error->message); + mm_obj_dbg (self, "QMI port open operation failed: %s", ctx->error->message); if (ctx->device) { qmi_device_close_async (ctx->device, @@ -591,7 +598,7 @@ port_open_step (GTask *task) return; } - mm_dbg ("QMI port open operation finished successfully"); + mm_obj_dbg (self, "QMI port open operation finished successfully"); /* Store device in private info */ g_assert (ctx->device); @@ -721,7 +728,7 @@ mm_port_qmi_close (MMPortQmi *self, for (l = self->priv->services; l; l = g_list_next (l)) { ServiceInfo *info = l->data; - mm_dbg ("Releasing client for service '%s'...", qmi_service_get_string (info->service)); + mm_obj_dbg (self, "Releasing client for service '%s'...", qmi_service_get_string (info->service)); qmi_device_release_client (ctx->qmi_device, info->client, QMI_DEVICE_RELEASE_CLIENT_FLAGS_RELEASE_CID, diff --git a/src/mm-port-serial-at.c b/src/mm-port-serial-at.c index 67525af0..680c9297 100644 --- a/src/mm-port-serial-at.c +++ b/src/mm-port-serial-at.c @@ -22,7 +22,7 @@ #include <string.h> #include "mm-port-serial-at.h" -#include "mm-log.h" +#include "mm-log-object.h" G_DEFINE_TYPE (MMPortSerialAt, mm_port_serial_at, MM_TYPE_PORT_SERIAL) @@ -435,10 +435,13 @@ mm_port_serial_at_command (MMPortSerialAt *self, } static void -debug_log (MMPortSerial *port, const char *prefix, const char *buf, gsize len) +debug_log (MMPortSerial *self, + const gchar *prefix, + const gchar *buf, + gsize len) { static GString *debug = NULL; - const char *s; + const char *s; if (!debug) debug = g_string_sized_new (256); @@ -461,7 +464,7 @@ debug_log (MMPortSerial *port, const char *prefix, const char *buf, gsize len) } g_string_append_c (debug, '\''); - mm_dbg ("(%s): %s", mm_port_get_device (MM_PORT (port)), debug->str); + mm_obj_dbg (self, "%s", debug->str); g_string_truncate (debug, 0); } @@ -497,7 +500,7 @@ mm_port_serial_at_run_init_sequence (MMPortSerialAt *self) if (!self->priv->init_sequence) return; - mm_dbg ("(%s): running init sequence...", mm_port_get_device (MM_PORT (self))); + mm_obj_dbg (self, "running init sequence..."); /* Just queue the init commands, don't wait for reply */ for (i = 0; self->priv->init_sequence[i]; i++) { diff --git a/src/mm-port-serial-gps.c b/src/mm-port-serial-gps.c index b316d05e..ea404994 100644 --- a/src/mm-port-serial-gps.c +++ b/src/mm-port-serial-gps.c @@ -19,7 +19,7 @@ #include <string.h> #include "mm-port-serial-gps.h" -#include "mm-log.h" +#include "mm-log-object.h" G_DEFINE_TYPE (MMPortSerialGps, mm_port_serial_gps, MM_TYPE_PORT_SERIAL) @@ -135,10 +135,13 @@ parse_response (MMPortSerial *port, /*****************************************************************************/ static void -debug_log (MMPortSerial *port, const char *prefix, const char *buf, gsize len) +debug_log (MMPortSerial *self, + const gchar *prefix, + const gchar *buf, + gsize len) { static GString *debug = NULL; - const char *s; + const gchar *s; if (!debug) debug = g_string_sized_new (256); @@ -161,7 +164,7 @@ debug_log (MMPortSerial *port, const char *prefix, const char *buf, gsize len) } g_string_append_c (debug, '\''); - mm_dbg ("(%s): %s", mm_port_get_device (MM_PORT (port)), debug->str); + mm_obj_dbg (self, "%s", debug->str); g_string_truncate (debug, 0); } diff --git a/src/mm-port-serial-qcdm.c b/src/mm-port-serial-qcdm.c index e723204b..e5bc94e6 100644 --- a/src/mm-port-serial-qcdm.c +++ b/src/mm-port-serial-qcdm.c @@ -27,7 +27,7 @@ #include "libqcdm/src/utils.h" #include "libqcdm/src/errors.h" #include "libqcdm/src/dm-commands.h" -#include "mm-log.h" +#include "mm-log-object.h" G_DEFINE_TYPE (MMPortSerialQcdm, mm_port_serial_qcdm, MM_TYPE_PORT_SERIAL) @@ -206,10 +206,13 @@ mm_port_serial_qcdm_command (MMPortSerialQcdm *self, } static void -debug_log (MMPortSerial *port, const char *prefix, const char *buf, gsize len) +debug_log (MMPortSerial *self, + const gchar *prefix, + const gchar *buf, + gsize len) { static GString *debug = NULL; - const char *s = buf; + const gchar *s = buf; if (!debug) debug = g_string_sized_new (512); @@ -219,7 +222,7 @@ debug_log (MMPortSerial *port, const char *prefix, const char *buf, gsize len) while (len--) g_string_append_printf (debug, " %02x", (guint8) (*s++ & 0xFF)); - mm_dbg ("(%s): %s", mm_port_get_device (MM_PORT (port)), debug->str); + mm_obj_dbg (self, "%s", debug->str); g_string_truncate (debug, 0); } diff --git a/src/mm-port-serial.c b/src/mm-port-serial.c index d5980189..b4ba6533 100644 --- a/src/mm-port-serial.c +++ b/src/mm-port-serial.c @@ -34,7 +34,7 @@ #include <mm-errors-types.h> #include "mm-port-serial.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-helper-enums-types.h" static gboolean port_serial_queue_process (gpointer data); @@ -398,11 +398,9 @@ internal_tcsetattr (MMPortSerial *self, memset (&other, 0, sizeof (struct termios)); errno = 0; if (tcgetattr (fd, &other) != 0) - mm_dbg ("(%s): couldn't get serial port attributes after setting them: %s", - mm_port_get_device (MM_PORT (self)), g_strerror (errno)); + mm_obj_dbg (self, "couldn't get serial port attributes after setting them: %s", g_strerror (errno)); else if (memcmp (options, &other, sizeof (struct termios)) != 0) - mm_dbg ("(%s): port attributes not fully set", - mm_port_get_device (MM_PORT (self))); + mm_obj_dbg (self, "port attributes not fully set"); #undef MAX_TCSETATTR_RETRIES @@ -430,19 +428,19 @@ set_flow_control_termios (MMPortSerial *self, /* setup the requested flags */ switch (flow_control) { case MM_FLOW_CONTROL_XON_XOFF: - mm_dbg ("(%s): enabling XON/XOFF flow control", mm_port_get_device (MM_PORT (self))); + mm_obj_dbg (self, "enabling XON/XOFF flow control"); options->c_iflag |= (IXON | IXOFF | IXANY); break; case MM_FLOW_CONTROL_RTS_CTS: - mm_dbg ("(%s): enabling RTS/CTS flow control", mm_port_get_device (MM_PORT (self))); + mm_obj_dbg (self, "enabling RTS/CTS flow control"); options->c_cflag |= (CRTSCTS); break; case MM_FLOW_CONTROL_NONE: case MM_FLOW_CONTROL_UNKNOWN: if (had_xon_xoff) - mm_dbg ("(%s): disabling XON/XOFF flow control", mm_port_get_device (MM_PORT (self))); + mm_obj_dbg (self, "disabling XON/XOFF flow control"); if (had_rts_cts) - mm_dbg ("(%s): disabling RTS/CTS flow control", mm_port_get_device (MM_PORT (self))); + mm_obj_dbg (self, "disabling RTS/CTS flow control"); break; default: g_assert_not_reached (); @@ -464,13 +462,9 @@ real_config_fd (MMPortSerial *self, int fd, GError **error) if (mm_port_get_subsys (MM_PORT (self)) != MM_PORT_SUBSYS_TTY) return TRUE; - mm_dbg ("(%s): setting up baudrate: %u", - mm_port_get_device (MM_PORT (self)), - self->priv->baud); + mm_obj_dbg (self, "setting up baudrate: %u", self->priv->baud); if (!parse_baudrate (self->priv->baud, &speed) || speed == B0) { - mm_warn ("(%s): baudrate invalid: %u; defaulting to 57600", - mm_port_get_device (MM_PORT (self)), - self->priv->baud); + mm_obj_warn (self, "baudrate invalid: %u; defaulting to 57600", self->priv->baud); speed = B57600; } @@ -479,11 +473,8 @@ real_config_fd (MMPortSerial *self, int fd, GError **error) stopbits = parse_stopbits (self->priv->stopbits); memset (&stbuf, 0, sizeof (struct termios)); - if (tcgetattr (fd, &stbuf) != 0) { - mm_warn ("(%s): tcgetattr() error: %d", - mm_port_get_device (MM_PORT (self)), - errno); - } + if (tcgetattr (fd, &stbuf) != 0) + mm_obj_warn (self, "error getting serial port attributes: %s", g_strerror (errno)); stbuf.c_cflag &= ~(CBAUD | CSIZE | CSTOPB | PARENB | PARODD | CRTSCTS); stbuf.c_iflag &= ~(IGNCR | ICRNL | IUCLC | INPCK | IXON | IXOFF | IXANY ); @@ -523,13 +514,10 @@ real_config_fd (MMPortSerial *self, int fd, GError **error) gchar *str; str = mm_flow_control_build_string_from_mask (self->priv->flow_control); - mm_dbg ("(%s): flow control explicitly requested for device is: %s", - mm_port_get_device (MM_PORT (self)), - str ? str : "unknown"); + mm_obj_dbg (self, "flow control explicitly requested for device is: %s", str ? str : "unknown"); g_free (str); } else - mm_dbg ("(%s): no flow control explicitly requested for device", - mm_port_get_device (MM_PORT (self))); + mm_obj_dbg (self, "no flow control explicitly requested for device"); set_flow_control_termios (self, self->priv->flow_control, &stbuf); @@ -537,7 +525,10 @@ real_config_fd (MMPortSerial *self, int fd, GError **error) } static void -serial_debug (MMPortSerial *self, const char *prefix, const char *buf, gsize len) +serial_debug (MMPortSerial *self, + const gchar *prefix, + const gchar *buf, + gsize len) { g_return_if_fail (len > 0); @@ -569,7 +560,7 @@ port_serial_process_command (MMPortSerial *self, /* Only print command the first time */ if (ctx->started == FALSE) { ctx->started = TRUE; - serial_debug (self, "-->", (const char *) ctx->command->data, ctx->command->len); + serial_debug (self, "-->", (const gchar *) ctx->command->data, ctx->command->len); } if (self->priv->send_delay == 0 || mm_port_get_subsys (MM_PORT (self)) != MM_PORT_SUBSYS_TTY) { @@ -616,7 +607,7 @@ port_serial_process_command (MMPortSerial *self, g_signal_emit (self, signals[TIMED_OUT], 0, self->priv->n_consecutive_timeouts); g_set_error (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_SEND_FAILED, - "Sending command failed: '%s'", strerror (errno)); + "Sending command failed: '%s'", g_strerror (errno)); return FALSE; } break; @@ -651,7 +642,7 @@ port_serial_process_command (MMPortSerial *self, self->priv->n_consecutive_timeouts++; g_signal_emit (self, signals[TIMED_OUT], 0, self->priv->n_consecutive_timeouts); g_set_error (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_SEND_FAILED, - "Sending command failed: '%s'", strerror (errno)); + "Sending command failed: '%s'", g_strerror (errno)); return FALSE; } @@ -959,15 +950,12 @@ common_input_available (MMPortSerial *self, gsize bytes_read; GIOStatus status = G_IO_STATUS_NORMAL; CommandContext *ctx; - const char *device; GError *error = NULL; gboolean iterate = TRUE; gboolean keep_source = G_SOURCE_CONTINUE; if (condition & G_IO_HUP) { - device = mm_port_get_device (MM_PORT (self)); - mm_dbg ("(%s) unexpected port hangup!", device); - + mm_obj_dbg (self, "unexpected port hangup!"); if (self->priv->response->len) g_byte_array_remove_range (self->priv->response, 0, self->priv->response->len); port_serial_close_force (self); @@ -995,11 +983,8 @@ common_input_available (MMPortSerial *self, &bytes_read, &error); if (status == G_IO_STATUS_ERROR) { - if (error) { - mm_warn ("(%s): read error: %s", - mm_port_get_device (MM_PORT (self)), - error->message); - } + if (error) + mm_obj_warn (self, "read error: %s", error->message); g_clear_error (&error); } } else if (self->priv->socket) { @@ -1016,9 +1001,7 @@ common_input_available (MMPortSerial *self, status = G_IO_STATUS_AGAIN; else status = G_IO_STATUS_ERROR; - mm_warn ("(%s): receive error: %s", - mm_port_get_device (MM_PORT (self)), - error->message); + mm_obj_warn (self, "receive error: %s", error->message); g_clear_error (&error); } else { bytes_read = (gsize) sbytes_read; @@ -1137,11 +1120,9 @@ port_connected (MMPortSerial *self, GParamSpec *pspec, gpointer user_data) connected = mm_port_get_connected (MM_PORT (self)); if (self->priv->fd >= 0 && ioctl (self->priv->fd, (connected ? TIOCNXCL : TIOCEXCL)) < 0) { - mm_warn ("(%s): could not %s serial port lock: (%d) %s", - mm_port_get_device (MM_PORT (self)), - connected ? "drop" : "re-acquire", - errno, - strerror (errno)); + mm_obj_warn (self, "could not %s serial port lock: %s", + connected ? "drop" : "re-acquire", + g_strerror (errno)); if (!connected) { // FIXME: do something here, maybe try again in a few seconds or // close the port and error out? @@ -1197,7 +1178,7 @@ mm_port_serial_open (MMPortSerial *self, GError **error) goto success; } - mm_dbg ("(%s) opening serial port...", device); + mm_obj_dbg (self, "opening serial port..."); g_get_current_time (&tv_start); @@ -1221,7 +1202,6 @@ mm_port_serial_open (MMPortSerial *self, GError **error) MM_SERIAL_ERROR, (errno == ENODEV) ? MM_SERIAL_ERROR_OPEN_FAILED_NO_DEVICE : MM_SERIAL_ERROR_OPEN_FAILED, "Could not open serial device %s: %s", device, strerror (errno_save)); - mm_warn ("(%s) could not open serial device (%d)", device, errno_save); return FALSE; } } @@ -1233,7 +1213,6 @@ mm_port_serial_open (MMPortSerial *self, GError **error) errno_save = errno; g_set_error (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_OPEN_FAILED, "Could not lock serial device %s: %s", device, strerror (errno_save)); - mm_warn ("(%s) could not lock serial device (%d)", device, errno_save); goto error; } @@ -1247,21 +1226,20 @@ mm_port_serial_open (MMPortSerial *self, GError **error) if (ioctl (self->priv->fd, TIOCGSERIAL, &sinfo) == 0) { sinfo.closing_wait = ASYNC_CLOSING_WAIT_NONE; if (ioctl (self->priv->fd, TIOCSSERIAL, &sinfo) < 0) - mm_warn ("(%s): couldn't set serial port closing_wait to none: %s", - device, g_strerror (errno)); + mm_obj_warn (self, "couldn't set serial port closing_wait to none: %s", g_strerror (errno)); } } g_warn_if_fail (MM_PORT_SERIAL_GET_CLASS (self)->config_fd); if (self->priv->fd >= 0 && !MM_PORT_SERIAL_GET_CLASS (self)->config_fd (self, self->priv->fd, error)) { - mm_dbg ("(%s) failed to configure serial device", device); + mm_obj_dbg (self, "failed to configure serial device"); goto error; } g_get_current_time (&tv_end); if (tv_end.tv_sec - tv_start.tv_sec > 7) - mm_warn ("(%s): open blocked by driver for more than 7 seconds!", device); + mm_obj_warn (self, "open blocked by driver for more than 7 seconds!"); if (mm_port_get_subsys (MM_PORT (self)) != MM_PORT_SUBSYS_UNIX) { /* Create new GIOChannel */ @@ -1327,7 +1305,7 @@ mm_port_serial_open (MMPortSerial *self, GError **error) success: self->priv->open_count++; - mm_dbg ("(%s) device open count is %d (open)", device, self->priv->open_count); + mm_obj_dbg (self, "device open count is %d (open)", self->priv->open_count); /* Run additional port config if just opened */ if (self->priv->open_count == 1 && MM_PORT_SERIAL_GET_CLASS (self)->config) @@ -1336,7 +1314,7 @@ success: return TRUE; error: - mm_warn ("(%s) failed to open serial device", device); + mm_obj_warn (self, "failed to open serial device"); if (self->priv->iochannel) { g_io_channel_unref (self->priv->iochannel); @@ -1369,8 +1347,7 @@ mm_port_serial_is_open (MMPortSerial *self) static void _close_internal (MMPortSerial *self, gboolean force) { - const char *device; - guint i; + guint i; g_return_if_fail (MM_IS_PORT_SERIAL (self)); @@ -1381,9 +1358,7 @@ _close_internal (MMPortSerial *self, gboolean force) self->priv->open_count--; } - device = mm_port_get_device (MM_PORT (self)); - - mm_dbg ("(%s) device open count is %d (close)", device, self->priv->open_count); + mm_obj_dbg (self, "device open count is %d (close)", self->priv->open_count); if (self->priv->open_count > 0) return; @@ -1402,7 +1377,7 @@ _close_internal (MMPortSerial *self, gboolean force) GTimeVal tv_start, tv_end; struct serial_struct sinfo = { 0 }; - mm_dbg ("(%s) closing serial port...", device); + mm_obj_dbg (self, "closing serial port..."); mm_port_set_connected (MM_PORT (self), FALSE); @@ -1415,11 +1390,10 @@ _close_internal (MMPortSerial *self, gboolean force) */ if (ioctl (self->priv->fd, TIOCGSERIAL, &sinfo) == 0) { if (sinfo.closing_wait != ASYNC_CLOSING_WAIT_NONE) { - mm_warn ("(%s): serial port closing_wait was reset!", device); + mm_obj_warn (self, "serial port closing_wait was reset!"); sinfo.closing_wait = ASYNC_CLOSING_WAIT_NONE; if (ioctl (self->priv->fd, TIOCSSERIAL, &sinfo) < 0) - mm_warn ("(%s): couldn't set serial port closing_wait to none: %s", - device, g_strerror (errno)); + mm_obj_warn (self, "couldn't set serial port closing_wait to none: %s", g_strerror (errno)); } } @@ -1452,7 +1426,7 @@ _close_internal (MMPortSerial *self, gboolean force) g_get_current_time (&tv_end); - mm_dbg ("(%s) serial port closed", device); + mm_obj_dbg (self, "serial port closed"); /* Some ports don't respond to data and when close is called * the serial layer waits up to 30 second (closing_wait) for @@ -1460,7 +1434,7 @@ _close_internal (MMPortSerial *self, gboolean force) * Log that. See GNOME bug #630670 for more details. */ if (tv_end.tv_sec - tv_start.tv_sec > 7) - mm_warn ("(%s): close blocked by driver for more than 7 seconds!", device); + mm_obj_warn (self, "close blocked by driver for more than 7 seconds!"); } /* Clear the command queue */ @@ -1514,7 +1488,7 @@ port_serial_close_force (MMPortSerial *self) if (self->priv->forced_close) return; - mm_dbg ("(%s) forced to close port", mm_port_get_device (MM_PORT (self))); + mm_obj_dbg (self, "forced to close port"); /* Mark as having forced the close, so that we don't warn about incorrect * open counts */ @@ -1651,9 +1625,7 @@ mm_port_serial_reopen (MMPortSerial *self, return; } - mm_dbg ("(%s) reopening port (%u)", - mm_port_get_device (MM_PORT (self)), - ctx->initial_open_count); + mm_obj_dbg (self, "reopening port (%u)", ctx->initial_open_count); for (i = 0; i < ctx->initial_open_count; i++) mm_port_serial_close (self); @@ -1896,16 +1868,14 @@ mm_port_serial_set_flow_control (MMPortSerial *self, /* Return if current settings are already what we want */ if (!set_flow_control_termios (self, flow_control, &options)) { - mm_dbg ("(%s): no need to change flow control settings: already %s", - mm_port_get_device (MM_PORT (self)), flow_control_str); + mm_obj_dbg (self, "no need to change flow control settings: already %s", flow_control_str); goto out; } if (!internal_tcsetattr (self, self->priv->fd, &options, &inner_error)) goto out; - mm_dbg ("(%s): flow control settings updated to %s", - mm_port_get_device (MM_PORT (self)), flow_control_str); + mm_obj_dbg (self, "flow control settings updated to %s", flow_control_str); out: g_free (flow_control_str); diff --git a/src/mm-port-serial.h b/src/mm-port-serial.h index b30bad77..e643d147 100644 --- a/src/mm-port-serial.h +++ b/src/mm-port-serial.h @@ -93,12 +93,12 @@ struct _MMPortSerialClass { /* Called to configure the serial port after it's opened. Errors, if any, * should get ignored. */ - void (*config) (MMPortSerial *self); + void (*config) (MMPortSerial *self); void (*debug_log) (MMPortSerial *self, - const char *prefix, - const char *buf, - gsize len); + const gchar *prefix, + const gchar *buf, + gsize len); /* Signals */ void (*buffer_full) (MMPortSerial *port, const GByteArray *buffer); diff --git a/src/mm-port.c b/src/mm-port.c index 0156f6e7..b9a80209 100644 --- a/src/mm-port.c +++ b/src/mm-port.c @@ -19,9 +19,13 @@ #include <string.h> #include "mm-port.h" -#include "mm-log.h" +#include "mm-port-enums-types.h" +#include "mm-log-object.h" -G_DEFINE_TYPE (MMPort, mm_port, G_TYPE_OBJECT) +static void log_object_iface_init (MMLogObjectInterface *iface); + +G_DEFINE_TYPE_EXTENDED (MMPort, mm_port, G_TYPE_OBJECT, 0, + G_IMPLEMENT_INTERFACE (MM_TYPE_LOG_OBJECT, log_object_iface_init)) enum { PROP_0, @@ -88,10 +92,7 @@ mm_port_set_connected (MMPort *self, gboolean connected) if (self->priv->connected != connected) { self->priv->connected = connected; g_object_notify (G_OBJECT (self), MM_PORT_CONNECTED); - - mm_dbg ("(%s): port now %s", - self->priv->device, - connected ? "connected" : "disconnected"); + mm_obj_dbg (self, "port now %s", connected ? "connected" : "disconnected"); } } @@ -105,6 +106,19 @@ mm_port_peek_kernel_device (MMPort *self) /*****************************************************************************/ +static gchar * +log_object_build_id (MMLogObject *_self) +{ + MMPort *self; + + self = MM_PORT (_self); + return g_strdup_printf ("%s/%s", + mm_port_get_device (self), + mm_modem_port_type_get_string (mm_port_get_port_type (self))); +} + +/*****************************************************************************/ + static void mm_port_init (MMPort *self) { @@ -195,6 +209,12 @@ dispose (GObject *object) } static void +log_object_iface_init (MMLogObjectInterface *iface) +{ + iface->build_id = log_object_build_id; +} + +static void mm_port_class_init (MMPortClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); |