/*  MIT License
 *
 * Copyright (c) 2012-2020 Samsung Electronics Co., Ltd
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is furnished
 * to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE. */


/**
 * @file dlog.h
 * @version	0.4
 * @brief This file is the header file of interface of Dlog.
 */


#ifndef	_DLOG_H_
#define	_DLOG_H_

#include <stdarg.h>
#include <string.h>
#include <tizen_error.h>
/*
 * This is for checking dlog_print format string.
 */
#pragma GCC diagnostic warning "-Wformat"


#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */


/*
 * This is the local tag used for the following simplified
 * logging macros. You can change this preprocessor definition
 * before using the other macros to change the tag.
 */
#ifndef LOG_TAG
#define LOG_TAG NULL
#endif


/**
 * @addtogroup CAPI_SYSTEM_DLOG
 * @{
 *
 */


/**
 * @brief Enumeration for Dlog Error.
 * @if MOBILE @since_tizen 2.3 @elseif WEARABLE @since_tizen 2.3.1 @endif
 */
typedef enum {
	DLOG_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
	DLOG_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
	DLOG_ERROR_NOT_PERMITTED = TIZEN_ERROR_NOT_PERMITTED /**< Operation not permitted */
} dlog_error_e;


/**
 * @}
 */


/**
 * @addtogroup CAPI_SYSTEM_DLOG
 * @{
 */


/**
 * @brief Enumeration for log priority values in ascending priority order.
 * @if MOBILE @since_tizen 2.3 @elseif WEARABLE @since_tizen 2.3.1 @endif
 */
typedef enum {
	DLOG_UNKNOWN = 0, /**< Keep this always at the start */
	DLOG_DEFAULT, /**< Default */
	DLOG_VERBOSE, /**< Verbose */
	DLOG_DEBUG, /**< Debug */
	DLOG_INFO, /**< Info */
	DLOG_WARN, /**< Warning */
	DLOG_ERROR, /**< Error */
	DLOG_FATAL, /**< Fatal */
	DLOG_SILENT, /**< Silent */
	DLOG_PRIO_MAX /**< Keep this always at the end. */
} log_priority;


/**
 * @}
 */


/**
 * @addtogroup CAPI_SYSTEM_DLOG
 * @{
 */


/**
 * @brief Sends log with priority and tag.
 * @details for application.
 * @if MOBILE @since_tizen 2.3 @elseif WEARABLE @since_tizen 2.3.1 @endif
 * @param[in] prio priority level of type #log_priority
 * @param[in] tag tag - a null-terminated string
 * @param[in] fmt format string - same as printf
 * @return On success, the function returns the number of bytes written.
 *         On error, a negative errno-style error code
 * @retval #DLOG_ERROR_INVALID_PARAMETER Invalid parameter
 * @retval #DLOG_ERROR_NOT_PERMITTED Operation not permitted
 * @pre none
 * @post none
 * @see dlog_vprint
 *
 * @code
#include<dlog.h>
int main(void)
{
    int integer = 21;
    char string[] = "test dlog";

	dlog_print(DLOG_INFO, "USR_TAG", "test dlog");
	dlog_print(DLOG_INFO, "USR_TAG", "%s, %d", string, integer);
    return 0;
}
 * @endcode
 */
int dlog_print(log_priority prio, const char *tag, const char *fmt, ...)  __attribute__((format(printf, 3, 4)));


/**
 * @brief Sends log with priority, tag, and va_list.
 * @details for application.
 * @if MOBILE @since_tizen 2.3 @elseif WEARABLE @since_tizen 2.3.1 @endif
 * @param[in] prio priority level of type #log_priority
 * @param[in] tag tag - a null-terminated string
 * @param[in] fmt format string - same as printf
 * @param[in] ap va_list
 * @return On success, the function returns the number of bytes written.
 *         On error, a negative errno-style error code
 * @retval #DLOG_ERROR_INVALID_PARAMETER Invalid parameter
 * @retval #DLOG_ERROR_NOT_PERMITTED Operation not permitted
 * @pre none
 * @post none
 * @see dlog_print
 *
 * @code
#include<dlog.h>
void my_debug_print(char *format, ...)
{
    va_list ap;

    va_start(ap, format);
    dlog_vprint(DLOG_INFO, "USR_TAG", format, ap);
    va_end(ap);
}

int main(void)
{
    my_debug_print("%s", "test dlog");
    my_debug_print("%s, %d", "test dlog", 21);
    return 0;
}
 * @endcode
 */
