[media] v4l2-ctrls: add helper functions for control events
authorHans Verkuil <hans.verkuil@cisco.com>
Fri, 27 Jan 2012 19:18:42 +0000 (16:18 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 14 Feb 2012 18:38:43 +0000 (16:38 -0200)
Many drivers just support control events, and most radio drivers just need
to poll for control events. Add some functions to simplify those jobs.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/v4l2-ctrls.c
include/media/v4l2-ctrls.h

index 7d58e4d420cd70153f55b095528950b3b524f5bc..909117203610a66bf812205a051a436b44132e90 100644 (file)
@@ -2394,3 +2394,23 @@ int v4l2_ctrl_log_status(struct file *file, void *fh)
        return 0;
 }
 EXPORT_SYMBOL(v4l2_ctrl_log_status);
+
+int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
+                               struct v4l2_event_subscription *sub)
+{
+       if (sub->type == V4L2_EVENT_CTRL)
+               return v4l2_event_subscribe(fh, sub, 0);
+       return -EINVAL;
+}
+EXPORT_SYMBOL(v4l2_ctrl_subscribe_event);
+
+unsigned int v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait)
+{
+       struct v4l2_fh *fh = file->private_data;
+
+       if (v4l2_event_pending(fh))
+               return POLLPRI;
+       poll_wait(file, &fh->wait, wait);
+       return 0;
+}
+EXPORT_SYMBOL(v4l2_ctrl_poll);
index 5f246c277ff8bbb941306cbe980e6b5416c32640..3dbd066385062a218a9798e97a1f0e729038270a 100644 (file)
@@ -33,6 +33,7 @@ struct video_device;
 struct v4l2_subdev;
 struct v4l2_subscribed_event;
 struct v4l2_fh;
+struct poll_table_struct;
 
 /** struct v4l2_ctrl_ops - The control operations that the driver has to provide.
   * @g_volatile_ctrl: Get a new value for this control. Generally only relevant
@@ -496,6 +497,14 @@ void v4l2_ctrl_del_event(struct v4l2_ctrl *ctrl,
    associated with the filehandle. */
 int v4l2_ctrl_log_status(struct file *file, void *fh);
 
+/* Can be used as a vidioc_subscribe_event function that just subscribes
+   control events. */
+int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
+                               struct v4l2_event_subscription *sub);
+
+/* Can be used as a poll function that just polls for control events. */
+unsigned int v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait);
+
 /* Helpers for ioctl_ops. If hdl == NULL then they will all return -EINVAL. */
 int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);
 int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm);