Adding head node for proper Plugin Parsing
[platform/core/system/batterymonitor-plugins.git] / plugin / cpu / include / bm_plugin_interface.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 __BM_PLUGIN_INTERFACE_H__
19 #define __BM_PLUGIN_INTERFACE_H__
20
21 #include <stdio.h>
22 #include <gmodule.h>
23 #include <time.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 typedef unsigned int    uint;
30 typedef unsigned char   uchar;
31
32 #define BM_DATA_TYPE_MAX (BM_DATA_TYPE_BATTERY + 1)
33 #define BM_PLUGIN_ID_MAX (BM_PLUGIN_ID_BATTERY + 1)
34 #define BM_DURATION_TYPE_MAX (BM_DURATION_TYPE_1WEEK + 1)
35
36 typedef enum {
37         BM_PLUGIN_ERROR_NONE = TIZEN_ERROR_NONE,                                /**< Successful */
38         BM_PLUGIN_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA,                          /**< No data */
39         BM_PLUGIN_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,      /**< Invalid parameter */
40         BM_PLUGIN_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY,              /**< Out of memory */
41         BM_PLUGIN_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED,              /**< Not supported */
42         BM_PLUGIN_ERROR_SERVICE_UNAVAILABLE = TIZEN_ERROR_UNKNOWN - 1           /**< Service unavailable */
43 } bm_plugin_error_e;
44
45 /*
46  * enum for plugin identifier
47  */
48 typedef enum {
49         BM_PLUGIN_ID_BLE=0,             /**< Bluetooth Low Energy */
50         BM_PLUGIN_ID_WIFI,              /**< Wi-Fi */
51         BM_PLUGIN_ID_CPU,               /**< CPU */
52         BM_PLUGIN_ID_DISPLAY,           /**< Display */
53         BM_PLUGIN_ID_DEVICE_NETWORK,    /**< Network */
54         BM_PLUGIN_ID_GPS_SENSOR,        /**< GPS */
55         BM_PLUGIN_ID_HRM_SENSOR,        /**< Heart Rate Monitor */
56         BM_PLUGIN_ID_BATTERY            /**< Battery */
57 } bm_plugin_id_e;
58
59 /*
60  * enum for feature data collection period
61  */
62 typedef enum {
63         BM_DURATION_TYPE_1DAY = 0,      /**< Set the period from a day ago to now */
64         BM_DURATION_TYPE_1WEEK          /**< Set the period from a week ago to now */
65 } bm_duration_type_e;
66
67 /*
68  * enum for feature data type
69  */
70 typedef enum {
71         BM_DATA_TYPE_BLE=0,             /**< Bluetooth Low Energy */
72         BM_DATA_TYPE_WIFI,              /**< Wi-Fi */
73         BM_DATA_TYPE_CPU,               /**< CPU */
74         BM_DATA_TYPE_DISPLAY,           /**< Display */
75         BM_DATA_TYPE_DEVICE_NETWORK,    /**< Network */
76         BM_DATA_TYPE_GPS_SENSOR,        /**< GPS */
77         BM_DATA_TYPE_HRM_SENSOR,        /**< Heart Rate Monitor */
78         BM_DATA_TYPE_BATTERY            /**< Battery */
79 } bm_plugin_data_type_e;
80
81 /*
82  * common structure for application time map.
83  */
84 typedef struct {
85         char *app_id;           /**< application id */
86         uint time;              /**< total duration for which application as active */
87 } app_time_map_st1;
88
89 typedef struct {
90         char *app_id;           /**< application id */
91         uint time;              /**< total duration for which application as active */
92         uint rx;                /**< Total Bytes received by the application during runtime */
93         uint tx;                /**< Total Bytes transmitted by the application during runtime */
94 } app_time_map_st2;
95
96 /*
97  * structure for "display" feature data.
98  */
99 typedef struct {
100         uint high;                      /**< total time in milliseconds during which brightness intensity was high */
101         uint low;                       /**< total time in milliseconds during which brightness intensity was low */
102         uint med;                       /**< total time in milliseconds during which brightness intensity was medium */
103         time_t start;                   /**< start time of feature data collection session */
104         time_t stop;                    /**< stop time of feature data collection session */
105         GSList *atm_list;               /**< application time map('app_time_map_st1') list for all active applications between start & stop */
106         GSList *display_list;           /**< list of nodes of 'bm_display_st' for next consecutive sessions */
107 } bm_display_st;
108
109 /*
110  * structure for "cpu" feature data.
111  */
112 typedef struct {
113         uint cpuTicks;                  /**< CPU Usage during the session */
114         uint cpuTimeBackground;         /**< Time spent in Background State average operating frequency will be used to calculate the power */
115         uint cpuTimeForeground;         /**< Time spent in Foreground state average operating frequency will be used to calculate the power */
116         GSList *atm_list;               /**< application time map('app_time_map_st1') list for all active applications between start & stop */
117         GSList *cpu_data_list;          /**< list of nodes of 'bm_cpu_st' for next consecutive sessions */
118 } bm_cpu_st;
119
120 /*
121  * structure for "device_network" feature data.
122  */
123 typedef struct {
124         uint time_level_0;              /**< Total time in milliseconds during which signal_strength was on level 0 */
125         uint time_level_1;              /**< Total time in milliseconds during which signal_strength was on level 1 */
126         uint time_level_2;              /**< Total time in milliseconds during which signal_strength was on level 2 */
127         uint time_level_3;              /**< Total time in milliseconds during which signal_strength was on level 3 */
128         uint time_level_4;              /**< Total time in milliseconds during which signal_strength was on level 4 */
129         uint time_level_5;              /**< Total time in milliseconds during which signal_strength was on level 5 */
130         uint time_level_6;              /**< Total time in milliseconds during which signal_strength was on level 6 */
131         GSList *atm_list;               /**< application time map('app_time_map_st2') list for all active applications between start & stop */
132         GSList *dn_data_list;           /**< list of nodes of 'bm_device_network_st' for next consecutive sessions */
133 } bm_device_network_st;
134
135 /*
136  * structure for "Wi-Fi" feature data.
137  */
138 typedef struct {
139         uint time_level_0;              /**< Total time in milliseconds during which rssi was on level 0 */
140         uint time_level_1;              /**< Total time in milliseconds during which rssi was on level 1 */
141         uint time_level_2;              /**< Total time in milliseconds during which rssi was on level 2 */
142         uint time_level_3;              /**< Total time in milliseconds during which rssi was on level 3 */
143         uint time_level_4;              /**< Total time in milliseconds during which rssi was on level 4 */
144         time_t startTime;               /**< start time of feature data collection session */
145         time_t endTime;                 /**< end time of feature data collection session */
146         uint scanTime;                  /**< Total time spent by the resource in (scan) mode during the session */
147         GSList *atm_list;               /**< application time map('app_time_map_st2') list for all active applications between start & stop */
148         GSList *wifi_data_list;         /**< list of nodes of 'bm_wifi_st' for next consecutive sessions */
149 } bm_wifi_st;
150
151 /*
152  * structure for "bluetooth" feature data.
153  */
154 typedef struct {
155         uint scanTime;                  /**< Total time spent by the resource in (scan) mode during the session */
156         uint connectedTime;             /**< Total time spent by the resource in (connected) mode during the session */
157         time_t startTime;               /**< start time of feature data collection session */
158         time_t stopTime;                /**< stop time of feature data collection session */
159         GSList *atm_list;               /**< application time map('app_time_map_st2') list for all active applications between start & stop */
160         GSList *bt_data_list;           /**< list of nodes of 'bm_bluetooth_st' for next consecutive sessions */
161 } bm_bluetooth_st;
162
163 /*
164  * structure for "gps" feature data.
165  */
166 typedef struct {
167         time_t connStartTime;           /**< start time of feature data collection session */
168         time_t connStopTime;            /**< stop time of feature data collection session */
169         GSList *atm_list;               /**< application time map('app_time_map_st1') list for all active applications between start & stop */
170         GSList *gps_data_list;          /**< list of nodes of 'bm_gps_st' for next consecutive sessions */
171 } bm_gps_st;
172
173 /*
174  * structure for "hrm-sensor" feature data.
175  */
176 typedef struct {
177         uint sensor_hub_wakeup_time;    /**< wake-up time of sensor-hub */
178         uint sensor_hub_wakeup_count;   /**< wake-up count of sensor-hub */
179         uint sensor_wakeup_time;        /**< sensor wake-up time */
180         uint sensor_wakeup_count;       /**< sensor wake-up count */
181         GSList *atm_list;               /**< application time map('app_time_map_st1') list for all active applications between start & stop */
182         GSList *hrm_data_list;          /**< list of nodes of 'bm_hrm_sensor_st' for next consecutive sessions */
183 } bm_hrm_sensor_st;
184
185 /*
186  * structure for "battery" feature data.
187  */
188 typedef struct {
189         uint battery_percent;           /**< Battery percent */
190         uint is_charging;               /**< State of charging */
191 } bm_battery_st;
192
193 /* ========================================================================== */
194
195 /*
196  * battery-monitor data handle
197  */
198 typedef void *bm_data_h;
199
200 /*
201  * Callback to be invoked when service is going OFF
202  *
203  * [Param] handle - handle through which service will provide data
204  *         to battery-monitor service daemon.
205  *
206  * [Param] result - the result of callback operation
207  */
208 typedef void (*bm_data_callback)(bm_plugin_error_e result, bm_data_h *handle);
209
210 /*
211  * battery-monitor callback structure
212  */
213 typedef struct {
214         bm_data_callback provide_feature_data;
215 } bm_callbacks_st;
216
217 /*
218  * structure for plugin API's
219  */
220 typedef struct {
221         /*
222         * [Sync API] To initialize plugin
223         */
224         int (*init)(const bm_callbacks_st *callbacks);
225         /*
226         * [Sync API] To deinitialize plugin
227         */
228         int (*deinit)(void);
229         /*
230         * [Sync API] To get feature data from plugin
231         *
232         * [Param] handle - battery-monitor data handle through which plugin
233         *       will provide data to the manager. This handle will be passed
234         *       as reference, plugin will assign a valid object which will be
235         *       set free by the manager; battery-monitor manager will typecast
236         *       the object provided through handle for each plugin and will use
237         *       it for further calculation.
238         *
239         * [Param] data_type - type of data like - BLE, WiFi, CPU etc.
240         */
241         int (*get_feature_data)(bm_data_h *handle, bm_plugin_data_type_e data_type);
242 } bm_api_st;
243
244 /*
245  * structure for plugin information
246  */
247 typedef struct {
248         /*
249         * Respective "identifier" of Plugin
250         */
251         int id;
252         /*
253         * Respective "name" of Plugin
254         */
255         const char *name;
256         /*
257         * Respective "author" of Plugin
258         */
259         const char *author;
260         /*
261         * Respective "version" of Plugin
262         */
263         const char *version;
264         /*
265         * Plugin init function
266         */
267         int (*init)(bm_api_st **api);
268         /*
269         * Plugin de-init function
270         */
271         int (*deinit)(void);
272 } bm_plugin_st;
273
274
275 /*
276  *  macro for adding plugin
277  */
278 #define BM_PLUGIN_ADD(id, name, author, version, init, deinit) \
279                 __attribute__ ((visibility("default"))) bm_plugin_st bm_plugin = { id, name, author, version, init, deinit };
280
281
282 #ifdef __cplusplus
283 }
284 #endif
285
286 #endif /* __BM_PLUGIN_INTERFACE_H__ */