0eab066b12838c0d0bd5cf47f03e01a37fe5668b
[platform/core/context/context-provider.git] / src / app-stats / app_inactive_detector / InactiveDetectorStorage.h
1 /*
2  * Copyright (c) 2015 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_INACTIVE_DETECTOR_STORAGE_H__
18 #define __CONTEXT_INACTIVE_DETECTOR_STORAGE_H__
19
20 #include <vector>
21 #include "AppInactiveDetectorTypes.h"
22 #include <Json.h>
23 #include <DatabaseManager.h>
24
25 namespace ctx {
26
27         class inactive_detector_storage : public IDatabaseListener
28         {
29                 private:
30                         //int type;  //TODO: enum
31                         void inject_params(std::string& str,
32                                 const std::string& from,
33                                 const std::string& to);
34
35                         void json_to_object(std::vector<Json>& records,
36                                 std::vector<app_t> *apps_with_weights, bool result_mode);
37
38                         std::string query_get_apps(const char *subject,
39                                 ctx::Json filter);
40
41                         std::string query_update_apps(std::vector<app_t> *apps_with_weights);
42
43                         std::string subquery_form_values(std::vector<app_t> *apps_with_weights);
44
45                         void onTableCreated(unsigned int query_id, int error) {}
46                         void onInserted(unsigned int query_id, int error, int64_t row_id) {}
47                         void onExecuted(unsigned int query_id, int error, std::vector<Json>& records);
48
49                         DatabaseManager __dbManager;
50
51                 public:
52                         inactive_detector_storage();
53                         ~inactive_detector_storage();
54
55                         int read(const char *subject,
56                                 ctx::Json filter);
57
58                         int update_ranks();
59                         int get_apps_info_w_weights(double timestamp_from);
60         };      /* class inactive_detector_storage */
61
62 }       /* namespace ctx */
63
64 #endif /* __CONTEXT_INACTIVE_DETECTOR_STORAGE_H__ */