255879c6eb707606f8132607a769ac7b40656818
[platform/core/context/app-history.git] / src / server / battery-stats / HeartDbReader.h
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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 #ifndef __CONTEXT_HEART_DB_READER_H__
18 #define __CONTEXT_HEART_DB_READER_H__
19
20 #include <vector>
21 #include <glib.h>
22 #include <gio/gio.h>
23 #include <sqlite3.h>
24
25 namespace ctx {
26
27         class HeartDbReader {
28         public:
29                 HeartDbReader(uid_t uid);
30                 ~HeartDbReader();
31
32                 bool dbOpen();
33                 void dbClose();
34                 bool readCpuLog(int __lastHeartAccessTime, std::vector<CtxJson>* cpuUsageLog);
35                 bool requestSync();
36
37         private:
38                 static int __cpuUsageLogCb(void *userData, int dim, char **value, char **column);
39                 static void __convertCpuUsageLog(CtxJson& row, CtxJson* newRow);
40
41                 bool __initializeDBusConnection();
42                 void __releaseDBusConnection();
43
44                 sqlite3 *__heartDb;
45                 GDBusConnection *__connection;
46                 int __dbRefCount;
47                 uid_t __uid;
48         };
49
50 }       /* namespace ctx */
51
52 #endif  /* __CONTEXT_HEART_DB_READER_H__ */