The pan-sensor service subsystem provides a lightweight sensor service framework. You can call APIs offered by this framework to query the sensor list, enable or disable a sensor, and subscribe to or unsubscribe from sensor data. The following figure shows the architecture of the lightweight sensor framework.
The pan-sensor service subsystem provides a lightweight sensor service framework. You can call APIs offered by this framework to query the sensor list, enable or disable a sensor, and subscribe to or unsubscribe from sensor data. The following figure shows the architecture of the lightweight sensor framework.
**Figure 1** Sensor service framework
**Figure 1** Sensor service framework

- Sensor API: provides APIs for performing basic operations on sensors, including querying the sensor list, subscribing to or unsubscribing from sensor data, and executing control commands. This module makes application development simpler.

- Sensor Framework: manages sensor data subscription, creates and destroys data channels, and implements communication with the Sensor Service module.
- Sensor API: provides APIs for performing basic operations on sensors, including querying the sensor list, subscribing to or unsubscribing from sensor data, and executing control commands. This module makes application development simpler.
- Sensor Service: interacts with the HDF module to receive, parse, and distribute data, manages sensors on hardware and sensor data reporting, and controls sensor permissions.
- Sensor Framework: manages sensor data subscription, creates and destroys data channels, and implements communication with the Sensor Service module.
- Sensor Service: interacts with the HDF module to receive, parse, and distribute data, manages sensors on hardware and sensor data reporting, and controls sensor permissions.
## Available APIs<a name="section7255104114110"></a>
<tdclass="cellrowborder"valign="top"width="25.722572257225725%"headers="mcps1.2.4.1.2 "><pid="p199227318499"><aname="p199227318499"></a><aname="p199227318499"></a>Obtains information about all sensors in the system.</p>
<pid="p9922153110492"><aname="p9922153110492"></a><aname="p9922153110492"></a><strongid="b2922183114917"><aname="b2922183114917"></a><aname="b2922183114917"></a>Return value</strong>: Returns <strongid="b15367115154516"><aname="b15367115154516"></a><aname="b15367115154516"></a>0</strong> if the information is obtained; returns a non-zero value otherwise.</p>
</td>
<tdclass="cellrowborder"valign="top"width="40.94409440944094%"headers="mcps1.2.4.1.3 "><pid="p4922173116498"><aname="p4922173116498"></a><aname="p4922173116498"></a><strongid="b633817407478"><aname="b633817407478"></a><aname="b633817407478"></a>sensorInfo</strong> (not NULL): information about all sensors in the system</p>
<pid="p18922931134919"><aname="p18922931134919"></a><aname="p18922931134919"></a><strongid="b8845650154711"><aname="b8845650154711"></a><aname="b8845650154711"></a>count</strong> (not NULL): total number of sensors in the system</p>
<tdclass="cellrowborder"valign="top"width="25.722572257225725%"headers="mcps1.2.4.1.2 "><pid="p14922113114914"><aname="p14922113114914"></a><aname="p14922113114914"></a>Subscribes to sensor data. The system will report the obtained sensor data to the subscriber.</p>
<pid="p5922331114916"><aname="p5922331114916"></a><aname="p5922331114916"></a><strongid="b7756437172"><aname="b7756437172"></a><aname="b7756437172"></a>Return value</strong>: Returns <strongid="b37618371173"><aname="b37618371173"></a><aname="b37618371173"></a>0</strong> if the subscription is successful; returns a non-zero value otherwise.</p>
</td>
<tdclass="cellrowborder"valign="top"width="40.94409440944094%"headers="mcps1.2.4.1.3 "><pid="p17922183120490"><aname="p17922183120490"></a><aname="p17922183120490"></a><strongid="b383183812561"><aname="b383183812561"></a><aname="b383183812561"></a>sensorTypeId</strong>: ID of a sensor type</p>
<pid="p8922193154917"><aname="p8922193154917"></a><aname="p8922193154917"></a><strongid="b15825101814564"><aname="b15825101814564"></a><aname="b15825101814564"></a>user</strong> (not NULL): sensor subscriber that requests sensor data. A subscriber can obtain data from only one sensor.</p>
<tdclass="cellrowborder"valign="top"width="25.722572257225725%"headers="mcps1.2.4.1.2 "><pid="p792383116495"><aname="p792383116495"></a><aname="p792383116495"></a>Unsubscribes from sensor data. The system will no longer report sensor data to the subscriber.</p>
<pid="p139231531184912"><aname="p139231531184912"></a><aname="p139231531184912"></a><strongid="b1698214914415"><aname="b1698214914415"></a><aname="b1698214914415"></a>Return value</strong>: Returns <strongid="b20983690447"><aname="b20983690447"></a><aname="b20983690447"></a>0</strong> if the unsubscription is successful; returns a non-zero value otherwise.</p>
</td>
<tdclass="cellrowborder"valign="top"width="40.94409440944094%"headers="mcps1.2.4.1.3 "><pid="p178981446572"><aname="p178981446572"></a><aname="p178981446572"></a><strongid="b5189141634413"><aname="b5189141634413"></a><aname="b5189141634413"></a>sensorTypeId</strong>: ID of a sensor type</p>
<pid="p178988410573"><aname="p178988410573"></a><aname="p178988410573"></a><strongid="b56761418164417"><aname="b56761418164417"></a><aname="b56761418164417"></a>user</strong> (not NULL): sensor subscriber that requests sensor data. A subscriber can obtain data from only one sensor.</p>
<tdclass="cellrowborder"valign="top"width="25.722572257225725%"headers="mcps1.2.4.1.2 "><pid="p14924831124913"><aname="p14924831124913"></a><aname="p14924831124913"></a>Sets the data sampling interval and data reporting interval for the specified sensor.</p>
<pid="p14924203134910"><aname="p14924203134910"></a><aname="p14924203134910"></a><strongid="b181731732463"><aname="b181731732463"></a><aname="b181731732463"></a>Return value</strong>: Returns <strongid="b417363104616"><aname="b417363104616"></a><aname="b417363104616"></a>0</strong> if the setting is successful; returns a non-zero value otherwise.</p>
</td>
<tdclass="cellrowborder"valign="top"width="40.94409440944094%"headers="mcps1.2.4.1.3 "><pid="p189243318494"><aname="p189243318494"></a><aname="p189243318494"></a><strongid="b4102102264610"><aname="b4102102264610"></a><aname="b4102102264610"></a>sensorTypeId</strong>: ID of a sensor type</p>
<pid="p167364493594"><aname="p167364493594"></a><aname="p167364493594"></a><strongid="b930712416461"><aname="b930712416461"></a><aname="b930712416461"></a>user</strong> (not NULL): sensor subscriber that requests sensor data. A subscriber can obtain data from only one sensor.</p>
<pid="p1692403115493"><aname="p1692403115493"></a><aname="p1692403115493"></a><strongid="b1866310191589"><aname="b1866310191589"></a><aname="b1866310191589"></a>samplingInterval</strong>: sensor data sampling interval, in nanoseconds</p>
<pid="p392443174917"><aname="p392443174917"></a><aname="p392443174917"></a><strongid="b851892113817"><aname="b851892113817"></a><aname="b851892113817"></a>reportInterval</strong>: sensor data reporting interval, in nanoseconds</p>
<tdclass="cellrowborder"valign="top"width="25.722572257225725%"headers="mcps1.2.4.1.2 "><pid="p1892583174920"><aname="p1892583174920"></a><aname="p1892583174920"></a>Enables the specified sensor that has been subscribed to.</p>
<pid="p16925113119497"><aname="p16925113119497"></a><aname="p16925113119497"></a><strongid="b1190011547620"><aname="b1190011547620"></a><aname="b1190011547620"></a>Return value</strong>: Returns <strongid="b1690019543620"><aname="b1690019543620"></a><aname="b1690019543620"></a>0</strong> if the sensor is successfully enabled; returns a non-zero value otherwise.</p>
</td>
<tdclass="cellrowborder"valign="top"width="40.94409440944094%"headers="mcps1.2.4.1.3 "><pid="p59255313493"><aname="p59255313493"></a><aname="p59255313493"></a><strongid="b269629475"><aname="b269629475"></a><aname="b269629475"></a>sensorTypeId</strong>: ID of a sensor type</p>
<pid="p1692517314499"><aname="p1692517314499"></a><aname="p1692517314499"></a><strongid="b1739417117716"><aname="b1739417117716"></a><aname="b1739417117716"></a>user</strong> (not NULL): sensor subscriber that requests sensor data. A subscriber can obtain data from only one sensor.</p>
<tdclass="cellrowborder"valign="top"width="25.722572257225725%"headers="mcps1.2.4.1.2 "><pid="p12925143118492"><aname="p12925143118492"></a><aname="p12925143118492"></a>Disables an enabled sensor.</p>
<pid="p5926031124914"><aname="p5926031124914"></a><aname="p5926031124914"></a><strongid="b13736235877"><aname="b13736235877"></a><aname="b13736235877"></a>Return value</strong>: Returns <strongid="b273720356714"><aname="b273720356714"></a><aname="b273720356714"></a>0</strong> if the sensor is successfully disabled; returns a non-zero value otherwise.</p>
</td>
<tdclass="cellrowborder"valign="top"width="40.94409440944094%"headers="mcps1.2.4.1.3 "><pid="p1692683112499"><aname="p1692683112499"></a><aname="p1692683112499"></a><strongid="b1452911411574"><aname="b1452911411574"></a><aname="b1452911411574"></a>sensorTypeId</strong>: ID of a sensor type</p>
<pid="p1081949113"><aname="p1081949113"></a><aname="p1081949113"></a><strongid="b11188443178"><aname="b11188443178"></a><aname="b11188443178"></a>user</strong> (not NULL): sensor subscriber that requests sensor data. A subscriber can obtain data from only one sensor.</p>
<tdclass="cellrowborder"valign="top"width="25.722572257225725%"headers="mcps1.2.4.1.2 "><pid="p892633118493"><aname="p892633118493"></a><aname="p892633118493"></a>Sets the data reporting mode for the specified sensor.</p>
<pid="p1927031114910"><aname="p1927031114910"></a><aname="p1927031114910"></a><strongid="b456216221484"><aname="b456216221484"></a><aname="b456216221484"></a>Return value</strong>: Returns <strongid="b12562112214811"><aname="b12562112214811"></a><aname="b12562112214811"></a>0</strong> if the sensor data reporting mode is successfully set; returns a non-zero value otherwise.</p>
</td>
<tdclass="cellrowborder"valign="top"width="40.94409440944094%"headers="mcps1.2.4.1.3 "><pid="p119277312492"><aname="p119277312492"></a><aname="p119277312492"></a><strongid="b19747144015816"><aname="b19747144015816"></a><aname="b19747144015816"></a>sensorTypeId</strong>: ID of a sensor type</p>
<pid="p159271031184915"><aname="p159271031184915"></a><aname="p159271031184915"></a><strongid="b1367209917"><aname="b1367209917"></a><aname="b1367209917"></a>user</strong> (not NULL): sensor subscriber that requests sensor data. A subscriber can obtain data from only one sensor.</p>
<pid="p0927173154916"><aname="p0927173154916"></a><aname="p0927173154916"></a><strongid="b3914356101520"><aname="b3914356101520"></a><aname="b3914356101520"></a>mode</strong>: data reporting mode of the sensor</p>
</td>
</tr>
</tbody>
</table>
| API| Description| Parameter|
| -------- | -------- | -------- |
| int32_t **GetAllSensors**( <br> SensorInfo \*\*sensorIn <br> fo, int32_t \*count) | Obtains information about all sensors in the system.<br>**Return value**: Returns **0** if the information is obtained; returns a non-zero value otherwise.| **sensorInfo** (not NULL): information about all sensors in the system<br>**count** (not NULL): total number of sensors in the system|
| int32_t **SubscribeSensor**<br> (int32_t sensorTypeId, <br> SensorUser \*user) | Subscribes to sensor data. The system will report the obtained sensor data to the subscriber.<br>**Return value**: Returns **0** if the subscription is successful; returns a non-zero value otherwise.| **sensorTypeId**: ID of a sensor type<br>**user** (not NULL): sensor subscriber that requests sensor data. A subscriber can obtain data from only one sensor.|
| int32_t **UnsubscribeSensor**<br> (int32_t sensorTypeId, SensorUser \*user) | Unsubscribes from sensor data. The system will no longer report sensor data to the subscriber.<br>**Return value**: Returns **0** if the sensor data reporting mode is successfully set; returns a non-zero value otherwise.| **sensorTypeId**: ID of a sensor type<br>**user** (not NULL): sensor subscriber that requests sensor data. A subscriber can obtain data from only one sensor.|
| int32_t **SetBatch**(int32_t sensorTypeId, SensorUser <br>\*user, int64_t samplingInterval, int64_t reportInterval) | Sets the data sampling interval and data reporting interval for the specified sensor.<br>**Return value**: Returns **0** if the sensor data reporting mode is successfully set; returns a non-zero value otherwise.| **sensorTypeId**: ID of a sensor type<br>**user** (not NULL): sensor subscriber that requests sensor data. A subscriber can obtain data from only one sensor.<br>**samplingInterval**: sensor data sampling interval, in nanoseconds<br>**reportInterval**: sensor data reporting interval, in nanoseconds|
| int32_t **ActivateSensor**(int32_t sensorTypeId, <br> SensorUser \*user) | Enables the specified sensor that has been subscribed to.<br>**Return value**: Returns **0** if the sensor data reporting mode is successfully set; returns a non-zero value otherwise.| **sensorTypeId**: ID of a sensor type<br>**user** (not NULL): sensor subscriber that requests sensor data. A subscriber can obtain data from only one sensor.|
| int32_t **DeactivateSensor**(int32_t sensor <br> TypeId, SensorUser \*user) | Disables an enabled sensor.<br>**Return value**: Returns **0** if the sensor data reporting mode is successfully set; returns a non-zero value otherwise.| **sensorTypeId**: ID of a sensor type<br>**user** (not NULL): sensor subscriber that requests sensor data. A subscriber can obtain data from only one sensor.|
| int32_t **SetMode**(int32_t sensorTypeId, <br> SensorUser \*user, int32_t mode) | Sets the data reporting mode for the specified sensor.<br>**Return value**: Returns **0** if the sensor data reporting mode is successfully set; returns a non-zero value otherwise.| **sensorTypeId**: ID of a sensor type<br>**user** (not NULL): sensor subscriber that requests sensor data. A subscriber can obtain data from only one sensor.<br>**mode**: data reporting mode of the sensor|