# Dependencies
SET(DEPS
- libtzplatform-config
vconf
- sqlite3
capi-system-info
capi-appfw-app-manager
appsvc
BuildRequires: cmake
BuildRequires: sed
-BuildRequires: pkgconfig(libtzplatform-config)
BuildRequires: pkgconfig(vconf)
-BuildRequires: pkgconfig(sqlite3)
BuildRequires: pkgconfig(capi-system-info)
BuildRequires: pkgconfig(capi-appfw-app-manager)
BuildRequires: pkgconfig(appsvc)
#include <types_internal.h>
#include "DBusServer.h"
-#include "db_mgr_impl.h"
#include "ContextManagerImpl.h"
#include "trigger/Trigger.h"
#include "Server.h"
static bool started = false;
static ctx::ContextManagerImpl *__contextMgr = NULL;
-static ctx::db_manager_impl *__databaseMgr = NULL;
static ctx::DBusServer *__dbusHandle = NULL;
static ctx::trigger::Trigger *__contextTrigger = NULL;
bool result = false;
- _I("Init Database Manager");
- __databaseMgr = new(std::nothrow) ctx::db_manager_impl();
- IF_FAIL_CATCH_TAG(__databaseMgr, _E, "Memory allocation failed");
- db_manager::set_instance(__databaseMgr);
- result = __databaseMgr->init();
- IF_FAIL_CATCH_TAG(result, _E, "Initialization Failed");
-
_I("Init Context Manager");
__contextMgr = new(std::nothrow) ctx::ContextManagerImpl();
IF_FAIL_CATCH_TAG(__contextMgr, _E, "Memory allocation failed");
if (__dbusHandle)
__dbusHandle->__release();
- _I("Close the Database");
- if (__databaseMgr)
- __databaseMgr->release();
-
g_main_loop_unref(mainloop);
delete __contextTrigger;
delete __contextMgr;
delete __dbusHandle;
- delete __databaseMgr;
}
static gboolean __postponeRequestAssignment(gpointer data)
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <sys/types.h>
-#include <unistd.h>
-#include <string>
-#include <sstream>
-#include <list>
-#include <tzplatform_config.h>
-#include <ScopeMutex.h>
-#include "Server.h"
-#include "db_mgr_impl.h"
-
-#define CONTEXT_DB_PATH tzplatform_mkpath(TZ_USER_DB, ".context-service.db")
-
-static bool initialized = false;
-static GMutex exec_mutex;
-
-ctx::db_manager_impl::db_manager_impl()
- : db_handle(NULL)
-{
-}
-
-ctx::db_manager_impl::~db_manager_impl()
-{
- release();
-}
-
-bool ctx::db_manager_impl::init()
-{
- IF_FAIL_RETURN_TAG(!initialized, true, _W, "Re-initialization");
- IF_FAIL_RETURN(open(), false);
- IF_FAIL_RETURN(start(), false);
- initialized = true;
- return true;
-}
-
-void ctx::db_manager_impl::release()
-{
- IF_FAIL_VOID(initialized);
- initialized = false;
- stop();
- close();
-}
-
-bool ctx::db_manager_impl::open()
-{
- sqlite3 *db = NULL;
- char *err = NULL;
- int ret;
-
- ret = sqlite3_open(CONTEXT_DB_PATH, &db);
- IF_FAIL_RETURN_TAG(ret == SQLITE_OK, false, _E, "Path: %s / Error: %s", CONTEXT_DB_PATH, sqlite3_errmsg(db));
-
- ret = sqlite3_exec(db, "PRAGMA journal_mode = WAL", NULL, NULL, &err);
- if (ret != SQLITE_OK) {
- _E("Setting journal mode failed: %s", err);
- sqlite3_free(err);
- }
-
- db_handle = db;
- return true;
-}
-
-void ctx::db_manager_impl::close()
-{
- if (db_handle) {
- sqlite3_close(db_handle);
- }
- db_handle = NULL;
-}
-
-void ctx::db_manager_impl::onEvent(int type, void* data)
-{
- IF_FAIL_VOID(data);
- query_info_s *info = static_cast<query_info_s*>(data);
-
- switch (type) {
- case QTYPE_CREATE_TABLE:
- case QTYPE_INSERT:
- case QTYPE_EXECUTE:
- _execute(type, info->id, info->query.c_str(), info->listener);
- break;
- default:
- _W("Unknown type: %d", type);
- break;
- }
-
- deleteEvent(type, data);
-}
-
-void ctx::db_manager_impl::deleteEvent(int type, void* data)
-{
- IF_FAIL_VOID(data);
- query_info_s *info = static_cast<query_info_s*>(data);
- delete info;
-}
-
-std::string ctx::db_manager_impl::compose_create_query(const char* table_name, const char* columns, const char* option)
-{
- std::string query;
- query = "CREATE TABLE IF NOT EXISTS ";
- query = query + table_name + " (row_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT," + columns + ")";
- if (option) {
- query = query + " " + option;
- }
- query += ";";
- return query;
-}
-
-bool ctx::db_manager_impl::create_table(unsigned int query_id, const char* table_name, const char* columns, const char* option, db_listener_iface* listener)
-{
- IF_FAIL_RETURN_TAG(initialized, false, _E, "Not initialized");
-
- query_info_s *info = new(std::nothrow) query_info_s;
- IF_FAIL_RETURN_TAG(info, false, _E, "Memory allocation failed");
-
- info->query = compose_create_query(table_name, columns, option);
- info->id = query_id;
- info->listener = listener;
-
- if (!pushEvent(QTYPE_CREATE_TABLE, info)) {
- _E("Pushing thread event failed");
- delete info;
- return false;
- }
-
- return true;
-}
-
-std::string ctx::db_manager_impl::compose_insert_query(const char* table_name, Json& record)
-{
- std::list<std::string> keys;
- IF_FAIL_RETURN_TAG(record.getKeys(&keys), "", _E, "Invalid record");
-
- std::ostringstream colstream;
- std::ostringstream valstream;
-
- for (std::list<std::string>::iterator it = keys.begin(); it != keys.end(); ++it) {
- std::string s;
- int64_t i;
- if (record.get(NULL, (*it).c_str(), &s)) {
- colstream << *it << ",";
-
- char* buf = sqlite3_mprintf("%Q", s.c_str());
- IF_FAIL_RETURN_TAG(buf, "", _E, "Memory allocation failed");
- valstream << buf << ",";
- sqlite3_free(buf);
- } else if (record.get(NULL, (*it).c_str(), &i)) {
- colstream << *it << ",";
- valstream << i << ",";
- }
- }
-
- std::string cols = colstream.str();
- std::string vals = valstream.str();
-
- IF_FAIL_RETURN_TAG(!cols.empty(), "", _E, "Invalid record");
-
- cols.erase(cols.size() - 1);
- vals.erase(vals.size() - 1);
-
- std::string query = "INSERT INTO ";
- query = query + table_name + " (" + cols + ") VALUES (" + vals + ");";
- query = query + "SELECT seq FROM sqlite_sequence WHERE name='" + table_name + "';";
-
- return query;
-}
-
-bool ctx::db_manager_impl::insert(unsigned int query_id, const char* table_name, Json& record, db_listener_iface* listener)
-{
- IF_FAIL_RETURN_TAG(initialized, false, _E, "Not initialized");
-
- std::string query = compose_insert_query(table_name, record);
- IF_FAIL_RETURN(!query.empty(), false);
-
- query_info_s *info = new(std::nothrow) query_info_s;
- IF_FAIL_RETURN_TAG(info, false, _E, "Memory allocation failed");
-
- info->query = query;
- info->id = query_id;
- info->listener = listener;
-
- if (!pushEvent(QTYPE_INSERT, info)) {
- _E("Pushing thread event failed");
- delete info;
- return false;
- }
-
- return true;
-}
-
-bool ctx::db_manager_impl::execute(unsigned int query_id, const char* query, db_listener_iface* listener)
-{
- IF_FAIL_RETURN_TAG(initialized, false, _E, "Not initialized");
- IF_FAIL_RETURN_TAG(query, false, _E, "Null query");
-
- query_info_s *info = new(std::nothrow) query_info_s;
- IF_FAIL_RETURN_TAG(info, false, _E, "Memory allocation failed");
-
- info->id = query_id;
- info->query = query;
- info->listener = listener;
-
- if (!pushEvent(QTYPE_EXECUTE, info)) {
- _E("Pushing thread event failed");
- delete info;
- return false;
- }
-
- return true;
-}
-
-void ctx::db_manager_impl::_execute(int query_type, unsigned int query_id, const char* query, db_listener_iface* listener)
-{
- IF_FAIL_VOID(query);
- IF_FAIL_VOID_TAG(db_handle, _E, "DB not opened");
- _SD("SQL(%d): %s", query_id, query);
-
- std::vector<Json> *query_result = new(std::nothrow) std::vector<Json>;
- IF_FAIL_VOID_TAG(query_result, _E, "Memory allocation failed");
-
- char *err = NULL;
- int ret;
-
- {
- ScopeMutex sm(&exec_mutex);
- ret = sqlite3_exec(db_handle, query, execution_result_cb, query_result, &err);
- }
-
- if (ret != SQLITE_OK) {
- _E("DB Error: %s", err);
- sqlite3_free(err);
- send_result(query_type, query_id, listener, ERR_OPERATION_FAILED, query_result);
- return;
- }
-
- send_result(query_type, query_id, listener, ERR_NONE, query_result);
- return;
-}
-
-int ctx::db_manager_impl::execution_result_cb(void *user_data, int dim, char **value, char **column)
-{
- std::vector<Json> *records = static_cast<std::vector<Json>*>(user_data);
- Json row;
- bool column_null = false;
-
- for (int i=0; i<dim; ++i) {
- if (value[i]) {
- row.set(NULL, column[i], value[i]);
- } else {
- column_null = true;
- }
- }
-
- if (!column_null) {
- records->push_back(row);
- } else {
- _W(RED("Null columns exist"));
- }
-
- return 0;
-}
-
-void ctx::db_manager_impl::send_result(int query_type, unsigned int query_id, db_listener_iface* listener, int error, std::vector<Json>* result)
-{
- query_result_s *qr = new(std::nothrow) query_result_s();
- IF_FAIL_VOID_TAG(qr, _E, "Memory allocation failed");
-
- qr->type = query_type;
- qr->id = query_id;
- qr->listener = listener;
- qr->error = error;
- qr->result = result;
-
- g_idle_add(_send_result, qr);
-}
-
-gboolean ctx::db_manager_impl::_send_result(gpointer data)
-{
- query_result_s *qr = static_cast<query_result_s*>(data);
-
- if (qr->listener) {
- switch (qr->type) {
- case QTYPE_CREATE_TABLE:
- qr->listener->on_creation_result_received(qr->id, qr->error);
- break;
- case QTYPE_INSERT:
- {
- int64_t row_id = -1;
- if (qr->error == ERR_NONE && qr->result && !qr->result->empty()) {
- qr->result->at(0).get(NULL, "seq", &row_id);
- _D("RowId: %d", row_id);
- }
- qr->listener->on_insertion_result_received(qr->id, qr->error, row_id);
- }
- break;
- case QTYPE_EXECUTE:
- qr->listener->on_query_result_received(qr->id, qr->error, *(qr->result));
- break;
- default:
- _W("Unknown query type: %d", qr->type);
- }
- }
-
- delete qr->result;
- delete qr;
- return FALSE;
-}
-
-bool ctx::db_manager_impl::create_table_sync(const char* table_name, const char* columns, const char* option)
-{
- IF_FAIL_RETURN_TAG(db_handle, false, _E, "DB not opened");
-
- std::string query = compose_create_query(table_name, columns, option);
- IF_FAIL_RETURN(!query.empty(), false);
- _SD("SQL: %s", query.c_str());
-
- char *err = NULL;
- int ret;
- {
- ScopeMutex sm(&exec_mutex);
- ret = sqlite3_exec(db_handle, query.c_str(), NULL, NULL, &err);
- }
-
- if (ret != SQLITE_OK) {
- _E("DB Error: %s", err);
- sqlite3_free(err);
- return false;
- }
-
- return true;
-}
-
-bool ctx::db_manager_impl::insert_sync(const char* table_name, Json& record, int64_t* row_id)
-{
- IF_FAIL_RETURN_TAG(db_handle, false, _E, "DB not opened");
- IF_FAIL_RETURN_TAG(table_name && row_id, false, _E, "Invalid parameter");
-
- std::string query = compose_insert_query(table_name, record);
- IF_FAIL_RETURN(!query.empty(), false);
- _SD("SQL: %s", query.c_str());
-
- std::vector<Json> query_result;
- char *err = NULL;
- int ret;
- {
- ScopeMutex sm(&exec_mutex);
- ret = sqlite3_exec(db_handle, query.c_str(), execution_result_cb, &query_result, &err);
- }
-
- if (ret != SQLITE_OK) {
- _E("DB Error: %s", err);
- sqlite3_free(err);
- return false;
- }
-
- IF_FAIL_RETURN_TAG(!query_result.empty(), false, _E, "No row id");
-
- *row_id = -1;
- query_result.at(0).get(NULL, "seq", row_id);
- _D("RowId: %lld", *row_id);
-
- return true;
-}
-
-bool ctx::db_manager_impl::execute_sync(const char* query, std::vector<Json>* records)
-{
- IF_FAIL_RETURN_TAG(db_handle, false, _E, "DB not opened");
- IF_FAIL_RETURN_TAG(query && records, false, _E, "Invalid parameter");
-
- _SD("SQL: %s", query);
-
- char *err = NULL;
- int ret;
- {
- ScopeMutex sm(&exec_mutex);
- ret = sqlite3_exec(db_handle, query, execution_result_cb, records, &err);
- }
-
- if (ret != SQLITE_OK) {
- _E("DB Error: %s", err);
- sqlite3_free(err);
- return false;
- }
-
- return true;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __CONTEXT_DB_MANAGER_IMPL_H__
-#define __CONTEXT_DB_MANAGER_IMPL_H__
-
-#include <vector>
-#include <Json.h>
-#include <sqlite3.h>
-
-#include <EventDrivenThread.h>
-#include <db_listener_iface.h>
-#include <db_mgr_iface.h>
-
-namespace ctx {
-
- class db_manager_impl : public EventDrivenThread, public db_manager_iface {
- private:
- enum query_type_e {
- QTYPE_CREATE_TABLE = 1,
- QTYPE_INSERT,
- QTYPE_EXECUTE,
- };
-
- struct query_info_s {
- unsigned int id;
- db_listener_iface* listener;
- std::string query;
- };
-
- struct query_result_s {
- int type;
- unsigned int id;
- int error;
- db_listener_iface* listener;
- std::vector<Json>* result;
- };
-
- sqlite3 *db_handle;
-
- void onEvent(int type, void* data);
- void deleteEvent(int type, void* data);
-
- bool open();
- void close();
-
- std::string compose_create_query(const char* table_name, const char* columns, const char* option);
- std::string compose_insert_query(const char* table_name, Json& record);
-
- void _execute(int query_type, unsigned int query_id, const char* query, db_listener_iface* listener);
- void send_result(int query_type, unsigned int query_id, db_listener_iface* listener, int error, std::vector<Json>* result);
-
- static int execution_result_cb(void *user_data, int dim, char **value, char **column);
- static gboolean _send_result(gpointer data);
-
- public:
- db_manager_impl();
- ~db_manager_impl();
-
- bool init();
- void release();
-
- bool create_table(unsigned int query_id, const char* table_name, const char* columns, const char* option = NULL, db_listener_iface* listener = NULL);
- bool insert(unsigned int query_id, const char* table_name, Json& record, db_listener_iface* listener = NULL);
- bool execute(unsigned int query_id, const char* query, db_listener_iface* listener);
-
- bool create_table_sync(const char* table_name, const char* columns, const char* option = NULL);
- bool insert_sync(const char* table_name, Json& record, int64_t* row_id);
- bool execute_sync(const char* query, std::vector<Json>* records);
-
- }; /* class db_manager */
-}
-
-#endif /* __CONTEXT_DB_MANAGER_IMPL_H__ */
#include <sstream>
#include <context_trigger_types_internal.h>
-#include <db_mgr.h>
#include <package_manager.h>
#include <Json.h>
#include "RuleManager.h"
std::string q1 = std::string("status INTEGER DEFAULT 0 NOT NULL, creator TEXT DEFAULT '' NOT NULL,")
+ "package_id TEXT DEFAULT '' NOT NULL, description TEXT DEFAULT '',"
+ "details TEXT DEFAULT '' NOT NULL";
- ret = db_manager::create_table(1, RULE_TABLE, q1.c_str(), NULL, NULL);
+ ret = __dbManager.createTableSync(RULE_TABLE, q1.c_str(), NULL);
IF_FAIL_RETURN_TAG(ret, false, _E, "Create rule table failed");
// Before re-enable rules, handle uninstalled app's rules
std::string q1 = "SELECT DISTINCT package_id FROM context_trigger_rule";
std::vector<Json> record;
- bool ret = db_manager::execute_sync(q1.c_str(), &record);
+ bool ret = __dbManager.executeSync(q1.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, -1, _E, "Query package ids of registered rules failed");
std::vector<Json>::iterator vecEnd = record.end();
q1 += ")";
std::vector<Json> record;
- ret = db_manager::execute_sync(q1.c_str(), &record);
+ ret = __dbManager.executeSync(q1.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Failed to query enabled rules of uninstalled packages");
std::vector<Json>::iterator vecEnd = record.end();
// Delete rules of uninstalled packages from DB
std::string q2 = "DELETE FROM context_trigger_rule WHERE " + pkgList;
std::vector<Json> dummy;
- ret = db_manager::execute_sync(q2.c_str(), &dummy);
+ ret = __dbManager.executeSync(q2.c_str(), &dummy);
IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Failed to remove rules from db");
_D("Uninstalled packages' rules are deleted from db");
{
std::string q = "SELECT row_id FROM context_trigger_rule WHERE (status=2) AND (details LIKE '%\"ITEM_NAME\":\"" + subject + "\"%');";
std::vector<Json> record;
- bool ret = db_manager::execute_sync(q.c_str(), &record);
+ bool ret = __dbManager.executeSync(q.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Failed to query row_ids to be paused");
IF_FAIL_RETURN(record.size() > 0, ERR_NONE);
{
std::string q = "SELECT row_id FROM context_trigger_rule WHERE (status=1) AND (details LIKE '%\"ITEM_NAME\":\"" + subject + "\"%');";
std::vector<Json> record;
- bool ret = db_manager::execute_sync(q.c_str(), &record);
+ bool ret = __dbManager.executeSync(q.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Query paused rule ids failed");
IF_FAIL_RETURN(record.size() > 0, ERR_NONE);
std::string q = "SELECT row_id FROM context_trigger_rule WHERE status = 2";
std::vector<Json> record;
- bool ret = db_manager::execute_sync(q.c_str(), &record);
+ bool ret = __dbManager.executeSync(q.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, false, _E, "Query row_ids of enabled rules failed");
IF_FAIL_RETURN_TAG(record.size() > 0, true, _D, "No rule to re-enable");
// For rules which is failed to re-enable
std::string qUpdate = "UPDATE context_trigger_rule SET status = 1 WHERE " + qRowId;
std::vector<Json> record2;
- ret = db_manager::execute_sync(qUpdate.c_str(), &record2);
+ ret = __dbManager.executeSync(qUpdate.c_str(), &record2);
IF_FAIL_RETURN_TAG(ret, false, _E, "Failed to update rules as paused");
return true;
q += "'";
std::vector<Json> record;
- bool ret = db_manager::execute_sync(q.c_str(), &record);
+ bool ret = __dbManager.executeSync(q.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, false, _E, "Query row_id, details by package id failed");
Json rDetails;
std::string qUpdate = "UPDATE context_trigger_rule SET description='" + rDesc + "' WHERE row_id = " + __intToString(rowId);
std::vector<Json> dummy;
- ret = db_manager::execute_sync(qUpdate.c_str(), &dummy);
+ ret = __dbManager.executeSync(qUpdate.c_str(), &dummy);
if (ret) {
_D("Rule%lld description is updated", rowId);
} else {
trigger::timer::handleTimerEvent(details);
record.set(NULL, "details", details.str());
- ret = db_manager::insert_sync(RULE_TABLE, record, &rid);
+ ret = __dbManager.insertSync(RULE_TABLE, record, &rid);
IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Insert rule to db failed");
// Save rule id
query += __intToString(ruleId);
std::vector<Json> record;
- ret = db_manager::execute_sync(query.c_str(), &record);
+ ret = __dbManager.executeSync(query.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Remove rule from db failed");
_D("Remove rule%d succeeded", ruleId);
// Get rule Json by rule id;
query = "SELECT details, package_id FROM context_trigger_rule WHERE row_id = ";
query += idStr;
- error = (db_manager::execute_sync(query.c_str(), &record))? ERR_NONE : ERR_OPERATION_FAILED;
+ error = (__dbManager.executeSync(query.c_str(), &record))? ERR_NONE : ERR_OPERATION_FAILED;
IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Query rule by rule id failed");
record[0].get(NULL, "details", &tmp);
// Update db to set 'enabled'
query = "UPDATE context_trigger_rule SET status = 2 WHERE row_id = ";
query += idStr;
- error = (db_manager::execute_sync(query.c_str(), &dummy))? ERR_NONE : ERR_OPERATION_FAILED;
+ error = (__dbManager.executeSync(query.c_str(), &dummy))? ERR_NONE : ERR_OPERATION_FAILED;
IF_FAIL_CATCH_TAG(error == ERR_NONE, _E, "Update db failed");
// Add rule instance to __ruleMap
std::string query = "UPDATE context_trigger_rule SET status = 0 WHERE row_id = ";
query += __intToString(ruleId);
std::vector<Json> record;
- ret = db_manager::execute_sync(query.c_str(), &record);
+ ret = __dbManager.executeSync(query.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Update db failed");
_D(YELLOW("Disable Rule%d succeeded"), ruleId);
query += __intToString(ruleId);
std::vector<Json> record;
- ret = db_manager::execute_sync(query.c_str(), &record);
+ ret = __dbManager.executeSync(query.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Update db failed");
// Remove rule instance from __ruleMap
q += __intToString(ruleId);
std::vector<Json> record;
- bool ret = db_manager::execute_sync(q.c_str(), &record);
+ bool ret = __dbManager.executeSync(q.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, false, _E, "Query package id by rule id failed");
if (record.size() == 0) {
q += __intToString(ruleId);
std::vector<Json> record;
- bool ret = db_manager::execute_sync(q.c_str(), &record);
+ bool ret = __dbManager.executeSync(q.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, false, _E, "Query enabled by rule id failed");
int status;
q += ")";
std::vector<Json> record;
- bool ret = db_manager::execute_sync(q.c_str(), &record);
+ bool ret = __dbManager.executeSync(q.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, false, _E, "Query rule by rule id failed");
if (record.size() == 0) {
q += "')";
std::vector<Json> record;
- bool ret = db_manager::execute_sync(q.c_str(), &record);
+ bool ret = __dbManager.executeSync(q.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Query rules failed");
std::vector<Json>::iterator vecEnd = record.end();
#include <set>
#include <map>
+#include <DatabaseManager.h>
namespace ctx {
void __applyTemplates(void);
std::set<std::string> __uninstalledPackages;
-
std::map<int, Rule*> __ruleMap;
+ DatabaseManager __dbManager;
}; /* class RuleManager */
} /* namespace trigger */
#include <sstream>
#include <types_internal.h>
#include <context_trigger_types_internal.h>
-#include <db_mgr.h>
#include "../ContextManagerImpl.h"
#include "RuleManager.h"
#include "TemplateManager.h"
+ "attributes TEXT DEFAULT '' NOT NULL, options TEXT DEFAULT '' NOT NULL, owner TEXT DEFAULT '' NOT NULL)";
std::vector<Json> record;
- bool ret = db_manager::execute_sync(q.c_str(), &record);
+ bool ret = __dbManager.executeSync(q.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, false, _E, "Create template table failed");
// Apply templates
+ owner + "'); ";
std::vector<Json> record;
- bool ret = db_manager::execute_sync(query.c_str(), &record);
+ bool ret = __dbManager.executeSync(query.c_str(), &record);
IF_FAIL_VOID_TAG(ret, _E, "Update template db failed");
if (!owner.empty()) {
std::string query = "DELETE FROM context_trigger_template WHERE name = '" + subject + "'; ";
std::vector<Json> record;
- bool ret = db_manager::execute_sync(query.c_str(), &record);
+ bool ret = __dbManager.executeSync(query.c_str(), &record);
IF_FAIL_VOID_TAG(ret, _E, "Update template db failed");
__ruleMgr->pauseRuleWithItem(subject);
std::string q = "SELECT * FROM context_trigger_template WHERE name = '" + subject + "'";
std::vector<Json> record;
- bool ret = db_manager::execute_sync(q.c_str(), &record);
+ bool ret = __dbManager.executeSync(q.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Query template failed");
IF_FAIL_RETURN_TAG(record.size() > 0, ERR_NOT_SUPPORTED, _E, "Template(%s) not found", subject.c_str());
IF_FAIL_RETURN_TAG(record.size() == 1, ERR_OPERATION_FAILED, _E, "Tepmlate duplicated");
#define _CONTEXT_TRIGGER_TEMPLATE_MANAGER_H_
#include <Json.h>
+#include <DatabaseManager.h>
namespace ctx {
static ContextManagerImpl *__contextMgr;
static RuleManager *__ruleMgr;
+ DatabaseManager __dbManager;
+
std::string __addTemplate(std::string &subject, int &operation, Json &attributes, Json &options, std::string &owner);
std::string __removeTemplate(std::string &subject);