core: rework logging

Make it more flexible, add logging to a file, and absolute and
relative timestamps.
This commit is contained in:
Dan Williams
2011-01-23 20:51:48 -06:00
parent f85b014d84
commit 16039244bb
30 changed files with 537 additions and 414 deletions

View File

@@ -28,6 +28,7 @@
#include "mm-callback-info.h" #include "mm-callback-info.h"
#include "mm-serial-port.h" #include "mm-serial-port.h"
#include "mm-serial-parsers.h" #include "mm-serial-parsers.h"
#include "mm-log.h"
static void modem_init (MMModem *modem_class); static void modem_init (MMModem *modem_class);
@@ -140,7 +141,7 @@ evdo_state_done (MMAtSerialPort *port,
G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
if (!r) { if (!r) {
/* Parse error; warn about it and assume EVDO is not available */ /* Parse error; warn about it and assume EVDO is not available */
g_warning ("AnyDATA(%s): *HSTATE parse regex creation failed.", __func__); mm_warn ("ANYDATA: *HSTATE parse regex creation failed.");
goto done; goto done;
} }
@@ -167,7 +168,7 @@ evdo_state_done (MMAtSerialPort *port,
reg_state = MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED; reg_state = MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
break; break;
default: default:
g_message ("ANYDATA: unknown *STATE (%d); assuming no service.", val); mm_warn ("ANYDATA: unknown *STATE (%d); assuming no service.", val);
/* fall through */ /* fall through */
case 0: /* NO SERVICE */ case 0: /* NO SERVICE */
case 1: /* ACQUISITION */ case 1: /* ACQUISITION */
@@ -206,7 +207,7 @@ state_done (MMAtSerialPort *port,
r = g_regex_new ("\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*([^,\\)]*)\\s*,.*", r = g_regex_new ("\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*([^,\\)]*)\\s*,.*",
G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
if (!r) { if (!r) {
g_warning ("AnyDATA(%s): *STATE parse regex creation failed.", __func__); mm_warn ("ANYDATA: *STATE parse regex creation failed.");
mm_callback_info_schedule (info); mm_callback_info_schedule (info);
return; return;
} }
@@ -235,7 +236,7 @@ state_done (MMAtSerialPort *port,
reg_state = MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED; reg_state = MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
break; break;
default: default:
g_warning ("ANYDATA: unknown *STATE (%d); assuming no service.", val); mm_warn ("ANYDATA: unknown *STATE (%d); assuming no service.", val);
/* fall through */ /* fall through */
case 0: /* NO SERVICE */ case 0: /* NO SERVICE */
break; break;

View File

@@ -27,6 +27,7 @@
#include "mm-callback-info.h" #include "mm-callback-info.h"
#include "mm-serial-port.h" #include "mm-serial-port.h"
#include "mm-serial-parsers.h" #include "mm-serial-parsers.h"
#include "mm-log.h"
static void modem_init (MMModem *modem_class); static void modem_init (MMModem *modem_class);
@@ -79,7 +80,7 @@ parse_quality (const char *str, const char *detail)
quality = strtol (str, NULL, 10); quality = strtol (str, NULL, 10);
if (errno == 0) { if (errno == 0) {
quality = CLAMP (quality, 0, 100); quality = CLAMP (quality, 0, 100);
g_debug ("%s: %ld", detail, quality); mm_dbg ("%s: %ld", detail, quality);
return (gint) quality; return (gint) quality;
} }
return -1; return -1;
@@ -177,7 +178,7 @@ sysinfo_done (MMAtSerialPort *port,
r = g_regex_new ("\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)", r = g_regex_new ("\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)",
G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
if (!r) { if (!r) {
g_warning ("Huawei(%s): ^SYSINFO parse regex creation failed.", __func__); mm_warn ("Huawei: ^SYSINFO parse regex creation failed.");
goto done; goto done;
} }
@@ -218,7 +219,7 @@ sysinfo_done (MMAtSerialPort *port,
mm_generic_cdma_query_reg_state_set_callback_1x_state (info, reg_state); mm_generic_cdma_query_reg_state_set_callback_1x_state (info, reg_state);
} }
} else } else
g_warning ("Huawei(%s): failed to parse ^SYSINFO response.", __func__); mm_warn ("Huawei: failed to parse ^SYSINFO response.");
g_match_info_free (match_info); g_match_info_free (match_info);
g_regex_unref (r); g_regex_unref (r);

View File

@@ -29,7 +29,7 @@
#include "mm-callback-info.h" #include "mm-callback-info.h"
#include "mm-at-serial-port.h" #include "mm-at-serial-port.h"
#include "mm-serial-parsers.h" #include "mm-serial-parsers.h"
#include "mm-options.h" #include "mm-log.h"
static void modem_init (MMModem *modem_class); static void modem_init (MMModem *modem_class);
static void modem_gsm_network_init (MMModemGsmNetwork *gsm_network_class); static void modem_gsm_network_init (MMModemGsmNetwork *gsm_network_class);
@@ -534,7 +534,7 @@ send_huawei_cpin_done (MMAtSerialPort *port,
else if (strstr (pin_type, MM_MODEM_GSM_CARD_SIM_PIN2)) else if (strstr (pin_type, MM_MODEM_GSM_CARD_SIM_PIN2))
num = 5; num = 5;
else { else {
g_debug ("%s: unhandled pin type '%s'", __func__, pin_type); mm_dbg ("unhandled pin type '%s'", pin_type);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "Unhandled PIN type"); info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "Unhandled PIN type");
} }
@@ -576,7 +576,7 @@ get_unlock_retries (MMModemGsmCard *modem,
char *command; char *command;
MMCallbackInfo *info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data); MMCallbackInfo *info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
g_debug ("%s: pin type '%s'", __func__, pin_type); mm_dbg ("pin type '%s'", pin_type);
/* Ensure we have a usable port to use for the command */ /* Ensure we have a usable port to use for the command */
port = mm_generic_gsm_get_best_at_port (MM_GENERIC_GSM (modem), &info->error); port = mm_generic_gsm_get_best_at_port (MM_GENERIC_GSM (modem), &info->error);
@@ -660,12 +660,11 @@ handle_mode_change (MMAtSerialPort *port,
} else if (a == 0) } else if (a == 0)
act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN;
else { else {
g_warning ("Couldn't parse mode change value: '%s'", str); mm_warn ("Couldn't parse mode change value: '%s'", str);
return; return;
} }
if (mm_options_debug ()) mm_dbg ("Access Technology: %d", act);
g_debug ("Access Technology: %d", act);
mm_generic_gsm_update_access_technology (MM_GENERIC_GSM (self), act); mm_generic_gsm_update_access_technology (MM_GENERIC_GSM (self), act);
} }
@@ -680,10 +679,8 @@ handle_status_change (MMAtSerialPort *port,
str = g_match_info_fetch (match_info, 1); str = g_match_info_fetch (match_info, 1);
if (sscanf (str, "%x,%x,%x,%x,%x,%x,%x", &n1, &n2, &n3, &n4, &n5, &n6, &n7)) { if (sscanf (str, "%x,%x,%x,%x,%x,%x,%x", &n1, &n2, &n3, &n4, &n5, &n6, &n7)) {
if (mm_options_debug ()) { mm_dbg ("Duration: %d Up: %d Kbps Down: %d Kbps Total: %d Total: %d\n",
g_debug ("Duration: %d Up: %d Kbps Down: %d Kbps Total: %d Total: %d\n", n1, n2 * 8 / 1000, n3 * 8 / 1000, n4 / 1024, n5 / 1024);
n1, n2 * 8 / 1000, n3 * 8 / 1000, n4 / 1024, n5 / 1024);
}
} }
g_free (str); g_free (str);
} }

View File

@@ -32,6 +32,7 @@
#include "mm-at-serial-port.h" #include "mm-at-serial-port.h"
#include "mm-generic-gsm.h" #include "mm-generic-gsm.h"
#include "mm-modem-helpers.h" #include "mm-modem-helpers.h"
#include "mm-log.h"
struct _MMModemIceraPrivate { struct _MMModemIceraPrivate {
/* Pending connection attempt */ /* Pending connection attempt */
@@ -325,7 +326,7 @@ icera_disconnect_done (MMModem *modem,
GError *error, GError *error,
gpointer user_data) gpointer user_data)
{ {
g_message ("Modem signaled disconnection from the network"); mm_info ("Modem signaled disconnection from the network");
} }
static void static void
@@ -380,7 +381,7 @@ connection_enabled (MMAtSerialPort *port,
connect_pending_done (self); connect_pending_done (self);
break; break;
default: default:
g_warning ("Unknown Icera connect status %d", status); mm_warn ("Unknown Icera connect status %d", status);
break; break;
} }
} }

View File

