libexplain  1.4.D001
libexplain/iocontrol/vidioc_reqbufs.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_buf_type.h>
00028 #include <libexplain/buffer/v4l2_requestbuffers.h>
00029 #include <libexplain/buffer/v4l2_memory.h>
00030 #include <libexplain/iocontrol/generic.h>
00031 #include <libexplain/iocontrol/vidioc_reqbufs.h>
00032 #include <libexplain/is_efault.h>
00033 
00034 #ifdef VIDIOC_REQBUFS
00035 
00036 
00037 static void
00038 print_data(const explain_iocontrol_t *p, explain_string_buffer_t *sb,
00039     int errnum, int fildes, int request, const void *data)
00040 {
00041     (void)p;
00042     (void)errnum;
00043     (void)fildes;
00044     (void)request;
00045     explain_buffer_v4l2_requestbuffers(sb, data);
00046 }
00047 
00048 
00049 static void
00050 print_explanation(const explain_iocontrol_t *p, explain_string_buffer_t *sb,
00051     int errnum, int fildes, int request, const void *data)
00052 {
00053     switch (errnum)
00054     {
00055     case EINVAL:
00056         if (!data)
00057         {
00058             explain_buffer_is_the_null_pointer(sb, "data");
00059             return;
00060         }
00061 
00062         {
00063             const struct v4l2_requestbuffers *arg;
00064 
00065             arg = data;
00066             if (explain_is_efault_pointer(arg, sizeof(arg)))
00067                 goto generic;
00068 
00069             /*
00070              * Check the type (the Linux kernel always does this first).
00071              */
00072             switch (explain_v4l2_buf_type_check(fildes, arg->type))
00073             {
00074             case explain_v4l2_buf_type_check_no_idea:
00075             default:
00076                 goto generic;
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 memory mode.
00092              */
00093             switch (arg->memory)
00094             {
00095             case V4L2_MEMORY_MMAP:
00096             case V4L2_MEMORY_USERPTR:
00097             case V4L2_MEMORY_OVERLAY:
00098                 break;
00099 
00100             default:
00101                 explain_buffer_einval_vague(sb, "data->memory");
00102                 return;
00103             }
00104         }
00105 
00106         /* a count of 0 is valid */
00107 
00108         /* no idea */
00109         goto generic;
00110 
00111     default:
00112         generic:
00113         explain_iocontrol_generic_print_explanation
00114         (
00115             p,
00116             sb,
00117             errnum,
00118             fildes,
00119             request,
00120             data
00121         );
00122         break;
00123     }
00124 }
00125 
00126 
00127 static void
00128 print_data_returned(const explain_iocontrol_t *p, explain_string_buffer_t *sb,
00129     int errnum, int fildes, int request, const void *data)
00130 {
00131     (void)p;
00132     (void)errnum;
00133     (void)fildes;
00134     (void)request;
00135     explain_buffer_v4l2_requestbuffers(sb, data);
00136 }
00137 
00138 
00139 const explain_iocontrol_t explain_iocontrol_vidioc_reqbufs =
00140 {
00141     "VIDIOC_REQBUFS", /* name */
00142     VIDIOC_REQBUFS, /* value */
00143     0, /* disambiguate */
00144     0, /* print_name */
00145     print_data,
00146     print_explanation,
00147     print_data_returned,
00148     sizeof(struct v4l2_requestbuffers), /* data_size */
00149     "struct v4l2_requestbuffers *", /* data_type */
00150     0, /* flags */
00151     __FILE__,
00152     __LINE__,
00153 };
00154 
00155 #else /* ndef VIDIOC_REQBUFS */
00156 
00157 const explain_iocontrol_t explain_iocontrol_vidioc_reqbufs =
00158 {
00159     0, /* name */
00160     0, /* value */
00161     0, /* disambiguate */
00162     0, /* print_name */
00163     0, /* print_data */
00164     0, /* print_explanation */
00165     0, /* print_data_returned */
00166     0, /* data_size */
00167     0, /* data_type */
00168     0, /* flags */
00169     __FILE__,
00170     __LINE__,
00171 };
00172 
00173 #endif /* VIDIOC_REQBUFS */
00174 
00175 /* vim: set ts=8 sw=4 et : */