diff options
Diffstat (limited to 'devlog.h')
-rw-r--r-- | devlog.h | 177 |
1 files changed, 177 insertions, 0 deletions
diff --git a/devlog.h b/devlog.h new file mode 100644 index 0000000..b44b1be --- /dev/null +++ b/devlog.h @@ -0,0 +1,177 @@ +/* + * devman + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: DongGi Jang <dg0402.jang@samsung.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ + + +#ifndef __DEVLOG_H__ +#define __DEVLOG_H__ + +/* + * SYSLOG_INFO(), SYSLOG_ERR(), SYSLOG_DBG() are syslog() wrappers. + * PRT_INFO(), PRT_ERR(), PRT_DBG() are fprintf() wrappers. + * + * If SLP_DEBUG is not defined, SYSLOG_DBG() and PRT_DBG() is ignored. + * + * IF SLP_SYSLOG_OUT is defined, + * INFO(), ERR(), DBG() are SYSLOG_XXX() + * IF ENABLE_DLOG_OUT is defined, + * INFO(), ERR(), DBG() are SLOGI(), SLOGE(), SLOGD() + * Otherwise, + * They are PRT_XXX() + * + * + * warn_if(exrp, fmt, ...) + * If expr is true, The fmt string is printed using ERR(). + * + * ret_if(), retv_if(), retm_if(), retvm_if() + * If expr is true, current function return. + * Postfix 'v' means that it has a return value and 'm' means that it has output message. + * + */ +#include <stdio.h> +#include <stdlib.h> + +#if defined(ENABLE_DLOG_OUT) +# define LOG_TAG "DEVMAN" +# include <dlog.h> +#else +# include <syslog.h> +# define __LOG(prio, fmt, arg...) \ + do { syslog(prio, fmt, ##arg); } while (0) +# define __LOGD(prio, fmt, arg...) \ + do { \ + if (getenv("SLP_DEBUG")) { \ + syslog(prio, "[%s:%d] "fmt"\n", __FILE__, __LINE__, ##arg); \ + } \ + } while (0) +#endif + +#define __PRTI(fmt, arg...) \ + do { fprintf(stdout, fmt"\n", ##arg); } while (0) +#define __PRTE(fmt, arg...) \ + do { fprintf(stderr, fmt"\n", ##arg); } while (0) +#define __PRTD(fmt, arg...) \ + do { \ + if (getenv("SLP_DEBUG")) { \ + fprintf(stdout, "[%s:%d] "fmt"\n", __FILE__, __LINE__, ##arg); \ + } \ + } while(0) +#define _NOUT(arg...) do { } while (0) + +#ifdef SLP_DEBUG +# define _LOGD __LOGD +# define _LOG __LOG +# define _PRTD __PRTD +# define _PRTI __PRTI +# define _PRTE __PRTE +#else +# define _LOGD _NOUT +# define _LOG __LOG +# define _PRTD _NOUT +# define _PRTI __PRTI +# define _PRTE __PRTE +#endif + +#define PRT_INFO(fmt, arg...) _PRTI(fmt, ##arg) +#define PRT_ERR(fmt, arg...) _PRTE(fmt, ##arg) +#define PRT_DBG(fmt, arg...) _PRTD(fmt, ##arg) + +#if defined(SLP_SYSLOG_OUT) +# define SYSLOG_INFO(fmt, arg...) _LOG(LOG_INFO, fmt, ##arg) +# define SYSLOG_ERR(fmt, arg...) _LOG(LOG_ERR, fmt, ##arg) +# define SYSLOG_DBG(fmt, arg...) _LOGD(LOG_DEBUG, fmt, ##arg) +# define INFO SYSLOG_INFO +# define ERR SYSLOG_ERR +# define DBG SYSLOG_DBG +#elif defined(ENABLE_DLOG_OUT) +# define INFO SLOGI +# define ERR SLOGE +# define DBG SLOGD +#else +# define INFO PRT_INFO +# define ERR PRT_ERR +# define DBG PRT_DBG +#endif + +#ifdef SLP_DEBUG +# define warn_if(expr, fmt, arg...) do { \ + if (expr) { \ + DBG("(%s) -> "fmt, #expr, ##arg); \ + } \ + } while (0) +# define ret_if(expr) do { \ + if (expr) { \ + DBG("(%s) -> %s() return", #expr, __FUNCTION__); \ + return; \ + } \ + } while (0) +# define retv_if(expr, val) do { \ + if (expr) { \ + DBG("(%s) -> %s() return", #expr, __FUNCTION__); \ + return (val); \ + } \ + } while (0) +# define retm_if(expr, fmt, arg...) do { \ + if (expr) { \ + ERR(fmt, ##arg); \ + DBG("(%s) -> %s() return", #expr, __FUNCTION__); \ + return; \ + } \ + } while (0) +# define retvm_if(expr, val, fmt, arg...) do { \ + if (expr) { \ + ERR(fmt, ##arg); \ + DBG("(%s) -> %s() return", #expr, __FUNCTION__); \ + return (val); \ + } \ + } while (0) + +#else +# define warn_if(expr, fmt, arg...) do { \ + if (expr) { \ + ERR(fmt, ##arg); \ + } \ + } while (0) +# define ret_if(expr) do { \ + if (expr) { \ + return; \ + } \ + } while (0) +# define retv_if(expr, val) do { \ + if (expr) { \ + return (val); \ + } \ + } while (0) +# define retm_if(expr, fmt, arg...) do { \ + if (expr) { \ + ERR(fmt, ##arg); \ + return; \ + } \ + } while (0) +# define retvm_if(expr, val, fmt, arg...) do { \ + if (expr) { \ + ERR(fmt, ##arg); \ + return (val); \ + } \ + } while (0) + +#endif + +#endif /* __DEVLOG_H__ */ |