Receiving Channel Data based on Conditions

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.


  1. 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;
    TInt secondNumber=150;
    HBufC8 *secondBufNumber=NULL;
    //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);
  2. 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
  3. Add the condition set to the required channel using the CSensrvChannel::AddConditionL() function.

    CSensrvChannel* channel;
  4. Create a condition listener implementation for the MSensrvChannelConditionListener interface, which listens for sensor data feeds based on CSensrvChannelConditionSet.

    class ConditionListener:public MSensrvChannelConditionListener
            void ConditionMet(CSensrvChannel &aChannel, CSensrvChannelConditionSet &aChannelConditionSet, TDesC8 &avalue)
        void ConditionError(CSensrvChannel &aChannel, TSensrvErrorSeverity aError)
        void GetChannelConditionListenerInterfaceL(TUid aInterfaceUid, TAny *&aInterface)
  5. 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;   
  6. 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.


Next actions

End the session with the sensor channel using the CSensrvChannel::CloseChannel() function.