Listening
for Channel Changes
The sensor channel APIs enable you to receive notifications when
a sensor channel is added or removed. This ensures that you are informed of
changes to sensor channels whenever there is a change. For example, you can
receive notifications when a specific proximity sensor channel is added.
- Create a channel
listener implementation for the MSensrvChannelListener interface.
class ChannelListener:public MSensrvChannelListener
{
public:
void ChannelChangeDetected(const TSensrvChannelInfo &aDetectedChannel, TSensrvChannelChangeType aChangeType)
{
...
//Implementation
}
void ChannelDetectionError(CSensrvChannelFinder aChannelFinder, TSensrvErrorSeverity aError)
{
...
//Implementation
}
void GetChannelListenerInterfaceL(TUid aInterfaceUid, TAny *aInterface)
{
...
//Implementation
}
};
- Start channel listening
by passing an instance of the channel listener implementation, using CSensrvChannelFinder::SetChannelListenerL() function.
//Instance of the channel listener implementation
ChannelListener channelListener;
//Channel search parameters
TSensrvChannelInfo &searchParameters
...
CSensrvChannelFinder* finder = CSensrvChannelFinder::NewLC();
...
channel->SetChannelListenerL(channelListener, searchParameters);
...
This listens for channels that meet the supplied search parameters.
When a channel change occurs, a ChannelChangeDetected notification
is delivered through the MSensrvChannelListener interface.
- Stop channel listening
by passing a NULL parameter to the CSensrvChannelFinder::SetChannelListenerL() function.
ChannelListener channelListener=NULL;
finder->SetChannelListenerL(channelListener, searchParameters);