use weak pointer for sensor service to track actual lifetime

This commit is contained in:
Robert Judka 2020-04-26 00:46:57 -05:00
parent 464da85686
commit 6cda29433a
2 changed files with 8 additions and 5 deletions

View File

@ -65,7 +65,7 @@ private:
projection::QtVideoOutput *qtVideoOutput_;
#endif
bool nightMode_;
std::shared_ptr<SensorService> sensorService_;
std::weak_ptr<SensorService> sensorService_;
};
}

View File

@ -70,8 +70,11 @@ ServiceList ServiceFactory::create(aasdk::messenger::IMessenger::Pointer messeng
projection::IAudioInput::Pointer audioInput(new projection::QtAudioInput(1, 16, 16000), std::bind(&QObject::deleteLater, std::placeholders::_1));
serviceList.emplace_back(std::make_shared<AudioInputService>(ioService_, messenger, std::move(audioInput)));
this->createAudioServices(serviceList, messenger);
sensorService_ = std::make_shared<SensorService>(ioService_, messenger, nightMode_);
serviceList.emplace_back(sensorService_);
std::shared_ptr<SensorService> sensorService = std::make_shared<SensorService>(ioService_, messenger, nightMode_);
sensorService_ = sensorService;
serviceList.emplace_back(sensorService);
serviceList.emplace_back(this->createVideoService(messenger));
serviceList.emplace_back(this->createBluetoothService(messenger));
serviceList.emplace_back(this->createInputService(messenger));
@ -187,7 +190,7 @@ void ServiceFactory::resize()
void ServiceFactory::setNightMode(bool nightMode)
{
nightMode_ = nightMode;
if (sensorService_ != nullptr) sensorService_->setNightMode(nightMode_);
if (std::shared_ptr<SensorService> sensorService = sensorService_.lock()) sensorService->setNightMode(nightMode_);
}
QRect ServiceFactory::mapActiveAreaToGlobal(QWidget* activeArea)