libexplain  1.4.D001
libexplain/iocontrol/vidioc_enum_dv_presets.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/enosys.h>
00026 #include <libexplain/buffer/is_the_null_pointer.h>
00027 #include <libexplain/buffer/v4l2_dv_enum_preset.h>
00028 #include <libexplain/iocontrol/generic.h>
00029 #include <libexplain/iocontrol/vidioc_enum_dv_presets.h>
00030 #include <libexplain/is_efault.h>
00031 
00032 #ifdef VIDIOC_ENUM_DV_PRESETS
00033 
00034 
00035 static void
00036 print_data(const explain_iocontrol_t *p, explain_string_buffer_t *sb,
00037     int errnum, int fildes, int request, const void *data)
00038 {
00039     (void)p;
00040     (void)errnum;
00041     (void)fildes;
00042     (void)request;
00043     explain_buffer_v4l2_dv_enum_preset(sb, data, 0);
00044 }
00045 
00046 
00047 static void
00048 print_explanation(const explain_iocontrol_t *p, explain_string_buffer_t *sb,
00049     int errnum, int fildes, int request, const void *data)
00050 {
00051     switch (errnum)
00052     {
00053     case EINVAL:
00054         if (!data)
00055         {
00056             explain_buffer_is_the_null_pointer(sb, "data");
00057             return;
00058         }
00059 
00060         {
00061             int             npresets;
00062 
00063             npresets = explain_v4l2_dv_enum_preset_get_n(fildes);
00064             if (npresets == 0)
00065             {
00066                 explain_buffer_enosys_fildes
00067                 (
00068                     sb,
00069                     fildes,
00070                     "fildes",
00071                     "ioctl VIDIOC_ENUM_DV_PRESETS"
00072                 );
00073                 return;
00074             }
00075             if (npresets > 0)
00076             {
00077                 const struct v4l2_dv_enum_preset *arg;
00078 
00079                 arg = data;
00080                 if
00081                 (
00082                     !explain_is_efault_pointer(arg, sizeof(*arg))
00083                 &&
00084                     arg->index >= (unsigned)npresets
00085                 )
00086                 {
00087                     explain_buffer_einval_out_of_range
00088                     (
00089                         sb,
00090                         "data->index",
00091                         0,
00092                         npresets - 1
00093                     );
00094                     return;
00095                 }
00096             }
00097         }
00098 
00099         /* No idea */
00100         explain_buffer_einval_vague(sb, "data");
00101         return;
00102 
00103     default:
00104         explain_iocontrol_generic_print_explanation
00105         (
00106             p,
00107             sb,
00108             errnum,
00109             fildes,
00110             request,
00111             data
00112         );
00113         break;
00114     }
00115 }
00116 
00117 
00118 static void
00119 print_data_returned(const explain_iocontrol_t *p, explain_string_buffer_t *sb,
00120     int errnum, int fildes, int request, const void *data)
00121 {
00122     (void)p;
00123     (void)errnum;
00124     (void)fildes;
00125     (void)request;
00126     explain_buffer_v4l2_dv_enum_preset(sb, data, 1);
00127 }
00128 
00129 
00130 const explain_iocontrol_t explain_iocontrol_vidioc_enum_dv_presets =
00131 {
00132     "VIDIOC_ENUM_DV_PRESETS", /* name */
00133     VIDIOC_ENUM_DV_PRESETS, /* value */
00134     0, /* disambiguate */
00135     0, /* print_name */
00136     print_data,
00137     print_explanation,
00138     print_data_returned,
00139     sizeof(struct v4l2_dv_enum_preset), /* data_size */
00140     "struct v4l2_dv_enum_preset *", /* data_type */
00141     0, /* flags */
00142     __FILE__,
00143     __LINE__,
00144 };
00145 
00146 #else /* ndef VIDIOC_ENUM_DV_PRESETS */
00147 
00148 const explain_iocontrol_t explain_iocontrol_vidioc_enum_dv_presets =
00149 {
00150     0, /* name */
00151     0, /* value */
00152     0, /* disambiguate */
00153     0, /* print_name */
00154     0, /* print_data */
00155     0, /* print_explanation */
00156     0, /* print_data_returned */
00157     0, /* data_size */
00158     0, /* data_type */
00159     0, /* flags */
00160     __FILE__,
00161     __LINE__,
00162 };
00163 
00164 #endif /* VIDIOC_ENUM_DV_PRESETS */
00165 
00166 /* vim: set ts=8 sw=4 et : */