Fix 'frequency' statistics for the trigger to emit proper results
[platform/core/context/statistics-context-provider.git] / src / shared / db_handle_base.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_STATS_DB_HANDLE_BASE_H__
18 #define __CONTEXT_STATS_DB_HANDLE_BASE_H__
19
20 #include <string>
21 #include <json.h>
22 #include <db_listener_iface.h>
23
24 namespace ctx {
25         class stats_db_handle_base : public db_listener_iface {
26                 protected:
27                         bool is_trigger_item;
28                         std::string req_subject;
29
30                         stats_db_handle_base(const char* zone);
31                         ~stats_db_handle_base();
32
33                         std::string create_where_clause(ctx::json filter);
34                         std::string create_sql_peak_time(ctx::json filter, const char* table_name, std::string where_clause);
35                         std::string create_sql_common_setting(ctx::json filter, const char* table_name, std::string where_clause);
36
37                         bool execute_query(const char* subject, ctx::json filter, const char* query);
38                         static int generate_qid();
39
40                 private:
41                         std::string req_zone;
42                         ctx::json req_filter;
43
44                         void json_vector_to_array(std::vector<json> &vec_json, ctx::json &json_result);
45
46                         void on_creation_result_received(unsigned int query_id, int error);
47                         void on_insertion_result_received(unsigned int query_id, int error, int64_t row_id);
48                         void on_query_result_received(unsigned int query_id, int error, std::vector<json>& records);
49         };
50 }
51
52 #endif /* __CONTEXT_STATS_DB_HANDLE_BASE_H__ */