dvb_logfunc: add a user private parameter
PATCH 1/2 dvb_logfunc: add a user private parameter
--- lib/include/libdvbv5/dvb-dev.h | 3 ++- lib/include/libdvbv5/dvb-fe.h | 9 +++++++-- lib/include/libdvbv5/dvb-log.h | 33 +++++++++++++++++---------------- lib/libdvbv5/dvb-dev.c | 3 ++- lib/libdvbv5/dvb-fe.c | 15 ++++++++------- lib/libdvbv5/dvb-log.c | 3 ++- utils/dvb/dvb-fe-tool.c | 2 +- utils/dvb/dvbv5-daemon.c | 9 +++++---- utils/dvb/dvbv5-scan.c | 2 +- utils/dvb/dvbv5-zap.c | 2 +- 10 files changed, 46 insertions(+), 35 deletions(-)
lib/include/libdvbv5/dvb-dev.h +2 -1
@@ -243,6 +243,7 @@ void dvb_dev_stop_monitor(struct dvb_device *dvb);* @param logfunc Callback function to be called when a log event * happens. Can either store the event into a file or * to print it at the TUI/GUI. Can be null. +* @param logpriv Private data for log function * * @details Sets the function to report log errors and to set the verbosity * level of debug report messages. If not called, or if logfunc is
@@ -252,7 +253,7 @@ void dvb_dev_stop_monitor(struct dvb_device *dvb);*/ void dvb_dev_set_log (struct dvb_device *dvb,unsigned verbose, -dvb_logfunc logfunc); +dvb_logfunc logfunc,void *logpriv);/** * @brief Opens a dvb device
lib/include/libdvbv5/dvb-fe.h +7 -2
@@ -107,6 +107,7 @@* @param freq_bpf SCR/Unicable band-pass filter frequency to use, in kHz * @param verbose Verbosity level of the library (RW) * @param dvb_logfunc Function used to write log messages (RO) +* @param logpriv Private data for logging function (RO) * @param default_charset Name of the charset used by the DVB standard (RW) * @param output_charset Name of the charset to output (system specific) (RW) *
@@ -140,7 +141,8 @@ struct dvb_v5_fe_parms {/* Function to write DVB logs */ unsigned verbose; -dvb_logfunc logfunc; +dvb_logfunc logfunc; +void *logpriv;/* Charsets to be used by the conversion utilities */ char *default_charset;
@@ -176,6 +178,7 @@ struct dvb_v5_fe_parms *dvb_fe_dummy(void);* happens. Can either store the event into a file * or to print it at the TUI/GUI. If NULL, the * library will use its internal handler. +* @param logpriv Private data for dvb_logfunc * @param flags Flags to be passed to open. Currently only two * flags are supported: O_RDONLY or O_RDWR. * Using O_NONBLOCK may hit unexpected issues.
@@ -195,6 +198,7 @@ struct dvb_v5_fe_parms *dvb_fe_open_flags(int adapter, int frontend,unsigned verbose, unsigned use_legacy_call, dvb_logfunc logfunc, + void *logpriv, int flags);/**
@@ -231,6 +235,7 @@ struct dvb_v5_fe_parms *dvb_fe_open(int adapter, int frontend,* @param logfunc Callback function to be called when a log event * happens. Can either store the event into a file * or to print it at the TUI/GUI. +* @param logpriv Private data for dvb_logfunc * * @details This function should be called before using any other function at * the frontend library (or the other alternatives: dvb_fe_open() or
@@ -240,7 +245,7 @@ struct dvb_v5_fe_parms *dvb_fe_open(int adapter, int frontend,*/ struct dvb_v5_fe_parms *dvb_fe_open2 (int adapter,int frontend,unsigned verbose,unsigned use_legacy_call, -dvb_logfunc logfunc); +dvb_logfunc logfunc,void *logpriv);/** * @brief Closes the frontend and frees allocated resources
lib/include/libdvbv5/dvb-log.h +17 -16
@@ -36,12 +36,12 @@*/ /** -* @typedef void (*dvb_logfunc)(int level, const char *fmt, ...) +* @typedef void (*dvb_logfunc)(void *logpriv, int level, const char *fmt, ...) * @brief typedef used by dvb_fe_open2 for the log function * @ingroup ancillary */ -typedef void (*dvb_logfunc )(int level,const char *fmt, ...) __attribute__ ((format ( printf,2 ,3 ))); +typedef void (*dvb_logfunc )(void *logpriv,int level,const char *fmt, ...) __attribute__ ((format ( printf,3 ,4 )));/* * Macros used internally inside libdvbv5 frontend part, to output logs
@@ -52,48 +52,48 @@ typedef void (*dvb_logfunc)(int level, const char *fmt, ...) __attribute__ (( fo#ifndef __DVB_FE_PRIV_H #define dvb_log(fmt, arg...) do {\ - parms->logfunc(LOG_INFO, fmt, ##arg); \ + parms->logfunc(parms->logpriv, LOG_INFO, fmt, ##arg); \ } while (0) #define dvb_logerr(fmt, arg...) do {\ - parms->logfunc(LOG_ERR, fmt, ##arg); \ + parms->logfunc(parms->logpriv, LOG_ERR, fmt, ##arg); \ } while (0) #define dvb_logdbg(fmt, arg...) do {\ - parms->logfunc(LOG_DEBUG, fmt, ##arg); \ + parms->logfunc(parms->logpriv, LOG_DEBUG, fmt, ##arg); \ } while (0) #define dvb_logwarn(fmt, arg...) do {\ - parms->logfunc(LOG_WARNING, fmt, ##arg); \ + parms->logfunc(parms->logpriv, LOG_WARNING, fmt, ##arg); \ } while (0) #define dvb_loginfo(fmt, arg...) do {\ - parms->logfunc(LOG_NOTICE, fmt, ##arg); \ + parms->logfunc(parms->logpriv, LOG_NOTICE, fmt, ##arg); \ } while (0)#define dvb_perror (msg) do {\ - parms->logfunc(LOG_ERR, "%s: %s", msg, strerror(errno)); \ + parms->logfunc(parms->logpriv, LOG_ERR, "%s: %s", msg, strerror(errno)); \ } while (0)#else #define dvb_log(fmt, arg...) do {\ - parms->p.logfunc(LOG_INFO, fmt, ##arg); \ + parms->p.logfunc(parms->p.logpriv, LOG_INFO, fmt, ##arg); \ } while (0) #define dvb_logerr(fmt, arg...) do {\ - parms->p.logfunc(LOG_ERR, fmt, ##arg); \ + parms->p.logfunc(parms->p.logpriv, LOG_ERR, fmt, ##arg); \ } while (0) #define dvb_logdbg(fmt, arg...) do {\ - parms->p.logfunc(LOG_DEBUG, fmt, ##arg); \ + parms->p.logfunc(parms->p.logpriv, LOG_DEBUG, fmt, ##arg); \ } while (0) #define dvb_logwarn(fmt, arg...) do {\ - parms->p.logfunc(LOG_WARNING, fmt, ##arg); \ + parms->p.logfunc(parms->p.logpriv, LOG_WARNING, fmt, ##arg); \ } while (0) #define dvb_loginfo(fmt, arg...) do {\ - parms->p.logfunc(LOG_NOTICE, fmt, ##arg); \ + parms->p.logfunc(parms->p.logpriv, LOG_NOTICE, fmt, ##arg); \ } while (0) #define dvb_loglevel(level, fmt, arg...) do {\ - parms->p.logfunc(level, fmt, ##arg); \ + parms->p.logfunc(parms->p.logpriv, level, fmt, ##arg); \ } while (0)#define dvb_perror (msg) do {\ - parms->p.logfunc(LOG_ERR, "%s: %s", msg, strerror(errno)); \ + parms->p.logfunc(parms->p.logpriv, LOG_ERR, "%s: %s", msg, strerror(errno)); \ } while (0)#endif
@@ -105,9 +105,10 @@ typedef void (*dvb_logfunc)(int level, const char *fmt, ...) __attribute__ (( fo* if the library client doesn't desire to override with something else. * @ingroup ancillary * +* @param logpriv private data, unused by the default function * @param level level of the message, as defined at syslog.h * @param fmt format string (same as format string on sprintf) */ -void dvb_default_log (int level,const char *fmt, ...) __attribute__ ((format ( printf,2 ,3 ))); +void dvb_default_log (void *logpriv,int level,const char *fmt, ...) __attribute__ ((format ( printf,3 ,4 )));#endif
lib/libdvbv5/dvb-dev.c +2 -1
@@ -163,12 +163,13 @@ struct dvb_dev_list *dvb_dev_seek_by_adapter(struct dvb_device *d, }void dvb_dev_set_log (struct dvb_device *dvb,unsigned verbose, -dvb_logfunc logfunc) +dvb_logfunc logfunc,void *logpriv) {struct dvb_v5_fe_parms_priv *parms = (void *)dvb->fe_parms;/* FIXME: how to get remote logs and set verbosity? */ parms->p.verbose = verbose; + parms->p.logpriv = logpriv;if (logfunc !=NULL ) parms->p.logfunc = logfunc;
lib/libdvbv5/dvb-fe.c +8 -7
@@ -113,22 +113,22 @@ struct dvb_v5_fe_parms *dvb_fe_open(int adapter, int frontend, unsigned use_legacy_call) {return dvb_fe_open_flags (adapter, frontend, verbose, use_legacy_call, -NULL ,O_RDWR ); +NULL ,NULL ,O_RDWR ); }struct dvb_v5_fe_parms *dvb_fe_open2 (int adapter,int frontend,unsigned verbose,unsigned use_legacy_call, -dvb_logfunc logfunc) +dvb_logfunc logfunc,void *logpriv) {return dvb_fe_open_flags (adapter, frontend, verbose, use_legacy_call, - logfunc,O_RDWR ); + logfunc, logpriv,O_RDWR ); }struct dvb_v5_fe_parms *dvb_fe_open_flags (int adapter,int frontend,unsigned verbose,unsigned use_legacy_call, -dvb_logfunc logfunc, +dvb_logfunc logfunc,void *logpriv,int flags) {int ret;
@@ -147,7 +147,7 @@ struct dvb_v5_fe_parms *dvb_fe_open_flags(int adapter, int frontend, dvb_dev =dvb_dev_seek_by_adapter (dvb, adapter, frontend,DVB_DEVICE_FRONTEND );if (!dvb_dev) { -logfunc (LOG_ERR ,_ ("adapter %d, frontend %d not found" ), +logfunc (logpriv,LOG_ERR ,_ ("adapter %d, frontend %d not found" ), adapter, frontend);dvb_dev_free (dvb);return NULL ;
@@ -155,12 +155,12 @@ struct dvb_v5_fe_parms *dvb_fe_open_flags(int adapter, int frontend, fname =strdup (dvb_dev->path);dvb_dev_free (dvb);if (!fname) { -logfunc (LOG_ERR ,_ ("fname calloc: %s" ),strerror (errno)); +logfunc (logpriv,LOG_ERR ,_ ("fname calloc: %s" ),strerror (errno));return NULL ; } parms =calloc (sizeof (*parms),1 );if (!parms) { -logfunc (LOG_ERR ,_ ("parms calloc: %s" ),strerror (errno)); +logfunc (logpriv,LOG_ERR ,_ ("parms calloc: %s" ),strerror (errno));free (fname);return NULL ; }
@@ -168,6 +168,7 @@ struct dvb_v5_fe_parms *dvb_fe_open_flags(int adapter, int frontend, parms->p.default_charset ="iso-8859-1" ; parms->p.output_charset ="utf-8" ; parms->p.logfunc = logfunc; + parms->p.logpriv = logpriv; parms->p.lna =LNA_AUTO ; parms->p.sat_number =-1 ; parms->p.abort =0 ;
lib/libdvbv5/dvb-log.c +2 -1
@@ -55,8 +55,9 @@ static const struct loglevel { };#define LOG_COLOROFF 8 -void dvb_default_log (int level,const char *fmt, ...) +void dvb_default_log (void *logpriv,int level,const char *fmt, ...) { + (void )logpriv;/* unused by default function */ if (level >sizeof (loglevels) /sizeof (struct loglevel ) -2 )// ignore LOG_COLOROFF as well level =LOG_INFO ;va_list ap;
utils/dvb/dvb-fe-tool.c +1 -1
@@ -349,7 +349,7 @@ int main(int argc, char *argv[])return -1 ; } -dvb_dev_set_log (dvb, verbose,NULL ); +dvb_dev_set_log (dvb, verbose,NULL ,NULL );if (device_mon) {dvb_dev_find (dvb, &dev_change_monitor,NULL );while (1 ) {
utils/dvb/dvbv5-daemon.c +5 -4
@@ -553,12 +553,13 @@ static ssize_t scan_data(char *buf, int buf_size, const char *fmt, ...)/* * Remote log */ -void dvb_remote_log (int level,const char *fmt, ...) +void dvb_remote_log (void *priv,int level,const char *fmt, ...) {int ret;char *buf;va_list ap; +int fd = *(int *)priv;va_start (ap, fmt); ret =vasprintf (&buf, fmt, ap);
@@ -569,8 +570,8 @@ void dvb_remote_log(int level, const char *fmt, ...)va_end (ap); -if (dvb_fd >0 ) -send_data (dvb_fd,"%i%s%i%s" ,0 ,"log" , level, buf); +if (fd >0 ) +send_data (fd,"%i%s%i%s" ,0 ,"log" , level, buf);else local_log (level, buf);
@@ -1486,7 +1487,7 @@ int main(int argc, char *argv[]) }/* FIXME: should allow the caller to set the verbosity */ -dvb_dev_set_log (dvb,1 , dvb_remote_log); +dvb_dev_set_log (dvb,1 , dvb_remote_log, &dvb_fd);/* Listen up to 5 connections */ listen (sockfd,5 );
utils/dvb/dvbv5-scan.c +1 -1
@@ -520,7 +520,7 @@ int main(int argc, char **argv) dvb =dvb_dev_alloc ();if (!dvb)return -1 ; -dvb_dev_set_log (dvb, verbose,NULL ); +dvb_dev_set_log (dvb, verbose,NULL ,NULL );dvb_dev_find (dvb,NULL ,NULL ); parms = dvb->fe_parms;
utils/dvb/dvbv5-zap.c +1 -1
@@ -884,7 +884,7 @@ int main(int argc, char **argv)return -1 ; } -dvb_dev_set_log (dvb, args.verbose,NULL ); +dvb_dev_set_log (dvb, args.verbose,NULL ,NULL );dvb_dev_find (dvb,NULL ,NULL ); parms = dvb->fe_parms;
Signature · 1 line
2.14.1
PATCH 2/2 dvbv5-daemon: 0 is a valid fd
--- utils/dvb/dvbv5-daemon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
utils/dvb/dvbv5-daemon.c +1 -1
@@ -570,7 +570,7 @@ void dvb_remote_log(void *priv, int level, const char *fmt, ...)va_end (ap); -if (fd >0 ) +if (fd >=0 )send_data (fd,"%i%s%i%s" ,0 ,"log" , level, buf);else local_log (level, buf);
Signature · 1 line
2.14.1
Re: [PATCH 2/2] dvbv5-daemon: 0 is a valid fd
Em Wed, 15 Nov 2017 12:33:36 +0100
Rafaël Carré <[email protected]> escreveu:
Quoted 9 lines
--- utils/dvb/dvbv5-daemon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)utils/dvb/dvbv5-daemon.c +0
-0
utils/dvb/dvbv5-daemon.c void dvb_remote_log(void *priv, int level, const char *fmt, ...) · line 576
Quoted 8 lines
utils/dvb/dvbv5-daemon.c +1
-1@@ -570,7 +570,7 @@ void dvb_remote_log(void *priv, int level, const char *fmt, ...)va_end (ap); -if (fd >0 ) +if (fd >=0 )send_data (fd,"%i%s%i%s" ,0 ,"log" , level, buf);else local_log (level, buf);
Patch looks OK. Just need a description explaining why we need to consider fd == 0 and a SOB.
Thanks,
Mauro
Re: [PATCH 2/2] dvbv5-daemon: 0 is a valid fd
Quoted 13 lines · Mauro Carvalho Chehab
Em Wed, 15 Nov 2017 12:33:36 +0100
Rafaël Carré <[email protected]> escreveu:Quoted 10 lines
--- utils/dvb/dvbv5-daemon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)utils/dvb/dvbv5-daemon.c +0
-0@@ -570,7 +570,7 @@ void dvb_remote_log(void *priv, int level, const char *fmt, ...)
Quoted 7 lines
utils/dvb/dvbv5-daemon.c void dvb_remote_log(void *priv, int level, const char *fmt, ...) · line 576
Quoted 7 lines
utils/dvb/dvbv5-daemon.c +1
-1va_end (ap); -if (fd >0 ) +if (fd >=0 )send_data (fd,"%i%s%i%s" ,0 ,"log" , level, buf);else local_log (level, buf);
Quoted 3 lines
Patch looks OK. Just need a description explaining why we need to consider fd == 0 and a SOB.
Sorry, I am not used to do sign-off, will try to remember.
fd == 0 can happen if the application closes stdin/out/err then opens a new fd.
Should I put this in the commit log?
Quoted 3 lines
Thanks,
Mauro
Re: [PATCH 2/2] dvbv5-daemon: 0 is a valid fd
Em Thu, 16 Nov 2017 12:36:24 +0100
Rafaël Carré <[email protected]> escreveu:
Quoted 28 lines · Mauro Carvalho Chehab
Quoted 13 lines
Em Wed, 15 Nov 2017 12:33:36 +0100
Rafaël Carré <[email protected]> escreveu:Quoted 10 lines
--- utils/dvb/dvbv5-daemon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)utils/dvb/dvbv5-daemon.c +0
-0@@ -570,7 +570,7 @@ void dvb_remote_log(void *priv, int level, const char *fmt, ...)Quoted 7 lines
utils/dvb/dvbv5-daemon.c void dvb_remote_log(void *priv, int level, const char *fmt, ...) · line 576
Quoted 7 lines
utils/dvb/dvbv5-daemon.c +1
-1va_end (ap); -if (fd >0 ) +if (fd >=0 )send_data (fd,"%i%s%i%s" ,0 ,"log" , level, buf);else local_log (level, buf);Signed-off-by Rafaël Carré <[email protected]>Quoted 3 lines
Patch looks OK. Just need a description explaining why we need to consider fd == 0 and a SOB.
Quoted 6 lines
Sorry, I am not used to do sign-off, will try to remember.
fd == 0 can happen if the application closes stdin/out/err then opens a new fd.
Should I put this in the commit log?
For this one, no need. Next time, the best is to resend, as I usually use patchwork also to pick the patches. Patchwork won't automatically pick new patch descriptions.
Quoted 5 lines
Quoted 4 lines
Thanks,
Mauro
Thanks,
Mauro
Em Wed, 15 Nov 2017 12:33:35 +0100
Rafaël Carré <[email protected]> escreveu:
At v4l-utils, we're using about the same submission rules as with the Linux Kernel. So, I would be expecting a patch description and, most importantly, a Signed-off-by.
Quoted 26 lines
--- lib/include/libdvbv5/dvb-dev.h | 3 ++- lib/include/libdvbv5/dvb-fe.h | 9 +++++++-- lib/include/libdvbv5/dvb-log.h | 33 +++++++++++++++++---------------- lib/libdvbv5/dvb-dev.c | 3 ++- lib/libdvbv5/dvb-fe.c | 15 ++++++++------- lib/libdvbv5/dvb-log.c | 3 ++- utils/dvb/dvb-fe-tool.c | 2 +- utils/dvb/dvbv5-daemon.c | 9 +++++---- utils/dvb/dvbv5-scan.c | 2 +- utils/dvb/dvbv5-zap.c | 2 +- 10 files changed, 46 insertions(+), 35 deletions(-)lib/include/libdvbv5/dvb-dev.h +1
-0@@ -243,6 +243,7 @@ void dvb_dev_stop_monitor(struct dvb_device *dvb);* @param logfunc Callback function to be called when a log event * happens. Can either store the event into a file or * to print it at the TUI/GUI. Can be null. +* @param logpriv Private data for log function * * @details Sets the function to report log errors and to set the verbosity * level of debug report messages. If not called, or if logfunc is
lib/include/libdvbv5/dvb-dev.h void dvb_dev_stop_monitor(struct dvb_device *dvb); · line 256
Quoted 5 lines
lib/include/libdvbv5/dvb-dev.h +1
-1@@ -252,7 +253,7 @@ void dvb_dev_stop_monitor(struct dvb_device *dvb);*/ void dvb_dev_set_log (struct dvb_device *dvb,unsigned verbose, -dvb_logfunc logfunc); +dvb_logfunc logfunc,void *logpriv);
That breaks the ABI. I guess the best here would be to create a new function (dvb_dev_set_logpriv?), and keep this function name for backward compatibility.
Quoted 16 lines
lib/include/libdvbv5/dvb-dev.h +0
-0/** * @brief Opens a dvb device lib/include/libdvbv5/dvb-fe.h +1
-0@@ -107,6 +107,7 @@* @param freq_bpf SCR/Unicable band-pass filter frequency to use, in kHz * @param verbose Verbosity level of the library (RW) * @param dvb_logfunc Function used to write log messages (RO) +* @param logpriv Private data for logging function (RO) * @param default_charset Name of the charset used by the DVB standard (RW) * @param output_charset Name of the charset to output (system specific) (RW) *
lib/include/libdvbv5/dvb-fe.h struct dvb_v5_fe_parms { · line 145
Quoted 6 lines
lib/include/libdvbv5/dvb-fe.h +2
-1@@ -140,7 +141,8 @@ struct dvb_v5_fe_parms {/* Function to write DVB logs */ unsigned verbose; -dvb_logfunc logfunc; +dvb_logfunc logfunc; +void *logpriv;
To avoid breaking API, please put this at dvb_v5_fe_parms_priv.
Quoted 42 lines
lib/include/libdvbv5/dvb-fe.h +4
-1/* Charsets to be used by the conversion utilities */ char *default_charset;@@ -176,6 +178,7 @@ struct dvb_v5_fe_parms *dvb_fe_dummy(void);* happens. Can either store the event into a file * or to print it at the TUI/GUI. If NULL, the * library will use its internal handler. +* @param logpriv Private data for dvb_logfunc * @param flags Flags to be passed to open. Currently only two * flags are supported: O_RDONLY or O_RDWR. * Using O_NONBLOCK may hit unexpected issues. @@ -195,6 +198,7 @@ struct dvb_v5_fe_parms *dvb_fe_open_flags(int adapter, int frontend,unsigned verbose, unsigned use_legacy_call, dvb_logfunc logfunc, + void *logpriv, int flags);/** @@ -231,6 +235,7 @@ struct dvb_v5_fe_parms *dvb_fe_open(int adapter, int frontend,* @param logfunc Callback function to be called when a log event * happens. Can either store the event into a file * or to print it at the TUI/GUI. +* @param logpriv Private data for dvb_logfunc * * @details This function should be called before using any other function at * the frontend library (or the other alternatives: dvb_fe_open() or @@ -240,7 +245,7 @@ struct dvb_v5_fe_parms *dvb_fe_open(int adapter, int frontend,*/ struct dvb_v5_fe_parms *dvb_fe_open2 (int adapter,int frontend,unsigned verbose,unsigned use_legacy_call, -dvb_logfunc logfunc); +dvb_logfunc logfunc,void *logpriv);/** * @brief Closes the frontend and frees allocated resources lib/include/libdvbv5/dvb-log.h +0
-0@@ -36,12 +36,12 @@*/
lib/include/libdvbv5/dvb-log.h line 44
Quoted 10 lines
lib/include/libdvbv5/dvb-log.h +2
-2/** -* @typedef void (*dvb_logfunc)(int level, const char *fmt, ...) +* @typedef void (*dvb_logfunc)(void *logpriv, int level, const char *fmt, ...) * @brief typedef used by dvb_fe_open2 for the log function * @ingroup ancillary */ -typedef void (*dvb_logfunc )(int level,const char *fmt, ...) __attribute__ ((format ( printf,2 ,3 ))); +typedef void (*dvb_logfunc )(void *logpriv,int level,const char *fmt, ...) __attribute__ ((format ( printf,3 ,4 )));
Same applies here: we'll likely need a new type, keeping the old one for backward compat.
Quoted 244 lines
lib/include/libdvbv5/dvb-log.h +15
-14/* * Macros used internally inside libdvbv5 frontend part, to output logs @@ -52,48 +52,48 @@ typedef void (*dvb_logfunc)(int level, const char *fmt, ...) __attribute__ (( fo#ifndef __DVB_FE_PRIV_H #define dvb_log(fmt, arg...) do {\ - parms->logfunc(LOG_INFO, fmt, ##arg); \ + parms->logfunc(parms->logpriv, LOG_INFO, fmt, ##arg); \ } while (0) #define dvb_logerr(fmt, arg...) do {\ - parms->logfunc(LOG_ERR, fmt, ##arg); \ + parms->logfunc(parms->logpriv, LOG_ERR, fmt, ##arg); \ } while (0) #define dvb_logdbg(fmt, arg...) do {\ - parms->logfunc(LOG_DEBUG, fmt, ##arg); \ + parms->logfunc(parms->logpriv, LOG_DEBUG, fmt, ##arg); \ } while (0) #define dvb_logwarn(fmt, arg...) do {\ - parms->logfunc(LOG_WARNING, fmt, ##arg); \ + parms->logfunc(parms->logpriv, LOG_WARNING, fmt, ##arg); \ } while (0) #define dvb_loginfo(fmt, arg...) do {\ - parms->logfunc(LOG_NOTICE, fmt, ##arg); \ + parms->logfunc(parms->logpriv, LOG_NOTICE, fmt, ##arg); \ } while (0)#define dvb_perror (msg) do {\ - parms->logfunc(LOG_ERR, "%s: %s", msg, strerror(errno)); \ + parms->logfunc(parms->logpriv, LOG_ERR, "%s: %s", msg, strerror(errno)); \ } while (0)#else #define dvb_log(fmt, arg...) do {\ - parms->p.logfunc(LOG_INFO, fmt, ##arg); \ + parms->p.logfunc(parms->p.logpriv, LOG_INFO, fmt, ##arg); \ } while (0) #define dvb_logerr(fmt, arg...) do {\ - parms->p.logfunc(LOG_ERR, fmt, ##arg); \ + parms->p.logfunc(parms->p.logpriv, LOG_ERR, fmt, ##arg); \ } while (0) #define dvb_logdbg(fmt, arg...) do {\ - parms->p.logfunc(LOG_DEBUG, fmt, ##arg); \ + parms->p.logfunc(parms->p.logpriv, LOG_DEBUG, fmt, ##arg); \ } while (0) #define dvb_logwarn(fmt, arg...) do {\ - parms->p.logfunc(LOG_WARNING, fmt, ##arg); \ + parms->p.logfunc(parms->p.logpriv, LOG_WARNING, fmt, ##arg); \ } while (0) #define dvb_loginfo(fmt, arg...) do {\ - parms->p.logfunc(LOG_NOTICE, fmt, ##arg); \ + parms->p.logfunc(parms->p.logpriv, LOG_NOTICE, fmt, ##arg); \ } while (0) #define dvb_loglevel(level, fmt, arg...) do {\ - parms->p.logfunc(level, fmt, ##arg); \ + parms->p.logfunc(parms->p.logpriv, level, fmt, ##arg); \ } while (0)#define dvb_perror (msg) do {\ - parms->p.logfunc(LOG_ERR, "%s: %s", msg, strerror(errno)); \ + parms->p.logfunc(parms->p.logpriv, LOG_ERR, "%s: %s", msg, strerror(errno)); \ } while (0)#endif @@ -105,9 +105,10 @@ typedef void (*dvb_logfunc)(int level, const char *fmt, ...) __attribute__ (( fo* if the library client doesn't desire to override with something else. * @ingroup ancillary * +* @param logpriv private data, unused by the default function * @param level level of the message, as defined at syslog.h * @param fmt format string (same as format string on sprintf) */ -void dvb_default_log (int level,const char *fmt, ...) __attribute__ ((format ( printf,2 ,3 ))); +void dvb_default_log (void *logpriv,int level,const char *fmt, ...) __attribute__ ((format ( printf,3 ,4 )));#endif lib/libdvbv5/dvb-dev.c +2
-1@@ -163,12 +163,13 @@ struct dvb_dev_list *dvb_dev_seek_by_adapter(struct dvb_device *d, }void dvb_dev_set_log (struct dvb_device *dvb,unsigned verbose, -dvb_logfunc logfunc) +dvb_logfunc logfunc,void *logpriv) {struct dvb_v5_fe_parms_priv *parms = (void *)dvb->fe_parms;/* FIXME: how to get remote logs and set verbosity? */ parms->p.verbose = verbose; + parms->p.logpriv = logpriv;if (logfunc !=NULL ) parms->p.logfunc = logfunc;lib/libdvbv5/dvb-fe.c +8
-7@@ -113,22 +113,22 @@ struct dvb_v5_fe_parms *dvb_fe_open(int adapter, int frontend, unsigned use_legacy_call) {return dvb_fe_open_flags (adapter, frontend, verbose, use_legacy_call, -NULL ,O_RDWR ); +NULL ,NULL ,O_RDWR ); }struct dvb_v5_fe_parms *dvb_fe_open2 (int adapter,int frontend,unsigned verbose,unsigned use_legacy_call, -dvb_logfunc logfunc) +dvb_logfunc logfunc,void *logpriv) {return dvb_fe_open_flags (adapter, frontend, verbose, use_legacy_call, - logfunc,O_RDWR ); + logfunc, logpriv,O_RDWR ); }struct dvb_v5_fe_parms *dvb_fe_open_flags (int adapter,int frontend,unsigned verbose,unsigned use_legacy_call, -dvb_logfunc logfunc, +dvb_logfunc logfunc,void *logpriv,int flags) {int ret;@@ -147,7 +147,7 @@ struct dvb_v5_fe_parms *dvb_fe_open_flags(int adapter, int frontend, dvb_dev =dvb_dev_seek_by_adapter (dvb, adapter, frontend,DVB_DEVICE_FRONTEND );if (!dvb_dev) { -logfunc (LOG_ERR ,_ ("adapter %d, frontend %d not found" ), +logfunc (logpriv,LOG_ERR ,_ ("adapter %d, frontend %d not found" ), adapter, frontend);dvb_dev_free (dvb);return NULL ;@@ -155,12 +155,12 @@ struct dvb_v5_fe_parms *dvb_fe_open_flags(int adapter, int frontend, fname =strdup (dvb_dev->path);dvb_dev_free (dvb);if (!fname) { -logfunc (LOG_ERR ,_ ("fname calloc: %s" ),strerror (errno)); +logfunc (logpriv,LOG_ERR ,_ ("fname calloc: %s" ),strerror (errno));return NULL ; } parms =calloc (sizeof (*parms),1 );if (!parms) { -logfunc (LOG_ERR ,_ ("parms calloc: %s" ),strerror (errno)); +logfunc (logpriv,LOG_ERR ,_ ("parms calloc: %s" ),strerror (errno));free (fname);return NULL ; }@@ -168,6 +168,7 @@ struct dvb_v5_fe_parms *dvb_fe_open_flags(int adapter, int frontend, parms->p.default_charset ="iso-8859-1" ; parms->p.output_charset ="utf-8" ; parms->p.logfunc = logfunc; + parms->p.logpriv = logpriv; parms->p.lna =LNA_AUTO ; parms->p.sat_number =-1 ; parms->p.abort =0 ;lib/libdvbv5/dvb-log.c +2
-1@@ -55,8 +55,9 @@ static const struct loglevel { };#define LOG_COLOROFF 8 -void dvb_default_log (int level,const char *fmt, ...) +void dvb_default_log (void *logpriv,int level,const char *fmt, ...) { + (void )logpriv;/* unused by default function */ if (level >sizeof (loglevels) /sizeof (struct loglevel ) -2 )// ignore LOG_COLOROFF as well level =LOG_INFO ;va_list ap;utils/dvb/dvb-fe-tool.c +1
-1@@ -349,7 +349,7 @@ int main(int argc, char *argv[])return -1 ; } -dvb_dev_set_log (dvb, verbose,NULL ); +dvb_dev_set_log (dvb, verbose,NULL ,NULL );if (device_mon) {dvb_dev_find (dvb, &dev_change_monitor,NULL );while (1 ) {utils/dvb/dvbv5-daemon.c +5
-4@@ -553,12 +553,13 @@ static ssize_t scan_data(char *buf, int buf_size, const char *fmt, ...)/* * Remote log */ -void dvb_remote_log (int level,const char *fmt, ...) +void dvb_remote_log (void *priv,int level,const char *fmt, ...) {int ret;char *buf;va_list ap; +int fd = *(int *)priv;va_start (ap, fmt); ret =vasprintf (&buf, fmt, ap);@@ -569,8 +570,8 @@ void dvb_remote_log(int level, const char *fmt, ...)va_end (ap); -if (dvb_fd >0 ) -send_data (dvb_fd,"%i%s%i%s" ,0 ,"log" , level, buf); +if (fd >0 ) +send_data (fd,"%i%s%i%s" ,0 ,"log" , level, buf);else local_log (level, buf);@@ -1486,7 +1487,7 @@ int main(int argc, char *argv[]) }/* FIXME: should allow the caller to set the verbosity */ -dvb_dev_set_log (dvb,1 , dvb_remote_log); +dvb_dev_set_log (dvb,1 , dvb_remote_log, &dvb_fd);/* Listen up to 5 connections */ listen (sockfd,5 );utils/dvb/dvbv5-scan.c +1
-1@@ -520,7 +520,7 @@ int main(int argc, char **argv) dvb =dvb_dev_alloc ();if (!dvb)return -1 ; -dvb_dev_set_log (dvb, verbose,NULL ); +dvb_dev_set_log (dvb, verbose,NULL ,NULL );dvb_dev_find (dvb,NULL ,NULL ); parms = dvb->fe_parms;utils/dvb/dvbv5-zap.c +0
-0
utils/dvb/dvbv5-zap.c int main(int argc, char **argv) · line 890
Quoted 8 lines
utils/dvb/dvbv5-zap.c +1
-1@@ -884,7 +884,7 @@ int main(int argc, char **argv)return -1 ; } -dvb_dev_set_log (dvb, args.verbose,NULL ); +dvb_dev_set_log (dvb, args.verbose,NULL ,NULL );dvb_dev_find (dvb,NULL ,NULL ); parms = dvb->fe_parms;
Thanks,
Mauro
PATCH v2 1/1 dvb_logfunc: add a user private parameter
In reply to Rafaël CarréThis is useful if an application is using 2 different devices, and want logging to be split by device, or if application logging needs some private context.
Care has been taken to not break the API/ABI and only add new functions, or only modify private structures.
A drawback is that when dvb_fe_open_flags() is called, the custom function can not be set yet, so dvb_fe_open_flags() will log errors using the old function without private context.
--- lib/include/libdvbv5/dvb-dev.h | 21 ++++++++++++ lib/include/libdvbv5/dvb-log.h | 73 ++++++++++++++++++++---------------------- lib/libdvbv5/dvb-dev.c | 13 ++++++++ lib/libdvbv5/dvb-fe-priv.h | 3 ++ lib/libdvbv5/dvb-fe.c | 8 +++++ utils/dvb/dvbv5-daemon.c | 9 +++--- 6 files changed, 85 insertions(+), 42 deletions(-)
lib/include/libdvbv5/dvb-dev.h +21 -0
@@ -234,6 +234,27 @@ struct dvb_dev_list *dvb_get_dev_info(struct dvb_device *dvb,*/ void dvb_dev_stop_monitor (struct dvb_device *dvb); +/** +* @brief Sets the DVB verbosity and log function with context private data +* @ingroup dvb_device +* +* @param dvb pointer to struct dvb_device to be used +* @param verbose Verbosity level of the messages that will be printed +* @param logfunc Callback function to be called when a log event +* happens. Can either store the event into a file or +* to print it at the TUI/GUI. Can be null. +* @param logpriv Private data for log function +* +* @details Sets the function to report log errors and to set the verbosity +* level of debug report messages. If not called, or if logfunc is +* NULL, the libdvbv5 will report error and debug messages via stderr, +* and will use colors for the debug messages. +* +*/ +void dvb_dev_set_logpriv (struct dvb_device *dvb, +unsigned verbose, +dvb_logfunc_priv logfunc,void *logpriv); +/** * @brief Sets the DVB verbosity and log function * @ingroup dvb_device
lib/include/libdvbv5/dvb-log.h +35 -38
96 lines not on this page · raw message
lib/libdvbv5/dvb-dev.c +13 -0
@@ -162,6 +162,19 @@ struct dvb_dev_list *dvb_dev_seek_by_adapter(struct dvb_device *d,return ops->seek_by_adapter (dvb, adapter, num, type); } +void dvb_dev_set_logpriv (struct dvb_device *dvb,unsigned verbose, +dvb_logfunc_priv logfunc_priv,void *logpriv) +{ +struct dvb_v5_fe_parms_priv *parms = (void *)dvb->fe_parms; + +/* FIXME: how to get remote logs and set verbosity? */ + parms->p.verbose = verbose; + parms->logpriv = logpriv; + +if (logfunc_priv !=NULL ) + parms->logfunc_priv = logfunc_priv; +} +void dvb_dev_set_log (struct dvb_device *dvb,unsigned verbose,dvb_logfunc logfunc) {
lib/libdvbv5/dvb-fe-priv.h +3 -0
@@ -75,6 +75,9 @@ struct dvb_v5_fe_parms_priv {/* Satellite specific stuff */ int high_band;unsigned freq_offset; + +dvb_logfunc_priv logfunc_priv; +void *logpriv; };/* Functions used internally by dvb-dev.c. Aren't part of the API */
lib/libdvbv5/dvb-fe.c +8 -0
@@ -28,6 +28,7 @@#include <stddef.h> #include <time.h> #include <unistd.h> +#include <stdarg.h> #include <config.h>
@@ -1899,3 +1900,10 @@ int dvb_fe_set_default_country(struct dvb_v5_fe_parms *p, const char *cc) parms->country =dvb_country_a2_to_id (cc);return (parms->country ==COUNTRY_UNKNOWN ) ? -EINVAL :0 ; } + +dvb_logfunc_priv dvb_get_log_priv (struct dvb_v5_fe_parms *p,void **priv) +{ +struct dvb_v5_fe_parms_priv *parms = (void *)p; + *priv = parms->logpriv; +return parms->logfunc_priv; +}
utils/dvb/dvbv5-daemon.c +5 -4
@@ -553,12 +553,13 @@ static ssize_t scan_data(char *buf, int buf_size, const char *fmt, ...)/* * Remote log */ -void dvb_remote_log (int level,const char *fmt, ...) +void dvb_remote_log (void *priv,int level,const char *fmt, ...) {int ret;char *buf;va_list ap; +int fd = *(int *)priv;va_start (ap, fmt); ret =vasprintf (&buf, fmt, ap);
@@ -569,8 +570,8 @@ void dvb_remote_log(int level, const char *fmt, ...)va_end (ap); -if (dvb_fd >=0 ) -send_data (dvb_fd,"%i%s%i%s" ,0 ,"log" , level, buf); +if (fd >=0 ) +send_data (fd,"%i%s%i%s" ,0 ,"log" , level, buf);else local_log (level, buf);
@@ -1486,7 +1487,7 @@ int main(int argc, char *argv[]) }/* FIXME: should allow the caller to set the verbosity */ -dvb_dev_set_log (dvb,1 , dvb_remote_log); +dvb_dev_set_logpriv (dvb,1 , dvb_remote_log, &dvb_fd);/* Listen up to 5 connections */ listen (sockfd,5 );
Signature · 1 line
2.14.1