Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There is now a sample plugin for sensor, chain, filter and adaptor. They make use of each other to demonstrate how logical sensors are created.
- Loading branch information
Timo Rongas
committed
Oct 26, 2010
1 parent
f12aa97
commit aa39c4a
Showing
19 changed files
with
985 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/** | ||
@file samplechain.cpp | ||
@brief SampleChain | ||
<p> | ||
Copyright (C) 2009-2010 Nokia Corporation | ||
@author Timo Rongas <ext-timo.2.rongas@nokia.com> | ||
This file is part of Sensord. | ||
Sensord is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License | ||
version 2.1 as published by the Free Software Foundation. | ||
Sensord is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with Sensord. If not, see <http://www.gnu.org/licenses/>. | ||
</p> | ||
*/ | ||
|
||
#include "samplechain.h" | ||
#include "sensord/sensormanager.h" | ||
#include "sensord/bin.h" | ||
#include "sensord/bufferreader.h" | ||
#include "sensord/config.h" | ||
#include "sensord/logging.h" | ||
|
||
SampleChain::SampleChain(const QString& id) : | ||
AbstractChain(id) | ||
{ | ||
SensorManager& sm = SensorManager::instance(); | ||
|
||
// Get a pointer (refcounted) to the adaptor from sensor manager | ||
sampleAdaptor_ = sm.requestDeviceAdaptor("sampleadaptor"); | ||
|
||
// Create a reader for the adaptor | ||
adaptorReader_ = new BufferReader<TimedUnsigned>(16); | ||
|
||
// Get an instance of filter from sensor manager | ||
sampleFilter_ = sm.instantiateFilter("samplefilter"); | ||
|
||
// Create and name output buffer. This name is used by other nodes | ||
// to find the buffer. | ||
outputBuffer_ = new RingBuffer<TimedUnsigned>(16); | ||
nameOutputBuffer("sampledata", outputBuffer_); | ||
|
||
// Create a new bin and add elements into it with names. | ||
filterBin_ = new Bin; | ||
filterBin_->add(adaptorReader_, "adaptor"); | ||
filterBin_->add(sampleFilter_, "filter"); | ||
filterBin_->add(outputBuffer_, "output"); | ||
|
||
// Make connections between the elements in the Bin. By default, | ||
// readers, ringbuffers and simple filters use source and sink | ||
// as buffer names. | ||
filterBin_->join("adaptor", "source", "filter", "sink"); | ||
filterBin_->join("filter", "source", "output", "sink"); | ||
|
||
// Connect the reader to the adaptor, specifically to buffer named | ||
// 'sample' | ||
connectToSource(sampleAdaptor_, "sample", adaptorReader_); | ||
|
||
// Setup metadata. A description is for each component, but as this | ||
// chain just modifies each sample coming from the adaptor, we can | ||
// push the responsibility for interval, datarange and such to the | ||
// adaptor. | ||
setDescription("Sample filtering with a chain"); | ||
setRangeSource(sampleAdaptor_); | ||
setIntervalSource(sampleAdaptor_); | ||
|
||
// Adaptors are normally stopped when device screen blanks. This | ||
// function is used to signify which sources should get the request | ||
// for overriding this behavior. | ||
addStandbyOverrideSource(sampleAdaptor_); | ||
} | ||
|
||
SampleChain::~SampleChain() | ||
{ | ||
SensorManager& sm = SensorManager::instance(); | ||
|
||
// Disconnect the reader from the adaptor | ||
disconnectFromSource(sampleAdaptor_, "sample", adaptorReader_); | ||
|
||
// Release the adaptor (must not delete, these are shared) | ||
sm.releaseDeviceAdaptor("sampleadaptor"); | ||
|
||
// ..and delete all locally owned stuff. | ||
delete adaptorReader_; | ||
delete sampleFilter_; | ||
delete outputBuffer_; | ||
delete filterBin_; | ||
} | ||
|
||
// In chains one must start the sources and internal bins. | ||
bool SampleChain::start() | ||
{ | ||
if (AbstractSensorChannel::start()) { | ||
sensordLogD() << "Starting SampleChain"; | ||
filterBin_->start(); | ||
|
||
// Adaptors are started on buffer basis, thus the buffer name | ||
sampleAdaptor_->startSensor("sample"); | ||
} | ||
return true; | ||
} | ||
|
||
// Stopping is pretty much start() in reverse. | ||
bool SampleChain::stop() | ||
{ | ||
if (AbstractSensorChannel::stop()) { | ||
sensordLogD() << "Stopping SampleChain"; | ||
sampleAdaptor_->stopSensor("sample"); | ||
filterBin_->stop(); | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
@file samplechain.h | ||
@brief SampleChain | ||
<p> | ||
Copyright (C) 2009-2010 Nokia Corporation | ||
@author Timo Rongas <ext-timo.2.rongas@nokia.com> | ||
This file is part of Sensord. | ||
Sensord is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License | ||
version 2.1 as published by the Free Software Foundation. | ||
Sensord is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with Sensord. If not, see <http://www.gnu.org/licenses/>. | ||
</p> | ||
*/ | ||
|
||
#ifndef SAMPLECHAIN_H | ||
#define SAMPLECHAIN_H | ||
|
||
// Include basetypes that we need to be aware of | ||
#include "deviceadaptor.h" | ||
#include "abstractsensor.h" | ||
#include "abstractchain.h" | ||
|
||
// Include any used datatypes | ||
#include "datatypes/timedunsigned.h" | ||
|
||
// Definition tricks, included from .cpp | ||
class Bin; | ||
template <class TYPE> class BufferReader; | ||
class FilterBase; | ||
|
||
|
||
class SampleChain : public AbstractChain | ||
{ | ||
Q_OBJECT; | ||
|
||
public: | ||
/** | ||
* Factory method for SampleChain. | ||
* @return Pointer to new SampleChain instance as AbstractChain* | ||
*/ | ||
static AbstractChain* factoryMethod(const QString& id) | ||
{ | ||
SampleChain* sc = new SampleChain(id); | ||
return sc; | ||
} | ||
|
||
public Q_SLOTS: | ||
bool start(); | ||
bool stop(); | ||
|
||
protected: | ||
SampleChain(const QString& id); | ||
~SampleChain(); | ||
|
||
private: | ||
// Bins contain a set of filters | ||
Bin* filterBin_; | ||
|
||
// We have one source | ||
DeviceAdaptor* sampleAdaptor_; | ||
|
||
// We need a reader for the source | ||
BufferReader<TimedUnsigned>* adaptorReader_; | ||
|
||
// We have one filter | ||
FilterBase* sampleFilter_; | ||
|
||
// ...and one output buffer. | ||
RingBuffer<TimedUnsigned>* outputBuffer_; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
TEMPLATE = lib | ||
CONFIG += plugin | ||
|
||
QT += dbus | ||
|
||
TARGET = samplechain | ||
|
||
include( ../../common-config.pri ) | ||
|
||
HEADERS += samplechain.h \ | ||
samplechainplugin.h | ||
|
||
SOURCES += samplechain.cpp \ | ||
samplechainplugin.cpp | ||
|
||
SENSORFW_INCLUDEPATHS = ../.. \ | ||
../../include \ | ||
../../sensord \ | ||
../../datatypes \ | ||
../../filters \ | ||
../../adaptors | ||
|
||
DEPENDPATH += $$SENSORFW_INCLUDEPATHS | ||
INCLUDEPATH += $$SENSORFW_INCLUDEPATHS | ||
|
||
include(../../common-install.pri) | ||
publicheaders.files += $$HEADERS | ||
target.path = $$PLUGINPATH | ||
|
||
INSTALLS += target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
@file samplechainplugin.cpp | ||
@brief Sample plugin for chains | ||
<p> | ||
Copyright (C) 2009-2010 Nokia Corporation | ||
@author Timo Rongas <ext-timo.2.rongas@nokia.com> | ||
This file is part of Sensord. | ||
Sensord is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License | ||
version 2.1 as published by the Free Software Foundation. | ||
Sensord is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with Sensord. If not, see <http://www.gnu.org/licenses/>. | ||
</p> | ||
*/ | ||
|
||
#include "samplechainplugin.h" | ||
#include "samplechain.h" | ||
#include "sensormanager.h" | ||
#include <QtDebug> | ||
|
||
void SampleChainPlugin::Register(class Loader&) | ||
{ | ||
qDebug() << "registering samplechain"; | ||
SensorManager& sm = SensorManager::instance(); | ||
sm.registerChain<SampleChain>("samplechain"); | ||
} | ||
|
||
// Specify other required plugins in this function. Dependencies are | ||
// anything that is required for this plugin to get data and filter it | ||
// (adaptors, filters, other chains). | ||
// | ||
// Here we have one adaptor and one filter that we need. | ||
QStringList SampleChainPlugin::Dependencies() { | ||
return QString("sampleadaptor:samplefilter").split(":", QString::SkipEmptyParts); | ||
} | ||
|
||
Q_EXPORT_PLUGIN2(samplechain, SampleChainPlugin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
@file samplechainplugin.h | ||
@brief Sample plugin for chains | ||
<p> | ||
Copyright (C) 2009-2010 Nokia Corporation | ||
@author Timo Rongas <ext-timo.2.rongas@nokia.com> | ||
This file is part of Sensord. | ||
Sensord is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License | ||
version 2.1 as published by the Free Software Foundation. | ||
Sensord is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with Sensord. If not, see <http://www.gnu.org/licenses/>. | ||
</p> | ||
*/ | ||
|
||
#ifndef SAMPLECHAINPLUGIN_H | ||
#define SAMPLECHAINPLUGIN_H | ||
|
||
#include "plugin.h" | ||
|
||
class SampleChainPlugin : public Plugin | ||
{ | ||
private: | ||
void Register(class Loader& l); | ||
QStringList Dependencies(); | ||
}; | ||
|
||
#endif |
Oops, something went wrong.