libexplain  1.4.D001
libexplain/iocontrol/vidioc_g_frequency.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_frequency.h>
00028 #include <libexplain/iocontrol/generic.h>
00029 #include <libexplain/iocontrol/vidioc_g_frequency.h>
00030 #include <libexplain/is_efault.h>
00031 
00032 #ifdef VIDIOC_G_FREQUENCY
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_frequency(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             const struct v4l2_frequency *arg;
00062 
00063             arg = data;
00064             if (!explain_is_efault_pointer(arg, sizeof(*arg)))
00065             {
00066                 int             ntuners;
00067 
00068                 ntuners = explain_v4l2_frequency_get_n(fildes);
00069                 if (ntuners == 0)
00070                 {
00071                     explain_buffer_enosys_fildes
00072                     (
00073                         sb,
00074                         fildes,
00075                         "fildes",
00076                         "ioctl VIDIOC_G_FREQUENCY"
00077                     );
00078                     return;
00079                 }
00080                 if (ntuners > 0 && arg->tuner >= (unsigned)ntuners)
00081                 {
00082                     explain_buffer_einval_out_of_range
00083                     (
00084                         sb,
00085                         "data->tuner",
00086                         0,
00087                         ntuners - 1
00088                     );
00089                     return;
00090                 }
00091             }
00092         }
00093 
00094         /* No idea */
00095         explain_buffer_einval_vague(sb, "data");
00096         return;
00097 
00098     default:
00099         explain_iocontrol_generic_print_explanation
00100         (
00101             p,
00102             sb,
00103             errnum,
00104             fildes,
00105             request,
00106             data
00107         );
00108         break;
00109     }
00110 }
00111 
00112 
00113 static void
00114 print_data_returned(const explain_iocontrol_t *p, explain_string_buffer_t *sb,
00115     int errnum, int fildes, int request, const void *data)
00116 {
00117     (void)p;
00118     (void)errnum;
00119     (void)fildes;
00120     (void)request;
00121     explain_buffer_v4l2_frequency(sb, data, 1);
00122 }
00123 
00124 
00125 const explain_iocontrol_t explain_iocontrol_vidioc_g_frequency =
00126 {
00127     "VIDIOC_G_FREQUENCY", /* name */
00128     VIDIOC_G_FREQUENCY, /* value */
00129     0, /* disambiguate */
00130     0, /* print_name */
00131     print_data,
00132     print_explanation,
00133     print_data_returned,
00134     sizeof(struct v4l2_frequency), /* data_size */
00135     "struct v4l2_frequency *", /* data_type */
00136     0, /* flags */
00137     __FILE__,
00138     __LINE__,
00139 };
00140 
00141 #else /* ndef VIDIOC_G_FREQUENCY */
00142 
00143 const explain_iocontrol_t explain_iocontrol_vidioc_g_frequency =
00144 {
00145     0, /* name */
00146     0, /* value */
00147     0, /* disambiguate */
00148     0, /* print_name */
00149     0, /* print_data */
00150     0, /* print_explanation */
00151     0, /* print_data_returned */
00152     0, /* data_size */
00153     0, /* data_type */
00154     0, /* flags */
00155     __FILE__,
00156     __LINE__,
00157 };
00158 
00159 #endif /* VIDIOC_G_FREQUENCY */
00160 
00161 /* vim: set ts=8 sw=4 et : */