This is an automatic generated email to let you know that the following patch were queued at the http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:
Subject: cec-info: add cec_device_find function Author: Hans Verkuil <hverkuil-ci...@xs4all.nl> Date: Mon Feb 4 14:00:32 2019 +0100 This function will find the first cec device whose driver and adapter names as returned by CEC_ADAP_G_CAPS matches the driver and adapter names given as arguments. This allows you to uniquely specify a cec device without having to rely on the device node numbering. Signed-off-by: Hans Verkuil <hverkuil-ci...@xs4all.nl> utils/common/cec-info.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ utils/common/cec-info.h | 2 ++ 2 files changed, 42 insertions(+) --- http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=4ee4b43b657f6ba951fb68d44ce5488f6f4d7fff diff --git a/utils/common/cec-info.cpp b/utils/common/cec-info.cpp index b91bdf31c1bd..31fb09fd10de 100644 --- a/utils/common/cec-info.cpp +++ b/utils/common/cec-info.cpp @@ -7,6 +7,10 @@ #include <stdio.h> #include <string> +#include <unistd.h> +#include <fcntl.h> +#include <dirent.h> +#include <sys/ioctl.h> #include <cec-info.h> static std::string caps2s(unsigned caps) @@ -438,3 +442,39 @@ void cec_driver_info(const struct cec_caps &caps, } } } + +std::string cec_device_find(const char *driver, const char *adapter) +{ + DIR *dp; + struct dirent *ep; + std::string name; + + dp = opendir("/dev"); + if (dp == NULL) { + perror("Couldn't open the directory"); + return name; + } + while ((ep = readdir(dp))) + if (!memcmp(ep->d_name, "cec", 3) && isdigit(ep->d_name[3])) { + std::string devname("/dev/"); + struct cec_caps caps; + int fd; + + devname += ep->d_name; + fd = open(devname.c_str(), O_RDWR); + + if (fd < 0) + continue; + int err = ioctl(fd, CEC_ADAP_G_CAPS, &caps); + close(fd); + if (err) + continue; + if ((!driver || !strcmp(driver, caps.driver)) && + (!adapter || !strcmp(adapter, caps.name))) { + name = devname; + break; + } + } + closedir(dp); + return name; +} diff --git a/utils/common/cec-info.h b/utils/common/cec-info.h index a086ece042d0..e979b5abd9e5 100644 --- a/utils/common/cec-info.h +++ b/utils/common/cec-info.h @@ -26,4 +26,6 @@ std::string status2s(const struct cec_msg &msg); void cec_driver_info(const struct cec_caps &caps, const struct cec_log_addrs &laddrs, __u16 phys_addr); +std::string cec_device_find(const char *driver, const char *adapter); + #endif _______________________________________________ linuxtv-commits mailing list linuxtv-commits@linuxtv.org https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits