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.
Create channel condition
items using CSensrvChannelCondition
constructor. These
conditions can be used to filter the sensor data feeds.
//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);
Create a channel
condition set using CSensrvChannelConditionSet
constructor.
Add the condition items to the condition set using the CSensrvChannelConditionSet::AddConditionL() function.
//Creates a ConditionSet with ConditionType OR CSensrvChannelConditionSet *ConditionSet=CSensrvChannelConditionSet::NewLC(ESensrvAndConditionSet); //Add channel1 and channel2 to conditonset ConditionSet->AddChannelConditionL(firstCondition); ConditionSet->AddChannelConditionL(secondCondition);
Add the condition set to the required channel using the CSensrvChannel::AddConditionL() function.
CSensrvChannel* channel; channel->AddConditionL(*ConditionSet);
Create a condition
listener implementation for the MSensrvChannelConditionListener
interface,
which listens for sensor data feeds based on CSensrvChannelConditionSet
.
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 } };
Start conditional listening by passing an instance of the condition listener implementation, using the CSensrvChannel::StartConditionListeningL() function.
//Instance of the condition listener implementation ConditionListener conditionListener; ... channel->StartConditionListeningL(conditionListener,1,1); ...
Once you get the required sensor data feeds from the sensor channel based on the conditions set, you can stop conditional listening using the CSensrvChannel::StopConditionListening() function.
channel->StopConditionListening();
End the session with the sensor channel using the CSensrvChannel::CloseChannel() function.