libexplain  1.4.D001
libexplain/iocontrol/vidioc_s_hw_freq_seek.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/is_the_null_pointer.h>
00027 #include <libexplain/buffer/v4l2_buf_type.h>
00028 #include <libexplain/buffer/v4l2_hw_freq_seek.h>
00029 #include <libexplain/buffer/v4l2_tuner.h>
00030 #include <libexplain/iocontrol/generic.h>
00031 #include <libexplain/iocontrol/vidioc_s_hw_freq_seek.h>
00032 #include <libexplain/is_efault.h>
00033 
00034 #ifdef VIDIOC_S_HW_FREQ_SEEK
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)request;
00044     explain_buffer_v4l2_hw_freq_seek(sb, data, fildes);
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_hw_freq_seek *arg;
00063 
00064             arg = data;
00065             if (!explain_is_efault_pointer(arg, sizeof(*arg)))
00066             {
00067                 struct v4l2_tuner qry;
00068                 int             ntuners;
00069 
00070                 /*
00071                  * The tuner may be wrong.
00072                  */
00073                 ntuners = explain_v4l2_tuner_get_n(fildes);
00074                 if (ntuners == 0)
00075                 {
00076                     explain_iocontrol_generic_print_explanation
00077                     (
00078                         p,
00079                         sb,
00080                         ENOTTY,
00081                         fildes,
00082                         request,
00083                         data
00084                     );
00085                     return;
00086                 }
00087                 if (ntuners > 0 && 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                 /*
00100                  * The type may be valid, but not supported by device.
00101                  * Specifically, it may not be the corerct type for this tuner.
00102                  */
00103                 memset(&qry, 0, sizeof(qry));
00104                 qry.index = arg->tuner;
00105                 if
00106                 (
00107                     ioctl(fildes, VIDIOC_G_TUNER, &qry) >= 0
00108                 &&
00109                     qry.type != arg->type
00110                 )
00111                 {
00112                     explain_buffer_einval_vague(sb, "data->type");
00113 
00114                     explain_string_buffer_puts(sb->footnotes, "; ");
00115                     explain_string_buffer_puts
00116                     (
00117                         sb->footnotes,
00118                         /* FIXME: i18n */
00119                         "the tuner type is "
00120                     );
00121                     explain_buffer_v4l2_buf_type(sb, qry.type);
00122                     return;
00123                 }
00124             }
00125         }
00126 
00127         /* No idea */
00128         explain_buffer_einval_vague(sb, "data");
00129         break;
00130 
00131     default:
00132         explain_iocontrol_generic_print_explanation
00133         (
00134             p,
00135             sb,
00136             errnum,
00137             fildes,
00138             request,
00139             data
00140         );
00141         break;
00142     }
00143 }
00144 
00145 
00146 const explain_iocontrol_t explain_iocontrol_vidioc_s_hw_freq_seek =
00147 {
00148     "VIDIOC_S_HW_FREQ_SEEK", /* name */
00149     VIDIOC_S_HW_FREQ_SEEK, /* value */
00150     0, /* disambiguate */
00151     0, /* print_name */
00152     print_data,
00153     print_explanation,
00154     0, /* print_data_returned */
00155     sizeof(struct v4l2_hw_freq_seek), /* data_size */
00156     "struct v4l2_hw_freq_seek *", /* data_type */
00157     0, /* flags */
00158     __FILE__,
00159     __LINE__,
00160 };
00161 
00162 #else /* ndef VIDIOC_S_HW_FREQ_SEEK */
00163 
00164 const explain_iocontrol_t explain_iocontrol_vidioc_s_hw_freq_seek =
00165 {
00166     0, /* name */
00167     0, /* value */
00168     0, /* disambiguate */
00169     0, /* print_name */
00170     0, /* print_data */
00171     0, /* print_explanation */
00172     0, /* print_data_returned */
00173     0, /* data_size */
00174     0, /* data_type */
00175     0, /* flags */
00176     __FILE__,
00177     __LINE__,
00178 };
00179 
00180 #endif /* VIDIOC_S_HW_FREQ_SEEK */
00181 
00182 /* vim: set ts=8 sw=4 et : */