2014-02-07 14:55:54 +01:00
|
|
|
// Stl includes
|
2016-08-08 00:17:00 +02:00
|
|
|
#include <exception>
|
2016-08-23 20:07:12 +02:00
|
|
|
#include <map>
|
2013-12-17 19:50:15 +01:00
|
|
|
|
2014-01-04 11:35:11 +01:00
|
|
|
// Build configuration
|
2013-12-29 20:43:01 +01:00
|
|
|
#include <HyperionConfig.h>
|
|
|
|
|
2013-12-17 19:50:15 +01:00
|
|
|
// Leddevice includes
|
|
|
|
#include <leddevice/LedDeviceFactory.h>
|
2019-01-01 19:47:07 +01:00
|
|
|
#include <leddevice/LedDeviceWrapper.h>
|
2016-06-25 22:08:17 +02:00
|
|
|
#include <utils/Logger.h>
|
2016-08-23 20:07:12 +02:00
|
|
|
#include <leddevice/LedDevice.h>
|
2013-12-17 19:50:15 +01:00
|
|
|
|
2019-01-01 19:47:07 +01:00
|
|
|
// autogen
|
2017-08-07 10:05:46 +02:00
|
|
|
#include "LedDevice_headers.h"
|
2016-03-04 09:07:02 +01:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
LedDevice * LedDeviceFactory::construct(const QJsonObject & deviceConfig)
|
2013-12-17 19:50:15 +01:00
|
|
|
{
|
2018-12-27 23:11:32 +01:00
|
|
|
Logger * log = Logger::getInstance("LEDDEVICE");
|
2016-10-13 21:59:58 +02:00
|
|
|
QJsonDocument config(deviceConfig);
|
2013-12-17 19:50:15 +01:00
|
|
|
|
2017-03-04 22:17:42 +01:00
|
|
|
QString type = deviceConfig["type"].toString("UNSPECIFIED").toLower();
|
2013-12-17 19:50:15 +01:00
|
|
|
|
2019-01-01 19:47:07 +01:00
|
|
|
const LedDeviceRegistry& devList = LedDeviceWrapper::getDeviceMap();
|
2016-08-23 20:07:12 +02:00
|
|
|
LedDevice* device = nullptr;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
for ( auto dev: devList)
|
2016-08-08 00:17:00 +02:00
|
|
|
{
|
2016-08-23 20:07:12 +02:00
|
|
|
if (dev.first == type)
|
|
|
|
{
|
|
|
|
device = dev.second(deviceConfig);
|
|
|
|
break;
|
|
|
|
}
|
2016-03-15 18:37:55 +01:00
|
|
|
}
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
if (device == nullptr)
|
2016-03-15 18:37:55 +01:00
|
|
|
{
|
2017-03-04 22:17:42 +01:00
|
|
|
Error(log, "Dummy device used, because configured device '%s' is unknown", QSTRING_CSTR(type) );
|
2016-08-08 00:17:00 +02:00
|
|
|
throw std::runtime_error("unknown device");
|
2016-03-15 18:37:55 +01:00
|
|
|
}
|
2016-05-30 23:58:31 +02:00
|
|
|
}
|
2016-08-23 20:07:12 +02:00
|
|
|
catch(std::exception& e)
|
2014-06-15 02:19:09 +02:00
|
|
|
{
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2017-03-04 22:17:42 +01:00
|
|
|
Error(log, "Dummy device used, because configured device '%s' throws error '%s'", QSTRING_CSTR(type), e.what());
|
2016-10-13 21:59:58 +02:00
|
|
|
const QJsonObject dummyDeviceConfig;
|
|
|
|
device = LedDeviceFile::construct(QJsonObject());
|
2013-12-17 19:50:15 +01:00
|
|
|
}
|
2016-06-25 22:08:17 +02:00
|
|
|
|
2013-12-17 19:50:15 +01:00
|
|
|
return device;
|
|
|
|
}
|