Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'jb41369_sensor_availability_config' into 'master'
Add plugin availability config and other fixes

See merge request mer-core/sensorfw!23
  • Loading branch information
spiiroin committed Jun 1, 2018
2 parents a0a1912 + 4a34bdb commit 7fad53f
Show file tree
Hide file tree
Showing 25 changed files with 631 additions and 304 deletions.
29 changes: 0 additions & 29 deletions .gitignore

This file was deleted.

File renamed without changes.
36 changes: 36 additions & 0 deletions config/20-sensors-default.conf
@@ -0,0 +1,36 @@
[available]
; Availability of some sensors can be defined in hw-settings configuration
; files. By enabling ssu-sysinfo usage, sensorfwd configuration can be
; written so that it just refers to hw-settings config. If ssu-sysinfo
; is not used, these will default to "True".
;
; In case of virtual sensors can be implemented on top of multiple real
; sensors, multiple '|' separated features can be given and the sensor
; is enabled if at least one of those is set in hw-settings.

accelerometersensor=Feature_AccelerationSensor
alssensor=Feature_LightSensor
compasssensor=Feature_CompassSensor
gyroscopesensor=Feature_GyroSensor
orientationsensor=Feature_GyroSensor|Feature_AccelerationSensor
proximitysensor=Feature_ProximitySensor

; In theory having Feature_CoverSensor == have lidsensor. However
; in practice only mce is expected to track lidsensor and atm it
; does it via suspend proofed evdev inputs rather than sensorfwd.
; So, even if the lidsensor adaptors provided by sensorfwd would
; work, they might interfere with the only user of the sensor.
; lidsensor=Feature_CoverSensor
lidsensor=False

; To avoid revisiting config files for all old ports, the defaults
; added sensors should be set "False" by default here, and to "True"
; in device specific override config as appropriate.

humiditysensor=False
magnetometersensor=False
pressuresensor=False
rotationsensor=False
stepcountersensor=False
tapsensor=False
temperaturesensor=False
25 changes: 25 additions & 0 deletions config/60-sensor-selection-oeverrides.conf
@@ -0,0 +1,25 @@
[available]

; Sensors that are disabled by default.
; -> Enable as appropriate

;humiditysensor=True
;magnetometersensor=True
;pressuresensor=True
;rotationsensor=True
;stepcountersensor=True
;tapsensor=True
;temperaturesensor=True

; Sensors that should/can be enabled/disabled based on
; hw settings config - or are enabled if sensorfwd is
; built without ssu-sysinfo support.
; -> Override as appropriate.

;accelerometersensor=False
;alssensor=False
;compasssensor=False
;gyroscopesensor=False
;lidsensor=False
;orientationsensor=False
;proximitysensor=False
98 changes: 36 additions & 62 deletions core/config.cpp
Expand Up @@ -39,94 +39,68 @@ Config::Config() {
}

Config::~Config() {
clearConfig();
}

void Config::clearConfig() {
foreach(QSettings* setting, settings)
delete setting;
settings.clear();
m_settings.clear();
}

bool Config::loadConfig(const QString &defConfigPath, const QString &configDPath) {
Config *config = NULL;
/* Not having config files is ok, failing to load one that exists is not */
bool ret = true;

/* Check/create new static config */
if (static_configuration) {
config = static_configuration;
} else {
config = new Config();
if (!static_configuration) {
static_configuration = new Config();
}

if (!config->loadConfigFile(defConfigPath))
ret = false;

/* Scan config.d dir */
QStringList fileList;
if(!configDPath.isEmpty())
{
/* Process config.d dir in alnum order */
if (!configDPath.isEmpty()) {
QDir dir(configDPath, "*.conf", QDir::Name, QDir::Files);
fileList = dir.entryList();
foreach(const QString& file, fileList)
{
if (!config->loadConfigFile(dir.absoluteFilePath(file)))
foreach(const QString &file, dir.entryList()) {
if (!static_configuration->loadConfigFile(dir.absoluteFilePath(file))) {
ret = false;
}
}
}

static_configuration = config;

/* Primary config file overrides config.d */
if (!defConfigPath.isEmpty() && QFile::exists(defConfigPath) ) {
if (!static_configuration->loadConfigFile(defConfigPath))
ret = false;
}
return ret;
}

bool Config::loadConfigFile(const QString &configFileName) {
if(!QFile::exists(configFileName))
{
/* Success means the file was loaded and processed without hiccups */
bool loaded = false;
if (!QFile::exists(configFileName)) {
sensordLogW() << "File does not exists \"" << configFileName << "\"";
return false;
}
QSettings* setting = new QSettings(configFileName, QSettings::IniFormat);
if(setting->status() == QSettings::NoError) {
settings.append(setting);
sensordLogD() << "Config file \"" << configFileName << "\" successfully loaded";
return true;
} else {
QSettings merge(configFileName, QSettings::IniFormat);
QSettings::Status status(merge.status());
if (status == QSettings::FormatError ) {
sensordLogW() << "Configuration file \"" << configFileName << "\" is in wrong format";
} else if (status != QSettings::NoError) {
sensordLogW() << "Unable to open \"" << configFileName << "\" configuration file";
} else {
foreach (const QString &key, merge.allKeys()) {
m_settings.setValue(key, merge.value(key));
}
loaded = true;
}
}
else if(setting->status() == QSettings::AccessError)
sensordLogW() << "Unable to open \"" << configFileName << "\" configuration file";
else if(setting->status() == QSettings::FormatError)
sensordLogW() << "Configuration file \"" << configFileName << "\" is in wrong format";
else
sensordLogW() << "Configuration file \"" << configFileName << "\" parsing failed to unknown error: " << setting->status();
delete setting;
return false;
return loaded;
}

QVariant Config::value(const QString &key) const {
/* Iterate through configs so that keys in the first files
* have preference over the last.
*/
foreach(QSettings* setting, settings) {
if(setting->contains(key))
{
QVariant var = setting->value(key, QVariant());
if(var.isValid())
sensordLogD() << "Value for key '" << key << "': " << var.toString();
return var;
}
QVariant var = m_settings.value(key, QVariant());
if(var.isValid()) {
sensordLogT() << "Value for key" << key << ":" << var.toString();
}
return QVariant();
return var;
}

QStringList Config::groups() const
{
QStringList groups;
foreach(QSettings* setting, settings) {
foreach(const QString& group, setting->childGroups()) {
if(!groups.contains(group))
groups << group;
}
}
QStringList groups = m_settings.childGroups();
return groups;
}

Expand Down
2 changes: 1 addition & 1 deletion core/config.h
Expand Up @@ -136,7 +136,7 @@ class Config
*/
void clearConfig();

QList<QSettings*> settings; /**< parsed QSettings */
QSettings m_settings; /**< parsed QSettings */
};

template<typename T>
Expand Down
5 changes: 5 additions & 0 deletions core/core.pro
Expand Up @@ -80,6 +80,11 @@ mce {
DEFINES += SENSORFW_MCE_WATCHER
}

contains(CONFIG,ssusysinfo) {
PKGCONFIG += ssu-sysinfo
QMAKE_CXXFLAGS += -DUSE_SSUSYSINFO
}

lunaservice {
SOURCES += lsclient.cpp
HEADERS += lsclient.h
Expand Down

0 comments on commit 7fad53f

Please sign in to comment.