/**
 * @file
 * @brief TUI LL log header
 * @copyright (C) 2012 - 2021, Samsung Electronics Co., Ltd.
 */

#pragma once

#if defined(CONFIG_TUILL_DEBUG) && !defined(CONFIG_SYSLOG_DEBUG)
#define CONFIG_SYSLOG_DEBUG
#endif
#if defined(CONFIG_TUILL_INFO) && !defined(CONFIG_SYSLOG_INFO)
#define CONFIG_SYSLOG_INFO
#endif
#if defined(CONFIG_TUILL_EXTRA) && !defined(CONFIG_SYSLOG_EXTRA)
#define CONFIG_SYSLOG_EXTRA
#endif

//TODO: delete after SDK update
#include <stdio.h>
//TODO: uncomment after SDK update
//extern const char *log_tag;

#ifdef CONFIG_TUILL_DEBUG

struct trace_info {
    const char *file;
    const char *func;
    const int pid;
};

void log_dump(const char *func, int line, uint8_t *buff, uint32_t len);
void _trace_out_(const struct trace_info *info);
struct trace_info _trace_in_(const char *file, const char *func, const int line);

#define TUILL_CALL_TRACE() __attribute__((cleanup(_trace_out_))) \
    _unused_ const struct trace_info __trace_info = _trace_in_(__FILE__, __func__, __LINE__)
#define LOG_DUMP(x, y) log_dump(__FUNCTION__, __LINE__, (uint8_t *)x, y)

#else  //CONFIG_TUILL_DEBUG

#define TUILL_CALL_TRACE()
#define LOG_DUMP(x, y)

#endif //CONFIG_TUILL_DEBUG

//TODO: delete after SDK update

#undef LOG_DEBUG
#undef LOG_NOTICE
#undef LOG_ERR
#undef syslog
#undef openlog

#define LOG_DEBUG  "DBG: "
#define LOG_NOTICE "NTC: "
#define LOG_ERR    "ERR: "

#define openlog(x, y, z)

//#define syslog(tag, fmt, args...) do {printf(MODULE_TAG tag "%s(%d): " fmt, __func__, __LINE__, ## args);} while(0)
//#define syslogtr(tag, fmt, args...) do {printf(MODULE_TAG tag fmt, ## args);} while(0)

#define syslog(tag, fmt, args...)
#define syslogtr(tag, fmt, args...)

//TODO: end
