tizen 2.3 release
[framework/system/deviced.git] / src / logd / src / liblogd-db / padvisor.h
1 /*
2  * logd
3  *
4  * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 /**
19  * @file padvisor.h
20  *
21  * @desc Contains API that can help to manage devices/processec for.decrease
22  * power consumption.
23  */
24
25 #ifndef _LOGD_PADVISER_H_
26 #define _LOGD_PADVISER_H_
27
28 #include <stdint.h>
29 #include <time.h>
30 #include <unistd.h>
31
32 #include "logd-db.h"
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 enum { LOGD_ADVISOR_MAX = 32 };
39
40 struct logd_idle_device {
41         uint64_t idle_time; /** Time when device was swithed on */
42         enum logd_object device; /** Device identifier */
43 };
44
45 struct logd_power_advisor {
46         /** Array of enabled devices */
47         struct logd_idle_device idle_devices[LOGD_ADVISOR_MAX];
48         /** Top <CODE>LOGD_ADVISOR_MAX</CODE> most power cunsuming application */
49         struct logd_proc_stat procs[LOGD_ADVISOR_MAX];
50         /** Count of devices in <CODE>idle_devices</CODE> */
51         int idle_devices_used_num;
52         /** Count of processes in <CODE>procs</CODE> */
53         int proc_stat_used_num;
54 };
55
56 struct logd_power_consumption {
57         enum logd_object device; /** Device identifier */
58         /** Persentage from all devices power consumption */
59         float percentage;
60         /** Time in sec when device was enabled */
61         int time;
62 };
63
64 struct device_power_consumption {
65         /** Array of all devices with theirs power consumption */
66         struct logd_power_consumption device_cons[LOGD_OBJECT_MAX];
67         /** Sum of all logd_power_consumption::time from device_cons in sec */
68         int total_time;
69 };
70
71 /* please, not use that function in your application, it isn't public API */
72 int padvisor_init(void);
73 int padvisor_finalize(void);
74
75 /* next functions are public API */
76
77 /**
78  * Return information about devices and processes.
79  *
80  * @return On success, pointer to <CODE>logd_power_advisor</CODE> struct.
81  * Returned pointer must be released by <CODE>logd_free_power_advisor</CODE>.
82  * On error, NULL.
83  */
84 struct logd_power_advisor *logd_get_power_advisor(void);
85 /**
86  * Release <CODE>logd_power_advisor</CODE> struct returned by
87  * <CODE>logd_get_power_advisor</CODE>.
88  * @param lpa pointer that must be free.
89  */
90 void logd_free_power_advisor(struct logd_power_advisor *lpa);
91
92 /**
93  * Return information about devices power consumption for given period.
94  *
95  * @param from Count power consumption from that time in unixtime format.
96  * @param to Count power consumption till that time in unixtime format.
97  * @return On success, pointer to <CODE>device_power_consumption</CODE> struct.
98  * Returned pointer must be released by <CODE>logd_free_device_power_cons</CODE>.
99  * On error, NULL.
100  */
101 struct device_power_consumption *
102 logd_get_device_power_cons(time_t from, time_t to);
103 /**
104  * Release <CODE>device_power_consumption</CODE> struct returned by
105  * <CODE>logd_get_device_power_cons</CODE>.
106  * @param pcons pointer that must be free.
107  */
108 void logd_free_device_power_cons(struct device_power_consumption* pcons);
109
110
111 #ifdef __cplusplus
112 }
113 #endif
114
115 #endif /* _LOGD_PADVISER_H_ */