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