2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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.
19 #include <stdlib.h> /* malloc */
20 #include <string.h> /* strdup, strerror */
21 #include <sys/types.h>
29 #include <com-core_packet.h>
33 #include <package-manager.h>
35 #include <vconf-keys.h>
40 #include "livebox-service.h"
42 #define EAPI __attribute__((visibility("default")))
43 #define DEFAULT_TIMEOUT 2.0
46 static struct supported_size_list {
49 } SIZE_LIST[NR_OF_SIZE_LIST] = {
50 { 172, 172 }, /*!< 1x1 */
51 { 348, 172 }, /*!< 2x1 */
52 { 348, 348 }, /*!< 2x2 */
53 { 700, 172 }, /*!< 4x1 */
54 { 700, 348 }, /*!< 4x2 */
55 { 700, 520 }, /*!< 4x3 */
56 { 700, 700 }, /*!< 4x4 */
62 const char *conf_file;
67 .dbfile = "/opt/dbspace/.livebox.db",
68 .conf_file = "/usr/share/data-provider-master/resolution.ini",
73 static inline int update_info(int width_type, int height_type, int width, int height)
77 if (width_type == 1 && height_type == 1) {
78 DbgPrint("1x1 Updated to %dx%d\n", width, height);
80 } else if (width_type == 2 && height_type == 1) {
81 DbgPrint("2x1 Updated to %dx%d\n", width, height);
83 } else if (width_type == 2 && height_type == 2) {
84 DbgPrint("2x2 Updated to %dx%d\n", width, height);
86 } else if (width_type == 4 && height_type == 1) {
87 DbgPrint("4x1 Updated to %dx%d\n", width, height);
89 } else if (width_type == 4 && height_type == 2) {
90 DbgPrint("4x2 Updated to %dx%d\n", width, height);
92 } else if (width_type == 4 && height_type == 3) {
93 DbgPrint("4x3 Updated to %dx%d\n", width, height);
95 } else if (width_type == 4 && height_type == 4) {
96 DbgPrint("4x4 Updated to %dx%d\n", width, height);
99 ErrPrint("Unknown size type: %dx%d (%dx%d)\n", width_type, height_type, width, height);
103 SIZE_LIST[idx].w = width;
104 SIZE_LIST[idx].h = height;
108 static inline int update_from_file(void)
116 char buffer[MAX_COLUMN];
130 fp = fopen(s_info.conf_file, "r");
132 ErrPrint("Open failed: %s\n", strerror(errno));
142 if (idx == MAX_COLUMN) {
143 ErrPrint("Buffer overflow. Too long line. LINE MUST BE SHOT THAN %d\n", MAX_COLUMN);
149 if (isspace(ch) || ch == EOF)
164 if (sscanf(buffer, "%dx%d", &width_type, &height_type) != 2) {
165 ErrPrint("Invalid syntax: [%s]\n", buffer);
169 } else if (ch == '=') {
172 if (sscanf(buffer, "%dx%d", &width_type, &height_type) != 2) {
173 ErrPrint("Invalid syntax: [%s]\n", buffer);
177 } else if (ch == EOF) {
178 ErrPrint("Invalid Syntax\n");
189 if (isspace(ch) || ch == EOF)
197 if (isspace(ch) || ch == EOF) {
201 if (sscanf(buffer, "%dx%d", &width, &height) != 2) {
202 ErrPrint("Invalid syntax: [%s]\n", buffer);
204 } else if (ch == EOF) {
205 updated += update_info(width_type, height_type, width, height);
212 updated += update_info(width_type, height_type, width, height);
217 if (ch == '\n' || ch == '\r' || ch == '\f')
221 if (ch == '\n' || ch == '\r' || ch == '\f')
225 ErrPrint("Unknown status. couldn't be reach to here\n");
231 return NR_OF_SIZE_LIST - updated;
234 static int update_resolution(void)
246 if (s_info.res_resolved)
249 disp = XOpenDisplay(NULL);
251 ErrPrint("Failed to open a display\n");
255 root = XDefaultRootWindow(disp);
256 if (!XGetGeometry(disp, root, &dummy, &x, &y, &width, &height, &border, &depth)) {
261 if (update_from_file() == 0)
262 DbgPrint("Resolution info is all updated by file\n");
264 DbgPrint("Screen resolution: %dx%d\n", width, height);
265 for (i = 0; i < NR_OF_SIZE_LIST; i++) {
266 SIZE_LIST[i].w = (unsigned int)((double)SIZE_LIST[i].w * (double)width / 720.0f);
267 SIZE_LIST[i].h = (unsigned int)((double)SIZE_LIST[i].h * (double)height / 1280.0f);
268 DbgPrint("(Ratio)Size is updated [%d] %dx%d\n", i, SIZE_LIST[i].w, SIZE_LIST[i].h);
272 s_info.res_resolved = 1;
276 static inline sqlite3 *open_db(void)
280 if (!s_info.handle) {
283 ret = db_util_open(s_info.dbfile, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
284 if (ret != SQLITE_OK) {
285 ErrPrint("Failed to open a DB\n");
289 handle = s_info.handle;
295 static inline void close_db(sqlite3 *handle)
298 db_util_close(handle);
301 static inline int convert_size_from_type(enum livebox_size_type type, int *width, int *height)
306 case LB_SIZE_TYPE_1x1: /*!< 172x172 */
309 case LB_SIZE_TYPE_2x1: /*!< 348x172 */
312 case LB_SIZE_TYPE_2x2: /*!< 348x348 */
315 case LB_SIZE_TYPE_4x1: /*!< 700x172 */
318 case LB_SIZE_TYPE_4x2: /*!< 700x348 */
321 case LB_SIZE_TYPE_4x3: /*!< 700x520 */
324 case LB_SIZE_TYPE_4x4: /*!< 700x700 */
331 if (update_resolution() < 0)
332 ErrPrint("Failed to update resolution\n");
334 *width = SIZE_LIST[idx].w;
335 *height = SIZE_LIST[idx].h;
339 EAPI int livebox_service_trigger_update(const char *pkgname, const char *cluster, const char *category)
341 struct packet *packet;
342 struct packet *result;
346 ErrPrint("Invalid argument\n");
350 if (access("/tmp/.live.paused", R_OK) == 0) {
351 DbgPrint("Provider is paused\n");
356 cluster = "user,created";
359 category = "default";
361 packet = packet_create("service_update", "sss", pkgname, cluster, category);
363 ErrPrint("Failed to create a packet for service_update\n");
367 result = com_core_packet_oneshot_send(SERVICE_SOCKET, packet, DEFAULT_TIMEOUT);
368 packet_unref(packet);
371 if (packet_get(result, "i", &ret) != 1) {
372 ErrPrint("Failed to parse a result packet\n");
376 packet_unref(result);
378 ErrPrint("Failed to get result packet\n");
385 EAPI int livebox_service_get_pkglist(int (*cb)(const char *appid, const char *pkgname, int is_prime, void *data), void *data)
401 ret = sqlite3_prepare_v2(handle, "SELECT appid, pkgid, prime FROM pkgmap", -1, &stmt, NULL);
402 if (ret != SQLITE_OK) {
403 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
409 while (sqlite3_step(stmt) == SQLITE_ROW) {
410 appid = (char *)sqlite3_column_text(stmt, 0);
411 if (!appid || !strlen(appid)) {
412 ErrPrint("APPID is not valid\n");
416 pkgid = (char *)sqlite3_column_text(stmt, 1);
417 if (!pkgid || !strlen(pkgid)) {
418 ErrPrint("pkgid is not valid\n");
422 is_prime = sqlite3_column_int(stmt, 2);
426 if (cb(appid, pkgid, is_prime, data) < 0) {
427 DbgPrint("Callback stopped package crawling\n");
433 sqlite3_finalize(stmt);
440 EAPI int livebox_service_get_supported_size_types(const char *pkgid, int *cnt, int *types)
447 if (!types || !cnt || !pkgid)
454 ret = sqlite3_prepare_v2(handle, "SELECT size_type FROM box_size WHERE pkgid = ? ORDER BY size_type ASC", -1, &stmt, NULL);
455 if (ret != SQLITE_OK) {
456 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
461 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
462 if (ret != SQLITE_OK) {
463 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
465 sqlite3_finalize(stmt);
470 if (*cnt > NR_OF_SIZE_LIST)
471 *cnt = NR_OF_SIZE_LIST;
474 while (sqlite3_step(stmt) == SQLITE_ROW && ret < *cnt) {
475 size = sqlite3_column_int(stmt, 0);
482 sqlite3_finalize(stmt);
489 static inline char *cur_locale(void)
492 language = vconf_get_str(VCONFKEY_LANGSET);
509 language = strdup("en-us");
511 ErrPrint("Heap: %s\n", strerror(errno));
517 static inline char *get_default_name(const char *pkgid)
528 ret = sqlite3_prepare_v2(handle, "SELECT name FROM client WHERE pkgid = ?", -1, &stmt, NULL);
529 if (ret != SQLITE_OK) {
530 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
535 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
536 if (ret != SQLITE_OK) {
537 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
541 ret = sqlite3_step(stmt);
542 if (ret == SQLITE_ROW) {
545 tmp = (const char *)sqlite3_column_text(stmt, 0);
546 if (tmp && strlen(tmp)) {
549 ErrPrint("Heap: %s\n", strerror(errno));
555 sqlite3_finalize(stmt);
560 static inline char *get_default_icon(const char *pkgid)
571 ret = sqlite3_prepare_v2(handle, "SELECT icon FROM client WHERE pkgid = ?", -1, &stmt, NULL);
572 if (ret != SQLITE_OK) {
573 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
578 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
579 if (ret != SQLITE_OK) {
580 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
584 ret = sqlite3_step(stmt);
585 if (ret == SQLITE_ROW) {
588 tmp = (const char *)sqlite3_column_text(stmt, 0);
589 if (tmp && strlen(tmp)) {
592 ErrPrint("Heap: %s\n", strerror(errno));
598 sqlite3_finalize(stmt);
603 EAPI char *livebox_service_content(const char *pkgid)
607 char *content = NULL;
614 ret = sqlite3_prepare_v2(handle, "SELECT content FROM client WHERE pkgid = ?", -1, &stmt, NULL);
615 if (ret != SQLITE_OK) {
616 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
621 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
622 if (ret != SQLITE_OK) {
623 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
627 ret = sqlite3_step(stmt);
628 if (ret == SQLITE_ROW) {
631 tmp = (const char *)sqlite3_column_text(stmt, 0);
632 if (tmp && strlen(tmp)) {
633 content = strdup(tmp);
635 ErrPrint("Heap: %s\n", strerror(errno));
641 sqlite3_finalize(stmt);
646 EAPI char *livebox_service_setup_appid(const char *lbid)
657 ret = sqlite3_prepare_v2(handle, "SELECT setup FROM client WHERE pkgid = ?", -1, &stmt, NULL);
658 if (ret != SQLITE_OK) {
659 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
665 ret = sqlite3_bind_text(stmt, 1, lbid, -1, NULL);
666 if (ret != SQLITE_OK) {
667 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
671 ret = sqlite3_step(stmt);
672 if (ret == SQLITE_ROW) {
675 tmp = (const char *)sqlite3_column_text(stmt, 0);
676 if (!tmp || !strlen(tmp))
681 ErrPrint("Error: %s\n", strerror(errno));
686 sqlite3_finalize(stmt);
691 EAPI int livebox_service_nodisplay(const char *pkgid)
701 ret = sqlite3_prepare_v2(handle, "SELECT nodisplay FROM client WHERE pkgid = ?", -1, &stmt, NULL);
702 if (ret != SQLITE_OK) {
703 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
708 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
709 if (ret != SQLITE_OK) {
710 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
715 ret = sqlite3_step(stmt);
716 if (ret == SQLITE_ROW)
717 ret = !!sqlite3_column_int(stmt, 0);
723 sqlite3_finalize(stmt);
728 EAPI int livebox_service_mouse_event(const char *pkgid)
738 ret = sqlite3_prepare_v2(handle, "SELECT mouse_event FROM client WHERE pkgid = ?", -1, &stmt, NULL);
739 if (ret != SQLITE_OK) {
740 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
745 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
746 if (ret != SQLITE_OK) {
747 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
752 ret = sqlite3_step(stmt);
753 if (ret == SQLITE_ROW)
754 ret = !!sqlite3_column_int(stmt, 0);
760 sqlite3_finalize(stmt);
765 EAPI char *livebox_service_preview(const char *pkgid, int size_type)
770 char *preview = NULL;
776 ret = sqlite3_prepare_v2(handle, "SELECT preview FROM box_size WHERE pkgid = ? AND size_type = ?", -1, &stmt, NULL);
777 if (ret != SQLITE_OK) {
778 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
783 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
784 if (ret != SQLITE_OK) {
785 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
789 ret = sqlite3_bind_int(stmt, 2, size_type);
790 if (ret != SQLITE_OK) {
791 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
795 ret = sqlite3_step(stmt);
796 if (ret == SQLITE_ROW) {
798 tmp = (const char *)sqlite3_column_text(stmt, 0);
799 if (tmp && strlen(tmp)) {
800 preview = strdup(tmp);
802 ErrPrint("Heap: %s\n", strerror(errno));
808 sqlite3_finalize(stmt);
813 EAPI char *livebox_service_i18n_icon(const char *pkgid, const char *lang)
822 language = strdup(lang);
824 ErrPrint("Heap: %s\n", strerror(errno));
828 language = cur_locale();
839 ret = sqlite3_prepare_v2(handle, "SELECT icon FROM i18n WHERE pkgid = ? AND lang = ?", -1, &stmt, NULL);
840 if (ret != SQLITE_OK) {
841 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
847 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
848 if (ret != SQLITE_OK) {
849 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
853 ret = sqlite3_bind_text(stmt, 2, language, -1, NULL);
854 if (ret != SQLITE_OK) {
855 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
859 ret = sqlite3_step(stmt);
860 if (ret == SQLITE_ROW) {
862 tmp = (const char *)sqlite3_column_text(stmt, 0);
863 if (!tmp || !strlen(tmp)) {
864 icon = get_default_icon(pkgid);
868 ErrPrint("Heap: %s\n", strerror(errno));
871 icon = get_default_icon(pkgid);
876 sqlite3_finalize(stmt);
882 EAPI char *livebox_service_i18n_name(const char *pkgid, const char *lang)
891 language = strdup(lang);
893 ErrPrint("Error: %s\n", strerror(errno));
897 language = cur_locale();
908 ret = sqlite3_prepare_v2(handle, "SELECT name FROM i18n WHERE pkgid = ? AND lang = ?", -1, &stmt, NULL);
909 if (ret != SQLITE_OK) {
910 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
916 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
917 if (ret != SQLITE_OK) {
918 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
922 ret = sqlite3_bind_text(stmt, 2, language, -1, NULL);
923 if (ret != SQLITE_OK) {
924 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
928 ret = sqlite3_step(stmt);
929 if (ret == SQLITE_ROW) {
931 tmp = (const char *)sqlite3_column_text(stmt, 0);
932 if (!tmp || !strlen(tmp)) {
933 name = get_default_name(pkgid);
937 ErrPrint("Heap: %s\n", strerror(errno));
940 name = get_default_name(pkgid);
945 sqlite3_finalize(stmt);
951 EAPI int livebox_service_get_supported_sizes(const char *pkgid, int *cnt, int *w, int *h)
958 if (!w || !h || !cnt || !pkgid)
965 ret = sqlite3_prepare_v2(handle, "SELECT size_type FROM box_size WHERE pkgid = ? ORDER BY size_type ASC", -1, &stmt, NULL);
966 if (ret != SQLITE_OK) {
967 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
972 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
973 if (ret != SQLITE_OK) {
974 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
976 sqlite3_finalize(stmt);
981 if (*cnt > NR_OF_SIZE_LIST)
982 *cnt = NR_OF_SIZE_LIST;
985 while (sqlite3_step(stmt) == SQLITE_ROW && ret < *cnt) {
986 size = sqlite3_column_int(stmt, 0);
987 ret += (convert_size_from_type(size, w + ret, h + ret) == 0);
992 sqlite3_finalize(stmt);
999 EAPI char *livebox_service_libexec(const char *pkgid)
1016 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.libexec FROM pkgmap, provider WHERE pkgmap.pkgid = ? AND provider.pkgid = ?", -1, &stmt, NULL);
1017 if (ret != SQLITE_OK) {
1018 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1022 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
1023 if (ret != SQLITE_OK) {
1024 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1025 sqlite3_finalize(stmt);
1029 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, NULL);
1030 if (ret != SQLITE_OK) {
1031 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1032 sqlite3_finalize(stmt);
1036 if (sqlite3_step(stmt) != SQLITE_ROW) {
1037 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1038 sqlite3_reset(stmt);
1039 sqlite3_finalize(stmt);
1041 libexec = util_conf_get_libexec(pkgid);
1042 DbgPrint("Fallback to conf checker: %s\n", libexec);
1046 appid = (char *)sqlite3_column_text(stmt, 0);
1047 if (!appid || !strlen(appid)) {
1048 ErrPrint("Invalid appid: %s\n", sqlite3_errmsg(handle));
1049 sqlite3_reset(stmt);
1050 sqlite3_finalize(stmt);
1054 path = (char *)sqlite3_column_text(stmt, 1);
1055 if (!path || !strlen(path)) {
1056 ErrPrint("Invalid libexec: %s\n", sqlite3_errmsg(handle));
1057 sqlite3_reset(stmt);
1058 sqlite3_finalize(stmt);
1062 libexec = strdup(path);
1064 ErrPrint("Heap: %s\n", strerror(errno));
1065 sqlite3_reset(stmt);
1066 sqlite3_finalize(stmt);
1070 DbgPrint("libexec: %s\n", libexec);
1072 sqlite3_reset(stmt);
1073 sqlite3_finalize(stmt);
1079 static inline char *get_lb_pkgname_by_appid(const char *appid)
1095 ret = sqlite3_prepare_v2(handle, "SELECT pkgid FROM pkgmap WHERE (appid = ? AND prime = 1) OR pkgid = ?", -1, &stmt, NULL);
1096 if (ret != SQLITE_OK) {
1097 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1102 ret = sqlite3_bind_text(stmt, 1, appid, -1, NULL);
1103 if (ret != SQLITE_OK) {
1104 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1108 ret = sqlite3_bind_text(stmt, 2, appid, -1, NULL);
1109 if (ret != SQLITE_OK) {
1110 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1114 if (sqlite3_step(stmt) != SQLITE_ROW) {
1115 ErrPrint("Error: %s (has no record? - %s)\n", sqlite3_errmsg(handle), appid);
1119 tmp = (char *)sqlite3_column_text(stmt, 0);
1120 if (tmp && strlen(tmp)) {
1121 pkgid = strdup(tmp);
1123 ErrPrint("Heap: %s\n", strerror(errno));
1127 sqlite3_reset(stmt);
1128 sqlite3_finalize(stmt);
1133 EAPI char *livebox_service_pkgname(const char *appid)
1136 pkgmgr_appinfo_h handle;
1143 lb_pkgname = get_lb_pkgname_by_appid(appid);
1149 * Try to get the package id using given appid
1151 ret = pkgmgr_appinfo_get_appinfo(appid, &handle);
1152 if (ret != PKGMGR_R_OK) {
1153 ErrPrint("Failed to get appinfo\n");
1157 ret = pkgmgr_appinfo_get_pkgname(handle, &new_appid);
1158 if (ret != PKGMGR_R_OK) {
1159 pkgmgr_appinfo_destroy_appinfo(handle);
1160 ErrPrint("Failed to get pkgname for (%s)\n", appid);
1164 lb_pkgname = get_lb_pkgname_by_appid(new_appid);
1165 pkgmgr_appinfo_destroy_appinfo(handle);
1167 if (!lb_pkgname && util_validate_livebox_package(appid) == 0)
1168 return strdup(appid);
1173 EAPI char *livebox_service_provider_name(const char *lbid)
1182 ErrPrint("Error: %s\n", strerror(errno));
1189 EAPI char *livebox_service_appid(const char *pkgname)
1195 int is_prime __attribute__((__unused__));
1206 ret = sqlite3_prepare_v2(handle, "SELECT appid, prime FROM pkgmap WHERE pkgid = ? OR appid = ?", -1, &stmt, NULL);
1207 if (ret != SQLITE_OK) {
1208 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1212 ret = sqlite3_bind_text(stmt, 1, pkgname, -1, NULL);
1213 if (ret != SQLITE_OK) {
1214 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1215 sqlite3_reset(stmt);
1216 sqlite3_finalize(stmt);
1220 ret = sqlite3_bind_text(stmt, 2, pkgname, -1, NULL);
1221 if (ret != SQLITE_OK) {
1222 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1223 sqlite3_reset(stmt);
1224 sqlite3_finalize(stmt);
1228 ret = sqlite3_step(stmt);
1229 if (ret != SQLITE_ROW) {
1230 pkgmgr_appinfo_h pkg_handle;
1233 ErrPrint("Has no record?: %s\n", sqlite3_errmsg(handle));
1234 sqlite3_reset(stmt);
1235 sqlite3_finalize(stmt);
1237 ret = pkgmgr_appinfo_get_appinfo(pkgname, &pkg_handle);
1238 if (ret != PKGMGR_R_OK) {
1239 ErrPrint("Failed to get appinfo: %s\n", pkgname);
1243 ret = pkgmgr_appinfo_get_pkgname(pkg_handle, &new_appid);
1244 if (ret != PKGMGR_R_OK) {
1245 ErrPrint("Failed to get pkgname for (%s)\n", appid);
1246 pkgmgr_appinfo_destroy_appinfo(pkg_handle);
1250 appid = strdup(new_appid);
1252 ErrPrint("Heap: %s\n", strerror(errno));
1254 pkgmgr_appinfo_destroy_appinfo(pkg_handle);
1258 tmp = (char *)sqlite3_column_text(stmt, 0);
1259 if (!tmp || !strlen(tmp)) {
1260 ErrPrint("APPID is NIL\n");
1261 sqlite3_reset(stmt);
1262 sqlite3_finalize(stmt);
1266 appid = strdup(tmp);
1268 ErrPrint("Heap: %s\n", strerror(errno));
1269 sqlite3_reset(stmt);
1270 sqlite3_finalize(stmt);
1274 is_prime = sqlite3_column_int(stmt, 1);
1276 sqlite3_reset(stmt);
1277 sqlite3_finalize(stmt);
1283 EAPI char *livebox_service_lb_script_path(const char *pkgid)
1300 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.box_src FROM provider, pkgmap WHERE pkgmap.pkgid = ? AND provider.pkgid = ?", -1, &stmt, NULL);
1301 if (ret != SQLITE_OK) {
1302 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1306 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
1307 if (ret != SQLITE_OK) {
1308 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1309 sqlite3_finalize(stmt);
1313 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, NULL);
1314 if (ret != SQLITE_OK) {
1315 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1316 sqlite3_finalize(stmt);
1320 ret = sqlite3_step(stmt);
1321 if (ret != SQLITE_ROW) {
1322 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1323 sqlite3_reset(stmt);
1324 sqlite3_finalize(stmt);
1328 appid = (char *)sqlite3_column_text(stmt, 0);
1329 if (!appid || !strlen(appid)) {
1330 ErrPrint("Invalid appid : %s\n", sqlite3_errmsg(handle));
1331 sqlite3_reset(stmt);
1332 sqlite3_finalize(stmt);
1336 lb_src = (char *)sqlite3_column_text(stmt, 1);
1337 if (!lb_src || !strlen(lb_src)) {
1338 ErrPrint("No records for lb src : %s\n", sqlite3_errmsg(handle));
1339 sqlite3_reset(stmt);
1340 sqlite3_finalize(stmt);
1344 path = strdup(lb_src);
1346 ErrPrint("Heap: %s\n", strerror(errno));
1347 sqlite3_reset(stmt);
1348 sqlite3_finalize(stmt);
1352 DbgPrint("LB Src: %s\n", path);
1354 sqlite3_reset(stmt);
1355 sqlite3_finalize(stmt);
1361 EAPI char *livebox_service_lb_script_group(const char *pkgid)
1377 ret = sqlite3_prepare_v2(handle, "SELECT box_group FROM provider WHERE pkgid = ?", -1, &stmt, NULL);
1378 if (ret != SQLITE_OK) {
1379 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1383 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
1384 if (ret != SQLITE_OK) {
1385 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1386 sqlite3_finalize(stmt);
1390 ret = sqlite3_step(stmt);
1391 if (ret != SQLITE_ROW) {
1392 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1393 sqlite3_reset(stmt);
1394 sqlite3_finalize(stmt);
1398 tmp = (char *)sqlite3_column_text(stmt, 0);
1399 if (tmp && strlen(tmp)) {
1400 group = strdup(tmp);
1402 ErrPrint("Heap: %s\n", strerror(errno));
1405 sqlite3_reset(stmt);
1406 sqlite3_finalize(stmt);
1412 EAPI char *livebox_service_pd_script_path(const char *pkgid)
1429 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.pd_src FROM provider, pkgmap WHERE provider.pkgid = ? AND pkgmap.pkgid = ?", -1, &stmt, NULL);
1430 if (ret != SQLITE_OK) {
1431 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1435 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
1436 if (ret != SQLITE_OK) {
1437 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1438 sqlite3_finalize(stmt);
1442 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, NULL);
1443 if (ret != SQLITE_OK) {
1444 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1445 sqlite3_finalize(stmt);
1449 ret = sqlite3_step(stmt);
1450 if (ret != SQLITE_ROW) {
1451 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1452 sqlite3_reset(stmt);
1453 sqlite3_finalize(stmt);
1457 appid = (char *)sqlite3_column_text(stmt, 0);
1458 if (!appid || !strlen(appid)) {
1459 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1460 sqlite3_reset(stmt);
1461 sqlite3_finalize(stmt);
1465 pd_src = (char *)sqlite3_column_text(stmt, 1);
1466 if (!pd_src || !strlen(pd_src)) {
1467 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1468 sqlite3_reset(stmt);
1469 sqlite3_finalize(stmt);
1473 path = strdup(pd_src);
1475 ErrPrint("Heap: %s\n", strerror(errno));
1476 sqlite3_reset(stmt);
1477 sqlite3_finalize(stmt);
1481 DbgPrint("PD Src: %s\n", path);
1482 sqlite3_reset(stmt);
1483 sqlite3_finalize(stmt);
1489 EAPI char *livebox_service_pd_script_group(const char *pkgid)
1505 ret = sqlite3_prepare_v2(handle, "SELECT pd_group FROM provider WHERE pkgid = ?", -1, &stmt, NULL);
1506 if (ret != SQLITE_OK) {
1507 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1511 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
1512 if (ret != SQLITE_OK) {
1513 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1514 sqlite3_finalize(stmt);
1518 ret = sqlite3_step(stmt);
1519 if (ret != SQLITE_ROW) {
1520 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1521 sqlite3_reset(stmt);
1522 sqlite3_finalize(stmt);
1526 tmp = (char *)sqlite3_column_text(stmt, 0);
1527 if (tmp && strlen(tmp)) {
1528 group = strdup(tmp);
1530 ErrPrint("Heap: %s\n", strerror(errno));
1532 sqlite3_reset(stmt);
1533 sqlite3_finalize(stmt);
1539 EAPI int livebox_service_enumerate_cluster_list(int (*cb)(const char *cluster, void *data), void *data)
1543 const char *cluster;
1555 ret = sqlite3_prepare_v2(handle, "SELECT DISTINCT cluster FROM groupinfo", -1, &stmt, NULL);
1556 if (ret != SQLITE_OK) {
1557 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1562 while (sqlite3_step(stmt) == SQLITE_ROW) {
1563 cluster = (const char *)sqlite3_column_text(stmt, 0);
1564 if (!cluster || !strlen(cluster))
1567 if (cb(cluster, data) < 0)
1573 sqlite3_reset(stmt);
1574 sqlite3_finalize(stmt);
1580 EAPI int livebox_service_enumerate_category_list(const char *cluster, int (*cb)(const char *cluster, const char *category, void *data), void *data)
1584 const char *category;
1588 if (!cluster || !cb)
1595 ret = sqlite3_prepare_v2(handle, "SELECT DISTINCT category FROM groupinfo WHERE cluster = ?", -1, &stmt, NULL);
1596 if (ret != SQLITE_OK) {
1597 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1603 while (sqlite3_step(stmt) == SQLITE_ROW) {
1604 category = (const char *)sqlite3_column_text(stmt, 0);
1605 if (!category || !strlen(category))
1608 if (cb(cluster, category, data) < 0)
1614 sqlite3_reset(stmt);
1615 sqlite3_finalize(stmt);
1621 EAPI int livebox_service_init(void)
1623 if (s_info.handle) {
1624 DbgPrint("Already initialized\n");
1625 s_info.init_count++;
1629 s_info.handle = open_db();
1630 if (s_info.handle) {
1631 s_info.init_count++;
1638 EAPI int livebox_service_fini(void)
1640 if (!s_info.handle || s_info.init_count <= 0) {
1641 ErrPrint("Service is not initialized\n");
1645 s_info.init_count--;
1646 if (s_info.init_count > 0) {
1647 DbgPrint("Init count %d\n", s_info.init_count);
1651 db_util_close(s_info.handle);
1652 s_info.handle = NULL;
1656 EAPI int livebox_service_get_size(int type, int *width, int *height)
1667 return convert_size_from_type(type, width, height);
1670 EAPI int livebox_service_size_type(int width, int height)
1674 if (update_resolution() < 0)
1675 ErrPrint("Failed to update the size list\n");
1677 for (idx = 0; idx < NR_OF_SIZE_LIST; idx++) {
1678 if (SIZE_LIST[idx].w == width && SIZE_LIST[idx].h == height)
1684 return LB_SIZE_TYPE_1x1;
1686 return LB_SIZE_TYPE_2x1;
1688 return LB_SIZE_TYPE_2x2;
1690 return LB_SIZE_TYPE_4x1;
1692 return LB_SIZE_TYPE_4x2;
1694 return LB_SIZE_TYPE_4x3;
1696 return LB_SIZE_TYPE_4x4;
1701 return LB_SIZE_TYPE_UNKNOWN;