dvb-log.h 3.1 KB

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