int dlog_vprint(log_priority prio, const char *tag, const char *fmt, va_list ap);


/**
 * @brief Sends log with priority and tag
 * @details The same as 'dlog_print' except controlled by 'enable_dotnet_api'
 * instead of 'enable_apps'
 * @since_tizen 7.5
 * @param[in] prio priority level of type #log_priority
 * @param[in] tag tag - a null-terminated string
 * @param[in] fmt format string - same as printf
 * @return On success, the function returns the number of bytes written.
 *         On error, a negative errno-style error code
 * @retval #DLOG_ERROR_INVALID_PARAMETER Invalid parameter
 * @retval #DLOG_ERROR_NOT_PERMITTED Operation not permitted
 * @pre none
 * @post none
 * @see dlog_vprint_dotnet
 * @see dlog_print
 */
int dlog_print_dotnet(log_priority prio, const char *tag, const char *fmt, ...)  __attribute__((format(printf, 3, 4)));

/**
 * @brief Sends log with priority and tag
 * @details The same as 'dlog_print' except controlled by 'enable_native_api'
 * instead of 'enable_apps'
 * @since_tizen 7.5
 * @param[in] prio priority level of type #log_priority
 * @param[in] tag tag - a null-terminated string
 * @param[in] fmt format string - same as printf
 * @return On success, the function returns the number of bytes written.
 *         On error, a negative errno-style error code
 * @retval #DLOG_ERROR_INVALID_PARAMETER Invalid parameter
 * @retval #DLOG_ERROR_NOT_PERMITTED Operation not permitted
 * @pre none
 * @post none
 * @see dlog_vprint_native
 * @see dlog_print
 */
int dlog_print_native(log_priority prio, const char *tag, const char *fmt, ...)  __attribute__((format(printf, 3, 4)));


/**
 * @brief Sends log with priority, tag, and va_list.
 * @details The same as 'dlog_vprint' except controlled by 'enable_dotnet_api'
 * instead of 'enable_apps'
 * @since_tizen 7.5
 * @param[in] prio priority level of type #log_priority
 * @param[in] tag tag - a null-terminated string
 * @param[in] fmt format string - same as printf
 * @param[in] ap va_list
 * @return On success, the function returns the number of bytes written.
 *         On error, a negative errno-style error code
 * @retval #DLOG_ERROR_INVALID_PARAMETER Invalid parameter
 * @retval #DLOG_ERROR_NOT_PERMITTED Operation not permitted
 * @pre none
 * @post none
 * @see dlog_print_dotnet
 * @see dlog_vprint
 */
int dlog_vprint_dotnet(log_priority prio, const char *tag, const char *fmt, va_list ap);

/**
 * @brief Sends log with priority, tag, and va_list.
 * @details The same as 'dlog_vprint' except controlled by 'enable_native_api'
 * instead of 'enable_apps'
 * @since_tizen 7.5
 * @param[in] prio priority level of type #log_priority
 * @param[in] tag tag - a null-terminated string
 * @param[in] fmt format string - same as printf
 * @param[in] ap va_list
 * @return On success, the function returns the number of bytes written.
 *         On error, a negative errno-style error code
 * @retval #DLOG_ERROR_INVALID_PARAMETER Invalid parameter
 * @retval #DLOG_ERROR_NOT_PERMITTED Operation not permitted
 * @pre none
 * @post none
 * @see dlog_print_native
 * @see dlog_vprint
 */
int dlog_vprint_native(log_priority prio, const char *tag, const char *fmt, va_list ap);


/**
 * @}
 */


#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _DLOG_H_*/
