aboutsummaryrefslogtreecommitdiff
path: root/rmidevice
diff options
context:
space:
mode:
authorAndrew Duggan <aduggan@synaptics.com>2016-05-16 13:03:24 -0700
committerAndrew Duggan <aduggan@synaptics.com>2016-05-16 15:10:07 -0700
commit21d9d3069254d0840c3c12f5f04fb802213e3c58 (patch)
treeb9290847bff15114fa2689af7f7be5ad4b7af545 /rmidevice
parent5aa97c91b96439cdaff175561403fbc9ff504272 (diff)
downloadrmi4utils-21d9d3069254d0840c3c12f5f04fb802213e3c58.tar.gz
Consolidate device discovery into the rmidevice library
Diffstat (limited to 'rmidevice')
-rw-r--r--rmidevice/hiddevice.cpp31
-rw-r--r--rmidevice/hiddevice.h2
-rw-r--r--rmidevice/rmidevice.h2
3 files changed, 34 insertions, 1 deletions
diff --git a/rmidevice/hiddevice.cpp b/rmidevice/hiddevice.cpp
index 7fc03c5..5bb804d 100644
--- a/rmidevice/hiddevice.cpp
+++ b/rmidevice/hiddevice.cpp
@@ -762,4 +762,33 @@ bool HIDDevice::WaitForHidRawDevice(int notifyFd, std::string & deviceName,
}
}
}
-} \ No newline at end of file
+}
+
+bool HIDDevice::FindDevice()
+{
+ DIR * devDir;
+ struct dirent * devDirEntry;
+ char deviceFile[PATH_MAX];
+ bool found;
+ int rc;
+
+ devDir = opendir("/dev");
+ if (!devDir)
+ return -1;
+
+ while ((devDirEntry = readdir(devDir)) != NULL) {
+ if (strstr(devDirEntry->d_name, "hidraw")) {
+ snprintf(deviceFile, PATH_MAX, "/dev/%s", devDirEntry->d_name);
+ rc = Open(deviceFile);
+ if (rc != 0) {
+ continue;
+ } else {
+ found = true;
+ break;
+ }
+ }
+ }
+ closedir(devDir);
+
+ return found;
+}
diff --git a/rmidevice/hiddevice.h b/rmidevice/hiddevice.h
index af1a385..6673c10 100644
--- a/rmidevice/hiddevice.h
+++ b/rmidevice/hiddevice.h
@@ -48,6 +48,8 @@ public:
virtual void PrintDeviceInfo();
+ virtual bool FindDevice();
+
private:
int m_fd;
diff --git a/rmidevice/rmidevice.h b/rmidevice/rmidevice.h
index c2b004c..af938ec 100644
--- a/rmidevice/rmidevice.h
+++ b/rmidevice/rmidevice.h
@@ -70,6 +70,8 @@ public:
unsigned int GetNumInterruptRegs() { return m_numInterruptRegs; }
+ virtual bool FindDevice() = 0;
+
protected:
std::vector<RMIFunction> m_functionList;
unsigned char m_manufacturerID;