@@ -1,7 +1,7 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* /*
* Copyright (C) 2008 - 2010 Ericsson AB * Copyright (C) 2008 - 2010 Ericsson AB
* Copyright (C) 2009 - 2010 Red Hat, Inc. * Copyright (C) 2009 - 2011 Red Hat, Inc.
* *
* Author: Per Hallsmark <per.hallsmark@ericsson.com> * Author: Per Hallsmark <per.hallsmark@ericsson.com>
* Bjorn Runaker <bjorn.runaker@ericsson.com> * Bjorn Runaker <bjorn.runaker@ericsson.com>
@@ -31,6 +31,7 @@
#include "mm-modem-gsm-card.h" #include "mm-modem-gsm-card.h"
#include "mm-errors.h" #include "mm-errors.h"
#include "mm-callback-info.h" #include "mm-callback-info.h"
#include "mm-log.h"
static void modem_init (MMModem *modem_class); static void modem_init (MMModem *modem_class);
static void modem_gsm_network_init (MMModemGsmNetwork *gsm_network_class); static void modem_gsm_network_init (MMModemGsmNetwork *gsm_network_class);
@@ -410,7 +411,7 @@ mbm_emrdy_done (MMAtSerialPort *port,
MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (info->modem); MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (info->modem);
if (g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) if (g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_RESPONSE_TIMEOUT))
g_warning ("%s: timed out waiting for EMRDY response.", __func__); mm_warn ("timed out waiting for EMRDY response.");
else else
priv->have_emrdy = TRUE; priv->have_emrdy = TRUE;
@@ -632,16 +633,16 @@ mbm_e2nap_received (MMAtSerialPort *port,
g_free (str); g_free (str);
if (MBM_E2NAP_DISCONNECTED == state) { if (MBM_E2NAP_DISCONNECTED == state) {
g_debug ("%s: disconnected", __func__); mm_dbg ("disconnected");
mbm_do_connect_done (MM_MODEM_MBM (user_data), FALSE); mbm_do_connect_done (MM_MODEM_MBM (user_data), FALSE);
} else if (MBM_E2NAP_CONNECTED == state) { } else if (MBM_E2NAP_CONNECTED == state) {
g_debug ("%s: connected", __func__); mm_dbg ("connected");
mbm_do_connect_done (MM_MODEM_MBM (user_data), TRUE); mbm_do_connect_done (MM_MODEM_MBM (user_data), TRUE);
} else if (MBM_E2NAP_CONNECTING == state) } else if (MBM_E2NAP_CONNECTING == state)
g_debug("%s: connecting", __func__); mm_dbg ("connecting");
else { else {
/* Should not happen */ /* Should not happen */
g_debug("%s: unhandled E2NAP state %d", __func__, state); mm_dbg ("unhandled E2NAP state %d", state);
mbm_do_connect_done (MM_MODEM_MBM (user_data), FALSE); mbm_do_connect_done (MM_MODEM_MBM (user_data), FALSE);
} }
} }
@@ -811,7 +812,7 @@ send_epin_done (MMAtSerialPort *port,
else if (strstr (pin_type, MM_MODEM_GSM_CARD_SIM_PUK2)) else if (strstr (pin_type, MM_MODEM_GSM_CARD_SIM_PUK2))
sscanf (response->str, "*EPIN: %*d, %*d, %*d, %d", &attempts_left); sscanf (response->str, "*EPIN: %*d, %*d, %*d, %d", &attempts_left);
else { else {
g_debug ("%s: unhandled pin type '%s'", __func__, pin_type); mm_dbg ("unhandled pin type '%s'", pin_type);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "Unhandled PIN type"); info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "Unhandled PIN type");
} }
@@ -838,7 +839,7 @@ mbm_get_unlock_retries (MMModemGsmCard *modem,
char *command; char *command;
MMCallbackInfo *info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data); MMCallbackInfo *info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
g_debug ("%s: pin type '%s'", __func__, pin_type); mm_dbg ("pin type '%s'", pin_type);
/* Ensure we have a usable port to use for the command */ /* Ensure we have a usable port to use for the command */
port = mm_generic_gsm_get_best_at_port (MM_GENERIC_GSM (modem), &info->error); port = mm_generic_gsm_get_best_at_port (MM_GENERIC_GSM (modem), &info->error);

View File

@@ -31,6 +31,7 @@
#include "mm-generic-cdma.h" #include "mm-generic-cdma.h"
#include "mm-errors.h" #include "mm-errors.h"
#include "mm-serial-parsers.h" #include "mm-serial-parsers.h"
#include "mm-log.h"
G_DEFINE_TYPE (MMPluginGeneric, mm_plugin_generic, MM_TYPE_PLUGIN_BASE) G_DEFINE_TYPE (MMPluginGeneric, mm_plugin_generic, MM_TYPE_PLUGIN_BASE)
@@ -127,10 +128,10 @@ grab_port (MMPluginBase *base,
g_set_error (error, 0, 0, "Could not get port's sysfs file."); g_set_error (error, 0, 0, "Could not get port's sysfs file.");
return NULL; return NULL;
} else { } else {
g_message ("%s: (%s/%s) WARNING: missing udev 'device' file", mm_warn ("%s: (%s/%s) WARNING: missing udev 'device' file",
mm_plugin_get_name (MM_PLUGIN (base)), mm_plugin_get_name (MM_PLUGIN (base)),
subsys, subsys,
name); name);
} }
} }

View File

