2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __CONTEXT_DB_MANAGER_IMPL_H__
18 #define __CONTEXT_DB_MANAGER_IMPL_H__
24 #include <event_driven.h>
25 #include <db_listener_iface.h>
26 #include <db_mgr_iface.h>
30 class db_manager_impl : public event_driven_thread, public db_listener_iface, public db_manager_iface {
33 QTYPE_CREATE_TABLE = 1,
40 db_listener_iface* listener;
44 struct query_result_s {
48 db_listener_iface* listener;
49 std::vector<json>* result;
54 static bool is_main_thread();
56 void on_thread_event_popped(int type, void* data);
57 void delete_thread_event(int type, void* data);
62 void _execute(int query_type, unsigned int query_id, const char* query, db_listener_iface* listener);
63 void send_result(int query_type, unsigned int query_id, db_listener_iface* listener, int error, std::vector<json>* result);
65 static int execution_result_cb(void *user_data, int dim, char **value, char **column);
66 static gboolean _send_result(gpointer data);
68 void on_creation_result_received(unsigned int query_id, int error);
69 void on_insertion_result_received(unsigned int query_id, int error, int64_t row_id);
70 void on_query_result_received(unsigned int query_id, int error, std::vector<json>& records);
79 bool create_table(unsigned int query_id, const char* table_name, const char* columns, const char* option = NULL, db_listener_iface* listener = NULL);
80 bool insert(unsigned int query_id, const char* table_name, json& record, db_listener_iface* listener = NULL);
81 bool execute(unsigned int query_id, const char* query, db_listener_iface* listener);
82 bool insert_sync(const char* table_name, json& record, int64_t* row_id);
83 bool execute_sync(const char* query, std::vector<json>* records);
85 }; /* class db_manager */
88 #endif /* __CONTEXT_DB_MANAGER_IMPL_H__ */