Listen for events on receiver device on timeout

Previously, if a receiver device didn't respond during the initial scan,
logid would not recognize it until it sent a wakeup/connect event.

This makes it so if the device times out, logid will listen for the next
event from the device and try detecting it. (e.g. shaking the mouse will
make it become detected)
This commit is contained in:
pixl
2020-07-12 04:42:44 -04:00
parent 1a056a1ecf
commit 4ce76f5927
7 changed files with 46 additions and 0 deletions

View File

@@ -404,6 +404,7 @@ void RawDevice::stopListener()
void RawDevice::addEventHandler(const std::string& nickname,
const std::shared_ptr<raw::RawEventHandler>& handler)
{
std::unique_lock<std::mutex> lock(_event_handler_lock);
auto it = _event_handlers.find(nickname);
assert(it == _event_handlers.end());
assert(handler);
@@ -412,17 +413,20 @@ void RawDevice::addEventHandler(const std::string& nickname,
void RawDevice::removeEventHandler(const std::string &nickname)
{
std::unique_lock<std::mutex> lock(_event_handler_lock);
_event_handlers.erase(nickname);
}
const std::map<std::string, std::shared_ptr<raw::RawEventHandler>>&
RawDevice::eventHandlers()
{
std::unique_lock<std::mutex> lock(_event_handler_lock);
return _event_handlers;
}
void RawDevice::_handleEvent(std::vector<uint8_t> &report)
{
std::unique_lock<std::mutex> lock(_event_handler_lock);
for(auto& handler : _event_handlers)
if(handler.second->condition(report))
handler.second->callback(report);

View File

@@ -80,6 +80,7 @@ namespace raw
std::map<std::string, std::shared_ptr<RawEventHandler>>
_event_handlers;
std::mutex _event_handler_lock;
void _handleEvent(std::vector<uint8_t>& report);
/* These will only be used internally and processed with a queue */