YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
InterfaceForCApi.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#pragma once
20
21#include <errno.h>
22#include <fcntl.h>
23#include <libudev.h>
24#include <linux/media.h>
25#include <linux/v4l2-subdev.h>
26#include <linux/videodev2.h>
27#include <string.h>
28#include <sys/ioctl.h>
29#include <sys/mman.h>
30#include <sys/stat.h>
31#include <sys/types.h>
32#include <unistd.h>
33
34// Wraper for unittest use of c style API
36public:
37 virtual int open_c(const char *path, int oflag) { return open(path, oflag); }
38
39 virtual int open_c(const char *path, int oflag, mode_t mode) {
40 return open(path, oflag, mode);
41 }
42
43 virtual struct udev *udev_new_c() { return udev_new(); }
44
45 // ioctl for system call in progress
46 virtual int xioctl(int fh, int request, void *arg) {
47 int r;
48 do {
49 r = ioctl(fh, request, arg);
50 } while (-1 == r && EINTR == errno);
51 return r;
52 }
53
54 virtual int xioctl_v4l2(int fh, int request, struct v4l2_buffer *arg) {
55 int r;
56 do {
57 r = ioctl(fh, request, arg);
58 } while (-1 == r && EINTR == errno);
59 return r;
60 }
61
62 virtual int ioctl_media_c(int fd, int value, struct media_entity_desc &info) {
63 return ioctl(fd, value, &info);
64 }
65
66 virtual int ioctl_control_c(int fd, int value, struct v4l2_control &info) {
67 return ioctl(fd, value, &info);
68 }
69
70 virtual int ioctl_query_c(int fd, int value, struct v4l2_queryctrl &info) {
71 return ioctl(fd, value, &info);
72 }
73
74 virtual dev_t makedev_c(int major, int minor) {
75 return makedev(major, minor);
76 }
77
78 virtual struct udev_device *
79 udev_device_new_from_devnum_c(struct udev *udev, char type, dev_t devnum) {
80 return udev_device_new_from_devnum(udev, type, devnum);
81 }
82
83 virtual const char *
85 return udev_device_get_devnode(udev_device);
86 }
87
88 virtual struct udev_device *
90 return udev_device_unref(udev_device);
91 }
92
93 virtual void *mmap_c(void *addr, size_t len, int prot, int flags, int fd,
94 __off_t offset) {
95 return mmap(addr, len, prot, flags, fd, offset);
96 }
97
98 virtual int select_c(int nfds, fd_set *readfds, fd_set *writefds,
99 fd_set *exceptfds, struct timeval *timeout) {
100 return select(nfds, readfds, writefds, exceptfds, timeout);
101 }
102
103 virtual void *memcpy_c(void *dest, const void *src, size_t size) {
104 return memcpy(dest, src, size);
105 }
106
107 virtual ~InterfaceForCApi(){};
108};
virtual int open_c(const char *path, int oflag, mode_t mode)
virtual int xioctl_v4l2(int fh, int request, struct v4l2_buffer *arg)
virtual int ioctl_query_c(int fd, int value, struct v4l2_queryctrl &info)
virtual struct udev * udev_new_c()
virtual struct udev_device * udev_device_new_from_devnum_c(struct udev *udev, char type, dev_t devnum)
virtual dev_t makedev_c(int major, int minor)
virtual int open_c(const char *path, int oflag)
virtual struct udev_device * udev_device_unref_c(struct udev_device *udev_device)
virtual const char * udev_device_get_devnode_c(struct udev_device *udev_device)
virtual ~InterfaceForCApi()
virtual int xioctl(int fh, int request, void *arg)
virtual int ioctl_media_c(int fd, int value, struct media_entity_desc &info)
virtual int select_c(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
virtual void * mmap_c(void *addr, size_t len, int prot, int flags, int fd, __off_t offset)
virtual int ioctl_control_c(int fd, int value, struct v4l2_control &info)
virtual void * memcpy_c(void *dest, const void *src, size_t size)