Use shared_ptr for devices in DeviceMonitor
This commit is contained in:
@@ -45,7 +45,7 @@ Device::Device(const std::string& path, DeviceIndex index):
|
||||
raw_device->addEventHandler("DEV_" + std::to_string(index), rawEventHandler);
|
||||
}
|
||||
|
||||
void Device::addEventHandler(const std::string& nickname, EventHandler& handler)
|
||||
void Device::addEventHandler(const std::string& nickname, const std::shared_ptr<EventHandler>& handler)
|
||||
{
|
||||
auto it = event_handlers.find(nickname);
|
||||
assert(it == event_handlers.end());
|
||||
@@ -61,8 +61,8 @@ void Device::removeEventHandler(const std::string& nickname)
|
||||
void Device::handleEvent(Report& report)
|
||||
{
|
||||
for(auto& handler : event_handlers)
|
||||
if(handler.second.condition(report))
|
||||
handler.second.callback(report);
|
||||
if(handler.second->condition(report))
|
||||
handler.second->callback(report);
|
||||
}
|
||||
|
||||
Report Device::sendReport(Report& report)
|
||||
|
@@ -44,7 +44,7 @@ namespace hidpp
|
||||
void listen(); // Runs asynchronously
|
||||
void stopListening();
|
||||
|
||||
void addEventHandler(const std::string& nickname, EventHandler& handler);
|
||||
void addEventHandler(const std::string& nickname, const std::shared_ptr<EventHandler>& handler);
|
||||
void removeEventHandler(const std::string& nickname);
|
||||
|
||||
Report sendReport(Report& report);
|
||||
@@ -56,7 +56,7 @@ namespace hidpp
|
||||
DeviceIndex index;
|
||||
uint8_t supported_reports;
|
||||
|
||||
std::map<std::string, EventHandler> event_handlers;
|
||||
std::map<std::string, std::shared_ptr<EventHandler>> event_handlers;
|
||||
};
|
||||
} } }
|
||||
|
||||
|
@@ -194,7 +194,7 @@ void RawDevice::stopListener()
|
||||
interruptRead();
|
||||
}
|
||||
|
||||
void RawDevice::addEventHandler(const std::string &nickname, RawEventHandler &handler)
|
||||
void RawDevice::addEventHandler(const std::string& nickname, RawEventHandler& handler)
|
||||
{
|
||||
auto it = event_handlers.find(nickname);
|
||||
assert(it == event_handlers.end());
|
||||
|
Reference in New Issue
Block a user