summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2016-12-08 22:58:25 +0100
committerAleksander Morgado <aleksander@aleksander.es>2017-01-16 11:24:15 +0100
commit98834008800a3aaac6a95e7e5fea76d16fd6b707 (patch)
tree09267b80876f809b9059a6270b164797f58fcadf
parent6adf441cca962aaf0216d1eae5ecb9f54c4f3493 (diff)
downloadlibqmi-98834008800a3aaac6a95e7e5fea76d16fd6b707.tar.gz
qmi-firmware-update: don't use libqmi to flag verbosity
-rw-r--r--src/qmi-firmware-update/Makefile.am1
-rw-r--r--src/qmi-firmware-update/qfu-at-device.c5
-rw-r--r--src/qmi-firmware-update/qfu-log.c113
-rw-r--r--src/qmi-firmware-update/qfu-log.h35
-rw-r--r--src/qmi-firmware-update/qfu-main.c66
-rw-r--r--src/qmi-firmware-update/qfu-qdl-device.c11
-rw-r--r--src/qmi-firmware-update/qfu-updater.c5
7 files changed, 163 insertions, 73 deletions
diff --git a/src/qmi-firmware-update/Makefile.am b/src/qmi-firmware-update/Makefile.am
index cbe8ed1b..29699ccc 100644
--- a/src/qmi-firmware-update/Makefile.am
+++ b/src/qmi-firmware-update/Makefile.am
@@ -60,6 +60,7 @@ qmi_firmware_update_SOURCES = \
qfu-operation-update.c \
qfu-operation-verify.c \
qfu-operation-reset.c \
+ qfu-log.h qfu-log.c \
qfu-updater.h qfu-updater.c \
qfu-udev-helpers.h qfu-udev-helpers.c \
qfu-image.h qfu-image.c \
diff --git a/src/qmi-firmware-update/qfu-at-device.c b/src/qmi-firmware-update/qfu-at-device.c
index 3dae7943..9ade1924 100644
--- a/src/qmi-firmware-update/qfu-at-device.c
+++ b/src/qmi-firmware-update/qfu-at-device.c
@@ -32,6 +32,7 @@
#include <libqmi-glib.h>
+#include "qfu-log.h"
#include "qfu-at-device.h"
#include "qfu-utils.h"
@@ -96,7 +97,7 @@ send_request (QfuAtDevice *self,
}
/* Debug output */
- if (qmi_utils_get_traces_enabled ())
+ if (qfu_log_get_verbose ())
g_debug ("[qfu-at-device,%s] >> %s", self->priv->name, request);
wlen = write (self->priv->fd, request, strlen (request));
@@ -197,7 +198,7 @@ receive_response (QfuAtDevice *self,
}
/* Debug output */
- if (qmi_utils_get_traces_enabled ())
+ if (qfu_log_get_verbose ())
g_debug ("[qfu-at-device,%s] << %s", self->priv->name, start);
if (response)
diff --git a/src/qmi-firmware-update/qfu-log.c b/src/qmi-firmware-update/qfu-log.c
new file mode 100644
index 00000000..a6686cb2
--- /dev/null
+++ b/src/qmi-firmware-update/qfu-log.c
@@ -0,0 +1,113 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * qmi-firmware-update -- Command line tool to update firmware in QMI devices
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2016 Zodiac Inflight Innovations
+ * Copyright (C) 2016 Aleksander Morgado <aleksander@aleksander.es>
+ */
+
+#include <glib.h>
+#include <glib/gprintf.h>
+
+#include <libqmi-glib.h>
+
+#include "qfu-log.h"
+
+static gboolean silent_flag;
+static gboolean verbose_flag;
+
+static void
+log_handler (const gchar *log_domain,
+ GLogLevelFlags log_level,
+ const gchar *message,
+ gpointer user_data)
+{
+ const gchar *log_level_str;
+ time_t now;
+ gchar time_str[64];
+ struct tm *local_time;
+ gboolean err;
+
+ /* Nothing to do if we're silent */
+ if (silent_flag)
+ return;
+
+ now = time ((time_t *) NULL);
+ local_time = localtime (&now);
+ strftime (time_str, 64, "%d %b %Y, %H:%M:%S", local_time);
+ err = FALSE;
+
+ switch (log_level) {
+ case G_LOG_LEVEL_WARNING:
+ log_level_str = "-Warning **";
+ err = TRUE;
+ break;
+
+ case G_LOG_LEVEL_CRITICAL:
+ case G_LOG_FLAG_FATAL:
+ case G_LOG_LEVEL_ERROR:
+ log_level_str = "-Error **";
+ err = TRUE;
+ break;
+
+ case G_LOG_LEVEL_DEBUG:
+ log_level_str = "[Debug]";
+ break;
+
+ default:
+ log_level_str = "";
+ break;
+ }
+
+ if (!verbose_flag && !err)
+ return;
+
+ g_fprintf (err ? stderr : stdout,
+ "[%s] %s %s\n",
+ time_str,
+ log_level_str,
+ message);
+}
+
+gboolean
+qfu_log_get_verbose (void)
+{
+ return verbose_flag;
+}
+
+gboolean
+qfu_log_init (gboolean verbose,
+ gboolean silent)
+{
+ if (verbose && silent) {
+ g_printerr ("error: cannot specify --verbose and --silent at the same time\n");
+ return FALSE;
+ }
+
+ /* Store flags */
+ verbose_flag = verbose;
+ silent_flag = silent;
+
+ /* Default application logging */
+ g_log_set_handler (NULL, G_LOG_LEVEL_MASK, log_handler, NULL);
+
+ /* libqmi logging */
+ g_log_set_handler ("Qmi", G_LOG_LEVEL_MASK, log_handler, NULL);
+ if (verbose_flag)
+ qmi_utils_set_traces_enabled (TRUE);
+
+ return TRUE;
+}
diff --git a/src/qmi-firmware-update/qfu-log.h b/src/qmi-firmware-update/qfu-log.h
new file mode 100644
index 00000000..adc7768e
--- /dev/null
+++ b/src/qmi-firmware-update/qfu-log.h
@@ -0,0 +1,35 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * qmi-firmware-update -- Command line tool to update firmware in QMI devices
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2016 Zodiac Inflight Innovations
+ * Copyright (C) 2016 Aleksander Morgado <aleksander@aleksander.es>
+ */
+
+#ifndef QFU_LOG_H
+#define QFU_LOG_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+gboolean qfu_log_init (gboolean verbose,
+ gboolean silent);
+gboolean qfu_log_get_verbose (void);
+
+G_END_DECLS
+
+#endif /* QFU_LOG_H */
diff --git a/src/qmi-firmware-update/qfu-main.c b/src/qmi-firmware-update/qfu-main.c
index 22daa4f8..6cdffe53 100644
--- a/src/qmi-firmware-update/qfu-main.c
+++ b/src/qmi-firmware-update/qfu-main.c
@@ -27,11 +27,9 @@
#include <string.h>
#include <glib.h>
-#include <glib/gprintf.h>
#include <gio/gio.h>
-#include <libqmi-glib.h>
-
+#include "qfu-log.h"
#include "qfu-operation.h"
#include "qfu-udev-helpers.h"
@@ -290,62 +288,6 @@ static const gchar *context_description =
" libqmi-devel@lists.freedesktop.org\n";
/*****************************************************************************/
-/* Logging output */
-
-static void
-log_handler (const gchar *log_domain,
- GLogLevelFlags log_level,
- const gchar *message,
- gpointer user_data)
-{
- const gchar *log_level_str;
- time_t now;
- gchar time_str[64];
- struct tm *local_time;
- gboolean err;
-
- /* Nothing to do if we're silent */
- if (silent_flag)
- return;
-
- now = time ((time_t *) NULL);
- local_time = localtime (&now);
- strftime (time_str, 64, "%d %b %Y, %H:%M:%S", local_time);
- err = FALSE;
-
- switch (log_level) {
- case G_LOG_LEVEL_WARNING:
- log_level_str = "-Warning **";
- err = TRUE;
- break;
-
- case G_LOG_LEVEL_CRITICAL:
- case G_LOG_FLAG_FATAL:
- case G_LOG_LEVEL_ERROR:
- log_level_str = "-Error **";
- err = TRUE;
- break;
-
- case G_LOG_LEVEL_DEBUG:
- log_level_str = "[Debug]";
- break;
-
- default:
- log_level_str = "";
- break;
- }
-
- if (!verbose_flag && !err)
- return;
-
- g_fprintf (err ? stderr : stdout,
- "[%s] %s %s\n",
- time_str,
- log_level_str,
- message);
-}
-
-/*****************************************************************************/
static void
print_version (void)
@@ -675,10 +617,8 @@ int main (int argc, char **argv)
goto out;
}
- g_log_set_handler (NULL, G_LOG_LEVEL_MASK, log_handler, NULL);
- g_log_set_handler ("Qmi", G_LOG_LEVEL_MASK, log_handler, NULL);
- if (verbose_flag)
- qmi_utils_set_traces_enabled (TRUE);
+ /* Initialize logging */
+ qfu_log_init (verbose_flag, silent_flag);
/* We don't allow multiple actions at the same time */
n_actions = (action_verify_flag +
diff --git a/src/qmi-firmware-update/qfu-qdl-device.c b/src/qmi-firmware-update/qfu-qdl-device.c
index aee07fa1..d045ad90 100644
--- a/src/qmi-firmware-update/qfu-qdl-device.c
+++ b/src/qmi-firmware-update/qfu-qdl-device.c
@@ -31,8 +31,7 @@
#include <glib-object.h>
#include <gio/gio.h>
-#include <libqmi-glib.h>
-
+#include "qfu-log.h"
#include "qfu-qdl-message.h"
#include "qfu-dload-message.h"
#include "qfu-qdl-device.h"
@@ -242,7 +241,7 @@ send_request (QfuQdlDevice *self,
}
/* Debug output */
- if (qmi_utils_get_traces_enabled ()) {
+ if (qfu_log_get_verbose ()) {
gchar *printable;
gsize printable_size = request_size;
gboolean shorted = FALSE;
@@ -288,7 +287,7 @@ send_framed_request (QfuQdlDevice *self,
gsize framed_size;
/* Debug output */
- if (qmi_utils_get_traces_enabled ()) {
+ if (qfu_log_get_verbose ()) {
gchar *printable;
gsize printable_size = request_size;
gboolean shorted = FALSE;
@@ -373,7 +372,7 @@ receive_response (QfuQdlDevice *self,
}
/* Debug output */
- if (qmi_utils_get_traces_enabled ()) {
+ if (qfu_log_get_verbose ()) {
gchar *printable;
gsize printable_size = rlen;
gboolean shorted = FALSE;
@@ -418,7 +417,7 @@ receive_response (QfuQdlDevice *self,
}
/* Debug output */
- if (qmi_utils_get_traces_enabled ()) {
+ if (qfu_log_get_verbose ()) {
gchar *printable;
gsize printable_size = unframed_size;
gboolean shorted = FALSE;
diff --git a/src/qmi-firmware-update/qfu-updater.c b/src/qmi-firmware-update/qfu-updater.c
index b5af7986..97105717 100644
--- a/src/qmi-firmware-update/qfu-updater.c
+++ b/src/qmi-firmware-update/qfu-updater.c
@@ -27,6 +27,7 @@
#include <libqmi-glib.h>
+#include "qfu-log.h"
#include "qfu-image-factory.h"
#include "qfu-updater.h"
#include "qfu-reseter.h"
@@ -314,7 +315,7 @@ run_context_step_download_image (GTask *task)
n_chunks = qfu_image_get_n_data_chunks (ctx->current_image);
for (sequence = 0; sequence < n_chunks; sequence++) {
- if (!qmi_utils_get_traces_enabled ())
+ if (!qfu_log_get_verbose ())
g_print (CLEAR_LINE "%s %04.1lf%%", progress[sequence % G_N_ELEMENTS (progress)], 100.0 * ((gdouble) sequence / (gdouble) n_chunks));
if (!qfu_qdl_device_ufwrite (ctx->qdl_device, ctx->current_image, sequence, cancellable, &error)) {
g_prefix_error (&error, "couldn't write in session: ");
@@ -322,7 +323,7 @@ run_context_step_download_image (GTask *task)
}
}
- if (!qmi_utils_get_traces_enabled ())
+ if (!qfu_log_get_verbose ())
g_print (CLEAR_LINE "%s %04.1lf%%\n", progress[sequence % G_N_ELEMENTS (progress)], 100.0);
g_debug ("[qfu-updater] all chunks ack-ed");