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.
This commit is contained in:
parent
ab6a20b6f0
commit
35dcb4bb6e
11
configure.ac
11
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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue