Skip to content

Commit

Permalink
Added PLUGIN-GUIDE to share information on writing plug-ins.
Browse files Browse the repository at this point in the history
Renamed old instructions instead of removing them, as there is some info
that is not yet available in the new document.

Added details to sampleadaptor.h example.
  • Loading branch information
Timo Rongas committed Oct 26, 2010
1 parent 1307632 commit d1a65eb
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 0 deletions.
179 changes: 179 additions & 0 deletions doc/PLUGIN-GUIDE
@@ -0,0 +1,179 @@
###
### INSTRUCTIONS FOR WRITING PLUG-INS FOR SENSOR FRAMEWORK
###
### 25.10.2010
###

##
## DISCLAIMER
##

These instructions apply to sensord-0.6.28 tagged in

http://meego.gitorious.org/meego-middleware/sensorfw/

Node interfaces in earlier version may differ.


##
## PLUG-INS
##

A plug-in for sensor framework can provide one (or more) of the following:

1) Device adaptor
2) Chain
3) Sensor
4) Filter

Device adaptors are responsible for interfacing the framework with data sources (generally device drivers). Adaptors are connected to chains or sensors, which contain a varying number of filters. Filters are used for calculating things from received samples. Sensors provide an interface to the resulting data for client applications, while chains are used as internal datasources for calculations shared by several sensors.


##
## WRITING A PLUG-IN
##

A plug-in buy itself is responsible for very few things. It contains an adaptor/sensor/chain/filter (or several), and introduces them to SensorManager.

In addition, plug-ins may specify that they need another plug-in for functioning. E.g. orientationchain (provides device orientation calculations) requires accelerometeradaptor (provides data from accelerometer) to function.

Plugin dependencies are based on meta-names. Any plugin that requires, e.g. sampleplugin, will specify the dependency as 'sampleplugin'. In reality, with varying platforms the real plugin could be called sampleplugin-ascii, sampleplugin-superior, sampleplugin-inputdev, etc. See the section 'configuration files' for further details.

The naming convention is roughly:

<type_of_sensor><type_of_node>plugin-<specifier>

For adaptors, the specifier has been agreed to be related to the type of underlying driver interface. Thus, we could for example have:

accelerometeradaptorplugin-inputdev

Not all plugins currently adhere to these rules, and there is no clear rule on what to use for the <specifier> in cases other than adaptors.

See the commented codes in examples/*/*plugin.[h|cpp] for plug-in construction.


##
## WRITING AN ADAPTOR
##

Device adaptors are responsible for reading data from a source (usually a device driver interface) and pushing it into the processing chain in sensor framework.

The easiest way to create a new device adaptor is to extend SysfsAdaptor. The base class will then handle most things as long as the adaptor class itself provides the interface specific details.

What needs to be implemented:
* Select busypoll or interrupt based approach
* Create and name an outputbuffer(s).
* Function for reading and propagating data.
* Specify metadata

## Interrupt based or busypoll

Files can be monitored either in SelectMode or IntervalMode. SelectMode uses epoll() to monitor for interrupts, while IntervalMode just busypolls with specified delay. Using SelectMode is encouraged due to power saving reasons as long as driver interface provides interrupts.

In case the driver interface provides possibility to control hardware sampling frequency (implies SelectMode), interval() and setInterval() should be reimplemented to make use of the functionality.

In case the driver initiates hardware measurement when the interface is read, the IntervalMode handles everything related to interval handling already (except specifying the allowed values).

## Buffers

An adaptor can have any number of output buffers. Usually there is only one, but if an adaptor monitors several filehandles, or a filehandle provides more than one type of output, it might occasionally make sense to provide several output buffers. The buffers are named and are searched by listeners based on the name.

## Reading data from driver

SysfsAdaptor provides method addPath() for registering filehandles for listening. The path can also be set as constructor parameter. There can any number of paths added, but mode of the adaptor will be the same for all of them, as well as the interval setting.

Whenever a registered filehandle has new data (signalled either by interrupt or by timeout), processSample(int pathId, int fd) gets called. Data can be read from fd, and pathId is used to separate which file the handle points to.

The function should be implemented to read data from fd and propagate it to listeners by writing to buffer.

## Metadata

Metadata for adaptors should represent the capabilities of the hardware and driver.

See section 'Metadata' at the end for generic details.

See examples/sampleadaptor/* for adaptor construction.


##
## WRITING A FILTER
##

TBD.

See examples/samplefilter/* for filter construction.

##
## WRITING A SENSOR
##

TDB.

See examples/samplesensor/* for sensor construction.

##
## WRITING A CHAIN
##

TBD.

See examples/samplechain/* for chain construction.

##
## METADATA
##

Each node (adaptor/chain/sensor, not filters) should define metadata for itself. The following things are included:

* Description
* Interval range(s)
* Data range(s)
* Standby override sources (sort of metadata)

# Description

Description should provide a human readable string that describes what is the output from the node.

# Interval range(s)

Interval ranges define the possible rates at which this node can provide output. They are given with min/max pairs, where any value between min and max is allowed. Resolution parameter is ignored.

Base class takes care of queuing and sorting the interval requests. Each node just needs to provide accepted ranges and set/get methods. Interval is specified as milliseconds between samples. The real used value will be the smallest value, ensuring that data is measured as fast as required. This behavior can be modified for a node, in case smallest == fastest does not apply for its sources.

For adaptors, the interval should represent the real capabilities of the hardware and driver.

Chains and sensors have more possibilities. In simplest case, they just delegate the interval for the source node by using setIntervalSource(). Then any requests are directly moved to the source node.

If a node has more than one source whose output affect the rate of the output for the node itself, setInterval() and interval() should be reimplemented to merge the requests into wanted rate.

## Data range(s)

Data ranges tell the possible min and max values and accuracy of measurements. Setting them closely resembles interval setting. The largest difference is that datarates are set with first-come-first-serve basis. The first requester of data range gets to keep the setting.

Currently there are no examples of sensors that would make use of multiple dataranges. For the sake of information, the rates should be described with introduceAvailableDataRange() or taken from a source with setIntervalSource().

## Standby override

Default behavior is to turn off all sensors when display goes blank.

Client can request a sensor to stay on in such a case by setting the standbyOverride -property to true. In practise, nodes specify which sources should stay on with addStandbyOverrideSource().

In adaptors, display blank will result in all filehandles being released. Setting the property to true prevents this from happening.

The property should be used with care and only when required in order to minimize power consumption.

##
## CONFIGURATION FILES
##

TBD.

##
## FURTHER INFORMATION
##

If you have questions that are not clear from the text and code, don't hesitate to ask us.

Cheerios,

Timo Rongas <ext-timo.2.rongas@nokia.com>
@@ -1,3 +1,11 @@

## NOTE: This file has been deprecated in favor of PLUGIN-GUIDE.
## There are a few pieces of information here that haven't
## been yet described at the other file, so keeping this here
## for now.
##


###
### INSTRUCTIONS FOR WRITING ADAPTOR PLUGINS FOR SENSOR FRAMEWORK
###
Expand Down
4 changes: 4 additions & 0 deletions examples/adaptorplugin/sampleadaptor.h
Expand Up @@ -67,6 +67,10 @@ class SampleAdaptor : public SysfsAdaptor
*/
~SampleAdaptor();

// If the sensor does not work (reliably) when the display is off,
// the setStandbyOverride() function should be reimplemented to
// reject requests.
// virtual bool setStandbyOverride(const bool override) { Q_UNUSED(override); return false; }
private:

/**
Expand Down

0 comments on commit d1a65eb

Please sign in to comment.