diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-10-09 13:44:16 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-10-09 15:23:48 +0200 |
commit | 35dcb4bb6ed2755d968cf97d69faff9ed5f6871f (patch) | |
tree | d1c3e766d31a3aead0ea9bd23d173bfa43c8f833 | |
parent | ab6a20b6f0403cdb779fe6344953f6c5a246a44a (diff) | |
download | external_libqmi-35dcb4bb6ed2755d968cf97d69faff9ed5f6871f.zip external_libqmi-35dcb4bb6ed2755d968cf97d69faff9ed5f6871f.tar.gz external_libqmi-35dcb4bb6ed2755d968cf97d69faff9ed5f6871f.tar.bz2 |
libqmi-glib: message traces compiled always
Message traces have been very useful when debugging issues in the protocol, and
we should avoid requiring a full recompilation in order to get them enabled.
Instead, we provide two new API methods, `qmi_utils_(get|set)_traces_enabled()',
which allow specifying whether traces should be dumped with g_debug() or not.
-rw-r--r-- | configure.ac | 11 | ||||
-rw-r--r-- | docs/reference/libqmi-glib/libqmi-glib-common.sections | 3 | ||||
-rw-r--r-- | libqmi-glib/qmi-device.c | 8 | ||||
-rw-r--r-- | libqmi-glib/qmi-utils.c | 33 | ||||
-rw-r--r-- | libqmi-glib/qmi-utils.h | 4 |
5 files changed, 42 insertions, 17 deletions
diff --git a/configure.ac b/configure.ac index 2a41e2c..ed49122 100644 --- a/configure.ac +++ b/configure.ac @@ -58,17 +58,6 @@ case $with_docs in esac GTK_DOC_CHECK(1.0) -dnl Protocol message tracing -AC_ARG_WITH(traces, AS_HELP_STRING([--with-traces], [Enable protocol debugging traces])) -AM_CONDITIONAL(WITH_TRACES, test "x$with_traces" = "xyes") -case $with_traces in - yes) - CFLAGS="-DMESSAGE_ENABLE_TRACE $CFLAGS" - ;; - *) - ;; -esac - dnl Tests AC_ARG_WITH(tests, AS_HELP_STRING([--with-tests], [Build libqmi tests])) AM_CONDITIONAL(WITH_TESTS, test "x$with_tests" = "xyes") diff --git a/docs/reference/libqmi-glib/libqmi-glib-common.sections b/docs/reference/libqmi-glib/libqmi-glib-common.sections index 2b596b6..9cc65e1 100644 --- a/docs/reference/libqmi-glib/libqmi-glib-common.sections +++ b/docs/reference/libqmi-glib/libqmi-glib-common.sections @@ -641,6 +641,9 @@ qmi_message_get_tlv_printable <SECTION> <FILE>qmi-utils</FILE> +<SUBSECTION Traces> +qmi_utils_get_traces_enabled +qmi_utils_set_traces_enabled <SUBSECTION Readers> qmi_utils_read_guint8_from_buffer qmi_utils_read_gint8_from_buffer diff --git a/libqmi-glib/qmi-device.c b/libqmi-glib/qmi-device.c index 43401bc..7bfc0a3 100644 --- a/libqmi-glib/qmi-device.c +++ b/libqmi-glib/qmi-device.c @@ -1043,8 +1043,7 @@ static void process_message (QmiDevice *self, QmiMessage *message) { -#ifdef MESSAGE_ENABLE_TRACE - { + if (qmi_utils_get_traces_enabled ()) { gchar *printable; printable = qmi_message_get_printable (message, ">>>>>> "); @@ -1053,7 +1052,6 @@ process_message (QmiDevice *self, printable); g_free (printable); } -#endif /* MESSAGE_ENABLE_TRACE */ if (qmi_message_is_indication (message)) { if (qmi_message_get_client_id (message) == QMI_CID_BROADCAST) { @@ -1715,8 +1713,7 @@ qmi_device_command (QmiDevice *self, return; } -#ifdef MESSAGE_ENABLE_TRACE - { + if (qmi_utils_get_traces_enabled ()) { gchar *printable; printable = qmi_message_get_printable (message, "<<<<<< "); @@ -1725,7 +1722,6 @@ qmi_device_command (QmiDevice *self, printable); g_free (printable); } -#endif /* MESSAGE_ENABLE_TRACE */ /* Get raw message */ raw_message = qmi_message_get_raw (message, &raw_message_len, &error); diff --git a/libqmi-glib/qmi-utils.c b/libqmi-glib/qmi-utils.c index e8d6762..3e5101b 100644 --- a/libqmi-glib/qmi-utils.c +++ b/libqmi-glib/qmi-utils.c @@ -36,6 +36,8 @@ * with the QMI library. **/ +/*****************************************************************************/ + gchar * __qmi_utils_str_hex (gconstpointer mem, gsize size, @@ -70,6 +72,8 @@ __qmi_utils_str_hex (gconstpointer mem, return new_str; } +/*****************************************************************************/ + #if defined UTILS_ENABLE_TRACE static void print_read_bytes_trace (const gchar *type, @@ -884,3 +888,32 @@ qmi_utils_write_fixed_size_string_to_buffer (guint8 **buffer, *buffer = &((*buffer)[fixed_size]); *buffer_size = (*buffer_size) - fixed_size; } + +/*****************************************************************************/ + +static volatile gint __traces_enabled = FALSE; + +/** + * qmi_utils_get_traces_enabled: + * + * Checks whether QMI message traces are currently enabled. + * + * Returns: %TRUE if traces are enabled, %FALSE otherwise. + */ +gboolean +qmi_utils_get_traces_enabled (void) +{ + return (gboolean) g_atomic_int_get (&__traces_enabled); +} + +/** + * qmi_utils_set_traces_enabled: + * @enabled: %TRUE to enable traces, %FALSE to disable them. + * + * Sets whether QMI message traces are enabled or disabled. + */ +void +qmi_utils_set_traces_enabled (gboolean enabled) +{ + g_atomic_int_set (&__traces_enabled, enabled); +} diff --git a/libqmi-glib/qmi-utils.h b/libqmi-glib/qmi-utils.h index 372ebcb..c67d332 100644 --- a/libqmi-glib/qmi-utils.h +++ b/libqmi-glib/qmi-utils.h @@ -121,6 +121,10 @@ void qmi_utils_write_fixed_size_string_to_buffer (guint8 **buffer, guint16 fixed_size, const gchar *in); +/* Enabling/Disabling traces */ +gboolean qmi_utils_get_traces_enabled (void); +void qmi_utils_set_traces_enabled (gboolean enabled); + /* Other private methods */ #if defined (LIBQMI_GLIB_COMPILATION) |