aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Duggan <andrew.duggan@gmail.com>2014-11-09 11:02:22 -0800
committerAndrew Duggan <aduggan@synaptics.com>2014-11-10 10:01:46 -0800
commitf73fdc75d90be91b2b2e3e61ec8a066b129c8a49 (patch)
treee5d80082e380eb61235c19291b2f566bab30d970
parentf6e278f677ae60c9db728059bc942bbeb9aec549 (diff)
downloadrmi4utils-f73fdc75d90be91b2b2e3e61ec8a066b129c8a49.tar.gz
Change GetReport to only read one report at a time and remove HIDDevice's attention report queue
Simplify GetReport and only have it read a single report and let the functions which call it decide if they have gotten the data which they are looking for. Also, remove in the HIDDevice attention report queue since reports are queued in the kernel so queueing in userspace is unnecessary.
-rw-r--r--rmidevice/hiddevice.cpp79
-rw-r--r--rmidevice/hiddevice.h23
-rw-r--r--rmidevice/rmidevice.h11
-rw-r--r--rmihidtool/main.cpp8
4 files changed, 60 insertions, 61 deletions
diff --git a/rmidevice/hiddevice.cpp b/rmidevice/hiddevice.cpp
index 9ef4c32..f756660 100644
--- a/rmidevice/hiddevice.cpp
+++ b/rmidevice/hiddevice.cpp
@@ -119,8 +119,8 @@ int HIDDevice::Open(const char * filename)
return -1;
}
- m_attnReportQueue = new unsigned char[m_inputReportSize * HID_REPORT_QUEUE_MAX_SIZE]();
- if (!m_attnReportQueue) {
+ m_attnData = new unsigned char[m_inputReportSize]();
+ if (!m_attnData) {
errno = -ENOMEM;
return -1;
}
@@ -221,6 +221,7 @@ int HIDDevice::Read(unsigned short addr, unsigned char *buf, unsigned short len)
size_t bytesPerRequest;
size_t bytesWritten;
size_t bytesToRequest;
+ int reportId;
int rc;
if (!m_deviceOpen)
@@ -262,8 +263,8 @@ int HIDDevice::Read(unsigned short addr, unsigned char *buf, unsigned short len)
bytesReadPerRequest = 0;
while (bytesReadPerRequest < bytesToRequest) {
- rc = GetReport(RMI_READ_DATA_REPORT_ID);
- if (rc > 0) {
+ rc = GetReport(&reportId);
+ if (rc > 0 && reportId == RMI_READ_DATA_REPORT_ID) {
bytesInDataReport = m_readData[HID_RMI4_READ_INPUT_COUNT];
memcpy(buf + bytesReadPerRequest, &m_readData[HID_RMI4_READ_INPUT_DATA],
bytesInDataReport);
@@ -338,51 +339,51 @@ void HIDDevice::Close()
m_outputReport = NULL;
delete[] m_readData;
m_readData = NULL;
- delete[] m_attnReportQueue;
- m_attnReportQueue = NULL;
+ delete[] m_attnData;
+ m_attnData = NULL;
}
-int HIDDevice::WaitForAttention(struct timeval * timeout, int *sources)
+int HIDDevice::WaitForAttention(struct timeval * timeout, unsigned int source_mask)
{
- return GetAttentionReport(timeout, sources, NULL, NULL);
+ return GetAttentionReport(timeout, source_mask, NULL, NULL);
}
-int HIDDevice::GetAttentionReport(struct timeval * timeout, int *sources, unsigned char *buf, unsigned int *len)
+int HIDDevice::GetAttentionReport(struct timeval * timeout, unsigned int source_mask,
+ unsigned char *buf, unsigned int *len)
{
- int rc;
- int interrupt_sources;
- const unsigned char * queue_report;
+ int rc = 0;
int bytes = m_inputReportSize;
+ int reportId;
if (len && m_inputReportSize < *len) {
bytes = *len;
*len = m_inputReportSize;
}
- rc = GetReport(RMI_ATTN_REPORT_ID, timeout);
- if (rc > 0) {
- queue_report = m_attnReportQueue
- + m_inputReportSize * m_tailIdx;
- interrupt_sources = queue_report[HID_RMI4_ATTN_INTERUPT_SOURCES];
- if (buf)
- memcpy(buf, queue_report, bytes);
- m_tailIdx = (m_tailIdx + 1) & (HID_REPORT_QUEUE_MAX_SIZE - 1);
- --m_attnQueueCount;
- if (sources)
- *sources = interrupt_sources;
- return rc;
+ // Assume the Linux implementation of select with timeout set to the
+ // time remaining.
+ while (!timeout || (timeout->tv_sec != 0 || timeout->tv_usec != 0)) {
+ rc = GetReport(&reportId, timeout);
+ if (rc > 0) {
+ if (reportId == RMI_ATTN_REPORT_ID) {
+ if (buf)
+ memcpy(buf, m_attnData, bytes);
+ if (source_mask & m_attnData[HID_RMI4_ATTN_INTERUPT_SOURCES])
+ return rc;
+ }
+ } else {
+ return rc;
+ }
}
return rc;
}
-int HIDDevice::GetReport(int reportid, struct timeval * timeout)
+int HIDDevice::GetReport(int *reportId, struct timeval * timeout)
{
ssize_t count = 0;
- unsigned char *queue_report;
fd_set fds;
int rc;
- int report_count = 0;
if (!m_deviceOpen)
return -1;
@@ -415,23 +416,19 @@ int HIDDevice::GetReport(int reportid, struct timeval * timeout)
break;
}
}
+ break;
+ }
- if (m_inputReport[HID_RMI4_REPORT_ID] == RMI_ATTN_REPORT_ID) {
- queue_report = m_attnReportQueue
- + m_inputReportSize * m_headIdx;
- memcpy(queue_report, m_inputReport, count);
- m_headIdx = (m_headIdx + 1) & (HID_REPORT_QUEUE_MAX_SIZE - 1);
- ++m_attnQueueCount;
- } else if (m_inputReport[HID_RMI4_REPORT_ID] == RMI_READ_DATA_REPORT_ID) {
- memcpy(m_readData, m_inputReport, count);
- m_dataBytesRead = count;
- }
- ++report_count;
+ if (reportId)
+ *reportId = m_inputReport[HID_RMI4_REPORT_ID];
- if (m_inputReport[HID_RMI4_REPORT_ID] == reportid)
- break;
+ if (m_inputReport[HID_RMI4_REPORT_ID] == RMI_ATTN_REPORT_ID) {
+ memcpy(m_attnData, m_inputReport, count);
+ } else if (m_inputReport[HID_RMI4_REPORT_ID] == RMI_READ_DATA_REPORT_ID) {
+ memcpy(m_readData, m_inputReport, count);
+ m_dataBytesRead = count;
}
- return report_count;
+ return 1;
}
void HIDDevice::PrintReport(const unsigned char *report)
diff --git a/rmidevice/hiddevice.h b/rmidevice/hiddevice.h
index 810d9a6..ba2d942 100644
--- a/rmidevice/hiddevice.h
+++ b/rmidevice/hiddevice.h
@@ -24,8 +24,8 @@
class HIDDevice : public RMIDevice
{
public:
- HIDDevice() : RMIDevice(), m_inputReport(NULL), m_outputReport(NULL), m_attnReportQueue(NULL), m_headIdx(0),
- m_tailIdx(0), m_readData(NULL), m_deviceOpen(false), m_attnQueueCount(0)
+ HIDDevice() : RMIDevice(), m_inputReport(NULL), m_outputReport(NULL), m_attnData(NULL),
+ m_readData(NULL), m_deviceOpen(false)
{}
virtual int Open(const char * filename);
virtual int Read(unsigned short addr, unsigned char *buf,
@@ -33,9 +33,10 @@ public:
virtual int Write(unsigned short addr, const unsigned char *buf,
unsigned short len);
virtual int SetMode(int mode);
- virtual int WaitForAttention(struct timeval * timeout = NULL, int *sources = NULL);
- virtual int GetAttentionReport(struct timeval * timeout, int *sources, unsigned char *buf,
- unsigned int *len);
+ virtual int WaitForAttention(struct timeval * timeout = NULL,
+ unsigned int source_mask = RMI_INTERUPT_SOURCES_ALL_MASK);
+ virtual int GetAttentionReport(struct timeval * timeout, unsigned int source_mask,
+ unsigned char *buf, unsigned int *len);
virtual void Close();
~HIDDevice() { Close(); }
@@ -48,9 +49,7 @@ private:
unsigned char *m_inputReport;
unsigned char *m_outputReport;
- unsigned char *m_attnReportQueue;
- int m_headIdx;
- int m_tailIdx;
+ unsigned char *m_attnData;
unsigned char *m_readData;
int m_dataBytesRead;
@@ -60,19 +59,15 @@ private:
bool m_deviceOpen;
- int m_attnQueueCount;
-
enum mode_type {
HID_RMI4_MODE_MOUSE = 0,
HID_RMI4_MODE_ATTN_REPORTS = 1,
HID_RMI4_MODE_NO_PACKED_ATTN_REPORTS = 2,
};
- int GetReport(int reportid, struct timeval * timeout = NULL);
+ int GetReport(int *reportId, struct timeval * timeout = NULL);
void PrintReport(const unsigned char *report);
void ParseReportSizes();
-
- static const int HID_REPORT_QUEUE_MAX_SIZE = 8;
};
-#endif /* _HIDDEVICE_H_ */ \ No newline at end of file
+#endif /* _HIDDEVICE_H_ */
diff --git a/rmidevice/rmidevice.h b/rmidevice/rmidevice.h
index d47ffe1..c6d83e5 100644
--- a/rmidevice/rmidevice.h
+++ b/rmidevice/rmidevice.h
@@ -25,6 +25,8 @@
#define RMI_PRODUCT_ID_LENGTH 10
+#define RMI_INTERUPT_SOURCES_ALL_MASK 0xFFFFFFFF
+
class RMIDevice
{
public:
@@ -36,9 +38,10 @@ public:
virtual int Write(unsigned short addr, const unsigned char *data,
unsigned short len) = 0;
virtual int SetMode(int mode) { return -1; /* Unsupported */ }
- virtual int WaitForAttention(struct timeval * timeout = NULL, int *sources = NULL) = 0;
- virtual int GetAttentionReport(struct timeval * timeout, int *sources, unsigned char *buf,
- unsigned int *len)
+ virtual int WaitForAttention(struct timeval * timeout = NULL,
+ unsigned int source_mask = RMI_INTERUPT_SOURCES_ALL_MASK) = 0;
+ virtual int GetAttentionReport(struct timeval * timeout, unsigned int source_mask,
+ unsigned char *buf, unsigned int *len)
{ return -1; /* Unsupported */ }
virtual void Close() = 0;
virtual void Cancel() { m_bCancel = true; }
@@ -101,4 +104,4 @@ protected:
long long diff_time(struct timespec *start, struct timespec *end);
int Sleep(int ms);
void print_buffer(const unsigned char *buf, unsigned int len);
-#endif /* _RMIDEVICE_H_ */ \ No newline at end of file
+#endif /* _RMIDEVICE_H_ */
diff --git a/rmihidtool/main.cpp b/rmihidtool/main.cpp
index f8a1770..8fcb858 100644
--- a/rmihidtool/main.cpp
+++ b/rmihidtool/main.cpp
@@ -168,7 +168,9 @@ void interactive(RMIDevice * device, unsigned char *report)
}
} else if (input[0] == 'a') {
unsigned int bytes = 256;
- device->GetAttentionReport(NULL, NULL, report, &bytes);
+ device->GetAttentionReport(NULL,
+ RMI_INTERUPT_SOURCES_ALL_MASK,
+ report, &bytes);
print_buffer(report, bytes);
} else if (input[0] == 'q') {
return;
@@ -323,7 +325,9 @@ int main(int argc, char ** argv)
report_attn = 1;
while(report_attn) {
unsigned int bytes = 256;
- rc = device->GetAttentionReport(NULL, NULL, report, &bytes);
+ rc = device->GetAttentionReport(NULL,
+ RMI_INTERUPT_SOURCES_ALL_MASK,
+ report, &bytes);
if (rc > 0) {
print_buffer(report, bytes);
fprintf(stdout, "\n");