Skip to content

Commit

Permalink
Fix 'Device' objects leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
andreylitvintsev authored Feb 27, 2024
1 parent 786817f commit 7444d14
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,26 +276,26 @@ void SubscribeAndHandleBroadcastEvents(uWS::App& app, DevicesInfoFetcher& device
};

for (auto& device : devicesInfoFetcher.GetDevices()) {
device->GetBattery().GetBatteryChangedEvent().Subscribe([onBatteryChangedListener, device](size_t listenerId, auto newValues) {
onBatteryChangedListener(device, newValues);
device->GetBattery().GetBatteryChangedEvent().Subscribe([onBatteryChangedListener, weakDevice = std::weak_ptr(device)](size_t listenerId, auto newValues) {
onBatteryChangedListener(weakDevice.lock(), newValues);
});
device->GetAnc().GetAncChangedEvent().Subscribe([onAncChangedListener, device](size_t listenerId, auto newValue) {
onAncChangedListener(device, newValue);
device->GetAnc().GetAncChangedEvent().Subscribe([onAncChangedListener, weakDevice = std::weak_ptr(device)](size_t listenerId, auto newValue) {
onAncChangedListener(weakDevice.lock(), newValue);
});
device->GetConnectedPropertyChangedEvent().Subscribe([onConnectedChangedListener, device](size_t listenerId, auto newValue) {
onConnectedChangedListener(device, newValue);
device->GetConnectedPropertyChangedEvent().Subscribe([onConnectedChangedListener, weakDevice = std::weak_ptr(device)](size_t listenerId, auto newValue) {
onConnectedChangedListener(weakDevice.lock(), newValue);
});
}
devicesInfoFetcher.GetOnDevicesAddEvent().Subscribe([onBatteryChangedListener, onAncChangedListener, onConnectedChangedListener](size_t listenerId, auto newDevices) {
for (auto& device : newDevices) {
device->GetBattery().GetBatteryChangedEvent().Subscribe([onBatteryChangedListener, device](size_t listenerId, auto newValues) {
onBatteryChangedListener(device, newValues);
device->GetBattery().GetBatteryChangedEvent().Subscribe([onBatteryChangedListener, weakDevice = std::weak_ptr(device)](size_t listenerId, auto newValues) {
onBatteryChangedListener(weakDevice.lock(), newValues);
});
device->GetAnc().GetAncChangedEvent().Subscribe([onAncChangedListener, device](size_t listenerId, auto newValue) {
onAncChangedListener(device, newValue);
device->GetAnc().GetAncChangedEvent().Subscribe([onAncChangedListener, weakDevice = std::weak_ptr(device)](size_t listenerId, auto newValue) {
onAncChangedListener(weakDevice.lock(), newValue);
});
device->GetConnectedPropertyChangedEvent().Subscribe([onConnectedChangedListener, device](size_t listenerId, auto newValue) {
onConnectedChangedListener(device, newValue);
device->GetConnectedPropertyChangedEvent().Subscribe([onConnectedChangedListener, weakDevice = std::weak_ptr(device)](size_t listenerId, auto newValue) {
onConnectedChangedListener(weakDevice.lock(), newValue);
});
}
});
Expand Down

0 comments on commit 7444d14

Please sign in to comment.