@@ -27,6 +27,7 @@
#include "mm-modem-huawei-cdma.h" #include "mm-modem-huawei-cdma.h"
#include "mm-serial-parsers.h" #include "mm-serial-parsers.h"
#include "mm-at-serial-port.h" #include "mm-at-serial-port.h"
#include "mm-log.h"
G_DEFINE_TYPE (MMPluginHuawei, mm_plugin_huawei, MM_TYPE_PLUGIN_BASE) G_DEFINE_TYPE (MMPluginHuawei, mm_plugin_huawei, MM_TYPE_PLUGIN_BASE)
@@ -240,10 +241,10 @@ supports_port (MMPluginBase *base,
info->id = g_timeout_add_seconds (7, probe_secondary_timeout, task); info->id = g_timeout_add_seconds (7, probe_secondary_timeout, task);
if (!mm_serial_port_open (MM_SERIAL_PORT (info->serial), &error)) { if (!mm_serial_port_open (MM_SERIAL_PORT (info->serial), &error)) {
g_warning ("%s: (Huawei) %s: couldn't open serial port: (%d) %s", mm_warn ("(Huawei) %s: couldn't open serial port: (%d) %s",
__func__, name, name,
error ? error->code : -1, error ? error->code : -1,
error && error->message ? error->message : "(unknown)"); error && error->message ? error->message : "(unknown)");
g_clear_error (&error); g_clear_error (&error);
huawei_supports_info_destroy (info); huawei_supports_info_destroy (info);
return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;

View File

@@ -84,7 +84,7 @@ supports_port (MMPluginBase *base,
client = g_udev_client_new (sys); client = g_udev_client_new (sys);
if (!client) { if (!client) {
g_warning ("mbm: could not get udev client."); g_warn_if_fail (client != NULL);
return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;
} }

View File

@@ -81,6 +81,8 @@ endif
modem_manager_SOURCES = \ modem_manager_SOURCES = \
main.c \ main.c \
mm-log.c \
mm-log.h \
mm-callback-info.c \ mm-callback-info.c \
mm-callback-info.h \ mm-callback-info.h \
$(auth_sources) \ $(auth_sources) \
@@ -109,8 +111,6 @@ modem_manager_SOURCES = \
mm-modem-gsm-ussd.h \ mm-modem-gsm-ussd.h \
mm-modem-simple.c \ mm-modem-simple.c \
mm-modem-simple.h \ mm-modem-simple.h \
mm-options.c \
mm-options.h \
mm-plugin.c \ mm-plugin.c \
mm-plugin.h \ mm-plugin.h \
mm-plugin-base.c \ mm-plugin-base.c \

View File

@@ -11,7 +11,7 @@
* GNU General Public License for more details: * GNU General Public License for more details:
* *
* Copyright (C) 2008 - 2009 Novell, Inc. * Copyright (C) 2008 - 2009 Novell, Inc.
* Copyright (C) 2009 - 2010 Red Hat, Inc. * Copyright (C) 2009 - 2011 Red Hat, Inc.
*/ */
#include <config.h> #include <config.h>
@@ -21,8 +21,10 @@
#include <unistd.h> #include <unistd.h>
#include <dbus/dbus-glib.h> #include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h> #include <dbus/dbus-glib-lowlevel.h>
#include <stdlib.h>
#include "mm-manager.h" #include "mm-manager.h"
#include "mm-options.h" #include "mm-log.h"
#if !defined(MM_DIST_VERSION) #if !defined(MM_DIST_VERSION)
# define MM_DIST_VERSION VERSION # define MM_DIST_VERSION VERSION
@@ -34,9 +36,9 @@ static void
mm_signal_handler (int signo) mm_signal_handler (int signo)
{ {
if (signo == SIGUSR1) if (signo == SIGUSR1)
mm_options_set_debug (!mm_options_debug ()); mm_log_usr1 ();
else if (signo == SIGINT || signo == SIGTERM) { else if (signo == SIGINT || signo == SIGTERM) {
g_message ("Caught signal %d, shutting down...", signo); mm_info ("Caught signal %d, shutting down...", signo);
if (loop) if (loop)
g_main_loop_quit (loop); g_main_loop_quit (loop);
else else
@@ -59,65 +61,10 @@ setup_signals (void)
sigaction (SIGINT, &action, NULL); sigaction (SIGINT, &action, NULL);
} }
static void
log_handler (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
gpointer ignored)
{
int syslog_priority;
switch (log_level) {
case G_LOG_LEVEL_ERROR:
syslog_priority = LOG_CRIT;
break;
case G_LOG_LEVEL_CRITICAL:
syslog_priority = LOG_ERR;
break;
case G_LOG_LEVEL_WARNING:
syslog_priority = LOG_WARNING;
break;
case G_LOG_LEVEL_MESSAGE:
syslog_priority = LOG_NOTICE;
break;
case G_LOG_LEVEL_DEBUG:
syslog_priority = LOG_DEBUG;
break;
case G_LOG_LEVEL_INFO:
default:
syslog_priority = LOG_INFO;
break;
}
syslog (syslog_priority, "%s", message);
}
static void
logging_setup (void)
{
openlog (G_LOG_DOMAIN, LOG_CONS, LOG_DAEMON);
g_log_set_handler (G_LOG_DOMAIN,
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
log_handler,
NULL);
}
static void
logging_shutdown (void)
{
closelog ();
}
static void static void
destroy_cb (DBusGProxy *proxy, gpointer user_data) destroy_cb (DBusGProxy *proxy, gpointer user_data)
{ {
g_message ("disconnected from the system bus, exiting."); mm_warn ("disconnected from the system bus, exiting.");
g_main_loop_quit (loop); g_main_loop_quit (loop);
} }
@@ -139,16 +86,16 @@ create_dbus_proxy (DBusGConnection *bus)
G_TYPE_INVALID, G_TYPE_INVALID,
G_TYPE_UINT, &request_name_result, G_TYPE_UINT, &request_name_result,
G_TYPE_INVALID)) { G_TYPE_INVALID)) {
g_warning ("Could not acquire the %s service.\n" mm_warn ("Could not acquire the %s service.\n"
" Message: '%s'", MM_DBUS_SERVICE, err->message); " Message: '%s'", MM_DBUS_SERVICE, err->message);
g_error_free (err); g_error_free (err);
g_object_unref (proxy); g_object_unref (proxy);
proxy = NULL; proxy = NULL;
} else if (request_name_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { } else if (request_name_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
g_warning ("Could not acquire the " MM_DBUS_SERVICE mm_warn ("Could not acquire the " MM_DBUS_SERVICE
" service as it is already taken. Return: %d", " service as it is already taken. Return: %d",
request_name_result); request_name_result);
g_object_unref (proxy); g_object_unref (proxy);
proxy = NULL; proxy = NULL;
@@ -175,17 +122,46 @@ main (int argc, char *argv[])
DBusGProxy *proxy; DBusGProxy *proxy;
MMManager *manager; MMManager *manager;
GError *err = NULL; GError *err = NULL;
GOptionContext *opt_ctx;
guint id; guint id;
const char *log_level = NULL, *log_file = NULL;
gboolean debug = FALSE, show_ts = FALSE, rel_ts = FALSE;
GOptionEntry entries[] = {
{ "debug", 0, 0, G_OPTION_ARG_NONE, &debug, "Output to console rather than syslog", NULL },
{ "log-level", 0, 0, G_OPTION_ARG_STRING, &log_level, "Log level: one of [ERR, WARN, INFO, DEBUG]", "INFO" },
{ "log-file", 0, 0, G_OPTION_ARG_STRING, &log_file, "Path to log file", NULL },
{ "timestamps", 0, 0, G_OPTION_ARG_NONE, &show_ts, "Show timestamps in log output", NULL },
{ "relative-timestamps", 0, 0, G_OPTION_ARG_NONE, &rel_ts, "Use relative timestamps (from MM start)", NULL },
{ NULL }
};
mm_options_parse (argc, argv);
g_type_init (); g_type_init ();
opt_ctx = g_option_context_new (NULL);
g_option_context_set_summary (opt_ctx, "DBus system service to communicate with modems.");
g_option_context_add_main_entries (opt_ctx, entries, NULL);
if (!g_option_context_parse (opt_ctx, &argc, &argv, &err)) {
g_warning ("%s\n", err->message);
g_error_free (err);
exit (1);
}
g_option_context_free (opt_ctx);
if (debug)
log_level = "DEBUG";
if (!mm_log_setup (log_level, log_file, show_ts, rel_ts, &err)) {
g_warning ("Failed to set up logging: %s", err->message);
g_error_free (err);
exit (1);
}
setup_signals (); setup_signals ();
if (!mm_options_debug ()) mm_info ("ModemManager (version " MM_DIST_VERSION ") starting...");
logging_setup ();
g_message ("ModemManager (version " MM_DIST_VERSION ") starting...");
bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err); bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err);
if (!bus) { if (!bus) {
@@ -235,7 +211,7 @@ main (int argc, char *argv[])
g_object_unref (proxy); g_object_unref (proxy);
dbus_g_connection_unref (bus); dbus_g_connection_unref (bus);
logging_shutdown (); mm_log_shutdown ();
return 0; return 0;
} }

View File

@@ -23,7 +23,7 @@
#include "mm-at-serial-port.h" #include "mm-at-serial-port.h"
#include "mm-errors.h" #include "mm-errors.h"
#include "mm-options.h" #include "mm-log.h"
G_DEFINE_TYPE (MMAtSerialPort, mm_at_serial_port, MM_TYPE_SERIAL_PORT) G_DEFINE_TYPE (MMAtSerialPort, mm_at_serial_port, MM_TYPE_SERIAL_PORT)
@@ -273,7 +273,6 @@ debug_log (MMSerialPort *port, const char *prefix, const char *buf, gsize len)
{ {
static GString *debug = NULL; static GString *debug = NULL;
const char *s; const char *s;
GTimeVal tv;
if (!debug) if (!debug)
debug = g_string_sized_new (256); debug = g_string_sized_new (256);
@@ -296,12 +295,7 @@ debug_log (MMSerialPort *port, const char *prefix, const char *buf, gsize len)
} }
g_string_append_c (debug, '\''); g_string_append_c (debug, '\'');
g_get_current_time (&tv); mm_dbg ("(%s): %s", mm_port_get_device (MM_PORT (port)), debug->str);
g_debug ("<%ld.%ld> (%s): %s",
tv.tv_sec,
tv.tv_usec,
mm_port_get_device (MM_PORT (port)),
debug->str);
g_string_truncate (debug, 0); g_string_truncate (debug, 0);
} }

View File

@@ -30,6 +30,7 @@
#include "mm-serial-parsers.h" #include "mm-serial-parsers.h"
#include "mm-modem-helpers.h" #include "mm-modem-helpers.h"
#include "libqcdm/src/commands.h" #include "libqcdm/src/commands.h"
#include "mm-log.h"
#define MM_GENERIC_CDMA_PREV_STATE_TAG "prev-state" #define MM_GENERIC_CDMA_PREV_STATE_TAG "prev-state"
@@ -1047,7 +1048,7 @@ get_signal_quality (MMModemCdma *modem,
at_port = mm_generic_cdma_get_best_at_port (MM_GENERIC_CDMA (modem), &info->error); at_port = mm_generic_cdma_get_best_at_port (MM_GENERIC_CDMA (modem), &info->error);
if (!at_port && !priv->qcdm) { if (!at_port && !priv->qcdm) {
g_message ("Returning saved signal quality %d", priv->cdma1x_quality); mm_dbg ("Returning saved signal quality %d", priv->cdma1x_quality);
mm_callback_info_set_result (info, GUINT_TO_POINTER (priv->cdma1x_quality), NULL); mm_callback_info_set_result (info, GUINT_TO_POINTER (priv->cdma1x_quality), NULL);
mm_callback_info_schedule (info); mm_callback_info_schedule (info);
return; return;
@@ -1876,8 +1877,8 @@ get_registration_state (MMModemCdma *modem,
port = mm_generic_cdma_get_best_at_port (MM_GENERIC_CDMA (modem), &info->error); port = mm_generic_cdma_get_best_at_port (MM_GENERIC_CDMA (modem), &info->error);
if (!port && !priv->qcdm) { if (!port && !priv->qcdm) {
g_message ("Returning saved registration states: 1x: %d EVDO: %d", mm_dbg ("Returning saved registration states: 1x: %d EVDO: %d",
priv->cdma_1x_reg_state, priv->evdo_reg_state); priv->cdma_1x_reg_state, priv->evdo_reg_state);
mm_generic_cdma_query_reg_state_set_callback_1x_state (info, priv->cdma_1x_reg_state); mm_generic_cdma_query_reg_state_set_callback_1x_state (info, priv->cdma_1x_reg_state);
mm_generic_cdma_query_reg_state_set_callback_evdo_state (info, priv->evdo_reg_state); mm_generic_cdma_query_reg_state_set_callback_evdo_state (info, priv->evdo_reg_state);
mm_callback_info_schedule (info); mm_callback_info_schedule (info);

View File

@@ -33,7 +33,7 @@
#include "mm-qcdm-serial-port.h" #include "mm-qcdm-serial-port.h"
#include "mm-serial-parsers.h" #include "mm-serial-parsers.h"
#include "mm-modem-helpers.h" #include "mm-modem-helpers.h"
#include "mm-options.h" #include "mm-log.h"
#include "mm-properties-changed-signal.h" #include "mm-properties-changed-signal.h"
#include "mm-utils.h" #include "mm-utils.h"
#include "mm-modem-location.h" #include "mm-modem-location.h"
@@ -471,10 +471,8 @@ get_iccid_done (MMModem *modem,
g_free (priv->simid); g_free (priv->simid);
priv->simid = g_strdup (g_checksum_get_string (sum)); priv->simid = g_strdup (g_checksum_get_string (sum));
if (mm_options_debug ()) { mm_dbg ("SIM ID source '%s'", response);
g_debug ("SIM ID source '%s'", response); mm_dbg ("SIM ID '%s'", priv->simid);
g_debug ("SIM ID '%s'", priv->simid);
}
g_object_notify (G_OBJECT (modem), MM_MODEM_GSM_CARD_SIM_IDENTIFIER); g_object_notify (G_OBJECT (modem), MM_MODEM_GSM_CARD_SIM_IDENTIFIER);
@@ -1306,12 +1304,9 @@ mm_generic_gsm_enable_complete (MMGenericGsm *self,
*/ */
if (priv->secondary) { if (priv->secondary) {
if (!mm_serial_port_open (MM_SERIAL_PORT (priv->secondary), &error)) { if (!mm_serial_port_open (MM_SERIAL_PORT (priv->secondary), &error)) {
if (mm_options_debug ()) { mm_dbg ("error opening secondary port: (%d) %s",
g_warning ("%s: error opening secondary port: (%d) %s", error ? error->code : -1,
__func__, error && error->message ? error->message : "(unknown)");
error ? error->code : -1,
error && error->message ? error->message : "(unknown)");
}
} }
} }
@@ -2237,7 +2232,7 @@ roam_disconnect_done (MMModem *modem,
GError *error, GError *error,
gpointer user_data) gpointer user_data)
{ {
g_message ("Disconnected because roaming is not allowed"); mm_info ("Disconnected because roaming is not allowed");
} }
static void static void
@@ -2268,9 +2263,9 @@ mm_generic_gsm_set_reg_status (MMGenericGsm *self,
if (priv->reg_status[rs_type - 1] == status) if (priv->reg_status[rs_type - 1] == status)
return; return;
g_debug ("%s registration state changed: %d", mm_dbg ("%s registration state changed: %d",
(rs_type == MM_GENERIC_GSM_REG_TYPE_CS) ? "CS" : "PS", (rs_type == MM_GENERIC_GSM_REG_TYPE_CS) ? "CS" : "PS",
status); status);
priv->reg_status[rs_type - 1] = status; priv->reg_status[rs_type - 1] = status;
port = mm_generic_gsm_get_best_at_port (self, NULL); port = mm_generic_gsm_get_best_at_port (self, NULL);
@@ -2389,11 +2384,8 @@ reg_state_changed (MMAtSerialPort *port,
GError *error = NULL; GError *error = NULL;
if (!mm_gsm_parse_creg_response (match_info, &state, &lac, &cell_id, &act, &cgreg, &error)) { if (!mm_gsm_parse_creg_response (match_info, &state, &lac, &cell_id, &act, &cgreg, &error)) {
if (mm_options_debug ()) { mm_warn ("error parsing unsolicited registration: %s",
g_warning ("%s: error parsing unsolicited registration: %s", error && error->message ? error->message : "(unknown)");
__func__,
error && error->message ? error->message : "(unknown)");
}
return; return;
} }
@@ -3891,10 +3883,8 @@ ussd_send_done (MMAtSerialPort *port,
if (reply) { if (reply) {
/* look for the reply data coding scheme */ /* look for the reply data coding scheme */
if (mm_options_debug ()) { if ((start = strrchr (end, ',')) != NULL)
if ((start = strrchr (end, ',')) != NULL) mm_dbg ("USSD data coding scheme %d", atoi (start + 1));
g_debug ("USSD data coding scheme %d", atoi (start + 1));
}
converted = mm_modem_charset_hex_to_utf8 (reply, priv->cur_charset); converted = mm_modem_charset_hex_to_utf8 (reply, priv->cur_charset);
mm_callback_info_set_result (info, converted, g_free); mm_callback_info_set_result (info, converted, g_free);
@@ -4164,6 +4154,7 @@ simple_state_machine (MMModem *modem, GError *error, gpointer user_data)
gboolean done = FALSE; gboolean done = FALSE;
MMModemGsmAllowedMode allowed_mode; MMModemGsmAllowedMode allowed_mode;
gboolean home_only = FALSE; gboolean home_only = FALSE;
char *data_device;
info->error = mm_modem_check_removed (modem, error); info->error = mm_modem_check_removed (modem, error);
if (info->error) if (info->error)
@@ -4171,16 +4162,9 @@ simple_state_machine (MMModem *modem, GError *error, gpointer user_data)
priv = MM_GENERIC_GSM_GET_PRIVATE (modem); priv = MM_GENERIC_GSM_GET_PRIVATE (modem);
if (mm_options_debug ()) { g_object_get (G_OBJECT (modem), MM_MODEM_DATA_DEVICE, &data_device, NULL);
GTimeVal tv; mm_dbg ("(%s): simple connect state %d", data_device, state);
char *data_device; g_free (data_device);
g_object_get (G_OBJECT (modem), MM_MODEM_DATA_DEVICE, &data_device, NULL);
g_get_current_time (&tv);
g_debug ("<%ld.%ld> (%s): simple connect state %d",
tv.tv_sec, tv.tv_usec, data_device, state);
g_free (data_device);
}
switch (state) { switch (state) {
case SIMPLE_STATE_CHECK_PIN: case SIMPLE_STATE_CHECK_PIN:
@@ -4279,29 +4263,21 @@ simple_connect (MMModemSimple *simple,
gpointer user_data) gpointer user_data)
{ {
MMCallbackInfo *info; MMCallbackInfo *info;
GHashTableIter iter;
gpointer key, value;
char *data_device;
/* If debugging, list all the simple connect properties */ /* List simple connect properties when debugging */
if (mm_options_debug ()) { g_object_get (G_OBJECT (simple), MM_MODEM_DATA_DEVICE, &data_device, NULL);
GHashTableIter iter; g_hash_table_iter_init (&iter, properties);
gpointer key, value; while (g_hash_table_iter_next (&iter, &key, &value)) {
GTimeVal tv; char *val_str;
char *data_device;
g_object_get (G_OBJECT (simple), MM_MODEM_DATA_DEVICE, &data_device, NULL); val_str = g_strdup_value_contents ((GValue *) value);
g_get_current_time (&tv); mm_dbg ("(%s): %s => %s", data_device, (const char *) key, val_str);
g_free (val_str);
g_hash_table_iter_init (&iter, properties);
while (g_hash_table_iter_next (&iter, &key, &value)) {
char *val_str;
val_str = g_strdup_value_contents ((GValue *) value);
g_debug ("<%ld.%ld> (%s): %s => %s",
tv.tv_sec, tv.tv_usec,
data_device, (const char *) key, val_str);
g_free (val_str);
}
g_free (data_device);
} }
g_free (data_device);
info = mm_callback_info_new (MM_MODEM (simple), callback, user_data); info = mm_callback_info_new (MM_MODEM (simple), callback, user_data);
mm_callback_info_set_data (info, "simple-connect-properties", mm_callback_info_set_data (info, "simple-connect-properties",

227
src/mm-log.c Normal file
View File

@@ -0,0 +1,227 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
*
* Copyright (C) 2011 Red Hat, Inc.
*/
#define _GNU_SOURCE
#include <config.h>
#include <stdio.h>
#include <syslog.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <unistd.h>
#include "mm-log.h"
enum {
TS_FLAG_NONE = 0,
TS_FLAG_WALL,
TS_FLAG_REL
};
static gboolean ts_flags = TS_FLAG_NONE;
static guint32 log_level = LOGL_INFO | LOGL_WARN | LOGL_ERR;
static GTimeVal rel_start = { 0, 0 };
static int logfd = -1;
typedef struct {
guint32 num;
const char *name;
} LogDesc;
static const LogDesc level_descs[] = {
{ LOGL_ERR, "ERR" },
{ LOGL_WARN | LOGL_ERR, "WARN" },
{ LOGL_INFO | LOGL_WARN | LOGL_ERR, "INFO" },
{ LOGL_DEBUG | LOGL_INFO | LOGL_WARN | LOGL_ERR, "DEBUG" },
{ 0, NULL }
};
void
_mm_log (const char *loc,
const char *func,
guint32 level,
const char *fmt,
...)
{
va_list args;
char *msg;
GTimeVal tv;
char tsbuf[100] = { 0 };
char msgbuf[512] = { 0 };
int syslog_priority = LOG_INFO;
const char *prefix = NULL;
if (!(log_level & level))
return;
va_start (args, fmt);
msg = g_strdup_vprintf (fmt, args);
va_end (args);
if (ts_flags == TS_FLAG_WALL) {
g_get_current_time (&tv);
snprintf (&tsbuf[0], sizeof (tsbuf), " [%09ld.%06ld]", tv.tv_sec, tv.tv_usec);
} else if (ts_flags == TS_FLAG_REL) {
time_t secs;
suseconds_t usecs;
g_get_current_time (&tv);
secs = tv.tv_sec - rel_start.tv_sec;
usecs = tv.tv_usec - rel_start.tv_usec;
if (usecs < 0) {
secs--;
usecs += 1000000;
}
snprintf (&tsbuf[0], sizeof (tsbuf), " [%06ld.%06ld]", secs, usecs);
}
if ((log_level & LOGL_DEBUG) && (level == LOGL_DEBUG))
prefix = "debug";
else if ((log_level & LOGL_INFO) && (level == LOGL_INFO))
prefix = "info";
else if ((log_level & LOGL_WARN) && (level == LOGL_WARN)) {
prefix = "warn";
syslog_priority = LOG_WARNING;
} else if ((log_level & LOGL_ERR) && (level == LOGL_ERR)) {
prefix = "err";
syslog_priority = LOG_ERR;
} else
g_warn_if_reached ();
if (prefix) {
if (log_level & LOGL_DEBUG)
snprintf (msgbuf, sizeof (msgbuf), "<%s>%s [%s] %s(): %s\n", prefix, tsbuf, loc, func, msg);
else
snprintf (msgbuf, sizeof (msgbuf), "<%s>%s %s\n", prefix, tsbuf, msg);
if (logfd < 0)
syslog (syslog_priority, "%s", msgbuf);
else {
write (logfd, msgbuf, strlen (msgbuf));
fsync (logfd); /* Make sure output is dumped to disk immediately */
}
}
g_free (msg);
}
static void
log_handler (const gchar *log_domain,
GLogLevelFlags level,
const gchar *message,
gpointer ignored)
{
int syslog_priority;
switch (level) {
case G_LOG_LEVEL_ERROR:
syslog_priority = LOG_CRIT;
break;
case G_LOG_LEVEL_CRITICAL:
syslog_priority = LOG_ERR;
break;
case G_LOG_LEVEL_WARNING:
syslog_priority = LOG_WARNING;
break;
case G_LOG_LEVEL_MESSAGE:
syslog_priority = LOG_NOTICE;
break;
case G_LOG_LEVEL_DEBUG:
syslog_priority = LOG_DEBUG;
break;
case G_LOG_LEVEL_INFO:
default:
syslog_priority = LOG_INFO;
break;
}
if (logfd < 0)
syslog (syslog_priority, "%s", message);
else
write (logfd, message, strlen (message));
}
gboolean
mm_log_setup (const char *level,
const char *log_file,
gboolean show_timestamps,
gboolean rel_timestamps,
GError **error)
{
/* levels */
if (level && strlen (level)) {
gboolean found = FALSE;
const LogDesc *diter;
for (diter = &level_descs[0]; diter->name; diter++) {
if (!strcasecmp (diter->name, level)) {
log_level = diter->num;
found = TRUE;
break;
}
}
if (!found) {
g_set_error (error, 0, 0, "Unknown log level '%s'", level);
return FALSE;
}
}
if (show_timestamps)
ts_flags = TS_FLAG_WALL;
else if (rel_timestamps)
ts_flags = TS_FLAG_REL;
/* Grab start time for relative timestamps */
g_get_current_time (&rel_start);
if (log_file == NULL)
openlog (G_LOG_DOMAIN, LOG_CONS | LOG_PID | LOG_PERROR, LOG_DAEMON);
else {
logfd = open (log_file,
O_CREAT | O_APPEND | O_WRONLY,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
if (logfd < 0) {
g_set_error (error, 0, 0, "Failed to open log file: (%d) %s",
errno, strerror (errno));
return FALSE;
}
}
g_log_set_handler (G_LOG_DOMAIN,
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
log_handler,
NULL);
return TRUE;
}
void
mm_log_usr1 (void)
{
}
void
mm_log_shutdown (void)
{
if (logfd < 0)
closelog ();
else
close (logfd);
}

61
src/mm-log.h Normal file
View File

@@ -0,0 +1,61 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
*
* Copyright (C) 2011 Red Hat, Inc.
*/
#ifndef MM_LOG_H
#define MM_LOG_H
#include <glib.h>
/* Log levels */
enum {
LOGL_ERR = 0x00000001,
LOGL_WARN = 0x00000002,
LOGL_INFO = 0x00000004,
LOGL_DEBUG = 0x00000008
};
#define mm_err(...) \
_mm_log (G_STRLOC, G_STRFUNC, LOGL_ERR, ## __VA_ARGS__ )
#define mm_warn(...) \
_mm_log (G_STRLOC, G_STRFUNC, LOGL_WARN, ## __VA_ARGS__ )
#define mm_info(...) \
_mm_log (G_STRLOC, G_STRFUNC, LOGL_INFO, ## __VA_ARGS__ )
#define mm_dbg(...) \
_mm_log (G_STRLOC, G_STRFUNC, LOGL_DEBUG, ## __VA_ARGS__ )
#define mm_log(level, ...) \
_mm_log (G_STRLOC, G_STRFUNC, level, ## __VA_ARGS__ )
void _mm_log (const char *loc,
const char *func,
guint32 level,
const char *fmt,
...) __attribute__((__format__ (__printf__, 4, 5)));
gboolean mm_log_setup (const char *level,
const char *log_file,
gboolean show_ts,
gboolean rel_ts,
GError **error);
void mm_log_usr1 (void);
void mm_log_shutdown (void);
#endif /* MM_LOG_H */

View File

@@ -24,6 +24,7 @@
#include "mm-manager.h" #include "mm-manager.h"
#include "mm-errors.h" #include "mm-errors.h"
#include "mm-plugin.h" #include "mm-plugin.h"
#include "mm-log.h"
static gboolean impl_manager_enumerate_devices (MMManager *manager, static gboolean impl_manager_enumerate_devices (MMManager *manager,
GPtrArray **devices, GPtrArray **devices,
@@ -112,9 +113,9 @@ load_plugin (const char *path)
plugin = (*plugin_create_func) (); plugin = (*plugin_create_func) ();
if (plugin) { if (plugin) {
g_object_weak_ref (G_OBJECT (plugin), (GWeakNotify) g_module_close, module); g_object_weak_ref (G_OBJECT (plugin), (GWeakNotify) g_module_close, module);
g_message ("Loaded plugin %s", mm_plugin_get_name (plugin)); mm_info ("Loaded plugin %s", mm_plugin_get_name (plugin));
} else } else
g_warning ("Could not load plugin %s: initialization failed", path); mm_warn ("Could not load plugin %s: initialization failed", path);
out: out:
if (!plugin) if (!plugin)
@@ -196,7 +197,7 @@ remove_modem (MMManager *manager, MMModem *modem)
device = mm_modem_get_device (modem); device = mm_modem_get_device (modem);
g_assert (device); g_assert (device);
g_debug ("Removed modem %s", device); mm_dbg ("Removed modem %s", device);
g_signal_emit (manager, signals[DEVICE_REMOVED], 0, modem); g_signal_emit (manager, signals[DEVICE_REMOVED], 0, modem);
g_hash_table_remove (priv->modems, device); g_hash_table_remove (priv->modems, device);
@@ -234,8 +235,8 @@ check_export_modem (MMManager *self, MMModem *modem)
SupportsInfo *info = value; SupportsInfo *info = value;
if (!strcmp (info->physdev_path, modem_physdev)) { if (!strcmp (info->physdev_path, modem_physdev)) {
g_debug ("(%s/%s): outstanding support task prevents export of %s", mm_dbg ("(%s/%s): outstanding support task prevents export of %s",
info->subsys, info->name, modem_physdev); info->subsys, info->name, modem_physdev);
goto out; goto out;
} }
} }
@@ -257,7 +258,7 @@ check_export_modem (MMManager *self, MMModem *modem)
dbus_g_connection_register_g_object (priv->connection, path, G_OBJECT (modem)); dbus_g_connection_register_g_object (priv->connection, path, G_OBJECT (modem));
g_object_set_data_full (G_OBJECT (modem), DBUS_PATH_TAG, path, (GDestroyNotify) g_free); g_object_set_data_full (G_OBJECT (modem), DBUS_PATH_TAG, path, (GDestroyNotify) g_free);
g_debug ("Exported modem %s as %s", modem_physdev, path); mm_dbg ("Exported modem %s as %s", modem_physdev, path);
physdev = g_udev_client_query_by_sysfs_path (priv->udev, modem_physdev); physdev = g_udev_client_query_by_sysfs_path (priv->udev, modem_physdev);
if (physdev) if (physdev)
@@ -268,10 +269,10 @@ check_export_modem (MMManager *self, MMModem *modem)
MM_MODEM_HW_VID, &vid, MM_MODEM_HW_VID, &vid,
MM_MODEM_HW_PID, &pid, MM_MODEM_HW_PID, &pid,
NULL); NULL);
g_debug ("(%s): VID 0x%04X PID 0x%04X (%s)", mm_dbg ("(%s): VID 0x%04X PID 0x%04X (%s)",
path, (vid & 0xFFFF), (pid & 0xFFFF), path, (vid & 0xFFFF), (pid & 0xFFFF),
subsys ? subsys : "unknown"); subsys ? subsys : "unknown");
g_debug ("(%s): data port is %s", path, data_device); mm_dbg ("(%s): data port is %s", path, data_device);
g_free (data_device); g_free (data_device);
if (physdev) if (physdev)
@@ -309,7 +310,7 @@ add_modem (MMManager *manager, MMModem *modem, MMPlugin *plugin)
g_hash_table_insert (priv->modems, g_strdup (device), modem); g_hash_table_insert (priv->modems, g_strdup (device), modem);
g_object_set_data (G_OBJECT (modem), MANAGER_PLUGIN_TAG, plugin); g_object_set_data (G_OBJECT (modem), MANAGER_PLUGIN_TAG, plugin);
g_debug ("Added modem %s", device); mm_dbg ("Added modem %s", device);
g_signal_connect (modem, "notify::" MM_MODEM_VALID, G_CALLBACK (modem_valid), manager); g_signal_connect (modem, "notify::" MM_MODEM_VALID, G_CALLBACK (modem_valid), manager);
check_export_modem (manager, modem); check_export_modem (manager, modem);
} }
@@ -446,7 +447,7 @@ supports_defer_timeout (gpointer user_data)
existing = find_modem_for_device (info->manager, info->physdev_path); existing = find_modem_for_device (info->manager, info->physdev_path);
g_debug ("(%s): re-checking support...", info->name); mm_dbg ("(%s): re-checking support...", info->name);
try_supports_port (info->manager, try_supports_port (info->manager,
MM_PLUGIN (info->cur_plugin->data), MM_PLUGIN (info->cur_plugin->data),
existing, existing,
@@ -478,9 +479,9 @@ try_supports_port (MMManager *manager,
supports_callback (plugin, info->subsys, info->name, 0, info); supports_callback (plugin, info->subsys, info->name, 0, info);
break; break;
case MM_PLUGIN_SUPPORTS_PORT_DEFER: case MM_PLUGIN_SUPPORTS_PORT_DEFER:
g_debug ("(%s): (%s) deferring support check", mm_dbg ("(%s): (%s) deferring support check",
mm_plugin_get_name (plugin), mm_plugin_get_name (plugin),
info->name); info->name);
if (info->defer_id) if (info->defer_id)
g_source_remove (info->defer_id); g_source_remove (info->defer_id);
@@ -549,22 +550,21 @@ do_grab_port (gpointer user_data)
type_name = "CDMA"; type_name = "CDMA";
device = mm_modem_get_device (modem); device = mm_modem_get_device (modem);
g_message ("(%s): %s modem %s claimed port %s", mm_info ("(%s): %s modem %s claimed port %s",
mm_plugin_get_name (info->best_plugin), mm_plugin_get_name (info->best_plugin),
type_name, type_name,
device, device,
info->name); info->name);
g_free (device); g_free (device);
add_modem (info->manager, modem, info->best_plugin); add_modem (info->manager, modem, info->best_plugin);
} else { } else {
g_warning ("%s: plugin '%s' claimed to support %s/%s but couldn't: (%d) %s", mm_warn ("plugin '%s' claimed to support %s/%s but couldn't: (%d) %s",
__func__, mm_plugin_get_name (info->best_plugin),
mm_plugin_get_name (info->best_plugin), info->subsys,
info->subsys, info->name,
info->name, error ? error->code : -1,
error ? error->code : -1, (error && error->message) ? error->message : "(unknown)");
(error && error->message) ? error->message : "(unknown)");
modem = existing; modem = existing;
} }
} }
@@ -613,8 +613,8 @@ supports_callback (MMPlugin *plugin,
* support this port, but this plugin is clearly the right plugin * support this port, but this plugin is clearly the right plugin
* since it claimed this port's physical modem, just drop the port. * since it claimed this port's physical modem, just drop the port.
*/ */
g_debug ("(%s/%s): ignoring port unsupported by physical modem's plugin", mm_dbg ("(%s/%s): ignoring port unsupported by physical modem's plugin",
info->subsys, info->name); info->subsys, info->name);
supports_cleanup (info->manager, info->subsys, info->name, existing); supports_cleanup (info->manager, info->subsys, info->name, existing);
return; return;
} }
@@ -631,14 +631,14 @@ supports_callback (MMPlugin *plugin,
*/ */
next_plugin = existing_plugin; next_plugin = existing_plugin;
} else { } else {
g_debug ("(%s/%s): plugin %p (%s) existing %p (%s) info->best %p (%s)", mm_dbg ("(%s/%s): plugin %p (%s) existing %p (%s) info->best %p (%s)",
info->subsys, info->name, info->subsys, info->name,
plugin, plugin,
plugin ? mm_plugin_get_name (plugin) : "none", plugin ? mm_plugin_get_name (plugin) : "none",
existing_plugin, existing_plugin,
existing_plugin ? mm_plugin_get_name (existing_plugin) : "none", existing_plugin ? mm_plugin_get_name (existing_plugin) : "none",
info->best_plugin, info->best_plugin,
info->best_plugin ? mm_plugin_get_name (info->best_plugin) : "none"); info->best_plugin ? mm_plugin_get_name (info->best_plugin) : "none");
g_assert_not_reached (); g_assert_not_reached ();
} }
} else { } else {
@@ -783,14 +783,14 @@ device_added (MMManager *manager, GUdevDevice *device)
&& strcmp (name, "lo") && strcmp (name, "lo")
&& strcmp (name, "tty") && strcmp (name, "tty")
&& !strstr (name, "virbr")) && !strstr (name, "virbr"))
g_debug ("(%s/%s): could not get port's parent device", subsys, name); mm_dbg ("(%s/%s): could not get port's parent device", subsys, name);
goto out; goto out;
} }
/* Is the device blacklisted? */ /* Is the device blacklisted? */
if (g_udev_device_get_property_as_boolean (physdev, "ID_MM_DEVICE_IGNORE")) { if (g_udev_device_get_property_as_boolean (physdev, "ID_MM_DEVICE_IGNORE")) {
g_debug ("(%s/%s): port's parent device is blacklisted", subsys, name); mm_dbg ("(%s/%s): port's parent device is blacklisted", subsys, name);
goto out; goto out;
} }
@@ -799,13 +799,13 @@ device_added (MMManager *manager, GUdevDevice *device)
if ( physdev_subsys if ( physdev_subsys
&& !strcmp (physdev_subsys, "platform") && !strcmp (physdev_subsys, "platform")
&& !g_udev_device_get_property_as_boolean (physdev, "ID_MM_PLATFORM_DRIVER_PROBE")) { && !g_udev_device_get_property_as_boolean (physdev, "ID_MM_PLATFORM_DRIVER_PROBE")) {
g_debug ("(%s/%s): port's parent platform driver is not whitelisted", subsys, name); mm_dbg ("(%s/%s): port's parent platform driver is not whitelisted", subsys, name);
goto out; goto out;
} }
physdev_path = g_udev_device_get_sysfs_path (physdev); physdev_path = g_udev_device_get_sysfs_path (physdev);
if (!physdev_path) { if (!physdev_path) {
g_debug ("(%s/%s): could not get port's parent device sysfs path", subsys, name); mm_dbg ("(%s/%s): could not get port's parent device sysfs path", subsys, name);
goto out; goto out;
} }
@@ -865,10 +865,10 @@ device_removed (MMManager *manager, GUdevDevice *device)
*/ */
const char *sysfs_path = g_udev_device_get_sysfs_path (device); const char *sysfs_path = g_udev_device_get_sysfs_path (device);
// g_debug ("Looking for a modem for removed device %s", sysfs_path); // mm_dbg ("Looking for a modem for removed device %s", sysfs_path);
modem = find_modem_for_device (manager, sysfs_path); modem = find_modem_for_device (manager, sysfs_path);
if (modem) { if (modem) {
g_debug ("Removing modem claimed by removed device %s", sysfs_path); mm_dbg ("Removing modem claimed by removed device %s", sysfs_path);
remove_modem (manager, modem); remove_modem (manager, modem);
return; return;
} }

View File

@@ -25,7 +25,7 @@
#include "mm-at-serial-port.h" #include "mm-at-serial-port.h"
#include "mm-qcdm-serial-port.h" #include "mm-qcdm-serial-port.h"
#include "mm-errors.h" #include "mm-errors.h"
#include "mm-options.h" #include "mm-log.h"
#include "mm-properties-changed-signal.h" #include "mm-properties-changed-signal.h"
#include "mm-callback-info.h" #include "mm-callback-info.h"
#include "mm-modem-helpers.h" #include "mm-modem-helpers.h"
@@ -148,15 +148,13 @@ mm_modem_base_add_port (MMModemBase *self,
if (!port) if (!port)
return NULL; return NULL;
if (mm_options_debug ()) { device = mm_modem_get_device (MM_MODEM (self));
device = mm_modem_get_device (MM_MODEM (self)); mm_dbg ("(%s) type %s claimed by %s",
name,
mm_port_type_to_name (ptype),
device);
g_free (device);
g_message ("(%s) type %s claimed by %s",
name,
mm_port_type_to_name (ptype),
device);
g_free (device);
}
key = get_hash_key (subsys, name); key = get_hash_key (subsys, name);
g_hash_table_insert (priv->ports, key, port); g_hash_table_insert (priv->ports, key, port);
return port; return port;
@@ -233,9 +231,9 @@ mm_modem_base_set_equipment_identifier (MMModemBase *self, const char *ident)
dbus_path = (const char *) g_object_get_data (G_OBJECT (self), DBUS_PATH_TAG); dbus_path = (const char *) g_object_get_data (G_OBJECT (self), DBUS_PATH_TAG);
if (dbus_path) { if (dbus_path) {
if (priv->equipment_ident) if (priv->equipment_ident)
g_message ("Modem %s: Equipment identifier set (%s)", dbus_path, priv->equipment_ident); mm_info ("Modem %s: Equipment identifier set (%s)", dbus_path, priv->equipment_ident);
else else
g_message ("Modem %s: Equipment identifier not set", dbus_path); mm_warn ("Modem %s: Equipment identifier not set", dbus_path);
} }
g_object_notify (G_OBJECT (self), MM_MODEM_EQUIPMENT_IDENTIFIER); g_object_notify (G_OBJECT (self), MM_MODEM_EQUIPMENT_IDENTIFIER);
@@ -274,9 +272,9 @@ mm_modem_base_set_unlock_required (MMModemBase *self, const char *unlock_require
dbus_path = (const char *) g_object_get_data (G_OBJECT (self), DBUS_PATH_TAG); dbus_path = (const char *) g_object_get_data (G_OBJECT (self), DBUS_PATH_TAG);
if (dbus_path) { if (dbus_path) {
if (priv->unlock_required) if (priv->unlock_required)
g_message ("Modem %s: unlock required (%s)", dbus_path, priv->unlock_required); mm_info ("Modem %s: unlock required (%s)", dbus_path, priv->unlock_required);
else else
g_message ("Modem %s: unlock no longer required", dbus_path); mm_info ("Modem %s: unlock no longer required", dbus_path);
} }
g_object_notify (G_OBJECT (self), MM_MODEM_UNLOCK_REQUIRED); g_object_notify (G_OBJECT (self), MM_MODEM_UNLOCK_REQUIRED);
@@ -311,11 +309,11 @@ mm_modem_base_set_unlock_retries (MMModemBase *self, guint unlock_retries)
dbus_path = (const char *) g_object_get_data (G_OBJECT (self), DBUS_PATH_TAG); dbus_path = (const char *) g_object_get_data (G_OBJECT (self), DBUS_PATH_TAG);
if (dbus_path) { if (dbus_path) {
if (priv->unlock_required) { if (priv->unlock_required) {
g_message ("Modem %s: # unlock retries for %s is %d", mm_info ("Modem %s: # unlock retries for %s is %d",
dbus_path, priv->unlock_required, priv->unlock_retries); dbus_path, priv->unlock_required, priv->unlock_retries);
} else { } else {
g_message ("Modem %s: # unlock retries is %d", mm_info ("Modem %s: # unlock retries is %d",
dbus_path, priv->unlock_retries); dbus_path, priv->unlock_retries);
} }
} }
@@ -446,8 +444,7 @@ card_info_cache_invoke (MMCallbackInfo *info)
priv->gsn, priv->gsn,
priv->revision, priv->revision,
priv->model, priv->model,
priv->manf, priv->manf);
mm_options_debug ());
g_object_notify (G_OBJECT (self), MM_MODEM_DEVICE_IDENTIFIER); g_object_notify (G_OBJECT (self), MM_MODEM_DEVICE_IDENTIFIER);
callback (info->modem, priv->manf, priv->model, priv->revision, info->error, info->user_data); callback (info->modem, priv->manf, priv->model, priv->revision, info->error, info->user_data);

View File

@@ -25,6 +25,7 @@
#include "mm-errors.h" #include "mm-errors.h"
#include "mm-modem-helpers.h" #include "mm-modem-helpers.h"
#include "mm-log.h"
const char * const char *
mm_strip_tag (const char *str, const char *cmd) mm_strip_tag (const char *str, const char *cmd)
@@ -829,10 +830,9 @@ mm_create_device_identifier (guint vid,
const char *gsn, const char *gsn,
const char *revision, const char *revision,
const char *model, const char *model,
const char *manf, const char *manf)
gboolean debug)
{ {
GString *devid, *dbg = NULL; GString *devid, *msg = NULL;
GChecksum *sum; GChecksum *sum;
char *p, *ret = NULL; char *p, *ret = NULL;
char str_vid[10], str_pid[10]; char str_vid[10], str_pid[10];
@@ -859,41 +859,35 @@ mm_create_device_identifier (guint vid,
return NULL; return NULL;
p = devid->str; p = devid->str;
if (debug) msg = g_string_sized_new (strlen (devid->str) + 17);
dbg = 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) {
snprintf (str_vid, sizeof (str_vid) - 1, "%08x", vid); snprintf (str_vid, sizeof (str_vid) - 1, "%08x", vid);
g_checksum_update (sum, (const guchar *) &str_vid[0], strlen (str_vid)); g_checksum_update (sum, (const guchar *) &str_vid[0], strlen (str_vid));
if (dbg) g_string_append_printf (msg, "%08x", vid);
g_string_append_printf (dbg, "%08x", vid);
} }
if (vid) { if (vid) {
snprintf (str_pid, sizeof (str_pid) - 1, "%08x", pid); snprintf (str_pid, sizeof (str_pid) - 1, "%08x", pid);
g_checksum_update (sum, (const guchar *) &str_pid[0], strlen (str_pid)); g_checksum_update (sum, (const guchar *) &str_pid[0], strlen (str_pid));
if (dbg) g_string_append_printf (msg, "%08x", pid);
g_string_append_printf (dbg, "%08x", pid);
} }
while (*p) { while (*p) {
/* Strip spaces and linebreaks */ /* Strip spaces and linebreaks */
if (!isblank (*p) && !isspace (*p) && isascii (*p)) { if (!isblank (*p) && !isspace (*p) && isascii (*p)) {
g_checksum_update (sum, (const guchar *) p, 1); g_checksum_update (sum, (const guchar *) p, 1);
if (dbg) g_string_append_c (msg, *p);
g_string_append_c (dbg, *p);
} }
p++; p++;
} }
ret = g_strdup (g_checksum_get_string (sum)); ret = g_strdup (g_checksum_get_string (sum));
g_checksum_free (sum); g_checksum_free (sum);
if (dbg) { mm_dbg ("Device ID source '%s'", msg->str);
g_debug ("Device ID source '%s'", dbg->str); mm_dbg ("Device ID '%s'", ret);
g_debug ("Device ID '%s'", ret); g_string_free (msg, TRUE);
g_string_free (dbg, TRUE);
}
return ret; return ret;
} }

View File

@@ -66,8 +66,7 @@ char *mm_create_device_identifier (guint vid,
const char *gsn, const char *gsn,
const char *revision, const char *revision,
const char *model, const char *model,
const char *manf, const char *manf);
gboolean debug);
typedef struct CindResponse CindResponse; typedef struct CindResponse CindResponse;
GHashTable *mm_parse_cind_test_response (const char *reply, GError **error); GHashTable *mm_parse_cind_test_response (const char *reply, GError **error);

View File

@@ -18,7 +18,7 @@
#include <string.h> #include <string.h>
#include <dbus/dbus-glib.h> #include <dbus/dbus-glib.h>
#include "mm-modem.h" #include "mm-modem.h"
#include "mm-options.h" #include "mm-log.h"
#include "mm-errors.h" #include "mm-errors.h"
#include "mm-callback-info.h" #include "mm-callback-info.h"
#include "mm-marshal.h" #include "mm-marshal.h"
@@ -755,22 +755,10 @@ mm_modem_set_state (MMModem *self,
dbus_path = (const char *) g_object_get_data (G_OBJECT (self), DBUS_PATH_TAG); dbus_path = (const char *) g_object_get_data (G_OBJECT (self), DBUS_PATH_TAG);
if (dbus_path) { if (dbus_path) {
if (mm_options_debug ()) { mm_info ("Modem %s: state changed (%s -> %s)",
GTimeVal tv; dbus_path,
state_to_string (old_state),
g_get_current_time (&tv); state_to_string (new_state));
g_debug ("<%ld.%ld> Modem %s: state changed (%s -> %s)",
tv.tv_sec,
tv.tv_usec,
dbus_path,
state_to_string (old_state),
state_to_string (new_state));
} else {
g_message ("Modem %s: state changed (%s -> %s)",
dbus_path,
state_to_string (old_state),
state_to_string (new_state));
}
} }
} }
} }

View File

@@ -1,55 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
*
* Copyright (C) 2008 Novell, Inc.
*/
#include <stdlib.h>
#include <glib.h>
#include "mm-options.h"
static gboolean debug = FALSE;
void
mm_options_parse (int argc, char *argv[])
{
GOptionContext *opt_ctx;
GError *error = NULL;
GOptionEntry entries[] = {
{ "debug", 0, 0, G_OPTION_ARG_NONE, &debug, "Output to console rather than syslog", NULL },
{ NULL }
};
opt_ctx = g_option_context_new (NULL);
g_option_context_set_summary (opt_ctx, "DBus system service to communicate with modems.");
g_option_context_add_main_entries (opt_ctx, entries, NULL);
if (!g_option_context_parse (opt_ctx, &argc, &argv, &error)) {
g_warning ("%s\n", error->message);
g_error_free (error);
exit (1);
}
g_option_context_free (opt_ctx);
}
void
mm_options_set_debug (gboolean enabled)
{
debug = enabled;
}
gboolean
mm_options_debug (void)
{
return debug;
}

View File

@@ -1,23 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
*
* Copyright (C) 2008 Novell, Inc.
*/
#ifndef MM_OPTIONS_H
#define MM_OPTIONS_H
void mm_options_parse (int argc, char *argv[]);
void mm_options_set_debug (gboolean enabled);
gboolean mm_options_debug (void);
#endif /* MM_OPTIONS_H */

View File

@@ -36,6 +36,7 @@
#include "mm-utils.h" #include "mm-utils.h"
#include "libqcdm/src/commands.h" #include "libqcdm/src/commands.h"
#include "libqcdm/src/utils.h" #include "libqcdm/src/utils.h"
#include "mm-log.h"
static void plugin_init (MMPlugin *plugin_class); static void plugin_init (MMPlugin *plugin_class);
@@ -807,9 +808,9 @@ try_open (gpointer user_data)
task_priv->full_id = g_signal_connect (task_priv->probe_port, "buffer-full", task_priv->full_id = g_signal_connect (task_priv->probe_port, "buffer-full",
G_CALLBACK (port_buffer_full), task); G_CALLBACK (port_buffer_full), task);
g_debug ("(%s): probe requested by plugin '%s'", mm_dbg ("(%s): probe requested by plugin '%s'",
g_udev_device_get_name (port), g_udev_device_get_name (port),
mm_plugin_get_name (MM_PLUGIN (task_priv->plugin))); mm_plugin_get_name (MM_PLUGIN (task_priv->plugin)));
mm_serial_port_flash (MM_SERIAL_PORT (task_priv->probe_port), 100, TRUE, flash_done, task); mm_serial_port_flash (MM_SERIAL_PORT (task_priv->probe_port), 100, TRUE, flash_done, task);
} }

View File

@@ -19,7 +19,7 @@
#include <string.h> #include <string.h>
#include "mm-port.h" #include "mm-port.h"
#include "mm-options.h" #include "mm-log.h"
G_DEFINE_TYPE (MMPort, mm_port, G_TYPE_OBJECT) G_DEFINE_TYPE (MMPort, mm_port, G_TYPE_OBJECT)
@@ -161,16 +161,10 @@ mm_port_set_connected (MMPort *self, gboolean connected)
if (priv->connected != connected) { if (priv->connected != connected) {
priv->connected = connected; priv->connected = connected;
g_object_notify (G_OBJECT (self), MM_PORT_CONNECTED); g_object_notify (G_OBJECT (self), MM_PORT_CONNECTED);
if (mm_options_debug()) {
GTimeVal tv;
g_get_current_time (&tv); mm_dbg ("(%s): port now %s",
g_debug ("<%ld.%ld> (%s): port now %s", priv->device,
tv.tv_sec, connected ? "connected" : "disconnected");
tv.tv_usec,
priv->device,
connected ? "connected" : "disconnected");
}
} }
} }

View File

@@ -21,6 +21,7 @@
#include "mm-marshal.h" #include "mm-marshal.h"
#include "mm-properties-changed-signal.h" #include "mm-properties-changed-signal.h"
#include "mm-properties-changed-glue.h" #include "mm-properties-changed-glue.h"
#include "mm-log.h"
#define DBUS_TYPE_G_MAP_OF_VARIANT (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE)) #define DBUS_TYPE_G_MAP_OF_VARIANT (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
#define DBUS_TYPE_G_ARRAY_OF_STRING (dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRING)) #define DBUS_TYPE_G_ARRAY_OF_STRING (dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRING))
@@ -150,10 +151,10 @@ properties_changed (gpointer data)
{ {
char buf[2048] = { 0, }; char buf[2048] = { 0, };
g_hash_table_foreach (props, add_to_string, &buf); g_hash_table_foreach (props, add_to_string, &buf);
g_message ("%s: %s -> (%s) %s", __func__, mm_dbg ("%s: %s -> (%s) %s", __func__,
G_OBJECT_TYPE_NAME (object), G_OBJECT_TYPE_NAME (object),
interface, interface,
buf); buf);
} }
#endif #endif

View File

@@ -21,9 +21,9 @@
#include "mm-qcdm-serial-port.h" #include "mm-qcdm-serial-port.h"
#include "mm-errors.h" #include "mm-errors.h"
#include "mm-options.h"
#include "libqcdm/src/com.h" #include "libqcdm/src/com.h"
#include "libqcdm/src/utils.h" #include "libqcdm/src/utils.h"
#include "mm-log.h"
G_DEFINE_TYPE (MMQcdmSerialPort, mm_qcdm_serial_port, MM_TYPE_SERIAL_PORT) G_DEFINE_TYPE (MMQcdmSerialPort, mm_qcdm_serial_port, MM_TYPE_SERIAL_PORT)
@@ -182,7 +182,6 @@ debug_log (MMSerialPort *port, const char *prefix, const char *buf, gsize len)
{ {
static GString *debug = NULL; static GString *debug = NULL;
const char *s = buf; const char *s = buf;
GTimeVal tv;
if (!debug) if (!debug)
debug = g_string_sized_new (512); debug = g_string_sized_new (512);
@@ -192,12 +191,7 @@ debug_log (MMSerialPort *port, const char *prefix, const char *buf, gsize len)
while (len--) while (len--)
g_string_append_printf (debug, " %02x", (guint8) (*s++ & 0xFF)); g_string_append_printf (debug, " %02x", (guint8) (*s++ & 0xFF));
g_get_current_time (&tv); mm_dbg ("(%s): %s", mm_port_get_device (MM_PORT (port)), debug->str);
g_debug ("<%ld.%ld> (%s): %s",
tv.tv_sec,
tv.tv_usec,
mm_port_get_device (MM_PORT (port)),
debug->str);
g_string_truncate (debug, 0); g_string_truncate (debug, 0);
} }

View File

@@ -19,6 +19,7 @@
#include "mm-serial-parsers.h" #include "mm-serial-parsers.h"
#include "mm-errors.h" #include "mm-errors.h"
#include "mm-log.h"
/* Clean up the response by removing control characters like <CR><LF> etc */ /* Clean up the response by removing control characters like <CR><LF> etc */
static void static void
@@ -174,7 +175,7 @@ mm_serial_parser_v0_parse (gpointer data,
response_clean (response); response_clean (response);
if (local_error) { if (local_error) {
g_debug ("Got failure code %d: %s", local_error->code, local_error->message); mm_dbg ("Got failure code %d: %s", local_error->code, local_error->message);
g_propagate_error (error, local_error); g_propagate_error (error, local_error);
} }
@@ -336,7 +337,7 @@ done:
response_clean (response); response_clean (response);
if (local_error) { if (local_error) {
g_debug ("Got failure code %d: %s", local_error->code, local_error->message); mm_dbg ("Got failure code %d: %s", local_error->code, local_error->message);
g_propagate_error (error, local_error); g_propagate_error (error, local_error);
} }

View File

@@ -30,7 +30,7 @@
#include "mm-serial-port.h" #include "mm-serial-port.h"
#include "mm-errors.h" #include "mm-errors.h"
#include "mm-options.h" #include "mm-log.h"
static gboolean mm_serial_port_queue_process (gpointer data); static gboolean mm_serial_port_queue_process (gpointer data);
@@ -152,10 +152,10 @@ mm_serial_port_print_config (MMSerialPort *port, const char *detail)
return; return;
} }
g_message ("*** %s (%s): (%s) baud rate: %d (%s)", mm_info ("(%s): (%s) baud rate: %d (%s)",
__func__, detail, mm_port_get_device (MM_PORT (port)), detail, mm_port_get_device (MM_PORT (port)),
stbuf.c_cflag & CBAUD, stbuf.c_cflag & CBAUD,
baud_to_string (stbuf.c_cflag & CBAUD)); baud_to_string (stbuf.c_cflag & CBAUD));
} }
#endif #endif
@@ -350,7 +350,7 @@ serial_debug (MMSerialPort *self, const char *prefix, const char *buf, gsize len
{ {
g_return_if_fail (len > 0); g_return_if_fail (len > 0);
if (mm_options_debug () && MM_SERIAL_PORT_GET_CLASS (self)->debug_log) if (MM_SERIAL_PORT_GET_CLASS (self)->debug_log)
MM_SERIAL_PORT_GET_CLASS (self)->debug_log (self, prefix, buf, len); MM_SERIAL_PORT_GET_CLASS (self)->debug_log (self, prefix, buf, len);
} }
@@ -686,7 +686,6 @@ mm_serial_port_open (MMSerialPort *self, GError **error)
MMSerialPortPrivate *priv; MMSerialPortPrivate *priv;
char *devfile; char *devfile;
const char *device; const char *device;
GTimeVal tv;
struct serial_struct sinfo; struct serial_struct sinfo;
g_return_val_if_fail (MM_IS_SERIAL_PORT (self), FALSE); g_return_val_if_fail (MM_IS_SERIAL_PORT (self), FALSE);
@@ -700,12 +699,7 @@ mm_serial_port_open (MMSerialPort *self, GError **error)
goto success; goto success;
} }
if (mm_options_debug ()) { mm_info ("(%s) opening serial port...", device);
g_get_current_time (&tv);
g_debug ("<%ld.%ld> (%s) opening serial port...",
tv.tv_sec, tv.tv_usec, device);
} else
g_message ("(%s) opening serial port...", device);
/* Only open a new file descriptor if we weren't given one already */ /* Only open a new file descriptor if we weren't given one already */
if (priv->fd < 0) { if (priv->fd < 0) {
@@ -767,11 +761,7 @@ mm_serial_port_open (MMSerialPort *self, GError **error)
success: success:
priv->open_count++; priv->open_count++;
if (mm_options_debug ()) { mm_dbg ("(%s) device open count is %d (open)", device, priv->open_count);
g_get_current_time (&tv);
g_debug ("<%ld.%ld> (%s) device open count is %d (open)",
tv.tv_sec, tv.tv_usec, device, priv->open_count);
}
return TRUE; return TRUE;
error: error:
@@ -794,7 +784,6 @@ mm_serial_port_close (MMSerialPort *self)
{ {
MMSerialPortPrivate *priv; MMSerialPortPrivate *priv;
const char *device; const char *device;
GTimeVal tv;
int i; int i;
g_return_if_fail (MM_IS_SERIAL_PORT (self)); g_return_if_fail (MM_IS_SERIAL_PORT (self));
@@ -806,11 +795,7 @@ mm_serial_port_close (MMSerialPort *self)
priv->open_count--; priv->open_count--;
if (mm_options_debug ()) { mm_dbg ("(%s) device open count is %d (close)", device, priv->open_count);
g_get_current_time (&tv);
g_debug ("<%ld.%ld> (%s) device open count is %d (close)",
tv.tv_sec, tv.tv_usec, device, priv->open_count);
}
if (priv->open_count > 0) if (priv->open_count > 0)
return; return;
@@ -823,12 +808,7 @@ mm_serial_port_close (MMSerialPort *self)
if (priv->fd >= 0) { if (priv->fd >= 0) {
GTimeVal tv_start, tv_end; GTimeVal tv_start, tv_end;
g_get_current_time (&tv_start); mm_info ("(%s) closing serial port...", device);
if (mm_options_debug ()) {
g_debug ("<%ld.%ld> (%s) closing serial port...",
tv_start.tv_sec, tv_start.tv_usec, device);
} else
g_message ("(%s) closing serial port...", device);
mm_port_set_connected (MM_PORT (self), FALSE); mm_port_set_connected (MM_PORT (self), FALSE);
@@ -842,16 +822,16 @@ mm_serial_port_close (MMSerialPort *self)
mm_serial_port_flash_cancel (self); mm_serial_port_flash_cancel (self);
g_get_current_time (&tv_start);
tcsetattr (priv->fd, TCSANOW, &priv->old_t); tcsetattr (priv->fd, TCSANOW, &priv->old_t);
tcflush (priv->fd, TCIOFLUSH); tcflush (priv->fd, TCIOFLUSH);
close (priv->fd); close (priv->fd);
priv->fd = -1; priv->fd = -1;
g_get_current_time (&tv_end); g_get_current_time (&tv_end);
if (mm_options_debug ()) {
g_debug ("<%ld.%ld> (%s) serial port closed", mm_info ("(%s) serial port closed", device);
tv_end.tv_sec, tv_end.tv_usec, device);
}
/* Some ports don't respond to data and when close is called /* Some ports don't respond to data and when close is called
* the serial layer waits up to 30 second (closing_wait) for * the serial layer waits up to 30 second (closing_wait) for
@@ -859,7 +839,7 @@ mm_serial_port_close (MMSerialPort *self)
* Log that. See GNOME bug #630670 for more details. * Log that. See GNOME bug #630670 for more details.
*/ */
if (tv_end.tv_sec - tv_start.tv_sec > 20) if (tv_end.tv_sec - tv_start.tv_sec > 20)
g_warning ("(%s): close blocked by driver for more than 20 seconds!", device); mm_warn ("(%s): close blocked by driver for more than 20 seconds!", device);
} }
/* Clear the command queue */ /* Clear the command queue */

View File

@@ -17,6 +17,7 @@
#include <string.h> #include <string.h>
#include "mm-modem-helpers.h" #include "mm-modem-helpers.h"
#include "mm-log.h"
typedef struct { typedef struct {
GPtrArray *solicited_creg; GPtrArray *solicited_creg;
@@ -1079,8 +1080,7 @@ test_devid_item (void *f, gpointer d)
item->gsn, item->gsn,
item->revision, item->revision,
item->model, item->model,
item->manf, item->manf);
FALSE);
g_assert (devid); g_assert (devid);
if (strcmp (devid, item->devid)) if (strcmp (devid, item->devid))
g_message ("%s", devid); g_message ("%s", devid);
@@ -1178,6 +1178,15 @@ test_data_free (TestData *data)
g_free (data); g_free (data);
} }
void
_mm_log (const char *loc,
const char *func,
guint32 level,
const char *fmt,
...)
{
/* Dummy log function */
}
#if GLIB_CHECK_VERSION(2,25,12) #if GLIB_CHECK_VERSION(2,25,12)
typedef GTestFixtureFunc TCFunc; typedef GTestFixtureFunc TCFunc;

View File

@@ -31,6 +31,7 @@
#include "libqcdm/src/commands.h" #include "libqcdm/src/commands.h"
#include "libqcdm/src/utils.h" #include "libqcdm/src/utils.h"
#include "libqcdm/src/com.h" #include "libqcdm/src/com.h"
#include "mm-log.h"
typedef struct { typedef struct {
int master; int master;
@@ -449,10 +450,14 @@ typedef void (*TCFunc)(void);
#define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (TCFunc) t, NULL) #define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (TCFunc) t, NULL)
#define TESTCASE_PTY(t, d) g_test_create_case (#t, sizeof (*d), d, (TCFunc) test_pty_create, (TCFunc) t, (TCFunc) test_pty_cleanup) #define TESTCASE_PTY(t, d) g_test_create_case (#t, sizeof (*d), d, (TCFunc) test_pty_create, (TCFunc) t, (TCFunc) test_pty_cleanup)
gboolean mm_options_debug (void); void
gboolean mm_options_debug (void) _mm_log (const char *loc,
const char *func,
guint32 level,
const char *fmt,
...)
{ {
return g_test_verbose (); /* Dummy log function */
} }
int main (int argc, char **argv) int main (int argc, char **argv)