2 * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
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.
23 /* For multi-user support */
24 #include <tzplatform_config.h>
26 #include "syspopup_db.h"
27 #include "simple_util.h"
29 #define SYSPOPUP_DB_PATH tzplatform_mkpath(TZ_SYS_DB, ".syspopup.db")
30 #define QUERY_MAXLEN 4096
32 #define SP_INFO_TBL "syspopup_info"
33 #define SP_INFO_TBL_F_NAME "name"
38 static int __init(void)
43 _D("Already initialized\n");
47 rc = sqlite3_open_v2(SYSPOPUP_DB_PATH, &db, SQLITE_OPEN_READONLY, NULL);
48 if (rc != SQLITE_OK) {
49 _E("Can't open database: %s / %d / %d", sqlite3_errmsg(db),
50 rc, sqlite3_extended_errcode(db));
53 _D("db open success");
59 static int __fini(void)
69 syspopup_info_t *_syspopup_info_get(const char *popup_name)
72 char sqlbuf[256] = {0,};
73 sqlite3_stmt *stmt = NULL;
74 syspopup_info_t *pinfo = NULL;
76 if (popup_name == NULL) {
84 snprintf(sqlbuf, sizeof(sqlbuf),
85 "SELECT name,prio,focus,timeout,term_act,endkey_act,pkgname FROM %s WHERE %s = ?;",
86 SP_INFO_TBL, SP_INFO_TBL_F_NAME);
88 rc = sqlite3_prepare_v2(db, sqlbuf, -1, &stmt, NULL);
89 if (rc != SQLITE_OK) {
90 _E("popup info prepare error(%d)", rc);
94 rc = sqlite3_bind_text(stmt, 1, popup_name, strlen(popup_name), SQLITE_STATIC);
95 if (rc != SQLITE_OK) {
96 _E("popup name bind error(%d)", rc);
100 rc = sqlite3_step(stmt);
101 if (rc != SQLITE_ROW) {
102 _E("error(%d) in prepare", rc);
106 pinfo = (syspopup_info_t *)malloc(sizeof(syspopup_info_t));
112 pinfo->name = strdup((char *)sqlite3_column_text(stmt, 0));
113 pinfo->prio = sqlite3_column_int(stmt, 1);
114 pinfo->focus = sqlite3_column_int(stmt, 2);
115 pinfo->timeout = sqlite3_column_int(stmt, 3);
116 pinfo->term_act = sqlite3_column_int(stmt, 4);
117 pinfo->endkey_act = sqlite3_column_int(stmt, 5);
119 if (sqlite3_column_text(stmt, 6) != NULL)
120 pinfo->pkgname = strdup((char *) sqlite3_column_text(stmt, 6));
122 pinfo->pkgname = NULL;
125 sqlite3_finalize(stmt);
131 void _syspopup_info_free(syspopup_info_t *pinfo)
137 free(pinfo->pkgname);
142 int _syspopup_info_foreach(int (*callback)(syspopup_info_t *, void *),
145 const char query[] = "SELECT name, prio, focus, timeout, term_act, "
146 "endkey_act, pkgname FROM syspopup_info;";
148 syspopup_info_t info;
152 if (callback == NULL) {
153 _E("Invalid parameter");
160 r = sqlite3_prepare_v2(db, query, sizeof(query), &stmt, NULL);
161 if (r != SQLITE_OK) {
162 _E("sqlite3_prepare_v2() is failed - %d(%s)",
163 r, sqlite3_errmsg(db));
168 while (sqlite3_step(stmt) == SQLITE_ROW) {
170 info.name = (char *)sqlite3_column_text(stmt, idx++);
171 info.prio = sqlite3_column_int(stmt, idx++);
172 info.focus = sqlite3_column_int(stmt, idx++);
173 info.timeout = sqlite3_column_int(stmt, idx++);
174 info.term_act = sqlite3_column_int(stmt, idx++);
175 info.endkey_act = sqlite3_column_int(stmt, idx++);
176 info.pkgname = (char *)sqlite3_column_text(stmt, idx);
178 if (callback(&info, user_data) < 0)
181 sqlite3_finalize(stmt);