libexplain  1.4.D001
libexplain/iocontrol/vidioc_querybuf.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/sys/ioctl.h>
00023 
00024 #include <libexplain/buffer/einval.h>
00025 #include <libexplain/buffer/enotsup.h>
00026 #include <libexplain/buffer/is_the_null_pointer.h>
00027 #include <libexplain/buffer/v4l2_buffer.h>
00028 #include <libexplain/buffer/v4l2_buf_type.h>
00029 #include <libexplain/iocontrol/generic.h>
00030 #include <libexplain/iocontrol/vidioc_querybuf.h>
00031 #include <libexplain/is_efault.h>
00032 
00033 #ifdef VIDIOC_QUERYBUF
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_buffer(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_buffer *arg;
00063 
00064             arg = data;
00065             if (explain_is_efault_pointer(arg, sizeof(*arg)))
00066                 goto generic;
00067 
00068             /*
00069              * Check the type (the Linux kernal always does this first).
00070              */
00071             switch (explain_v4l2_buf_type_check(fildes, arg->type))
00072             {
00073             case explain_v4l2_buf_type_check_no_idea:
00074             default:
00075                 /* guess it's not the problem */
00076                 break;
00077 
00078             case explain_v4l2_buf_type_check_notsup:
00079                 explain_buffer_enotsup_device(sb, "data->type");
00080                 return;
00081 
00082             case explain_v4l2_buf_type_check_nosuch:
00083                 explain_buffer_einval_vague(sb, "data->type");
00084                 return;
00085 
00086             case explain_v4l2_buf_type_check_ok:
00087                 break;
00088             }
00089 
00090             /*
00091              * Check the frame index.
00092              */
00093             {
00094                 int             nframes;
00095 
00096                 nframes = explain_v4l2_buffer_get_nframes(fildes, arg->type);
00097                 if (nframes == 0)
00098                 {
00099                     explain_string_buffer_puts
00100                     (
00101                         sb,
00102                         /* FIXME: i18n */
00103                         "no frames have been allocated yet"
00104                     );
00105                     return;
00106                 }
00107                 if (nframes > 0 && arg->index >= (unsigned)nframes)
00108                 {
00109                     explain_buffer_einval_out_of_range
00110                     (
00111                         sb,
00112                         "data->index",
00113                         0,
00114                         nframes - 1
00115                     );
00116                     return;
00117                 }
00118             }
00119         }
00120 
00121         /* no idea */
00122         goto generic;
00123 
00124     default:
00125         generic:
00126         explain_iocontrol_generic_print_explanation
00127         (
00128             p,
00129             sb,
00130             errnum,
00131             fildes,
00132             request,
00133             data
00134         );
00135         break;
00136     }
00137 }
00138 
00139 
00140 static void
00141 print_data_returned(const explain_iocontrol_t *p, explain_string_buffer_t *sb,
00142     int errnum, int fildes, int request, const void *data)
00143 {
00144     (void)p;
00145     (void)errnum;
00146     (void)fildes;
00147     (void)request;
00148     explain_buffer_v4l2_buffer(sb, data, 1);
00149 }
00150 
00151 
00152 const explain_iocontrol_t explain_iocontrol_vidioc_querybuf =
00153 {
00154     "VIDIOC_QUERYBUF", /* name */
00155     VIDIOC_QUERYBUF, /* value */
00156     0, /* disambiguate */
00157     0, /* print_name */
00158     print_data,
00159     print_explanation,
00160     print_data_returned,
00161     sizeof(struct v4l2_buffer), /* data_size */
00162     "struct v4l2_buffer *", /* data_type */
00163     0, /* flags */
00164     __FILE__,
00165     __LINE__,
00166 };
00167 
00168 #else /* ndef VIDIOC_QUERYBUF */
00169 
00170 const explain_iocontrol_t explain_iocontrol_vidioc_querybuf =
00171 {
00172     0, /* name */
00173     0, /* value */
00174     0, /* disambiguate */
00175     0, /* print_name */
00176     0, /* print_data */
00177     0, /* print_explanation */
00178     0, /* print_data_returned */
00179     0, /* data_size */
00180     0, /* data_type */
00181     0, /* flags */
00182     __FILE__,
00183     __LINE__,
00184 };
00185 
00186 #endif /* VIDIOC_QUERYBUF */
00187 
00188 /* vim: set ts=8 sw=4 et : */