You must open the channel before starting to listen for channel data.
The following example shows how to start listening to a double tapping channel and receive data from it.
Channel data is received into the receiving buffer, and it can be read
using the GetData()
method. When new data is available in the receiving buffer, a DataReceived()
notification is delivered via the data listener callback interface MSensrvDataListener
.
In case of double tapping channel, the desired count and maximum count
parameters are set to one to get a DataReceived()
notification
per one double tapping. The buffering period is set to zero to get the DataReceived()
notification
only when double tapping is done.
To read channel data the receiving buffer, use the GetData()
method.
The receiving buffer is allocated from heap in the client's thread and its size is the channel data item size multiplied by maximum number of data items.
There are two receiving buffers for one client, for example if the channel data item size is 20 bytes and the maximum count is 10, this results in 400 bytes memory consumption (20bytes*10*2=400 bytes). On the other hand, a small desired data count increases interprocess communication.
You need to provide a pointer to the data listener for the channel to be
able to receive DataReceived()
notifications.
iSensorChannel->StartDataListeningL( this, //this object is data listener for this channel 1, //aDesiredCount is one, i.e. each double tapping is notified separately 1, //aMaximumCount is one, i.e. object count in receiving data buffer is one 0 );//buffering period is not used
To implement the data listener, inherit from the MSensrvDataListener
interface
class and implement the declared pure virtual methods. When a new data item
is available in the sensor channel and data listening is started, the DataReceived()
method
is called by the sensor framework.
The following example shows how to handle double tapping data received notification.
First the channel type of the received data is checked and then data object
is get with the GetData()
method. The aCount
parameter
tells the number of data objects in the channels receiving buffer and it can
be zero if the buffering period was used when data listening was started.
The aDataLost
parameter tells the number of the lost data
objects e.g. in heavy load situations.
void CTestClass::DataReceived( CSensrvChannel& aChannel, TInt aCount, TInt aDataLost ) { if ( aChannel.GetChannelInfo().iChannelType == KSensrvChannelTypeIdAccelerometerDoubleTappingData ) { TSensrvTappingData tappingData; TPckg<TSensrvTappingData> tappingPackage( tappingData ); aChannel.GetData( tappingPackage ); } }
When you do not need to listen for sensor channel data any more, stop the
listening using the StopDataListening()
method.