169d56e742c3e546f47093b194867c437a502169
[platform/core/api/batterymonitor.git] / include / battery_monitor.h
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #ifndef __TIZEN_SYSTEM_BATTERY_MONITOR_H__
19 #define __TIZEN_SYSTEM_BATTERY_MONITOR_H__
20
21 #include <tizen.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /**
28  * @addtogroup  CAPI_SYSTEM_BATTERY_BATTERY_MONITOR_MODULE
29  * @{
30  */
31
32 // TODO : this macro will be moved to the tizen_error.h
33 #ifndef TIZEN_ERROR_BATTERY_MONITOR
34 #define TIZEN_ERROR_BATTERY_MONITOR     -0x03060000
35 #endif
36
37 /**
38  * @brief        Enumeration for error codes for battery monitor.
39  * @since_tizen  5.5
40  */
41 typedef enum {
42         BATTERY_MONITOR_ERROR_NONE = TIZEN_ERROR_NONE,                                  /**< Successful */
43         BATTERY_MONITOR_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY,                /**< Out of memory */
44         BATTERY_MONITOR_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,        /**< Invalid parameter */
45         BATTERY_MONITOR_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA,                            /**< Empty data */
46         BATTERY_MONITOR_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED,        /**< Permission denied */
47         BATTERY_MONITOR_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED,                /**< Not supported */
48         BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND = TIZEN_ERROR_BATTERY_MONITOR | 0x01,    /**< Related record does not exist */
49         BATTERY_MONITOR_ERROR_DB_FAILED = TIZEN_ERROR_BATTERY_MONITOR | 0x02,           /**< DB operation failed */
50         BATTERY_MONITOR_ERROR_DB_NOT_OPENED = TIZEN_ERROR_BATTERY_MONITOR | 0x03,       /**< DB is not connected */
51         BATTERY_MONITOR_ERROR_INTERNAL = TIZEN_ERROR_BATTERY_MONITOR | 0x04             /**< Internal error for generic use */
52 } battery_monitor_error_e;
53
54 /**
55  * @brief        Enumeration for feature data type.
56  * @since_tizen  5.5
57  */
58 typedef enum {
59         BATTERY_MONITOR_RESOURCE_ID_BLE = 0,            /**< Bluetooth Low Energy */
60         BATTERY_MONITOR_RESOURCE_ID_WIFI,               /**< Wi-Fi */
61         BATTERY_MONITOR_RESOURCE_ID_CPU,                /**< CPU */
62         BATTERY_MONITOR_RESOURCE_ID_DISPLAY,            /**< Display */
63         BATTERY_MONITOR_RESOURCE_ID_DEVICE_NETWORK,     /**< Network */
64         BATTERY_MONITOR_RESOURCE_ID_GPS_SENSOR,         /**< GPS */
65         BATTERY_MONITOR_RESOURCE_ID_HRM_SENSOR,         /**< Heart Rate Monitor */
66         BATTERY_MONITOR_RESOURCE_ID_BATTERY,            /**< Battery */
67 } battery_monitor_resource_id_e;
68
69 /**
70  * @brief        Enumeration for feature data collection period.
71  * @since_tizen  5.5
72  */
73 typedef enum {
74         BATTERY_MONITOR_DURATION_TYPE_1DAY = 0,  /**< Set the period from a day ago to now */
75         BATTERY_MONITOR_DURATION_TYPE_1WEEK,     /**< Set the period from a week ago to now */
76 } battery_monitor_duration_type_e;
77
78 /**
79  * @brief        Handle for total battery consumption structure.
80  * @since_tizen  5.5
81  */
82 typedef struct battery_monitor_total_consumption_s* battery_monitor_h;
83
84 /**
85  * @brief  Creates a handle to the Battery Consumption for getting resource based usage.
86  * @since_tizen  5.5
87  *
88  * @remarks  @a handle should be released using battery_monitor_destroy().
89  *
90  * @param[in] handle  Battery usage consumption handle reference for the app-id usage
91  *
92  * @return  @c 0 on success,
93  *          otherwise a negative error value
94  * @retval #BATTERY_MONITOR_ERROR_NONE                  Successful
95  * @retval #BATTERY_MONITOR_ERROR_NOT_SUPPORTED         Feature Not Supported
96  * @retval #BATTERY_MONITOR_ERROR_INVALID_PARAMETER     Invalid Parameter
97  * @retval #BATTERY_MONITOR_ERROR_OUT_OF_MEMORY         Out of Memory
98  */
99 int battery_monitor_create(battery_monitor_h *handle);
100
101 /**
102  * @brief  Destroys the Battery Consumption handle and releases all its resources.
103  * @since_tizen  5.5
104  *
105  * @param[in] handle  Battery usage consumption handle for the app-id
106  *
107  * @return  @c 0 on success,
108  *          otherwise a negative error value
109  * @retval #BATTERY_MONITOR_ERROR_NONE                  Successful
110  * @retval #BATTERY_MONITOR_ERROR_NOT_SUPPORTED         Feature Not Supported
111  * @retval #BATTERY_MONITOR_ERROR_INVALID_PARAMETER     Invalid Parameter
112  */
113 int battery_monitor_destroy(battery_monitor_h handle);
114
115 /**
116  * @brief  Gets the battery-percent for specific resource from available data.
117  * @since_tizen  5.5
118  * @privlevel  public
119  * @privilege  %http://tizen.org/privilege/battery.monitor
120  *
121  * @param[in] handle  Battery usage consumption handle for the app-id
122  * @param[in] resource_id  Identifier of resource type . BLE, WiFi, CPU etc
123  * @param[out] battery_usage  Battery usage consumption for resource_id
124  *
125  * @return  @c 0 on success,
126  *          otherwise a negative error value
127  * @retval #BATTERY_MONITOR_ERROR_NONE                  Successful
128  * @retval #BATTERY_MONITOR_ERROR_NOT_SUPPORTED         Feature Not Supported
129  * @retval #BATTERY_MONITOR_ERROR_PERMISSION_DENIED     Permission Denied
130  * @retval #BATTERY_MONITOR_ERROR_INVALID_PARAMETER     Invalid Parameter
131  */
132 int battery_monitor_get_usage_for_resource_id(battery_monitor_h handle, battery_monitor_resource_id_e resource_id, int *battery_usage);
133
134 /**
135  * @brief  Gets the battery-percent for all resources used by app_id.
136  * @since_tizen  5.5
137  * @privlevel  public
138  * @privilege  %http://tizen.org/privilege/battery.monitor
139  *
140  * @remarks  The @a handle should be released using battery_monitor_destroy().
141  *
142  * @param[in] app_id  App-id for which battery usage is required
143  * @param[in] duration  Time duration for which battery usage is requested
144  * @param[out] handle  Battery usage consumption for the app-id
145  *
146  * @return  @c 0 on success,
147  *          otherwise a negative error value
148  * @retval #BATTERY_MONITOR_ERROR_NONE                  Successful
149  * @retval #BATTERY_MONITOR_ERROR_NOT_SUPPORTED         Feature Not Supported
150  * @retval #BATTERY_MONITOR_ERROR_PERMISSION_DENIED     Permission Denied
151  * @retval #BATTERY_MONITOR_ERROR_INVALID_PARAMETER     Invalid Parameter
152  * @retval #BATTERY_MONITOR_ERROR_DB_NOT_OPENED         DB not Opened
153  * @retval #BATTERY_MONITOR_ERROR_DB_FAILED             DB operation failed
154  * @retval #BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND      Record Not found
155  * @retval #BATTERY_MONITOR_ERROR_INTERNAL              Internal Error
156  *
157  * @see battery_monitor_get_usage_for_resource_id()
158  */
159 int battery_monitor_get_usage_by_app_id_for_all_resource_id(char *app_id, battery_monitor_duration_type_e duration, battery_monitor_h *handle);
160
161 /**
162  * @brief  Gets the battery-percent by an app-id for a specific resource.
163  * @since_tizen  5.5
164  * @privlevel  public
165  * @privilege  %http://tizen.org/privilege/battery.monitor
166  *
167  * @param[in] app_id  App-id for which battery usage is required
168  * @param[in] resource_id  Identifier of resource type . BLE, WiFi, CPU etc
169  * @param[in] duration  Time duration for which battery usage is requested
170  * @param[out] battery_usage  Battery usage consumption for the app-id
171  *
172  * @return  @c 0 on success,
173  *          otherwise a negative error value
174  * @retval #BATTERY_MONITOR_ERROR_NONE                  Successful
175  * @retval #BATTERY_MONITOR_ERROR_NOT_SUPPORTED         Feature Not Supported
176  * @retval #BATTERY_MONITOR_ERROR_PERMISSION_DENIED     Permission Denied
177  * @retval #BATTERY_MONITOR_ERROR_INVALID_PARAMETER     Invalid Parameter
178  * @retval #BATTERY_MONITOR_ERROR_DB_NOT_OPENED         DB not Opened
179  * @retval #BATTERY_MONITOR_ERROR_DB_FAILED             DB operation failed
180  * @retval #BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND      Record Not found
181  * @retval #BATTERY_MONITOR_ERROR_INTERNAL              Internal Error
182  */
183 int battery_monitor_get_usage_by_app_id_for_resource_id(char *app_id, battery_monitor_resource_id_e resource_id, battery_monitor_duration_type_e duration, int *battery_usage);
184
185 /**
186  * @brief  Gets the total battery usage in percent by an app-id for certain time duration.
187  * @details  This will be sum of all battery consumed by resources used by application.
188  * @since_tizen  5.5
189  * @privlevel  public
190  * @privilege  %http://tizen.org/privilege/battery.monitor
191  *
192  * @param[in] app_id  App-id for which battery usage is required
193  * @param[in] duration  Time duration for which battery usage is requested
194  * @param[out] battery_usage  Battery usage consumption for the app-id
195  *
196  * @return  @c 0 on success,
197  *          otherwise a negative error value
198  * @retval #BATTERY_MONITOR_ERROR_NONE                  Successful
199  * @retval #BATTERY_MONITOR_ERROR_NOT_SUPPORTED         Feature Not Supported
200  * @retval #BATTERY_MONITOR_ERROR_PERMISSION_DENIED     Permission Denied
201  * @retval #BATTERY_MONITOR_ERROR_INVALID_PARAMETER     Invalid Parameter
202  * @retval #BATTERY_MONITOR_ERROR_DB_NOT_OPENED         DB not Opened
203  * @retval #BATTERY_MONITOR_ERROR_DB_FAILED             DB operation failed
204  * @retval #BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND      Record Not found
205  * @retval #BATTERY_MONITOR_ERROR_INTERNAL              Internal Error
206 */
207 int battery_monitor_get_total_usage_by_app_id(char *app_id, battery_monitor_duration_type_e duration, int *battery_usage);
208
209 /**
210  * @brief  Gets the battery-percent usage by a resource for certain time duration.
211  * @since_tizen  5.5
212  * @privlevel  public
213  * @privilege  %http://tizen.org/privilege/battery.monitor
214  *
215  * @param[in] resource_id  Resource identifier for which battery usage is requested
216  * @param[in] duration  Time duration for which battery usage is requested
217  * @param[out] battery_usage  Battery usage consumption for resource-id
218  *
219  * @return  @c 0 on success,
220  *          otherwise a negative error value
221  * @retval #BATTERY_MONITOR_ERROR_NONE                  Successful
222  * @retval #BATTERY_MONITOR_ERROR_NOT_SUPPORTED         Feature Not Supported
223  * @retval #BATTERY_MONITOR_ERROR_PERMISSION_DENIED     Permission Denied
224  * @retval #BATTERY_MONITOR_ERROR_INVALID_PARAMETER     Invalid Parameter
225  * @retval #BATTERY_MONITOR_ERROR_DB_NOT_OPENED         DB not Opened
226  * @retval #BATTERY_MONITOR_ERROR_DB_FAILED             DB operation failed
227  * @retval #BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND      Record Not found
228  * @retval #BATTERY_MONITOR_ERROR_INTERNAL              Internal Error
229 */
230 int battery_monitor_get_total_usage_by_resource_id(battery_monitor_resource_id_e resource_id, battery_monitor_duration_type_e duration, int *battery_usage);
231
232 /**
233  * @}
234  */
235
236 #ifdef __cplusplus
237 }
238 #endif
239
240 #endif /* __TIZEN_SYSTEM_BATTERY_MONITOR_H__ */