summaryrefslogtreecommitdiff
path: root/gobex/gobex-debug.h
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2011-10-22 13:29:30 +0300
committerMarcel Holtmann <marcel@holtmann.org>2012-12-04 22:22:03 +0100
commit54da6b6ad2b73818769bcf22bb9c4f5cd5c50bd4 (patch)
treed117a5813f16f19290bb433b9d5d7ecbcd4b4ee8 /gobex/gobex-debug.h
parente058d7a519c28f83ff202c20a923cd4256996c96 (diff)
downloadbluez-54da6b6ad2b73818769bcf22bb9c4f5cd5c50bd4.tar.gz
gobex: add initial support for debug
This adds support for debug using GOBEX_DEBUG environment variable.
Diffstat (limited to 'gobex/gobex-debug.h')
-rw-r--r--gobex/gobex-debug.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/gobex/gobex-debug.h b/gobex/gobex-debug.h
new file mode 100644
index 000000000..589104e13
--- /dev/null
+++ b/gobex/gobex-debug.h
@@ -0,0 +1,76 @@
+/*
+ * OBEX library with GLib integration
+ *
+ * Copyright (C) 2011 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef __GOBEX_DEBUG_H
+#define __GOBEX_DEBUG_H
+
+#include <glib.h>
+#include <stdio.h>
+#include <ctype.h>
+
+#define G_OBEX_DEBUG_NONE 1
+#define G_OBEX_DEBUG_ERROR (1 << 1)
+#define G_OBEX_DEBUG_COMMAND (1 << 2)
+#define G_OBEX_DEBUG_TRANSFER (1 << 3)
+#define G_OBEX_DEBUG_HEADER (1 << 4)
+#define G_OBEX_DEBUG_PACKET (1 << 5)
+#define G_OBEX_DEBUG_DATA (1 << 6)
+
+extern guint gobex_debug;
+
+#define g_obex_debug(level, format, ...) \
+ if (gobex_debug & level) \
+ g_debug("%s:%s() " format, __FILE__, __FUNCTION__, \
+ ## __VA_ARGS__)
+
+static inline void g_obex_dump(const char *prefix, const void *buf,
+ gsize len)
+{
+ const guint8 *data = buf;
+ int n = 0;
+
+ if (!(gobex_debug & G_OBEX_DEBUG_DATA))
+ return;
+
+ while (len > 0) {
+ int i, size;
+
+ printf("%s %04x:", prefix, n);
+
+ size = len > 16 ? 16 : len;
+
+ for (i = 0; i < size; i++)
+ printf("%02x%s", data[i], (i + 1) % 8 ? " " : " ");
+
+ for (; i < 16; i++)
+ printf(" %s", (i + 1) % 8 ? " " : " ");
+
+ for (i = 0; i < size; i++)
+ printf("%1c", isprint(data[i]) ? data[i] : '.');
+
+ printf("\n");
+
+ data += size;
+ len -= size;
+ n += size;
+ }
+}
+
+#endif /* __GOBEX_DEBUG_H */