Skip to content

Commit

Permalink
[hybrisadaptor] Subject sensor type specific actions to common policy
Browse files Browse the repository at this point in the history
Sensor specific adaptors derived from HybrisAdaptor class can be configured
to enable/disable sensors directly via sysfs. While doing that they also
bypass enable/disable policy that is implemented in HybrisAdaptor.

Fix each HybrisXxxAdaptor class so that common policy logic is executed
first, and direct sysfs manipulation is done based on policy decision.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Sep 27, 2018
1 parent 8fab553 commit ed38fb4
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 39 deletions.
9 changes: 4 additions & 5 deletions adaptors/hybrisaccelerometer/hybrisaccelerometeradaptor.cpp
Expand Up @@ -44,20 +44,19 @@ HybrisAccelerometerAdaptor::~HybrisAccelerometerAdaptor()

bool HybrisAccelerometerAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;

if (isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
sensordLogD() << "Hybris AccelAdaptor start\n";
return true;
}

void HybrisAccelerometerAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
if (!isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
sensordLogD() << "Hybris AccelAdaptor stop\n";
}

Expand Down
9 changes: 4 additions & 5 deletions adaptors/hybrisalsadaptor/hybrisalsadaptor.cpp
Expand Up @@ -52,11 +52,10 @@ HybrisAlsAdaptor::~HybrisAlsAdaptor()

bool HybrisAlsAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;

if (isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
sensordLogD() << "Hybris HybrisAlsAdaptor start\n";
return true;
}
Expand Down Expand Up @@ -120,9 +119,9 @@ void HybrisAlsAdaptor::sendInitialData()

void HybrisAlsAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
if (!isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
sensordLogD() << "Hybris HybrisAlsAdaptor stop\n";
}

Expand Down
9 changes: 4 additions & 5 deletions adaptors/hybrisgyroscopeadaptor/hybrisgyroscopeadaptor.cpp
Expand Up @@ -51,20 +51,19 @@ HybrisGyroscopeAdaptor::~HybrisGyroscopeAdaptor()

bool HybrisGyroscopeAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;

if (isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
sensordLogD() << "HybrisGyroscopeAdaptor start\n";
return true;
}

void HybrisGyroscopeAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
if (!isRunning() &&!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
sensordLogD() << "HybrisGyroscopeAdaptor stop\n";
}

Expand Down
Expand Up @@ -48,20 +48,19 @@ HybrisMagnetometerAdaptor::~HybrisMagnetometerAdaptor()

bool HybrisMagnetometerAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;

if (isRunning() &&!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
sensordLogD() << "HybrisMagnetometerAdaptor start\n";
return true;
}

void HybrisMagnetometerAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
if (!isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
sensordLogD() << "HybrisMagnetometerAdaptor stop\n";
}

Expand Down
Expand Up @@ -64,20 +64,19 @@ HybrisOrientationAdaptor::~HybrisOrientationAdaptor()

bool HybrisOrientationAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;

if (isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
sensordLogD() << "Hybris OrientationAdaptor start\n";
return true;
}

void HybrisOrientationAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
if (!isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
sensordLogD() << "Hybris OrientationAdaptor stop\n";
}

Expand Down
9 changes: 4 additions & 5 deletions adaptors/hybrispressureadaptor/hybrispressureadaptor.cpp
Expand Up @@ -50,20 +50,19 @@ HybrisPressureAdaptor::~HybrisPressureAdaptor()

bool HybrisPressureAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;

if (isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
sensordLogD() << "Hybris HybrisPressureAdaptor start\n";
return true;
}

void HybrisPressureAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
if (!isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
sensordLogD() << "Hybris HybrisPressureAdaptor stop\n";
}

Expand Down
8 changes: 4 additions & 4 deletions adaptors/hybrisproximityadaptor/hybrisproximityadaptor.cpp
Expand Up @@ -57,10 +57,10 @@ HybrisProximityAdaptor::~HybrisProximityAdaptor()

bool HybrisProximityAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;
if (isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
sensordLogD() << "HybrisProximityAdaptor start\n";
return true;
}
Expand Down Expand Up @@ -127,9 +127,9 @@ void HybrisProximityAdaptor::sendInitialData()

void HybrisProximityAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
if (!isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
sensordLogD() << "HybrisProximityAdaptor stop\n";
}

Expand Down
Expand Up @@ -56,11 +56,10 @@ HybrisStepCounterAdaptor::~HybrisStepCounterAdaptor()

bool HybrisStepCounterAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;

if (isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
sensordLogD() << "Hybris HybrisStepCounterAdaptor start\n";
return true;
}
Expand All @@ -72,9 +71,9 @@ void HybrisStepCounterAdaptor::sendInitialData()

void HybrisStepCounterAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
if (!isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
sensordLogD() << "Hybris HybrisStepCounterAdaptor stop\n";
}

Expand Down
2 changes: 2 additions & 0 deletions core/hybrisadaptor.cpp
Expand Up @@ -809,6 +809,7 @@ void HybrisAdaptor::evaluateSensor()

bool HybrisAdaptor::startSensor()
{
// Note: This is overloaded and called by each HybrisXxxAdaptor::startSensor()
if (!m_shouldBeRunning) {
m_shouldBeRunning = true;
sensordLogT("%s m_shouldBeRunning = %d", sensorTypeName(m_sensorType), m_shouldBeRunning);
Expand All @@ -819,6 +820,7 @@ bool HybrisAdaptor::startSensor()

void HybrisAdaptor::stopSensor()
{
// Note: This is overloaded and called by each HybrisXxxAdaptor::stopSensor()
if (m_shouldBeRunning) {
m_shouldBeRunning = false;
sensordLogT("%s m_shouldBeRunning = %d", sensorTypeName(m_sensorType), m_shouldBeRunning);
Expand Down

0 comments on commit ed38fb4

Please sign in to comment.