Listening for Property Changes

The sensor channel APIs enable the client applications to be notified about the changes to properties associated with a sensor channel.

Context

The client applications can use the property listener to monitor the property changes made by other clients.

Prerequisites

Before listening for the property changes of a sensor channel, you must open the sensor channel.

Steps

  1. Create a property listener implementation for the MSensrvPropertyListener interface.

    class PropertyListener:public MSensrvPropertyListener
        {
        public:    
        void PropertyChanged(CSensrvChannel &aChannel, const TSensrvProperty &aChangedProperty)
            {
            ...
             //Implementation
            }
        void PropertyError(CSensrvChannel &aChannel, TSensrvErrorSeverity aError)
            {
            ...
             //Implementation
            }
        void SetPropertySuccessIndicationChanged(TSetPropertySuccessIndicator aIndication)
            {
            ...
             //Implementation
            }
        void GetPropertyListenerInterfaceL(TUid aInterfaceUid, TAny *&aInterface)
            {
            ...
             //Implementation
            }
        };
  2. Start property listening by passing an instance of property listener implementation using CSensrvChannel::SetPropertyListenerL().

    //Instance of the property listener implementation
    PropertyListener propListener;
    ...
    CSensrvChannel* channel;
    ...
    channel->SetPropertyListenerL(&propListener);
    ...
    When a property change occurs, a PropertyChanged() notification is delivered through the MSensrvPropertyListener callback interface to the clients that are listening for property changes.

    Note: The client that set the property is not notified.

  3. Once you get the required property changes associated with the sensor channel, you can stop property listening by passing a NULL parameter to the CSensrvChannel::SetPropertyListenerL() function.

    channel->SetPropertyListenerL();