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.
Before listening for channel data, you must open the sensor channel.
//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);
//Creates a ConditionSet with ConditionType OR CSensrvChannelConditionSet *ConditionSet=CSensrvChannelConditionSet::NewLC(ESensrvAndConditionSet); //Add channel1 and channel2 to conditonset ConditionSet->AddChannelConditionL(firstCondition); ConditionSet->AddChannelConditionL(secondCondition);
CSensrvChannel* channel; channel->AddConditionL(*ConditionSet);
class ConditionListener:public MSensrvChannelConditionListener { public: void ConditionMet(CSensrvChannel &aChannel, CSensrvChannelConditionSet &aChannelConditionSet, TDesC8 &avalue) { ... //Implementation } void ConditionError(CSensrvChannel &aChannel, TSensrvErrorSeverity aError) { ... //Implementation } void GetChannelConditionListenerInterfaceL(TUid aInterfaceUid, TAny *&aInterface) { ... //Implementation } };
//Instance of the condition listener implementation ConditionListener conditionListener; ... channel->StartConditionListeningL(conditionListener,1,1); ...
channel->StopConditionListening();
End the session with the sensor channel using the CSensrvChannel::CloseChannel() function.