| /* |
| * |
| * Connection Manager |
| * |
| * Copyright (C) 2007-2013 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 __CONNMAN_LOG_H |
| #define __CONNMAN_LOG_H |
| |
| #ifdef __cplusplus |
| extern "C" { |
| #endif |
| |
| /** |
| * SECTION:log |
| * @title: Logging premitives |
| * @short_description: Functions for logging error and debug information |
| */ |
| |
| void connman_info(const char *format, ...) |
| __attribute__((format(printf, 1, 2))); |
| void connman_warn(const char *format, ...) |
| __attribute__((format(printf, 1, 2))); |
| void connman_error(const char *format, ...) |
| __attribute__((format(printf, 1, 2))); |
| void connman_debug(const char *format, ...) |
| __attribute__((format(printf, 1, 2))); |
| |
| #define connman_warn_once(fmt, arg...) do { \ |
| static bool printed; \ |
| if (!printed) { \ |
| connman_warn(fmt, ## arg); \ |
| printed = true; \ |
| } \ |
| } while (0) |
| |
| struct connman_debug_desc { |
| const char *name; |
| const char *file; |
| #define CONNMAN_DEBUG_FLAG_DEFAULT (0) |
| #define CONNMAN_DEBUG_FLAG_PRINT (1 << 0) |
| #define CONNMAN_DEBUG_FLAG_ALIAS (1 << 1) |
| unsigned int flags; |
| } __attribute__((aligned(8))); |
| |
| #define CONNMAN_DEBUG_DEFINE(name) \ |
| static struct connman_debug_desc __debug_alias_ ## name \ |
| __attribute__((used, section("__debug"), aligned(8))) = { \ |
| #name, __FILE__, CONNMAN_DEBUG_FLAG_ALIAS \ |
| }; |
| |
| /** |
| * DBG: |
| * @fmt: format string |
| * @arg...: list of arguments |
| * |
| * Simple macro around connman_debug() which also include the function |
| * name it is called in. |
| */ |
| #define DBG(fmt, arg...) do { \ |
| static struct connman_debug_desc __connman_debug_desc \ |
| __attribute__((used, section("__debug"), aligned(8))) = { \ |
| .file = __FILE__, .flags = CONNMAN_DEBUG_FLAG_DEFAULT, \ |
| }; \ |
| if (__connman_debug_desc.flags & CONNMAN_DEBUG_FLAG_PRINT) \ |
| connman_debug("%s:%s() " fmt, \ |
| __FILE__, __FUNCTION__ , ## arg); \ |
| } while (0) |
| |
| #if !defined(CONNMAN_DEBUG) |
| #define CONNMAN_DEBUG DEBUG && !NDEBUG |
| #endif |
| |
| #if CONNMAN_DEBUG |
| extern unsigned int trace_depth; |
| extern char trace_tabbuf[]; |
| |
| extern void connman_create_indent(unsigned int depth, char *buffer); |
| |
| #define connman_trace(dir, fmt, arg...) \ |
| do { \ |
| connman_create_indent(trace_depth, trace_tabbuf); \ |
| connman_debug("%s" dir " (%d) %s: " fmt, \ |
| trace_tabbuf, \ |
| trace_depth, \ |
| __FUNCTION__, \ |
| ## arg); \ |
| } while (0) |
| |
| #define connman_trace_in(fmt, arg...) \ |
| do { \ |
| connman_trace("-->", fmt, ## arg); \ |
| trace_depth++; \ |
| } while (0) |
| |
| #define connman_trace_out(fmt, arg...) \ |
| do { \ |
| --trace_depth; \ |
| connman_trace("<--", fmt, ## arg); \ |
| } while (0) |
| #else |
| #define connman_trace_in(fmt, arg...) |
| #define connman_trace_out(fmt, arg...) |
| #endif |
| |
| extern void connman_assert_handler(const char *name, const char *predicate, const char *message, const char *file, unsigned int line, void *value, int terminate); |
| |
| #if !defined(CONNMAN_ASSERT) |
| #define CONNMAN_ASSERT(name, predicate, message, file, line, value) connman_assert_handler(name, predicate, message, file, line, value, 0) |
| #endif |
| |
| #if !defined(CONNMAN_ASSERT_MODULE) |
| #define CONNMAN_ASSERT_MODULE NULL |
| #endif |
| |
| #if CONNMAN_DEBUG |
| #define connman_assert(predicate) \ |
| do { \ |
| if (!(predicate)) { \ |
| connman_assert_handler(CONNMAN_ASSERT_MODULE, \ |
| #predicate, \ |
| NULL, \ |
| __FILE__, \ |
| __LINE__, \ |
| 0, \ |
| 1); \ |
| } \ |
| } while (0) |
| #else |
| #define connman_assert(predicate) |
| #endif |
| |
| #if CONNMAN_DEBUG |
| #define connman_check_message(predicate, message) \ |
| do { \ |
| if (!(predicate)) { \ |
| CONNMAN_ASSERT(CONNMAN_ASSERT_MODULE, \ |
| #predicate, \ |
| message, \ |
| __FILE__, \ |
| __LINE__, \ |
| 0); \ |
| } \ |
| } while (0) |
| #else |
| #define connman_check_message(predicate, message) |
| #endif |
| |
| #if CONNMAN_DEBUG |
| #define connman_check(predicate) \ |
| connman_check_message(predicate, NULL) |
| #else |
| #define connman_check(predicate) |
| #endif |
| |
| #if CONNMAN_DEBUG |
| #define connman_check_ok_message(error, message) \ |
| do { \ |
| if ((error) != 0) { \ |
| CONNMAN_ASSERT(CONNMAN_ASSERT_MODULE, \ |
| #error " == 0", \ |
| message, \ |
| __FILE__, \ |
| __LINE__, \ |
| (void *)error); \ |
| } \ |
| } while (0) |
| #else |
| #define connman_check_ok_message(error, message) |
| #endif |
| |
| #if CONNMAN_DEBUG |
| #define connman_check_ok(error) \ |
| connman_check_ok_message(error, NULL) |
| #else |
| #define connman_check_ok(error) |
| #endif |
| |
| #if CONNMAN_DEBUG |
| #define connman_verify_message(predicate, message) \ |
| connman_check_message(predicate, message) |
| #else |
| #define connman_verify_message(predicate, message) \ |
| do { \ |
| if (!predicate) { } \ |
| } while (0) |
| #endif |
| |
| #define connman_verify(predicate) \ |
| connman_verify_message(predicate, NULL) |
| |
| #if CONNMAN_DEBUG |
| #define connman_verify_execute_message(predicate, action, message) \ |
| do { \ |
| if (!(predicate)) { \ |
| CONNMAN_ASSERT(CONNMAN_ASSERT_MODULE, \ |
| #predicate, \ |
| message, \ |
| __FILE__, \ |
| __LINE__, \ |
| 0); \ |
| { \ |
| action; \ |
| } \ |
| } \ |
| } while (0) |
| #else |
| #define connman_verify_execute_message(predicate, action, message) \ |
| do { \ |
| if (!(predicate)) { \ |
| { \ |
| action; \ |
| } \ |
| } \ |
| } while (0) |
| #endif |
| |
| #define connman_verify_execute(predicate, action) \ |
| connman_verify_execute_message(predicate, action, NULL) |
| |
| #if CONNMAN_DEBUG |
| #define connman_verify_ok_message(error, message) \ |
| connman_check_ok_message(error, message) |
| #else |
| #define connman_verify_ok_message(error, message) \ |
| connman_verify_message(error == 0, message) |
| #endif |
| |
| #define connman_verify_ok(error) \ |
| connman_verify_ok_message(error, NULL) |
| |
| #define connman_require_quiet(predicate, label) \ |
| do { \ |
| if (!(predicate)) { \ |
| goto label; \ |
| } \ |
| } while (0) |
| |
| #if CONNMAN_DEBUG |
| #define connman_require_message(predicate, label, message) \ |
| do { \ |
| if (!(predicate)) { \ |
| CONNMAN_ASSERT(CONNMAN_ASSERT_MODULE, \ |
| #predicate, \ |
| message, \ |
| __FILE__, \ |
| __LINE__, \ |
| 0); \ |
| goto label; \ |
| } \ |
| } while (0) |
| #else |
| #define connman_require_message(predicate, label, message) \ |
| connman_require(predicate, label) |
| #endif |
| |
| #define connman_require(predicate, label) \ |
| connman_require_message(predicate, label, NULL) |
| |
| #define connman_require_execute_quiet(predicate, label, action) \ |
| do { \ |
| if (!(predicate)) { \ |
| { \ |
| action; \ |
| } \ |
| goto label; \ |
| } \ |
| } while (0) |
| |
| #if CONNMAN_DEBUG |
| #define connman_require_execute_message(predicate, label, action, message) \ |
| do { \ |
| if (!(predicate)) { \ |
| CONNMAN_ASSERT( \ |
| CONNMAN_ASSERT_MODULE, \ |
| #predicate, \ |
| message, \ |
| __FILE__, \ |
| __LINE__, \ |
| 0); \ |
| { \ |
| action; \ |
| } \ |
| goto label; \ |
| } \ |
| } while (0) |
| #else |
| #define connman_require_execute_message(predicate, label, action, message) \ |
| connman_require_execute_message_quiet(predicate, label, action, message) |
| #endif |
| |
| #define connman_require_execute(predicate, label, action) \ |
| connman_require_execute_message(predicate, label, action, NULL) |
| |
| #define connman_require_ok_quiet(error, label) \ |
| connnman_require_quiet(error == 0, label) |
| |
| #if CONNMAN_DEBUG |
| #define connman_require_ok_message(error, label, message) \ |
| do { \ |
| if ((error) != 0) { \ |
| CONNMAN_ASSERT(CONNMAN_ASSERT_MODULE, \ |
| #error " == 0 ", \ |
| message, \ |
| __FILE__, \ |
| __LINE__, \ |
| error); \ |
| goto label; \ |
| } \ |
| } while (0) |
| #else |
| #define connman_require_ok_message(error, label, message) \ |
| connman_require_ok_quiet(error, label) |
| #endif |
| |
| #define connman_require_ok(error, label) \ |
| connman_require_ok_message(error, label, NULL) |
| |
| #define connman_require_ok_execute_quiet(error, label, action) \ |
| do { \ |
| if ((error) != 0) { \ |
| { \ |
| action; \ |
| } \ |
| goto label; \ |
| } \ |
| } while (0) |
| #if CONNMAN_DEBUG |
| #define connman_require_ok_execute_message(error, label, action, message) \ |
| do { \ |
| if ((error) != 0) { \ |
| CONNMAN_ASSERT(CONNMAN_ASSERT_MODULE, \ |
| #error " == 0 ", \ |
| message, \ |
| __FILE__, \ |
| __LINE__, \ |
| error); \ |
| { \ |
| action; \ |
| } \ |
| goto label; \ |
| } \ |
| } while (0) |
| #else |
| #define connman_require_ok_execute_message(error, label, action, message) \ |
| connman_require_ok_execute_quiet(error, label, action) |
| #endif |
| |
| #define connman_require_ok_execute(error, label, action) \ |
| connman_require_ok_execute_message(error, label, action, NULL) |
| |
| #ifdef __cplusplus |
| } |
| #endif |
| |
| #endif /* __CONNMAN_LOG_H */ |