Symbian3/SDK/Source/GUID-60EE22AA-402D-4FC2-9AD1-B3AEF822E8DC.dita
author Dominic Pinkman <dominic.pinkman@nokia.com>
Fri, 11 Jun 2010 15:24:34 +0100
changeset 9 59758314f811
parent 8 ae94777fff8f
child 13 48780e181b38
permissions -rw-r--r--
Week 23 contribution of PDK documentation content. See release notes for details. Fixes bugs Bug 2714, Bug 462.

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE task
  PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd">
<task id="GUID-60EE22AA-402D-4FC2-9AD1-B3AEF822E8DC" xml:lang="en"><title>Receiving
Channel Data based on Conditions</title><shortdesc>Conditional listening enables you to receive sensor data feeds
based on a specific condition. For example, you can choose to receive sensor
feeds that are only movement specific.</shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody>
<prereq id="GUID-A4F41A1D-D093-418E-BA65-30C36DA0B0DA">       <p>Before listening
for channel data, you must <xref href="GUID-4B709839-8EEF-4AD2-9868-9AF0176B1E5B.dita#GUID-4B709839-8EEF-4AD2-9868-9AF0176B1E5B/GUID-FBBD3A8B-F240-4DC0-B516-3A51FDD86A88">open
the sensor channel</xref>.</p>      </prereq>
<steps id="GUID-4DD07DEC-6017-4237-BE46-1D69E5FBD744-GENID-1-10-1-9-1-1-6-1-4-1-4-1-10-1-3-2">
<step id="GUID-9A69E5AD-E938-4092-A8C2-CB65C37C8962-GENID-1-10-1-9-1-1-6-1-4-1-4-1-10-1-3-2-1"><cmd>Create channel condition
items using <parmname>CSensrvChannelCondition</parmname> constructor. These
conditions can be used to filter the sensor data feeds.</cmd>
<stepxmp><codeblock xml:space="preserve">//Comparison values needed for condition
...
TInt firstNumber=45;
HBufC8 *firstBufNumber=NULL;
InetProtTextUtils::ConvertIntToDescriptorL(firstNumber,firstBufNumber);
CleanupStack::PushL(firstBufNumber);

TInt secondNumber=150;
HBufC8 *secondBufNumber=NULL;
InetProtTextUtils::ConvertIntToDescriptorL(secondNumber,secondBufNumber);
CleanupStack::PushL(secondBufNumber);

//Creates a SingleLimit Condition with a GreaterThan operator
CSensrvChannelCondition *firstCondition = CSensrvChannelCondition::NewL(ESensrvSingleLimitCondition,ESensrvOperatorGreaterThan,1,*firstBufNumber);

//Creates a SingleLimit Condition with a LessThan operator
CSensrvChannelCondition *secondCondition = CSensrvChannelCondition::NewL(ESensrvSingleLimitCondition,ESensrvOperatorLessThan,2,*secondBufNumber);</codeblock></stepxmp>
</step>
<step id="GUID-A94F1F87-9CD4-45E9-9FDA-B53E26C8F92D"><cmd>Create a channel
condition set using <parmname>CSensrvChannelConditionSet</parmname> constructor.
Add the condition items to the condition set using the <xref href="GUID-AF4BAE05-7111-3DF7-964D-C8A49D8F3D08.dita#GUID-AF4BAE05-7111-3DF7-964D-C8A49D8F3D08/GUID-84740BEB-2E6E-38E6-822B-9F6E4A55DF7D"><apiname>CSensrvChannelConditionSet::AddConditionL()</apiname></xref> function.</cmd>
<stepxmp><codeblock xml:space="preserve">//Creates a ConditionSet with ConditionType OR 
    CSensrvChannelConditionSet *ConditionSet=CSensrvChannelConditionSet::NewLC(ESensrvAndConditionSet);
    
    //Add channel1 and channel2 to conditonset
    ConditionSet-&gt;AddChannelConditionL(firstCondition);
    ConditionSet-&gt;AddChannelConditionL(secondCondition);</codeblock></stepxmp>
</step>
<step id="GUID-E51A9E16-67C8-43AB-BBEF-99411A3EEE0F"><cmd>Add the condition
set to the required channel using the <xref href="GUID-22DC917F-D833-3531-AB2D-A6E2D52EF844.dita#GUID-22DC917F-D833-3531-AB2D-A6E2D52EF844/GUID-006A659E-72F1-3D5D-8476-952619E3BA2F"><apiname>CSensrvChannel::AddConditionL()</apiname></xref> function.</cmd>
<stepxmp><codeblock xml:space="preserve">CSensrvChannel* channel;
channel-&gt;AddConditionL(*ConditionSet);   
</codeblock></stepxmp>
</step>
<step id="GUID-47EED068-A9C7-4DCF-AF03-3803CECAE7C8"><cmd>Create a condition
listener implementation for the <parmname>MSensrvChannelConditionListener</parmname> interface,
which listens for sensor data feeds based on <parmname>CSensrvChannelConditionSet</parmname>.</cmd>
<stepxmp><codeblock xml:space="preserve">class ConditionListener:public MSensrvChannelConditionListener
    {
    public:
        void ConditionMet(CSensrvChannel &amp;aChannel, CSensrvChannelConditionSet &amp;aChannelConditionSet, TDesC8 &amp;avalue)
        {
        ...
         //Implementation
        }
    void ConditionError(CSensrvChannel &amp;aChannel, TSensrvErrorSeverity aError)
        {
        ...
         //Implementation
        }
    void GetChannelConditionListenerInterfaceL(TUid aInterfaceUid, TAny *&amp;aInterface)
        {
        ...
         //Implementation
        }
    };</codeblock></stepxmp>
</step>
<step id="GUID-196F04E0-2A98-4479-8165-9A803823E6AD"><cmd>Start conditional
listening by passing an instance of the condition listener implementation,
using the <xref href="GUID-22DC917F-D833-3531-AB2D-A6E2D52EF844.dita#GUID-22DC917F-D833-3531-AB2D-A6E2D52EF844/GUID-4CA77329-E958-3568-B34D-1086AA34A334"><apiname>CSensrvChannel::StartConditionListeningL()</apiname></xref> function.</cmd>
<stepxmp><codeblock xml:space="preserve">//Instance of the condition listener implementation
ConditionListener conditionListener;   
...
channel-&gt;StartConditionListeningL(conditionListener,1,1);
...</codeblock></stepxmp>
</step>
<step id="GUID-93BD0200-C12B-4AB1-9D23-F11AC54D39E6"><cmd>Once you get the
required sensor data feeds from the sensor channel based on the conditions
set, you can stop conditional listening using the <xref href="GUID-22DC917F-D833-3531-AB2D-A6E2D52EF844.dita#GUID-22DC917F-D833-3531-AB2D-A6E2D52EF844/GUID-78F64EA2-2901-3304-B4AE-B865D18772E8"><apiname>CSensrvChannel::StopConditionListening()</apiname></xref> function.</cmd>
<stepxmp><codeblock xml:space="preserve">channel-&gt;StopConditionListening();
</codeblock></stepxmp>
</step>
</steps>
<postreq id="GUID-40C4B810-AD44-4A28-8C29-8A08E914970D"><p>End the session
with the sensor channel using the <xref href="GUID-22DC917F-D833-3531-AB2D-A6E2D52EF844.dita#GUID-22DC917F-D833-3531-AB2D-A6E2D52EF844/GUID-0B8F50A6-2CA1-316A-82AB-AA026005E810"><apiname>CSensrvChannel::CloseChannel()</apiname></xref> function.</p></postreq>
</taskbody></task>