libexplain  1.4.D001
libexplain/iocontrol/vidioc_querymenu.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - a library of system-call-specific strerror replacements
00003  * Copyright (C) 2011, 2013 Peter Miller
00004  * Written by Peter Miller <pmiller@opensource.org.au>
00005  *
00006  * This program is free software; you can redistribute it and/or modify it
00007  * under the terms of the GNU Lesser General Public License as published by
00008  * the Free Software Foundation; either version 3 of the License, or (at your
00009  * option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful, but WITHOUT
00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00014  * License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00018  */
00019 
00020 #include <libexplain/ac/errno.h>
00021 #include <libexplain/ac/linux/videodev2.h>
00022 #include <libexplain/ac/string.h>
00023 #include <libexplain/ac/sys/ioctl.h>
00024 
00025 #include <libexplain/buffer/einval.h>
00026 #include <libexplain/buffer/is_the_null_pointer.h>
00027 #include <libexplain/buffer/v4l2_ctrl_type.h>
00028 #include <libexplain/buffer/v4l2_querymenu.h>
00029 #include <libexplain/iocontrol/generic.h>
00030 #include <libexplain/iocontrol/vidioc_querymenu.h>
00031 #include <libexplain/is_efault.h>
00032 
00033 #ifdef VIDIOC_QUERYMENU
00034 
00035 
00036 static void
00037 print_data(const explain_iocontrol_t *p, explain_string_buffer_t *sb,
00038     int errnum, int fildes, int request, const void *data)
00039 {
00040     (void)p;
00041     (void)errnum;
00042     (void)fildes;
00043     (void)request;
00044     explain_buffer_v4l2_querymenu(sb, data, 0);
00045 }
00046 
00047 
00048 static void
00049 print_explanation(const explain_iocontrol_t *p, explain_string_buffer_t *sb,
00050     int errnum, int fildes, int request, const void *data)
00051 {
00052     switch (errnum)
00053     {
00054     case EINVAL:
00055         if (!data)
00056         {
00057             explain_buffer_is_the_null_pointer(sb, "data");
00058             return;
00059         }
00060 
00061         {
00062             const struct v4l2_querymenu *arg;
00063             struct v4l2_queryctrl ctrl;
00064 
00065             arg = data;
00066             if (explain_is_efault_pointer(arg, sizeof(*arg)))
00067                 goto generic;
00068 
00069             memset(&ctrl, 0, sizeof(ctrl));
00070             ctrl.id = arg->id;
00071             if (ioctl(fildes, VIDIOC_QUERYCTRL, &ctrl) < 0)
00072             {
00073                 explain_buffer_einval_vague(sb, "data->id");
00074                 return;
00075             }
00076             if (ctrl.type != V4L2_CTRL_TYPE_MENU)
00077             {
00078                 explain_buffer_einval_vague(sb, "data->id");
00079 
00080                 /*
00081                  * Foot note the actual type.
00082                  */
00083                 explain_string_buffer_puts(sb->footnotes, "; ");
00084                 explain_string_buffer_puts
00085                 (
00086                     sb->footnotes,
00087                     /* FIXME: i18n */
00088                     "the control is of type "
00089                 );
00090                 explain_buffer_v4l2_ctrl_type(sb->footnotes, ctrl.type);
00091                 return;
00092             }
00093         }
00094 
00095         /* no idea */
00096         goto generic;
00097 
00098     default:
00099         generic:
00100         explain_iocontrol_generic_print_explanation
00101         (
00102             p,
00103             sb,
00104             errnum,
00105             fildes,
00106             request,
00107             data
00108         );
00109         break;
00110     }
00111 }
00112 
00113 
00114 static void
00115 print_data_returned(const explain_iocontrol_t *p, explain_string_buffer_t *sb,
00116     int errnum, int fildes, int request, const void *data)
00117 {
00118     (void)p;
00119     (void)errnum;
00120     (void)fildes;
00121     (void)request;
00122     explain_buffer_v4l2_querymenu(sb, data, 1);
00123 }
00124 
00125 
00126 const explain_iocontrol_t explain_iocontrol_vidioc_querymenu =
00127 {
00128     "VIDIOC_QUERYMENU", /* name */
00129     VIDIOC_QUERYMENU, /* value */
00130     0, /* disambiguate */
00131     0, /* print_name */
00132     print_data,
00133     print_explanation,
00134     print_data_returned,
00135     sizeof(struct v4l2_querymenu), /* data_size */
00136     "struct v4l2_querymenu *", /* data_type */
00137     0, /* flags */
00138     __FILE__,
00139     __LINE__,
00140 };
00141 
00142 #else /* ndef VIDIOC_QUERYMENU */
00143 
00144 const explain_iocontrol_t explain_iocontrol_vidioc_querymenu =
00145 {
00146     0, /* name */
00147     0, /* value */
00148     0, /* disambiguate */
00149     0, /* print_name */
00150     0, /* print_data */
00151     0, /* print_explanation */
00152     0, /* print_data_returned */
00153     0, /* data_size */
00154     0, /* data_type */
00155     0, /* flags */
00156     __FILE__,
00157     __LINE__,
00158 };
00159 
00160 #endif /* VIDIOC_QUERYMENU */
00161 
00162 /* vim: set ts=8 sw=4 et : */