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