• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup PanSensor
18  * @{
19  *
20  * @brief Provides standard open APIs for you to use common capabilities of sensors.
21  *
22  * For example, you can call these APIs to obtain sensor information,
23  * subscribe to or unsubscribe from sensor data, enable or disable a sensor,
24  * and set the sensor data reporting mode.
25  *
26  * @since 5
27  */
28 
29 /**
30  * @file sensor_agent.h
31  *
32  * @brief Declares common APIs for sensor management, such as APIs for subscribing to
33  * and obtaining sensor data, enabling a sensor, and setting the sensor data reporting mode.
34  *
35  * @since 5
36  */
37 
38 #ifndef SENSOR_AGENT_H
39 #define SENSOR_AGENT_H
40 
41 #include "sensor_agent_type.h"
42 
43 #ifdef __cplusplus
44 #if __cplusplus
45 extern "C" {
46 #endif
47 #endif
48 
49 /**
50  * @brief Obtains information about all sensors in the system.
51  *
52  * @param sensorInfo Indicates the double pointer to the information about all sensors in the system.
53  * For details, see {@link SensorInfo}.
54  * @param count Indicates the pointer to the total number of sensors in the system.
55  * @return Returns <b>0</b> if the information is obtained; returns a non-zero value otherwise.
56  *
57  * @since 5
58  */
59 int32_t GetAllSensors(SensorInfo **sensorInfo, int32_t *count);
60 /**
61  * @brief Subscribes to sensor data. The system will report the obtained sensor data to the subscriber.
62  *
63  * @param sensorTypeId Indicates the ID of a sensor type. For details, see {@link SensorTypeId}.
64  * @param user Indicates the pointer to the sensor subscriber that requests sensor data. For details,
65  * see {@link SensorUser}. A subscriber can obtain data from only one sensor.
66  * @return Returns <b>0</b> if the subscription is successful; returns a non-zero value otherwise.
67  *
68  * @since 5
69  */
70 int32_t SubscribeSensor(int32_t sensorTypeId, const SensorUser *user);
71 /**
72  * @brief Unsubscribes from sensor data.
73  *
74  * @param sensorTypeId Indicates the ID of a sensor type. For details, see {@link SensorTypeId}.
75  * @param user Indicates the pointer to the sensor subscriber that requests sensor data.
76  * For details, see {@link SensorUser}. A subscriber can obtain data from only one sensor.
77  * @return Returns <b>0</b> if the unsubscription is successful; returns a non-zero value otherwise.
78  *
79  * @since 5
80  */
81 int32_t UnsubscribeSensor(int32_t sensorTypeId, const SensorUser *user);
82 /**
83  * @brief Sets the data sampling interval and data reporting interval for the specified sensor.
84  *
85  * @param sensorTypeId Indicates the ID of a sensor type. For details, see {@link SensorTypeId}.
86  * @param user Indicates the pointer to the sensor subscriber that requests sensor data.
87  * For details, see {@link SensorUser}. A subscriber can obtain data from only one sensor.
88  * @param samplingInterval Indicates the sensor data sampling interval to set, in nanoseconds.
89  * @param reportInterval Indicates the sensor data reporting interval, in nanoseconds.
90  * @return Returns <b>0</b> if the setting is successful; returns a non-zero value otherwise.
91  *
92  * @since 5
93  */
94 int32_t SetBatch(int32_t sensorTypeId, const SensorUser *user, int64_t samplingInterval, int64_t reportInterval);
95 /**
96  * @brief Enables the sensor that has been subscribed to. The subscriber can obtain the sensor data
97  * only after the sensor is enabled.
98  *
99  * @param sensorTypeId Indicates the ID of a sensor type. For details, see {@link SensorTypeId}.
100  * @param user Indicates the pointer to the sensor subscriber that requests sensor data.
101  * For details, see {@link SensorUser}. A subscriber can obtain data from only one sensor.
102  * @return Returns <b>0</b> if the sensor is successfully enabled; returns a non-zero value otherwise.
103  *
104  * @since 5
105  */
106 int32_t ActivateSensor(int32_t sensorTypeId, const SensorUser *user);
107 /**
108  * @brief Disables an enabled sensor.
109  *
110  * @param sensorTypeId Indicates the ID of a sensor type. For details, see {@link SensorTypeId}.
111  * @param user Indicates the pointer to the sensor subscriber that requests sensor data.
112  * For details, see {@link SensorUser}. A subscriber can obtain data from only one sensor.
113  * @return Returns <b>0</b> if the sensor is successfully disabled; returns a non-zero value otherwise.
114  *
115  * @since 5
116  */
117 int32_t DeactivateSensor(int32_t sensorTypeId, const SensorUser *user);
118 /**
119  * @brief Sets the data reporting mode for the specified sensor.
120  *
121  * @param sensorTypeId Indicates the ID of a sensor type. For details, see {@link SensorTypeId}.
122  * @param user Indicates the pointer to the sensor subscriber that requests sensor data.
123  * For details, see {@link SensorUser}. A subscriber can obtain data from only one sensor.
124  * @param mode Indicates the data reporting mode to set. For details, see {@link SensorMode}.
125  * @return Returns <b>0</b> if the sensor data reporting mode is successfully set; returns a non-zero value otherwise.
126  *
127  * @since 5
128  */
129 int32_t SetMode(int32_t sensorTypeId, const SensorUser *user, int32_t mode);
130 
131 /**
132  * @brief 挂起一个进程订阅的所有传感器
133  *
134  * @param pid 将被挂起的进程的进程号
135  * @return 返回0表示成功,否则表示失败
136  *
137  * @since 10
138  */
139 int32_t SuspendSensors(int32_t pid);
140 
141 /**
142  * @brief 唤醒一个进程订阅的所有传感器
143  *
144  * @param pid 将被唤醒的进程的进程号
145  * @return 返回0表示成功,否则表示失败
146  *
147  * @since 10
148  */
149 int32_t ResumeSensors(int32_t pid);
150 
151 /**
152  * @brief 查询一个进程打开的所有传感器的信息
153  *
154  * @param pid 将被查询的进程的进程号
155  * @param sensorActiveInfos 返回进程打开的所有传感器信息
156  * @param count 返回进程打开的传感器数量
157  * @return 返回0表示成功,否则表示失败
158  *
159  * @since 10
160  */
161 int32_t GetActiveSensorInfos(int32_t pid, SensorActiveInfo **sensorActiveInfos, int32_t *count);
162 
163 /**
164  * @brief 订阅激活的传感器的信息
165  *
166  * @param callback 回调函数,返回激活的传感器的信息
167  * @return 返回0表示成功,否则表示失败
168  *
169  * @since 10
170  */
171 int32_t Register(SensorActiveInfoCB callback);
172 
173 /**
174  * @brief 取消订阅激活的传感器的信息
175  *
176  * @param callback 取消对此回调函数的订阅
177  * @return 返回0表示成功,否则表示失败
178  *
179  * @since 10
180  */
181 int32_t Unregister(SensorActiveInfoCB callback);
182 
183 /**
184  * @brief 重置休眠的所有传感器
185  *
186  * @return 返回0表示成功,否则表示失败
187  *
188  * @since 10
189  */
190 int32_t ResetSensors();
191 
192 #ifdef __cplusplus
193 #if __cplusplus
194 }
195 #endif
196 #endif
197 #endif /* SENSOR_AGENT_H */
198 /** @} */