Implement dj::Receiver class

Again, many things were done here.
This commit is contained in:
pixl
2020-06-19 03:58:00 -04:00
parent 47db60fad8
commit b41649b0de
18 changed files with 819 additions and 26 deletions

View File

@@ -75,6 +75,8 @@ RawDevice::RawDevice(std::string path) : path (path), continue_listen (false)
close(fd);
throw std::system_error(err, std::system_category(), "RawDevice pipe open failed");
}
continue_listen = false;
}
RawDevice::~RawDevice()
@@ -106,6 +108,27 @@ std::vector<uint8_t> RawDevice::sendReport(const std::vector<uint8_t>& report)
return _respondToReport(report);
}
// DJ commands are not systematically acknowledged, do not expect a result.
void RawDevice::sendReportNoResponse(const std::vector<uint8_t>& report)
{
assert(supportedReportID(report[0]));
/* If the listener will stop, handle I/O manually.
* Otherwise, push to queue and wait for result. */
if(continue_listen)
{
std::packaged_task<std::vector<uint8_t>()> task([this, report]() {
this->_sendReport(report);
return std::vector<uint8_t>();
});
auto f = task.get_future();
write_queue.push(&task);
f.get();
}
else
_sendReport(report);
}
std::vector<uint8_t> RawDevice::_respondToReport
(const std::vector<uint8_t>& request)
{

View File

@@ -29,6 +29,7 @@ namespace raw
std::vector<uint8_t> reportDescriptor() const { return rdesc; }
std::vector<uint8_t> sendReport(const std::vector<uint8_t>& report);
void sendReportNoResponse(const std::vector<uint8_t>& report);
void interruptRead();
void listen();