aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <m.chehab@samsung.com>2014-09-14 09:52:29 -0300
committerMauro Carvalho Chehab <m.chehab@samsung.com>2014-09-14 13:01:26 -0300
commita2c7b05cf8d7f0e526801f852b00572c54fe96aa (patch)
treeab8deb468882d0357f5fc06baec7790b80e3f4de
parentb7f9d0ce01a17de4ce8b5bbf3376627c500230f9 (diff)
libdvbv5: Add support for opening FE on read only mode
Currently, all frontend opens happen on R/W mode. That prevents some types of usage where it is desired to just monitor an interface without touching it, like what femon does. So, add a new method to allow doing that. Ideally, we should also add (or fix/check) support for O_NONBLOCK mode, but this would require more efforts. So, for now, add a todo entry about that. Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
-rw-r--r--lib/include/libdvbv5/dvb-fe.h71
-rw-r--r--lib/libdvbv5/dvb-fe-priv.h1
-rw-r--r--lib/libdvbv5/dvb-fe.c27
3 files changed, 75 insertions, 24 deletions
diff --git a/lib/include/libdvbv5/dvb-fe.h b/lib/include/libdvbv5/dvb-fe.h
index 398f2a62..3bb4f1f8 100644
--- a/lib/include/libdvbv5/dvb-fe.h
+++ b/lib/include/libdvbv5/dvb-fe.h
@@ -169,9 +169,45 @@ struct dvb_v5_fe_parms *dvb_fe_dummy(void);
*
* @param adapter Number of the adapter to open
* @param frontend Number of the frontend to open
- * @param verbose Verbosity level of the messages that will be printed
- * @param use_legacy_call Force to use the DVBv3 calls, instead of using the
- * DVBv5 API
+ * @param verbose Verbosity level of the messages that will be
+ * printed
+ * @param use_legacy_call Force to use the DVBv3 calls, instead of using
+ * the DVBv5 API
+ * @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. If NULL, the
+ * library will use its internal handler.
+ * @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.
+ *
+ * @todo Add/check support for O_NONBLOCK at the scan routines.
+ *
+ * @details This function should be called before using any other function at
+ * the frontend library (or the other alternatives: dvb_fe_open() or
+ * dvb_fe_dummy().
+ *
+ * In general, this is called using O_RDWR, except if all that it is wanted
+ * is to check the DVB frontend statistics.
+ *
+ * @return Returns a pointer to an allocated data pointer or NULL on error.
+ */
+struct dvb_v5_fe_parms *dvb_fe_open_flags(int adapter, int frontend,
+ unsigned verbose,
+ unsigned use_legacy_call,
+ dvb_logfunc logfunc,
+ int flags);
+
+/**
+ * @brief Opens a frontend and allocates a structure to work with
+ * @ingroup frontend
+ *
+ * @param adapter Number of the adapter to open
+ * @param frontend Number of the frontend to open
+ * @param verbose Verbosity level of the messages that will be
+ * printed
+ * @param use_legacy_call Force to use the DVBv3 calls, instead of using
+ * the DVBv5 API
*
* @details This function should be called before using any other function at
* the frontend library (or the other alternatives: dvb_fe_open2() or
@@ -179,8 +215,14 @@ struct dvb_v5_fe_parms *dvb_fe_dummy(void);
*
* @return Returns a pointer to an allocated data pointer or NULL on error.
*/
-struct dvb_v5_fe_parms *dvb_fe_open(int adapter, int frontend,
- unsigned verbose, unsigned use_legacy_call);
+static inline struct dvb_v5_fe_parms *dvb_fe_open(int adapter, int frontend,
+ unsigned verbose,
+ unsigned use_legacy_call)
+{
+ return dvb_fe_open_flags(adapter, frontend, verbose, use_legacy_call,
+ NULL, O_RDWR);
+
+};
/**
* @brief Opens a frontend and allocates a structure to work with
@@ -188,12 +230,13 @@ struct dvb_v5_fe_parms *dvb_fe_open(int adapter, int frontend,
*
* @param adapter Number of the adapter to open
* @param frontend Number of the frontend to open
- * @param verbose Verbosity level of the messages that will be printed
- * @param use_legacy_call Force to use the DVBv3 calls, instead of using the
- * DVBv5 API
+ * @param verbose Verbosity level of the messages that will be
+ * printed
+ * @param use_legacy_call Force to use the DVBv3 calls, instead of using
+ * the DVBv5 API
* @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.
+ * happens. Can either store the event into a file
+ * or to print it at the TUI/GUI.
*
* @details This function should be called before using any other function at
* the frontend library (or the other alternatives: dvb_fe_open() or
@@ -201,9 +244,13 @@ struct dvb_v5_fe_parms *dvb_fe_open(int adapter, int frontend,
*
* @return Returns a pointer to an allocated data pointer or NULL on error.
*/
-struct dvb_v5_fe_parms *dvb_fe_open2(int adapter, int frontend,
+static inline struct dvb_v5_fe_parms *dvb_fe_open2(int adapter, int frontend,
unsigned verbose, unsigned use_legacy_call,
- dvb_logfunc logfunc);
+ dvb_logfunc logfunc)
+{
+ return dvb_fe_open_flags(adapter, frontend, verbose, use_legacy_call,
+ logfunc, O_RDWR);
+}
/**
* @brief Closes the frontend and frees allocated resources
diff --git a/lib/libdvbv5/dvb-fe-priv.h b/lib/libdvbv5/dvb-fe-priv.h
index 195c3bfb..f3e99dd0 100644
--- a/lib/libdvbv5/dvb-fe-priv.h
+++ b/lib/libdvbv5/dvb-fe-priv.h
@@ -59,6 +59,7 @@ struct dvb_v5_fe_parms_priv {
struct dvb_v5_fe_parms p;
int fd;
+ int fe_flags; /* open() flags */
char *fname;
int n_props;
struct dtv_property dvb_prop[DTV_MAX_COMMAND];
diff --git a/lib/libdvbv5/dvb-fe.c b/lib/libdvbv5/dvb-fe.c
index f733b270..71d6e5cd 100644
--- a/lib/libdvbv5/dvb-fe.c
+++ b/lib/libdvbv5/dvb-fe.c
@@ -49,21 +49,20 @@ struct dvb_v5_fe_parms *dvb_fe_dummy()
return &parms->p;
}
-struct dvb_v5_fe_parms *dvb_fe_open(int adapter, int frontend, unsigned verbose,
- unsigned use_legacy_call)
-{
- return dvb_fe_open2(adapter, frontend, verbose, use_legacy_call,
- dvb_default_log);
-}
-
-struct dvb_v5_fe_parms *dvb_fe_open2(int adapter, int frontend, unsigned verbose,
- unsigned use_legacy_call, dvb_logfunc logfunc)
+struct dvb_v5_fe_parms *dvb_fe_open_flags(int adapter, int frontend,
+ unsigned verbose,
+ unsigned use_legacy_call,
+ dvb_logfunc logfunc,
+ int flags)
{
int fd, i, r;
char *fname;
struct dtv_properties dtv_prop;
struct dvb_v5_fe_parms_priv *parms = NULL;
+ if (logfunc == NULL)
+ logfunc = dvb_default_log;
+
r = asprintf(&fname, "/dev/dvb/adapter%i/frontend%i", adapter, frontend);
if (r < 0) {
logfunc(LOG_ERR, "asprintf error");
@@ -74,7 +73,7 @@ struct dvb_v5_fe_parms *dvb_fe_open2(int adapter, int frontend, unsigned verbose
return NULL;
}
- fd = open(fname, O_RDWR, 0);
+ fd = open(fname, flags, 0);
if (fd == -1) {
logfunc(LOG_ERR, "%s while opening %s", strerror(errno), fname);
free(fname);
@@ -88,8 +87,9 @@ struct dvb_v5_fe_parms *dvb_fe_open2(int adapter, int frontend, unsigned verbose
return NULL;
}
parms->fname = fname;
- parms->p.verbose = verbose;
parms->fd = fd;
+ parms->fe_flags = flags;
+ parms->p.verbose = verbose;
parms->p.default_charset = "iso-8859-1";
parms->p.output_charset = "utf-8";
parms->p.logfunc = logfunc;
@@ -231,7 +231,10 @@ struct dvb_v5_fe_parms *dvb_fe_open2(int adapter, int frontend, unsigned verbose
parms->p.current_sys = parms->p.systems[0];
/* Prepare to use the delivery system */
- dvb_set_sys(&parms->p, parms->p.current_sys);
+ parms->n_props = dvb_add_parms_for_sys(&parms->p, parms->p.current_sys);
+
+ if ((flags & O_ACCMODE) == O_RDWR)
+ dvb_set_sys(&parms->p, parms->p.current_sys);
/*
* Prepare the status struct - DVBv5.10 parameters should

Privacy Policy