1 /* 2 * Copyright (c) 2011-2014 - Mauro Carvalho Chehab 3 * Copyright (c) 2012 - Andre Roth <neolynx@gmail.com> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU Lesser General Public License as published by 7 * the Free Software Foundation version 2.1 of the License. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 18 * 19 */ 20 21 #ifndef _LOG_H 22 #define _LOG_H 23 24 #include <syslog.h> 25 26 /** 27 * @file dvb-log.h 28 * @ingroup ancillary 29 * @brief Provides interfaces to handle libdvbv5 log messages. 30 * @copyright GNU Lesser General Public License version 2.1 (LGPLv2.1) 31 * @author Mauro Carvalho Chehab 32 * @author Andre Roth 33 * 34 * @par Bug Report 35 * Please submit bug reports and patches to linux-media@vger.kernel.org 36 */ 37 38 /** 39 * @typedef void (*dvb_logfunc)(int level, const char *fmt, ...) 40 * @brief typedef used by dvb_fe_open2 for the log function 41 * @ingroup ancillary 42 */ 43 44 typedef void (*dvb_logfunc)(int level, const char *fmt, ...) __attribute__ (( format( printf, 2, 3 ))); 45 46 /** 47 * @typedef void (*dvb_logfunc)(void *logpriv, int level, const char *fmt, ...) 48 * @brief typedef used by dvb_fe_open2 for the log function with private context 49 * @ingroup ancillary 50 */ 51 52 typedef void (*dvb_logfunc_priv)(void *logpriv, int level, const char *fmt, ...); 53 54 /* 55 * Macros used internally inside libdvbv5 frontend part, to output logs 56 */ 57 58 #ifndef _DOXYGEN 59 60 struct dvb_v5_fe_parms; 61 /** 62 * @brief retrieve the logging function with private data from the private fe params. 63 */ 64 dvb_logfunc_priv dvb_get_log_priv(struct dvb_v5_fe_parms *, void **); 65 66 #ifndef __DVB_FE_PRIV_H 67 68 #define dvb_loglevel(level, fmt, arg...) do {\ 69 void *priv;\ 70 dvb_logfunc_priv f = dvb_get_log_priv(parms, &priv);\ 71 if (f) {\ 72 f(priv, level, fmt, ##arg);\ 73 } else {\ 74 parms->logfunc(level, fmt, ##arg); \ 75 }\ 76 } while (0) 77 78 #else 79 80 #define dvb_loglevel(level, fmt, arg...) do {\ 81 if (parms->logfunc_priv) {\ 82 parms->logfunc_priv(parms->logpriv, level, fmt, ##arg);\ 83 } else {\ 84 parms->p.logfunc(level, fmt, ##arg); \ 85 }\ 86 } while (0) 87 88 #endif 89 90 #define dvb_log(fmt, arg...) dvb_loglevel(LOG_INFO, fmt, ##arg) 91 #define dvb_logerr(fmt, arg...) dvb_loglevel(LOG_ERR, fmt, ##arg) 92 #define dvb_logdbg(fmt, arg...) dvb_loglevel(LOG_DEBUG, fmt, ##arg) 93 #define dvb_logwarn(fmt, arg...) dvb_loglevel(LOG_WARNING, fmt, ##arg) 94 #define dvb_loginfo(fmt, arg...) dvb_loglevel(LOG_NOTICE, fmt, ##arg) 95 96 #define dvb_perror(msg) dvb_logerr("%s: %s", msg, strerror(errno)) 97 98 #endif /* _DOXYGEN */ 99 100 /** 101 * @brief This is the prototype of the internal log function that it is used, 102 * if the library client doesn't desire to override with something else. 103 * @ingroup ancillary 104 * 105 * @param level level of the message, as defined at syslog.h 106 * @param fmt format string (same as format string on sprintf) 107 */ 108 void dvb_default_log(int level, const char *fmt, ...) __attribute__ (( format( printf, 2, 3 ))); 109 110 #endif 111