Symbian3/SDK/Source/GUID-BA0D9DA9-3B54-4964-A4D6-9ADA4DEB7231.dita
changeset 7 51a74ef9ed63
child 8 ae94777fff8f
equal deleted inserted replaced
6:43e37759235e 7:51a74ef9ed63
       
     1 <?xml version="1.0" encoding="utf-8"?>
       
     2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
       
     3 <!-- This component and the accompanying materials are made available under the terms of the License 
       
     4 "Eclipse Public License v1.0" which accompanies this distribution, 
       
     5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
       
     6 <!-- Initial Contributors:
       
     7     Nokia Corporation - initial contribution.
       
     8 Contributors: 
       
     9 -->
       
    10 <!DOCTYPE task
       
    11   PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd">
       
    12 <task id="GUID-BA0D9DA9-3B54-4964-A4D6-9ADA4DEB7231" xml:lang="en"><title>Receiving
       
    13 Data from Sensors</title><shortdesc>You can implement a data listener to receive data from the sensors.
       
    14 Based on the data received, you can perform specific actions on the Symbian
       
    15 device. For example, if you receive information from the sensor about the
       
    16 distance between the device and the user then based on this information, you
       
    17 can disable or enable the loudspeaker mode on the Symbian device.</shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody>
       
    18 <prereq id="GUID-E09C6ABC-F717-4791-A2EE-491421D2BD30">       <p>Before listening
       
    19 for sensor channel data, you must <xref href="GUID-4B709839-8EEF-4AD2-9868-9AF0176B1E5B.dita#GUID-4B709839-8EEF-4AD2-9868-9AF0176B1E5B/GUID-FBBD3A8B-F240-4DC0-B516-3A51FDD86A88">open
       
    20 the sensor channel</xref>.</p>     </prereq>
       
    21 <steps id="GUID-4DD07DEC-6017-4237-BE46-1D69E5FBD744-GENID-1-8-1-9-1-1-6-1-4-1-4-1-5-1-3-2">
       
    22 <step id="GUID-CE0EE6EE-84A7-46F6-8590-C75FAA381843"><cmd>Implement the data
       
    23 listener.</cmd>
       
    24 <info><p>Inherit from the <parmname>MSensrvDataListener</parmname> interface
       
    25 and implement the following pure virtual functions: <xref href="GUID-519E744E-246C-3F4A-A869-F25B03F1126F.dita#GUID-519E744E-246C-3F4A-A869-F25B03F1126F/GUID-92EDE76E-F5D8-3D45-939B-FD5C03347AE8"><apiname>MSensrvDataListener::DataReceived</apiname></xref>, <xref href="GUID-519E744E-246C-3F4A-A869-F25B03F1126F.dita#GUID-519E744E-246C-3F4A-A869-F25B03F1126F/GUID-F6C22940-A276-38C2-890F-CA45B75D613F"><apiname>MSensrvDataListener::DataError</apiname></xref> and <xref href="GUID-519E744E-246C-3F4A-A869-F25B03F1126F.dita#GUID-519E744E-246C-3F4A-A869-F25B03F1126F/GUID-4062844D-2F25-38FC-B91A-DD5B41E6FF3F"><apiname>MSensrvDataListener::GetDataListenerInterfaceL</apiname></xref></p><codeblock xml:space="preserve">class DataListener:public MSensrvDataListener
       
    26     {
       
    27     public:
       
    28         void DataReceived(CSensrvChannel&amp; aChannel, TInt aCount, TInt aDataLost )
       
    29         {
       
    30         ...
       
    31          //Implementation
       
    32         }
       
    33     void DataError( CSensrvChannel&amp;, TSensrvErrorSeverity)
       
    34         {
       
    35         ...
       
    36          //Implementation
       
    37         }
       
    38     void GetDataListenerInterfaceL( TUid, TAny*&amp;)
       
    39         {
       
    40         ...
       
    41          //Implementation
       
    42         }
       
    43     };</codeblock></info>
       
    44 </step>
       
    45 <step id="GUID-107B26D8-CD5A-4571-8441-F1A5A2C0EB2B"><cmd>Start data listening.</cmd>
       
    46 <info><p>Pass an instance of data listener implementation using the <xref href="GUID-22DC917F-D833-3531-AB2D-A6E2D52EF844.dita#GUID-22DC917F-D833-3531-AB2D-A6E2D52EF844/GUID-F851A108-C72F-3132-BE15-DC41CACB64F9"><apiname>CSensrvChannel::StartDataListeningL()</apiname></xref> function.</p><codeblock xml:space="preserve">//Instance of the data listener implementation
       
    47 DataListener dataListener; 
       
    48 ...
       
    49 CSensrvChannel* channel;
       
    50 ...
       
    51 channel-&gt;StartDataListeningL(&amp;dataListener, 1, 1, 0);
       
    52 ...</codeblock><p> When new data is available to be read in the sensor channel,
       
    53 the client is notified by the <xref href="GUID-519E744E-246C-3F4A-A869-F25B03F1126F.dita#GUID-519E744E-246C-3F4A-A869-F25B03F1126F/GUID-7EE31046-31A6-356E-AFEF-2E8C003A7F15"><apiname>MSensrvDataListener::DataReceived(CSensrvChannel
       
    54 &amp;,TInt,TInt)</apiname></xref> callback function. The channel data is received
       
    55 into the receiving buffer. The receiving buffer is allocated from the heap
       
    56 in the client's thread and its size is the channel data item size multiplied
       
    57 by the maximum number of data items. </p></info>
       
    58 </step>
       
    59 <step id="GUID-40F9F566-475E-4ECD-B420-70EB1B77DEAA"><cmd>Read the channel
       
    60 data from the receiving buffer using the <xref href="GUID-22DC917F-D833-3531-AB2D-A6E2D52EF844.dita#GUID-22DC917F-D833-3531-AB2D-A6E2D52EF844/GUID-EC1AF564-F05D-3729-B0C9-7573A1F79B86"><apiname>CSensrvChannel::GetData()</apiname></xref> function.
       
    61 For more information about handling data notifications, see the following <xref href="GUID-BA0D9DA9-3B54-4964-A4D6-9ADA4DEB7231.dita#GUID-BA0D9DA9-3B54-4964-A4D6-9ADA4DEB7231/5876a529-0484-497d-8cf8-9ceb9c725388">Example</xref>.</cmd>
       
    62 </step>
       
    63 <step id="GUID-D3928C98-3D10-40BE-A63E-584969AA0416"><cmd>After you get the
       
    64 required sensor data feeds from the sensor channel, you can stop data listening
       
    65 using the <xref href="GUID-22DC917F-D833-3531-AB2D-A6E2D52EF844.dita#GUID-22DC917F-D833-3531-AB2D-A6E2D52EF844/GUID-0129F5FA-BD26-37F0-8FE4-19F393AA817C"><apiname>CSensrvChannel::StopDataListening()</apiname></xref> function.</cmd>
       
    66 <stepxmp><codeblock xml:space="preserve">channel-&gt;StopDataListening();</codeblock></stepxmp>
       
    67 </step>
       
    68 </steps>
       
    69 <example id="5876A529-0484-497D-8CF8-9CEB9C725388"><p>The following example
       
    70 shows how to handle the double tapping data notification that is received. </p><p>Check
       
    71 the channel type of the received data and then receive the data object using
       
    72 the <xref href="GUID-22DC917F-D833-3531-AB2D-A6E2D52EF844.dita#GUID-22DC917F-D833-3531-AB2D-A6E2D52EF844/GUID-EC1AF564-F05D-3729-B0C9-7573A1F79B86"><apiname>CSensrvChannel::GetData()</apiname></xref> function. The <parmname>aCount</parmname> parameter
       
    73 provides the details about the number of data objects in the channels receiving
       
    74 buffer. This number can be zero if the buffering period is used when data
       
    75 listening is started. The <parmname>aDataLost</parmname> parameter provides
       
    76 the details about the number of the lost data objects. For example, in heavy
       
    77 load situations. </p><codeblock xml:space="preserve">void CTestClass::DataReceived( CSensrvChannel&amp; aChannel, 
       
    78                                TInt aCount, 
       
    79                                TInt aDataLost )
       
    80     {
       
    81     if ( aChannel.GetChannelInfo().iChannelType == KSensrvChannelTypeIdAccelerometerDoubleTappingData )
       
    82         {
       
    83         TSensrvTappingData tappingData;
       
    84         TPckg &lt;TSensrvTappingData&gt; tappingPackage( tappingData );
       
    85         aChannel.GetData( tappingPackage );
       
    86         }
       
    87     }</codeblock></example>
       
    88 <postreq id="GUID-69071DC2-EB41-43BA-8DFC-CE2D4423AF8A"><p>End the session
       
    89 with the sensor channel using the <xref href="GUID-22DC917F-D833-3531-AB2D-A6E2D52EF844.dita#GUID-22DC917F-D833-3531-AB2D-A6E2D52EF844/GUID-0B8F50A6-2CA1-316A-82AB-AA026005E810"><apiname>CSensrvChannel::CloseChannel()</apiname></xref> function.</p></postreq>
       
    90 </taskbody></task>