aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--utils/common/cec-info.cpp40
-rw-r--r--utils/common/cec-info.h2
2 files changed, 42 insertions, 0 deletions
diff --git a/utils/common/cec-info.cpp b/utils/common/cec-info.cpp
index b91bdf31..31fb09fd 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 a086ece0..e979b5ab 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

Privacy Policy