2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.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>
34 #include <pkgmgr-info.h>
36 #include <vconf-keys.h>
42 #include "livebox-service.h"
43 #include "livebox-errno.h"
45 #define SAMSUNG_PREFIX "com.samsung."
46 #define EAPI __attribute__((visibility("default")))
47 #define DEFAULT_TIMEOUT 2.0
50 static struct supported_size_list {
53 } SIZE_LIST[NR_OF_SIZE_LIST] = {
54 { 175, 175 }, /*!< 1x1 */
55 { 354, 175 }, /*!< 2x1 */
56 { 354, 354 }, /*!< 2x2 */
57 { 712, 175 }, /*!< 4x1 */
58 { 712, 354 }, /*!< 4x2 */
59 { 712, 533 }, /*!< 4x3 */
60 { 712, 712 }, /*!< 4x4 */
61 { 712, 891 }, /*!< 4x5 */
62 { 712, 1070 }, /*!< 4x6 */
63 { 207, 207 }, /*!< 21x21 */
64 { 645, 207 }, /*!< 23x21 */
65 { 645, 645 }, /*!< 23x23 */
66 { 720, 1280 }, /*!< 0x0 */
72 const char *conf_file;
77 .dbfile = "/opt/dbspace/.livebox.db",
78 .conf_file = "/usr/share/data-provider-master/resolution.ini",
83 static inline int update_info(int width_type, int height_type, int width, int height)
87 if (width_type == 1 && height_type == 1) {
88 DbgPrint("1x1 Updated to %dx%d\n", width, height);
90 } else if (width_type == 2 && height_type == 1) {
91 DbgPrint("2x1 Updated to %dx%d\n", width, height);
93 } else if (width_type == 2 && height_type == 2) {
94 DbgPrint("2x2 Updated to %dx%d\n", width, height);
96 } else if (width_type == 4 && height_type == 1) {
97 DbgPrint("4x1 Updated to %dx%d\n", width, height);
99 } else if (width_type == 4 && height_type == 2) {
100 DbgPrint("4x2 Updated to %dx%d\n", width, height);
102 } else if (width_type == 4 && height_type == 3) {
103 DbgPrint("4x3 Updated to %dx%d\n", width, height);
105 } else if (width_type == 4 && height_type == 4) {
106 DbgPrint("4x4 Updated to %dx%d\n", width, height);
108 } else if (width_type == 4 && height_type == 5) {
109 DbgPrint("4x5 Updated to %dx%d\n", width, height);
111 } else if (width_type == 4 && height_type == 6) {
112 DbgPrint("4x6 Updated to %dx%d\n", width, height);
114 } else if (width_type == 21 && height_type == 21) {
115 DbgPrint("Easy 1x1 Updated to %dx%d\n", width, height);
117 } else if (width_type == 23 && height_type == 21) {
118 DbgPrint("Easy 3x1 Updated to %dx%d\n", width, height);
120 } else if (width_type == 23 && height_type == 23) {
121 DbgPrint("Easy 3x3 Updated to %dx%d\n", width, height);
123 } else if (width_type == 0 && height_type == 0) {
124 DbgPrint("Special 0x0 Updated to %dx%d\n", width, height);
127 ErrPrint("Unknown size type: %dx%d (%dx%d)\n", width_type, height_type, width, height);
131 SIZE_LIST[idx].w = width;
132 SIZE_LIST[idx].h = height;
136 static inline int update_from_file(void)
144 char buffer[MAX_COLUMN];
158 fp = fopen(s_info.conf_file, "r");
160 ErrPrint("Open failed: %s\n", strerror(errno));
161 return LB_STATUS_ERROR_IO;
170 if (idx == MAX_COLUMN) {
171 ErrPrint("Buffer overflow. Too long line. LINE MUST BE SHOT THAN %d\n", MAX_COLUMN);
177 if (isspace(ch) || ch == EOF)
192 if (sscanf(buffer, "%dx%d", &width_type, &height_type) != 2) {
193 ErrPrint("Invalid syntax: [%s]\n", buffer);
197 } else if (ch == '=') {
200 if (sscanf(buffer, "%dx%d", &width_type, &height_type) != 2) {
201 ErrPrint("Invalid syntax: [%s]\n", buffer);
205 } else if (ch == EOF) {
206 ErrPrint("Invalid Syntax\n");
217 if (isspace(ch) || ch == EOF)
225 if (isspace(ch) || ch == EOF) {
229 if (sscanf(buffer, "%dx%d", &width, &height) != 2) {
230 ErrPrint("Invalid syntax: [%s]\n", buffer);
232 } else if (ch == EOF) {
233 updated += update_info(width_type, height_type, width, height);
240 updated += update_info(width_type, height_type, width, height);
245 if (ch == '\n' || ch == '\r' || ch == '\f')
249 if (ch == '\n' || ch == '\r' || ch == '\f')
253 ErrPrint("Unknown status. couldn't be reach to here\n");
259 return NR_OF_SIZE_LIST - updated;
262 static int update_resolution(void)
274 if (s_info.res_resolved)
275 return LB_STATUS_SUCCESS;
277 disp = XOpenDisplay(NULL);
279 ErrPrint("Failed to open a display\n");
280 return LB_STATUS_ERROR_FAULT;
283 root = XDefaultRootWindow(disp);
284 if (!XGetGeometry(disp, root, &dummy, &x, &y, &width, &height, &border, &depth)) {
286 return LB_STATUS_ERROR_FAULT;
289 if (update_from_file() == 0)
290 DbgPrint("Resolution info is all updated by file\n");
292 DbgPrint("Screen resolution: %dx%d\n", width, height);
293 for (i = 0; i < NR_OF_SIZE_LIST; i++) {
294 SIZE_LIST[i].w = (unsigned int)((double)SIZE_LIST[i].w * (double)width / 720.0f);
295 SIZE_LIST[i].h = (unsigned int)((double)SIZE_LIST[i].h * (double)width / 720.0f);
296 DbgPrint("(Ratio)Size is updated [%d] %dx%d\n", i, SIZE_LIST[i].w, SIZE_LIST[i].h);
300 s_info.res_resolved = 1;
301 return LB_STATUS_SUCCESS;
304 static inline sqlite3 *open_db(void)
308 if (!s_info.handle) {
311 ret = db_util_open(s_info.dbfile, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
312 if (ret != SQLITE_OK) {
313 ErrPrint("Failed to open a DB\n");
317 handle = s_info.handle;
323 static inline void close_db(sqlite3 *handle)
326 db_util_close(handle);
329 static inline int convert_size_from_type(enum livebox_size_type type, int *width, int *height)
334 case LB_SIZE_TYPE_1x1: /*!< 175x175 */
337 case LB_SIZE_TYPE_2x1: /*!< 354x175 */
340 case LB_SIZE_TYPE_2x2: /*!< 354x354 */
343 case LB_SIZE_TYPE_4x1: /*!< 712x175 */
346 case LB_SIZE_TYPE_4x2: /*!< 712x354 */
349 case LB_SIZE_TYPE_4x3: /*!< 712x533 */
352 case LB_SIZE_TYPE_4x4: /*!< 712x712 */
355 case LB_SIZE_TYPE_4x5: /*!< 712x891 */
358 case LB_SIZE_TYPE_4x6: /*!< 712x1070 */
361 case LB_SIZE_TYPE_EASY_1x1: /*< 207x207 */
364 case LB_SIZE_TYPE_EASY_3x1: /*!< 645x207 */
367 case LB_SIZE_TYPE_EASY_3x3: /*!< 645x645 */
370 case LB_SIZE_TYPE_0x0: /*!< 720x1280 */
374 return LB_STATUS_ERROR_INVALID;
377 if (update_resolution() < 0)
378 ErrPrint("Failed to update resolution\n");
380 *width = SIZE_LIST[idx].w;
381 *height = SIZE_LIST[idx].h;
382 return LB_STATUS_SUCCESS;
385 EAPI int livebox_service_change_period(const char *pkgname, const char *id, double period)
387 struct packet *packet;
388 struct packet *result;
392 if (!pkgname || !id || period < 0.0f) {
393 ErrPrint("Invalid argument\n");
394 return LB_STATUS_ERROR_INVALID;
397 uri = util_id_to_uri(id);
399 return LB_STATUS_ERROR_MEMORY;
401 packet = packet_create("service_change_period", "ssd", pkgname, uri, period);
404 ErrPrint("Failed to create a packet for period changing\n");
405 return LB_STATUS_ERROR_FAULT;
408 result = com_core_packet_oneshot_send(SERVICE_SOCKET, packet, DEFAULT_TIMEOUT);
409 packet_unref(packet);
412 if (packet_get(result, "i", &ret) != 1) {
413 ErrPrint("Failed to parse a result packet\n");
414 ret = LB_STATUS_ERROR_INVALID;
416 packet_unref(result);
418 ErrPrint("Failed to get result packet\n");
419 ret = LB_STATUS_ERROR_FAULT;
425 EAPI int livebox_service_trigger_update(const char *pkgname, const char *id, const char *cluster, const char *category, int force)
427 struct packet *packet;
428 struct packet *result;
433 ErrPrint("Invalid argument\n");
434 return LB_STATUS_ERROR_INVALID;
437 if (!force && access("/tmp/.live.paused", R_OK) == 0) {
438 DbgPrint("Provider is paused\n");
439 return LB_STATUS_ERROR_CANCEL;
442 uri = util_id_to_uri(id);
444 return LB_STATUS_ERROR_MEMORY;
447 cluster = "user,created";
450 category = "default";
452 packet = packet_create("service_update", "ssss", pkgname, uri, cluster, category);
455 ErrPrint("Failed to create a packet for service_update\n");
456 return LB_STATUS_ERROR_FAULT;
459 result = com_core_packet_oneshot_send(SERVICE_SOCKET, packet, DEFAULT_TIMEOUT);
460 packet_unref(packet);
463 if (packet_get(result, "i", &ret) != 1) {
464 ErrPrint("Failed to parse a result packet\n");
465 ret = LB_STATUS_ERROR_INVALID;
468 packet_unref(result);
470 ErrPrint("Failed to get result packet\n");
471 ret = LB_STATUS_ERROR_FAULT;
477 EAPI int livebox_service_get_pkglist(int (*cb)(const char *appid, const char *pkgname, int is_prime, void *data), void *data)
487 return LB_STATUS_ERROR_INVALID;
491 return LB_STATUS_ERROR_IO;
493 ret = sqlite3_prepare_v2(handle, "SELECT appid, pkgid, prime FROM pkgmap", -1, &stmt, NULL);
494 if (ret != SQLITE_OK) {
495 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
496 ret = LB_STATUS_ERROR_IO;
501 while (sqlite3_step(stmt) == SQLITE_ROW) {
502 appid = (char *)sqlite3_column_text(stmt, 0);
503 if (!appid || !strlen(appid)) {
504 ErrPrint("APPID is not valid\n");
508 pkgid = (char *)sqlite3_column_text(stmt, 1);
509 if (!pkgid || !strlen(pkgid)) {
510 ErrPrint("pkgid is not valid\n");
514 is_prime = sqlite3_column_int(stmt, 2);
518 if (cb(appid, pkgid, is_prime, data) < 0) {
519 DbgPrint("Callback stopped package crawling\n");
525 sqlite3_finalize(stmt);
532 EAPI int livebox_service_get_pkglist_by_pkgid(const char *pkgid, int (*cb)(const char *lbid, int is_prime, void *data), void *data)
541 return LB_STATUS_ERROR_INVALID;
545 return LB_STATUS_ERROR_IO;
547 ret = sqlite3_prepare_v2(handle, "SELECT pkgid, prime FROM pkgmap WHERE appid = ?", -1, &stmt, NULL);
548 if (ret != SQLITE_OK) {
549 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
550 ret = LB_STATUS_ERROR_IO;
554 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
555 if (ret != SQLITE_OK) {
556 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
558 sqlite3_finalize(stmt);
559 ret = LB_STATUS_ERROR_IO;
564 while (sqlite3_step(stmt) == SQLITE_ROW) {
565 lbid = (const char *)sqlite3_column_text(stmt, 0);
566 if (!lbid || !strlen(lbid)) {
567 ErrPrint("LBID is not valid\n");
571 is_prime = sqlite3_column_int(stmt, 1);
575 if (cb(lbid, is_prime, data) < 0) {
576 DbgPrint("Callback stopped package crawling\n");
582 sqlite3_finalize(stmt);
589 struct pkgmgr_cbdata {
591 void (*cb)(const char *lbid, const char *appid, void *data);
595 static int pkgmgr_cb(const pkgmgrinfo_appinfo_h handle, void *user_data)
597 struct pkgmgr_cbdata *cbdata = (struct pkgmgr_cbdata *)user_data;
601 ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
603 ErrPrint("Unable to get appid\n");
605 cbdata->cb(cbdata->lbid, appid, cbdata->cbdata);
610 static inline char *pkgmgr_get_mainapp(const char *pkgid)
612 pkgmgrinfo_pkginfo_h handle;
615 if (pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle) != PMINFO_R_OK) {
616 ErrPrint("Unable to get mainapp: %s\n", pkgid);
620 if (pkgmgrinfo_pkginfo_get_mainappid(handle, &ret) == PMINFO_R_OK) {
623 ErrPrint("Failed to get mainappid\n");
624 ret = NULL; /* I cannot believe the pkgmgrinfo_pkginfo_get_mainappid. it maybe able to touch my "ret" even though it fails */
628 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
632 static inline int pkgmgr_get_applist(const char *pkgid, const char *lbid, void (*cb)(const char *lbid, const char *appid, void *data), void *data)
634 struct pkgmgr_cbdata cbdata;
635 pkgmgrinfo_pkginfo_h handle;
638 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
640 ErrPrint("Unable to get pkginfo: %s\n", pkgid);
646 cbdata.cbdata = data;
648 ret = pkgmgrinfo_appinfo_get_list(handle, PM_UI_APP, pkgmgr_cb, &cbdata);
650 ErrPrint("Failed to get applist\n");
652 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
656 EAPI int livebox_service_get_applist(const char *lbid, void (*cb)(const char *lbid, const char *appid, void *data), void *data)
665 return LB_STATUS_ERROR_INVALID;
669 return LB_STATUS_ERROR_IO;
671 ret = sqlite3_prepare_v2(handle, "SELECT appid FROM pkgmap WHERE (pkgid = ?) or (appid = ?)", -1, &stmt, NULL);
672 if (ret != SQLITE_OK) {
673 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
674 ret = LB_STATUS_ERROR_IO;
678 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
679 if (ret != SQLITE_OK) {
680 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
681 ret = LB_STATUS_ERROR_IO;
685 ret = sqlite3_bind_text(stmt, 2, lbid, -1, SQLITE_TRANSIENT);
686 if (ret != SQLITE_OK) {
687 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
688 ret = LB_STATUS_ERROR_IO;
692 if (sqlite3_step(stmt) != SQLITE_ROW) {
693 ret = LB_STATUS_ERROR_INVALID;
695 sqlite3_finalize(stmt);
699 tmp = (const char *)sqlite3_column_text(stmt, 0);
700 if (!tmp || !strlen(tmp)) {
701 ErrPrint("Invalid package name (%s)\n", lbid);
702 ret = LB_STATUS_ERROR_INVALID;
704 sqlite3_finalize(stmt);
710 ErrPrint("Error: %s\n", strerror(errno));
711 ret = LB_STATUS_ERROR_MEMORY;
713 sqlite3_finalize(stmt);
718 sqlite3_finalize(stmt);
720 ret = pkgmgr_get_applist(pkgid, lbid, cb, data);
728 EAPI char *livebox_service_mainappid(const char *lbid)
743 if (sqlite3_prepare_v2(handle, "SELECT appid, uiapp FROM pkgmap WHERE (pkgid = ?) or (appid = ? and prime = 1)", -1, &stmt, NULL) != SQLITE_OK) {
744 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
748 if (sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
749 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
753 if (sqlite3_bind_text(stmt, 2, lbid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
754 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
758 if (sqlite3_step(stmt) != SQLITE_ROW) {
760 sqlite3_finalize(stmt);
764 tmp = (const char *)sqlite3_column_text(stmt, 0);
765 if (!tmp || !strlen(tmp)) {
766 ErrPrint("Invalid package name (%s)\n", lbid);
768 sqlite3_finalize(stmt);
772 pkgid = (const char *)sqlite3_column_text(stmt, 1);
773 if (!pkgid || !strlen(pkgid)) {
775 * This record has no uiapp.
776 * Try to find the main ui-app id.
778 ret = pkgmgr_get_mainapp(tmp);
782 ErrPrint("Error: %s\n", strerror(errno));
786 sqlite3_finalize(stmt);
793 EAPI int livebox_service_get_supported_size_types(const char *pkgid, int *cnt, int *types)
800 if (!types || !cnt || !pkgid)
801 return LB_STATUS_ERROR_INVALID;
805 return LB_STATUS_ERROR_IO;
807 ret = sqlite3_prepare_v2(handle, "SELECT size_type FROM box_size WHERE pkgid = ? ORDER BY size_type ASC", -1, &stmt, NULL);
808 if (ret != SQLITE_OK) {
809 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
810 ret = LB_STATUS_ERROR_IO;
814 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
815 if (ret != SQLITE_OK) {
816 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
818 sqlite3_finalize(stmt);
819 ret = LB_STATUS_ERROR_IO;
823 if (*cnt > NR_OF_SIZE_LIST)
824 *cnt = NR_OF_SIZE_LIST;
827 while (sqlite3_step(stmt) == SQLITE_ROW && ret < *cnt) {
828 size = sqlite3_column_int(stmt, 0);
835 sqlite3_finalize(stmt);
842 static inline char *cur_locale(void)
845 language = vconf_get_str(VCONFKEY_LANGSET);
862 language = strdup("en-us");
864 ErrPrint("Heap: %s\n", strerror(errno));
870 static inline char *get_default_name(const char *pkgid)
881 ret = sqlite3_prepare_v2(handle, "SELECT name FROM client WHERE pkgid = ?", -1, &stmt, NULL);
882 if (ret != SQLITE_OK) {
883 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
888 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
889 if (ret != SQLITE_OK) {
890 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
894 ret = sqlite3_step(stmt);
895 if (ret == SQLITE_ROW) {
898 tmp = (const char *)sqlite3_column_text(stmt, 0);
899 if (tmp && strlen(tmp)) {
902 ErrPrint("Heap: %s\n", strerror(errno));
908 sqlite3_finalize(stmt);
913 static inline char *get_default_icon(const char *pkgid)
924 ret = sqlite3_prepare_v2(handle, "SELECT icon FROM client WHERE pkgid = ?", -1, &stmt, NULL);
925 if (ret != SQLITE_OK) {
926 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
931 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
932 if (ret != SQLITE_OK) {
933 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
937 ret = sqlite3_step(stmt);
938 if (ret == SQLITE_ROW) {
941 tmp = (const char *)sqlite3_column_text(stmt, 0);
942 if (tmp && strlen(tmp)) {
945 ErrPrint("Heap: %s\n", strerror(errno));
951 sqlite3_finalize(stmt);
956 EAPI char *livebox_service_content(const char *pkgid)
960 char *content = NULL;
967 ret = sqlite3_prepare_v2(handle, "SELECT content FROM client WHERE pkgid = ?", -1, &stmt, NULL);
968 if (ret != SQLITE_OK) {
969 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
974 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
975 if (ret != SQLITE_OK) {
976 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
980 ret = sqlite3_step(stmt);
981 if (ret == SQLITE_ROW) {
984 tmp = (const char *)sqlite3_column_text(stmt, 0);
985 if (tmp && strlen(tmp)) {
986 content = strdup(tmp);
988 ErrPrint("Heap: %s\n", strerror(errno));
994 sqlite3_finalize(stmt);
999 EAPI char *livebox_service_setup_appid(const char *lbid)
1010 ret = sqlite3_prepare_v2(handle, "SELECT setup FROM client WHERE pkgid = ?", -1, &stmt, NULL);
1011 if (ret != SQLITE_OK) {
1012 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1018 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
1019 if (ret != SQLITE_OK) {
1020 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1024 ret = sqlite3_step(stmt);
1025 if (ret == SQLITE_ROW) {
1028 tmp = (const char *)sqlite3_column_text(stmt, 0);
1029 if (!tmp || !strlen(tmp))
1032 appid = strdup(tmp);
1034 ErrPrint("Error: %s\n", strerror(errno));
1038 sqlite3_reset(stmt);
1039 sqlite3_finalize(stmt);
1044 EAPI int livebox_service_nodisplay(const char *pkgid)
1054 ret = sqlite3_prepare_v2(handle, "SELECT nodisplay FROM client WHERE pkgid = ?", -1, &stmt, NULL);
1055 if (ret != SQLITE_OK) {
1056 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1061 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1062 if (ret != SQLITE_OK) {
1063 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1068 ret = sqlite3_step(stmt);
1069 if (ret == SQLITE_ROW)
1070 ret = !!sqlite3_column_int(stmt, 0);
1075 sqlite3_reset(stmt);
1076 sqlite3_finalize(stmt);
1081 static inline char *get_lb_pkgname_by_appid(const char *appid)
1097 ret = sqlite3_prepare_v2(handle, "SELECT pkgid FROM pkgmap WHERE (appid = ? AND prime = 1) OR pkgid = ?", -1, &stmt, NULL);
1098 if (ret != SQLITE_OK) {
1099 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1104 ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT);
1105 if (ret != SQLITE_OK) {
1106 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1110 ret = sqlite3_bind_text(stmt, 2, appid, -1, SQLITE_TRANSIENT);
1111 if (ret != SQLITE_OK) {
1112 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1116 if (sqlite3_step(stmt) != SQLITE_ROW) {
1117 ErrPrint("Error: %s (has no record? - %s)\n", sqlite3_errmsg(handle), appid);
1121 tmp = (char *)sqlite3_column_text(stmt, 0);
1122 if (tmp && strlen(tmp)) {
1123 pkgid = strdup(tmp);
1125 ErrPrint("Heap: %s\n", strerror(errno));
1129 sqlite3_reset(stmt);
1130 sqlite3_finalize(stmt);
1135 EAPI int livebox_service_need_frame(const char *pkgid, int size_type)
1144 ErrPrint("Unable to open a DB\n");
1148 ret = sqlite3_prepare_v2(handle, "SELECT need_frame FROM box_size WHERE pkgid = ? AND size_type = ?", -1, &stmt, NULL);
1149 if (ret != SQLITE_OK) {
1150 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1157 lbid = livebox_service_pkgname(pkgid);
1159 ErrPrint("Invalid appid (%s)\n", pkgid);
1164 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
1166 if (ret != SQLITE_OK) {
1167 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1172 ret = sqlite3_bind_int(stmt, 2, size_type);
1173 if (ret != SQLITE_OK) {
1174 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1179 ret = sqlite3_step(stmt);
1180 if (ret == SQLITE_ROW) {
1181 ret = !!sqlite3_column_int(stmt, 0);
1184 ErrPrint("There is no such result\n");
1187 sqlite3_reset(stmt);
1188 sqlite3_finalize(stmt);
1193 EAPI int livebox_service_touch_effect(const char *pkgid, int size_type)
1202 ErrPrint("Unable to open a DB\n");
1206 ret = sqlite3_prepare_v2(handle, "SELECT touch_effect FROM box_size WHERE pkgid = ? AND size_type = ?", -1, &stmt, NULL);
1207 if (ret != SQLITE_OK) {
1208 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1215 * This function will validate the "pkgid"
1216 * call the exported API in the exported API is not recomended
1219 lbid = livebox_service_pkgname(pkgid);
1221 ErrPrint("Invalid appid (%s)\n", pkgid);
1226 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
1228 if (ret != SQLITE_OK) {
1229 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1234 ret = sqlite3_bind_int(stmt, 2, size_type);
1235 if (ret != SQLITE_OK) {
1236 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1241 ret = sqlite3_step(stmt);
1242 if (ret == SQLITE_ROW) {
1243 ret = !!sqlite3_column_int(stmt, 0);
1245 ret = 1; /*!< Default true: In this case the DB is corrupted. */
1246 ErrPrint("There is no result\n");
1250 sqlite3_reset(stmt);
1251 sqlite3_finalize(stmt);
1256 EAPI int livebox_service_mouse_event(const char *pkgid)
1267 ret = sqlite3_prepare_v2(handle, "SELECT mouse_event FROM client WHERE pkgid = ?", -1, &stmt, NULL);
1268 if (ret != SQLITE_OK) {
1269 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1274 lbid = livebox_service_pkgname(pkgid);
1276 ErrPrint("Failed to get lbid: %s\n", pkgid);
1281 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
1283 if (ret != SQLITE_OK) {
1284 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1289 ret = sqlite3_step(stmt);
1290 if (ret == SQLITE_ROW) {
1291 ret = !!sqlite3_column_int(stmt, 0);
1293 ret = 0; /*!< Default is false, In this case the DB is corrupted */
1294 ErrPrint("There is no result.\n");
1298 sqlite3_reset(stmt);
1299 sqlite3_finalize(stmt);
1304 EAPI char *livebox_service_preview(const char *pkgid, int size_type)
1309 char *preview = NULL;
1315 ret = sqlite3_prepare_v2(handle, "SELECT preview FROM box_size WHERE pkgid = ? AND size_type = ?", -1, &stmt, NULL);
1316 if (ret != SQLITE_OK) {
1317 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1322 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1323 if (ret != SQLITE_OK) {
1324 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1328 ret = sqlite3_bind_int(stmt, 2, size_type);
1329 if (ret != SQLITE_OK) {
1330 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1334 ret = sqlite3_step(stmt);
1335 if (ret == SQLITE_ROW) {
1337 tmp = (const char *)sqlite3_column_text(stmt, 0);
1338 if (tmp && strlen(tmp)) {
1339 preview = strdup(tmp);
1341 ErrPrint("Heap: %s\n", strerror(errno));
1346 sqlite3_reset(stmt);
1347 sqlite3_finalize(stmt);
1352 EAPI char *livebox_service_i18n_icon(const char *pkgid, const char *lang)
1361 language = strdup(lang);
1363 ErrPrint("Heap: %s\n", strerror(errno));
1367 language = cur_locale();
1378 ret = sqlite3_prepare_v2(handle, "SELECT icon FROM i18n WHERE pkgid = ? AND lang = ?", -1, &stmt, NULL);
1379 if (ret != SQLITE_OK) {
1380 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1386 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1387 if (ret != SQLITE_OK) {
1388 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1392 ret = sqlite3_bind_text(stmt, 2, language, -1, SQLITE_TRANSIENT);
1393 if (ret != SQLITE_OK) {
1394 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1398 ret = sqlite3_step(stmt);
1399 if (ret == SQLITE_ROW) {
1401 tmp = (const char *)sqlite3_column_text(stmt, 0);
1402 if (!tmp || !strlen(tmp)) {
1403 icon = get_default_icon(pkgid);
1407 ErrPrint("Heap: %s\n", strerror(errno));
1410 icon = get_default_icon(pkgid);
1414 sqlite3_reset(stmt);
1415 sqlite3_finalize(stmt);
1421 EAPI char *livebox_service_i18n_name(const char *pkgid, const char *lang)
1430 language = strdup(lang);
1432 ErrPrint("Error: %s\n", strerror(errno));
1436 language = cur_locale();
1447 ret = sqlite3_prepare_v2(handle, "SELECT name FROM i18n WHERE pkgid = ? AND lang = ?", -1, &stmt, NULL);
1448 if (ret != SQLITE_OK) {
1449 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1455 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1456 if (ret != SQLITE_OK) {
1457 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1461 ret = sqlite3_bind_text(stmt, 2, language, -1, SQLITE_TRANSIENT);
1462 if (ret != SQLITE_OK) {
1463 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1467 ret = sqlite3_step(stmt);
1468 if (ret == SQLITE_ROW) {
1470 tmp = (const char *)sqlite3_column_text(stmt, 0);
1471 if (!tmp || !strlen(tmp)) {
1472 name = get_default_name(pkgid);
1476 ErrPrint("Heap: %s\n", strerror(errno));
1479 name = get_default_name(pkgid);
1483 sqlite3_reset(stmt);
1484 sqlite3_finalize(stmt);
1490 EAPI int livebox_service_get_supported_sizes(const char *pkgid, int *cnt, int *w, int *h)
1497 if (!w || !h || !cnt || !pkgid)
1498 return LB_STATUS_ERROR_INVALID;
1502 return LB_STATUS_ERROR_IO;
1504 ret = sqlite3_prepare_v2(handle, "SELECT size_type FROM box_size WHERE pkgid = ? ORDER BY size_type ASC", -1, &stmt, NULL);
1505 if (ret != SQLITE_OK) {
1506 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1507 ret = LB_STATUS_ERROR_IO;
1511 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1512 if (ret != SQLITE_OK) {
1513 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1514 sqlite3_reset(stmt);
1515 sqlite3_finalize(stmt);
1516 ret = LB_STATUS_ERROR_IO;
1520 if (*cnt > NR_OF_SIZE_LIST)
1521 *cnt = NR_OF_SIZE_LIST;
1524 while (sqlite3_step(stmt) == SQLITE_ROW && ret < *cnt) {
1525 size = sqlite3_column_int(stmt, 0);
1526 ret += (convert_size_from_type(size, w + ret, h + ret) == 0);
1530 sqlite3_reset(stmt);
1531 sqlite3_finalize(stmt);
1538 EAPI char *livebox_service_libexec(const char *pkgid)
1555 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.libexec FROM pkgmap, provider WHERE pkgmap.pkgid = ? AND provider.pkgid = ?", -1, &stmt, NULL);
1556 if (ret != SQLITE_OK) {
1557 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1561 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1562 if (ret != SQLITE_OK) {
1563 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1564 sqlite3_finalize(stmt);
1568 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1569 if (ret != SQLITE_OK) {
1570 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1571 sqlite3_finalize(stmt);
1575 if (sqlite3_step(stmt) != SQLITE_ROW) {
1576 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1577 sqlite3_reset(stmt);
1578 sqlite3_finalize(stmt);
1580 libexec = util_conf_get_libexec(pkgid);
1581 DbgPrint("Fallback to conf checker: %s\n", libexec);
1585 appid = (char *)sqlite3_column_text(stmt, 0);
1586 if (!appid || !strlen(appid)) {
1587 ErrPrint("Invalid appid: %s\n", sqlite3_errmsg(handle));
1588 sqlite3_reset(stmt);
1589 sqlite3_finalize(stmt);
1593 path = (char *)sqlite3_column_text(stmt, 1);
1594 if (!path || !strlen(path)) {
1595 ErrPrint("Invalid libexec: %s\n", sqlite3_errmsg(handle));
1596 sqlite3_reset(stmt);
1597 sqlite3_finalize(stmt);
1601 libexec = strdup(path);
1603 ErrPrint("Heap: %s\n", strerror(errno));
1604 sqlite3_reset(stmt);
1605 sqlite3_finalize(stmt);
1609 DbgPrint("libexec: %s\n", libexec);
1611 sqlite3_reset(stmt);
1612 sqlite3_finalize(stmt);
1618 EAPI char *livebox_service_pkgname(const char *appid)
1621 pkgmgr_appinfo_h handle;
1628 lb_pkgname = get_lb_pkgname_by_appid(appid);
1634 * Try to get the package id using given appid
1636 ret = pkgmgr_appinfo_get_appinfo(appid, &handle);
1637 if (ret != PKGMGR_R_OK) {
1638 ErrPrint("Failed to get appinfo\n");
1642 ret = pkgmgr_appinfo_get_pkgname(handle, &new_appid);
1643 if (ret != PKGMGR_R_OK) {
1644 pkgmgr_appinfo_destroy_appinfo(handle);
1645 ErrPrint("Failed to get pkgname for (%s)\n", appid);
1649 lb_pkgname = get_lb_pkgname_by_appid(new_appid);
1650 pkgmgr_appinfo_destroy_appinfo(handle);
1652 if (!lb_pkgname && util_validate_livebox_package(appid) == 0)
1653 return strdup(appid);
1658 EAPI char *livebox_service_provider_name(const char *lbid)
1664 char *str = SAMSUNG_PREFIX;
1669 while (str[idx] && lbid[idx] && lbid[idx] == str[idx]) {
1671 if (seq < 2 && lbid[idx] == '.') {
1677 if (!str[idx] && lbid[idx]) {
1679 return strdup(lbid);
1680 } else if (seq < 2) {
1682 if (lbid[idx] == '.') {
1684 } else if (!lbid[idx]) {
1685 ErrPrint("Invalid lbid: %s\n", lbid);
1697 ret = strdup(lbid + stage);
1699 ErrPrint("Error: %s\n", strerror(errno));
1706 EAPI int livebox_service_is_enabled(const char *lbid)
1715 pkgname = livebox_service_appid(lbid);
1719 ret = ail_get_appinfo(pkgname, &ai);
1720 if (ret != AIL_ERROR_OK) {
1725 if (ail_appinfo_get_bool(ai, AIL_PROP_X_SLP_ENABLED_BOOL, &enabled) != AIL_ERROR_OK)
1728 ail_destroy_appinfo(ai);
1730 return enabled == true;
1734 EAPI int livebox_service_is_primary(const char *lbid)
1747 ret = sqlite3_prepare_v2(handle, "SELECT prime FROM pkgmap WHERE pkgid = ?", -1, &stmt, NULL);
1748 if (ret != SQLITE_OK) {
1749 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1754 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
1755 if (ret != SQLITE_OK) {
1756 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1760 ret = sqlite3_step(stmt);
1761 if (ret != SQLITE_ROW) {
1762 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1766 ret = sqlite3_column_int(stmt, 0);
1769 sqlite3_reset(stmt);
1770 sqlite3_finalize(stmt);
1776 * appid == Package ID
1777 * pkgid == Livebox ID
1779 EAPI char *livebox_service_appid(const char *pkgname)
1785 int is_prime __attribute__((__unused__));
1796 ret = sqlite3_prepare_v2(handle, "SELECT appid, prime FROM pkgmap WHERE pkgid = ? OR appid = ?", -1, &stmt, NULL);
1797 if (ret != SQLITE_OK) {
1798 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1802 ret = sqlite3_bind_text(stmt, 1, pkgname, -1, SQLITE_TRANSIENT);
1803 if (ret != SQLITE_OK) {
1804 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1805 sqlite3_reset(stmt);
1806 sqlite3_finalize(stmt);
1810 ret = sqlite3_bind_text(stmt, 2, pkgname, -1, SQLITE_TRANSIENT);
1811 if (ret != SQLITE_OK) {
1812 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1813 sqlite3_reset(stmt);
1814 sqlite3_finalize(stmt);
1818 ret = sqlite3_step(stmt);
1819 if (ret != SQLITE_ROW) {
1820 pkgmgr_appinfo_h pkg_handle;
1823 ErrPrint("Has no record?: %s\n", sqlite3_errmsg(handle));
1824 sqlite3_reset(stmt);
1825 sqlite3_finalize(stmt);
1827 ret = pkgmgr_appinfo_get_appinfo(pkgname, &pkg_handle);
1828 if (ret != PKGMGR_R_OK) {
1829 ErrPrint("Failed to get appinfo: %s\n", pkgname);
1833 ret = pkgmgr_appinfo_get_pkgname(pkg_handle, &new_appid);
1834 if (ret != PKGMGR_R_OK) {
1835 ErrPrint("Failed to get pkgname for (%s)\n", appid);
1836 pkgmgr_appinfo_destroy_appinfo(pkg_handle);
1840 appid = strdup(new_appid);
1842 ErrPrint("Heap: %s\n", strerror(errno));
1844 pkgmgr_appinfo_destroy_appinfo(pkg_handle);
1848 tmp = (char *)sqlite3_column_text(stmt, 0);
1849 if (!tmp || !strlen(tmp)) {
1850 ErrPrint("APPID is NIL\n");
1851 sqlite3_reset(stmt);
1852 sqlite3_finalize(stmt);
1856 appid = strdup(tmp);
1858 ErrPrint("Heap: %s\n", strerror(errno));
1859 sqlite3_reset(stmt);
1860 sqlite3_finalize(stmt);
1864 is_prime = sqlite3_column_int(stmt, 1);
1866 sqlite3_reset(stmt);
1867 sqlite3_finalize(stmt);
1873 EAPI char *livebox_service_lb_script_path(const char *pkgid)
1890 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.box_src FROM provider, pkgmap WHERE pkgmap.pkgid = ? AND provider.pkgid = ?", -1, &stmt, NULL);
1891 if (ret != SQLITE_OK) {
1892 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1896 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1897 if (ret != SQLITE_OK) {
1898 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1899 sqlite3_finalize(stmt);
1903 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1904 if (ret != SQLITE_OK) {
1905 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1906 sqlite3_finalize(stmt);
1910 ret = sqlite3_step(stmt);
1911 if (ret != SQLITE_ROW) {
1912 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1913 sqlite3_reset(stmt);
1914 sqlite3_finalize(stmt);
1918 appid = (char *)sqlite3_column_text(stmt, 0);
1919 if (!appid || !strlen(appid)) {
1920 ErrPrint("Invalid appid : %s\n", sqlite3_errmsg(handle));
1921 sqlite3_reset(stmt);
1922 sqlite3_finalize(stmt);
1926 lb_src = (char *)sqlite3_column_text(stmt, 1);
1927 if (!lb_src || !strlen(lb_src)) {
1928 ErrPrint("No records for lb src : %s\n", sqlite3_errmsg(handle));
1929 sqlite3_reset(stmt);
1930 sqlite3_finalize(stmt);
1934 path = strdup(lb_src);
1936 ErrPrint("Heap: %s\n", strerror(errno));
1937 sqlite3_reset(stmt);
1938 sqlite3_finalize(stmt);
1942 DbgPrint("LB Src: %s\n", path);
1944 sqlite3_reset(stmt);
1945 sqlite3_finalize(stmt);
1951 EAPI char *livebox_service_lb_script_group(const char *pkgid)
1967 ret = sqlite3_prepare_v2(handle, "SELECT box_group FROM provider WHERE pkgid = ?", -1, &stmt, NULL);
1968 if (ret != SQLITE_OK) {
1969 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1973 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1974 if (ret != SQLITE_OK) {
1975 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1976 sqlite3_finalize(stmt);
1980 ret = sqlite3_step(stmt);
1981 if (ret != SQLITE_ROW) {
1982 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1983 sqlite3_reset(stmt);
1984 sqlite3_finalize(stmt);
1988 tmp = (char *)sqlite3_column_text(stmt, 0);
1989 if (tmp && strlen(tmp)) {
1990 group = strdup(tmp);
1992 ErrPrint("Heap: %s\n", strerror(errno));
1995 sqlite3_reset(stmt);
1996 sqlite3_finalize(stmt);
2002 EAPI char *livebox_service_pd_script_path(const char *pkgid)
2019 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.pd_src FROM provider, pkgmap WHERE provider.pkgid = ? AND pkgmap.pkgid = ?", -1, &stmt, NULL);
2020 if (ret != SQLITE_OK) {
2021 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2025 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
2026 if (ret != SQLITE_OK) {
2027 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2028 sqlite3_finalize(stmt);
2032 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
2033 if (ret != SQLITE_OK) {
2034 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2035 sqlite3_finalize(stmt);
2039 ret = sqlite3_step(stmt);
2040 if (ret != SQLITE_ROW) {
2041 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2042 sqlite3_reset(stmt);
2043 sqlite3_finalize(stmt);
2047 appid = (char *)sqlite3_column_text(stmt, 0);
2048 if (!appid || !strlen(appid)) {
2049 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2050 sqlite3_reset(stmt);
2051 sqlite3_finalize(stmt);
2055 pd_src = (char *)sqlite3_column_text(stmt, 1);
2056 if (!pd_src || !strlen(pd_src)) {
2057 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2058 sqlite3_reset(stmt);
2059 sqlite3_finalize(stmt);
2063 path = strdup(pd_src);
2065 ErrPrint("Heap: %s\n", strerror(errno));
2066 sqlite3_reset(stmt);
2067 sqlite3_finalize(stmt);
2071 DbgPrint("PD Src: %s\n", path);
2072 sqlite3_reset(stmt);
2073 sqlite3_finalize(stmt);
2079 EAPI char *livebox_service_pd_script_group(const char *pkgid)
2095 ret = sqlite3_prepare_v2(handle, "SELECT pd_group FROM provider WHERE pkgid = ?", -1, &stmt, NULL);
2096 if (ret != SQLITE_OK) {
2097 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2101 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
2102 if (ret != SQLITE_OK) {
2103 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2104 sqlite3_finalize(stmt);
2108 ret = sqlite3_step(stmt);
2109 if (ret != SQLITE_ROW) {
2110 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2111 sqlite3_reset(stmt);
2112 sqlite3_finalize(stmt);
2116 tmp = (char *)sqlite3_column_text(stmt, 0);
2117 if (tmp && strlen(tmp)) {
2118 group = strdup(tmp);
2120 ErrPrint("Heap: %s\n", strerror(errno));
2122 sqlite3_reset(stmt);
2123 sqlite3_finalize(stmt);
2129 EAPI int livebox_service_enumerate_cluster_list(int (*cb)(const char *cluster, void *data), void *data)
2133 const char *cluster;
2138 return LB_STATUS_ERROR_INVALID;
2142 return LB_STATUS_ERROR_IO;
2145 ret = sqlite3_prepare_v2(handle, "SELECT DISTINCT cluster FROM groupinfo", -1, &stmt, NULL);
2146 if (ret != SQLITE_OK) {
2147 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2148 cnt = LB_STATUS_ERROR_IO;
2152 while (sqlite3_step(stmt) == SQLITE_ROW) {
2153 cluster = (const char *)sqlite3_column_text(stmt, 0);
2154 if (!cluster || !strlen(cluster))
2157 if (cb(cluster, data) < 0)
2163 sqlite3_reset(stmt);
2164 sqlite3_finalize(stmt);
2170 EAPI int livebox_service_enumerate_category_list(const char *cluster, int (*cb)(const char *cluster, const char *category, void *data), void *data)
2174 const char *category;
2178 if (!cluster || !cb)
2179 return LB_STATUS_ERROR_INVALID;
2183 return LB_STATUS_ERROR_IO;
2185 ret = sqlite3_prepare_v2(handle, "SELECT DISTINCT category FROM groupinfo WHERE cluster = ?", -1, &stmt, NULL);
2186 if (ret != SQLITE_OK) {
2187 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2188 cnt = LB_STATUS_ERROR_IO;
2193 while (sqlite3_step(stmt) == SQLITE_ROW) {
2194 category = (const char *)sqlite3_column_text(stmt, 0);
2195 if (!category || !strlen(category))
2198 if (cb(cluster, category, data) < 0)
2204 sqlite3_reset(stmt);
2205 sqlite3_finalize(stmt);
2211 EAPI int livebox_service_init(void)
2213 if (s_info.handle) {
2214 DbgPrint("Already initialized\n");
2215 s_info.init_count++;
2219 s_info.handle = open_db();
2220 if (s_info.handle) {
2221 s_info.init_count++;
2225 return LB_STATUS_ERROR_IO;
2228 EAPI int livebox_service_fini(void)
2230 if (!s_info.handle || s_info.init_count <= 0) {
2231 ErrPrint("Service is not initialized\n");
2232 return LB_STATUS_ERROR_IO;
2235 s_info.init_count--;
2236 if (s_info.init_count > 0) {
2237 DbgPrint("Init count %d\n", s_info.init_count);
2241 db_util_close(s_info.handle);
2242 s_info.handle = NULL;
2246 EAPI int livebox_service_get_size(int type, int *width, int *height)
2257 return convert_size_from_type(type, width, height);
2260 EAPI int livebox_service_size_type(int width, int height)
2264 if (update_resolution() < 0)
2265 ErrPrint("Failed to update the size list\n");
2267 for (idx = 0; idx < NR_OF_SIZE_LIST; idx++) {
2268 if (SIZE_LIST[idx].w == width && SIZE_LIST[idx].h == height)
2274 return LB_SIZE_TYPE_1x1;
2276 return LB_SIZE_TYPE_2x1;
2278 return LB_SIZE_TYPE_2x2;
2280 return LB_SIZE_TYPE_4x1;
2282 return LB_SIZE_TYPE_4x2;
2284 return LB_SIZE_TYPE_4x3;
2286 return LB_SIZE_TYPE_4x4;
2288 return LB_SIZE_TYPE_4x5;
2290 return LB_SIZE_TYPE_4x6;
2292 return LB_SIZE_TYPE_EASY_1x1;
2294 return LB_SIZE_TYPE_EASY_3x1;
2296 return LB_SIZE_TYPE_EASY_3x3;
2298 return LB_SIZE_TYPE_0x0;
2303 return LB_SIZE_TYPE_UNKNOWN;