libexplain
1.4.D001
|
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/enotsup.h> 00028 #include <libexplain/buffer/is_the_null_pointer.h> 00029 #include <libexplain/buffer/v4l2_dv_preset.h> 00030 #include <libexplain/iocontrol/generic.h> 00031 #include <libexplain/iocontrol/vidioc_s_dv_preset.h> 00032 #include <libexplain/is_efault.h> 00033 00034 #ifdef VIDIOC_S_DV_PRESET 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_dv_preset(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 EBUSY: 00056 explain_string_buffer_puts 00057 ( 00058 sb, 00059 /* FIXME: i18n */ 00060 "the device is currently streaming data" 00061 ); 00062 break; 00063 00064 case EINVAL: 00065 if (!data) 00066 { 00067 explain_buffer_is_the_null_pointer(sb, "data"); 00068 return; 00069 } 00070 00071 { 00072 struct v4l2_dv_preset qry; 00073 00074 memset(&qry, 0, sizeof(qry)); 00075 if 00076 ( 00077 ioctl(fildes, VIDIOC_G_DV_PRESET, &qry) < 0 00078 && 00079 errno == EINVAL 00080 ) 00081 { 00082 explain_buffer_enosys_fildes 00083 ( 00084 sb, 00085 fildes, 00086 "fildes", 00087 "ioctl VIDIOC_S_DV_PRESET" 00088 ); 00089 return; 00090 } 00091 } 00092 00093 { 00094 const struct v4l2_dv_preset *arg; 00095 00096 arg = data; 00097 if (!explain_is_efault_pointer(arg, sizeof(*arg))) 00098 { 00099 unsigned idx; 00100 00101 for (idx = 0; ; ++idx) 00102 { 00103 struct v4l2_dv_enum_preset qry; 00104 00105 memset(&qry, 0, sizeof(qry)); 00106 qry.index = idx; 00107 if (ioctl(fildes, VIDIOC_ENUM_DV_PRESETS, &qry) < 0) 00108 { 00109 if (errno == EINVAL) 00110 { 00111 explain_buffer_enotsup_device(sb, "data->preset"); 00112 return; 00113 } 00114 break; 00115 } 00116 if (qry.preset == arg->preset) 00117 { 00118 /* 00119 * The value is supported by the device, 00120 * there must be some other reson it failed. 00121 */ 00122 break; 00123 } 00124 } 00125 } 00126 } 00127 00128 /* No idea */ 00129 explain_buffer_einval_vague(sb, "data"); 00130 break; 00131 00132 default: 00133 explain_iocontrol_generic_print_explanation 00134 ( 00135 p, 00136 sb, 00137 errnum, 00138 fildes, 00139 request, 00140 data 00141 ); 00142 break; 00143 } 00144 } 00145 00146 00147 const explain_iocontrol_t explain_iocontrol_vidioc_s_dv_preset = 00148 { 00149 "VIDIOC_S_DV_PRESET", /* name */ 00150 VIDIOC_S_DV_PRESET, /* value */ 00151 0, /* disambiguate */ 00152 0, /* print_name */ 00153 print_data, 00154 print_explanation, 00155 print_data, /* print_data_returned */ 00156 sizeof(struct v4l2_dv_preset), /* data_size */ 00157 "struct v4l2_dv_preset *", /* data_type */ 00158 0, /* flags */ 00159 __FILE__, 00160 __LINE__, 00161 }; 00162 00163 #else /* ndef VIDIOC_S_DV_PRESET */ 00164 00165 const explain_iocontrol_t explain_iocontrol_vidioc_s_dv_preset = 00166 { 00167 0, /* name */ 00168 0, /* value */ 00169 0, /* disambiguate */ 00170 0, /* print_name */ 00171 0, /* print_data */ 00172 0, /* print_explanation */ 00173 0, /* print_data_returned */ 00174 0, /* data_size */ 00175 0, /* data_type */ 00176 0, /* flags */ 00177 __FILE__, 00178 __LINE__, 00179 }; 00180 00181 #endif /* VIDIOC_S_DV_PRESET */ 00182 00183 /* vim: set ts=8 sw=4 et : */