Upgrade bluez5_37 :Merge the code from private
[platform/upstream/bluez.git] / src / log.h
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2004-2010  Marcel Holtmann <marcel@holtmann.org>
6  *
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23
24 #include <stdint.h>
25
26 void error(const char *format, ...) __attribute__((format(printf, 1, 2)));
27 void warn(const char *format, ...) __attribute__((format(printf, 1, 2)));
28 void info(const char *format, ...) __attribute__((format(printf, 1, 2)));
29
30 void btd_log(uint16_t index, int priority, const char *format, ...)
31                                         __attribute__((format(printf, 3, 4)));
32
33 void btd_error(uint16_t index, const char *format, ...)
34                                         __attribute__((format(printf, 2, 3)));
35 void btd_warn(uint16_t index, const char *format, ...)
36                                         __attribute__((format(printf, 2, 3)));
37 void btd_info(uint16_t index, const char *format, ...)
38                                         __attribute__((format(printf, 2, 3)));
39 void btd_debug(uint16_t index, const char *format, ...)
40                                         __attribute__((format(printf, 2, 3)));
41
42 #ifdef __TIZEN_PATCH__
43 void __hci_attach_log_init(void );
44 #endif
45 void __btd_log_init(const char *debug, int detach);
46 void __btd_log_cleanup(void);
47 void __btd_toggle_debug(void);
48
49 struct btd_debug_desc {
50         const char *file;
51 #define BTD_DEBUG_FLAG_DEFAULT (0)
52 #define BTD_DEBUG_FLAG_PRINT   (1 << 0)
53         unsigned int flags;
54 } __attribute__((aligned(8)));
55
56 void __btd_enable_debug(struct btd_debug_desc *start,
57                                         struct btd_debug_desc *stop);
58
59 /**
60  * DBG:
61  * @fmt: format string
62  * @arg...: list of arguments
63  *
64  * Simple macro around btd_debug() which also include the function
65  * name it is called in.
66  */
67 #define DBG_IDX(idx, fmt, arg...) do { \
68         static struct btd_debug_desc __btd_debug_desc \
69         __attribute__((used, section("__debug"), aligned(8))) = { \
70                 .file = __FILE__, .flags = BTD_DEBUG_FLAG_DEFAULT, \
71         }; \
72         if (__btd_debug_desc.flags & BTD_DEBUG_FLAG_PRINT) \
73                 btd_debug(idx, "%s:%s() " fmt, __FILE__, __func__ , ## arg); \
74 } while (0)
75
76 #define DBG(fmt, arg...) DBG_IDX(0xffff, fmt, ## arg)