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 */
627 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
631 static inline int pkgmgr_get_applist(const char *pkgid, const char *lbid, void (*cb)(const char *lbid, const char *appid, void *data), void *data)
633 struct pkgmgr_cbdata cbdata;
634 pkgmgrinfo_pkginfo_h handle;
637 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
639 ErrPrint("Unable to get pkginfo: %s\n", pkgid);
645 cbdata.cbdata = data;
647 ret = pkgmgrinfo_appinfo_get_list(handle, PM_UI_APP, pkgmgr_cb, &cbdata);
649 ErrPrint("Failed to get applist\n");
651 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
655 EAPI int livebox_service_get_applist(const char *lbid, void (*cb)(const char *lbid, const char *appid, void *data), void *data)
664 return LB_STATUS_ERROR_INVALID;
668 return LB_STATUS_ERROR_IO;
670 ret = sqlite3_prepare_v2(handle, "SELECT appid FROM pkgmap WHERE (pkgid = ?) or (appid = ?)", -1, &stmt, NULL);
671 if (ret != SQLITE_OK) {
672 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
673 ret = LB_STATUS_ERROR_IO;
677 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
678 if (ret != SQLITE_OK) {
679 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
680 ret = LB_STATUS_ERROR_IO;
684 ret = sqlite3_bind_text(stmt, 2, lbid, -1, SQLITE_TRANSIENT);
685 if (ret != SQLITE_OK) {
686 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
687 ret = LB_STATUS_ERROR_IO;
691 if (sqlite3_step(stmt) != SQLITE_ROW) {
692 ret = LB_STATUS_ERROR_INVALID;
694 sqlite3_finalize(stmt);
698 tmp = (const char *)sqlite3_column_text(stmt, 0);
699 if (!tmp || !strlen(tmp)) {
700 ErrPrint("Invalid package name (%s)\n", lbid);
701 ret = LB_STATUS_ERROR_INVALID;
703 sqlite3_finalize(stmt);
709 ErrPrint("Error: %s\n", strerror(errno));
710 ret = LB_STATUS_ERROR_MEMORY;
712 sqlite3_finalize(stmt);
717 sqlite3_finalize(stmt);
719 ret = pkgmgr_get_applist(pkgid, lbid, cb, data);
727 EAPI char *livebox_service_mainappid(const char *lbid)
742 if (sqlite3_prepare_v2(handle, "SELECT appid FROM pkgmap WHERE (pkgid = ?) or (appid = ?)", -1, &stmt, NULL) != SQLITE_OK) {
743 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
747 if (sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
748 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
752 if (sqlite3_bind_text(stmt, 2, lbid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
753 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
757 if (sqlite3_step(stmt) != SQLITE_ROW) {
759 sqlite3_finalize(stmt);
763 tmp = (const char *)sqlite3_column_text(stmt, 0);
764 if (!tmp || !strlen(tmp)) {
765 ErrPrint("Invalid package name (%s)\n", lbid);
767 sqlite3_finalize(stmt);
773 ErrPrint("Error: %s\n", strerror(errno));
775 sqlite3_finalize(stmt);
780 sqlite3_finalize(stmt);
782 ret = pkgmgr_get_mainapp(pkgid);
790 EAPI int livebox_service_get_supported_size_types(const char *pkgid, int *cnt, int *types)
797 if (!types || !cnt || !pkgid)
798 return LB_STATUS_ERROR_INVALID;
802 return LB_STATUS_ERROR_IO;
804 ret = sqlite3_prepare_v2(handle, "SELECT size_type FROM box_size WHERE pkgid = ? ORDER BY size_type ASC", -1, &stmt, NULL);
805 if (ret != SQLITE_OK) {
806 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
807 ret = LB_STATUS_ERROR_IO;
811 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
812 if (ret != SQLITE_OK) {
813 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
815 sqlite3_finalize(stmt);
816 ret = LB_STATUS_ERROR_IO;
820 if (*cnt > NR_OF_SIZE_LIST)
821 *cnt = NR_OF_SIZE_LIST;
824 while (sqlite3_step(stmt) == SQLITE_ROW && ret < *cnt) {
825 size = sqlite3_column_int(stmt, 0);
832 sqlite3_finalize(stmt);
839 static inline char *cur_locale(void)
842 language = vconf_get_str(VCONFKEY_LANGSET);
859 language = strdup("en-us");
861 ErrPrint("Heap: %s\n", strerror(errno));
867 static inline char *get_default_name(const char *pkgid)
878 ret = sqlite3_prepare_v2(handle, "SELECT name FROM client WHERE pkgid = ?", -1, &stmt, NULL);
879 if (ret != SQLITE_OK) {
880 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
885 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
886 if (ret != SQLITE_OK) {
887 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
891 ret = sqlite3_step(stmt);
892 if (ret == SQLITE_ROW) {
895 tmp = (const char *)sqlite3_column_text(stmt, 0);
896 if (tmp && strlen(tmp)) {
899 ErrPrint("Heap: %s\n", strerror(errno));
905 sqlite3_finalize(stmt);
910 static inline char *get_default_icon(const char *pkgid)
921 ret = sqlite3_prepare_v2(handle, "SELECT icon FROM client WHERE pkgid = ?", -1, &stmt, NULL);
922 if (ret != SQLITE_OK) {
923 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
928 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
929 if (ret != SQLITE_OK) {
930 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
934 ret = sqlite3_step(stmt);
935 if (ret == SQLITE_ROW) {
938 tmp = (const char *)sqlite3_column_text(stmt, 0);
939 if (tmp && strlen(tmp)) {
942 ErrPrint("Heap: %s\n", strerror(errno));
948 sqlite3_finalize(stmt);
953 EAPI char *livebox_service_content(const char *pkgid)
957 char *content = NULL;
964 ret = sqlite3_prepare_v2(handle, "SELECT content FROM client WHERE pkgid = ?", -1, &stmt, NULL);
965 if (ret != SQLITE_OK) {
966 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
971 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
972 if (ret != SQLITE_OK) {
973 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
977 ret = sqlite3_step(stmt);
978 if (ret == SQLITE_ROW) {
981 tmp = (const char *)sqlite3_column_text(stmt, 0);
982 if (tmp && strlen(tmp)) {
983 content = strdup(tmp);
985 ErrPrint("Heap: %s\n", strerror(errno));
991 sqlite3_finalize(stmt);
996 EAPI char *livebox_service_setup_appid(const char *lbid)
1007 ret = sqlite3_prepare_v2(handle, "SELECT setup FROM client WHERE pkgid = ?", -1, &stmt, NULL);
1008 if (ret != SQLITE_OK) {
1009 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1015 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
1016 if (ret != SQLITE_OK) {
1017 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1021 ret = sqlite3_step(stmt);
1022 if (ret == SQLITE_ROW) {
1025 tmp = (const char *)sqlite3_column_text(stmt, 0);
1026 if (!tmp || !strlen(tmp))
1029 appid = strdup(tmp);
1031 ErrPrint("Error: %s\n", strerror(errno));
1035 sqlite3_reset(stmt);
1036 sqlite3_finalize(stmt);
1041 EAPI int livebox_service_nodisplay(const char *pkgid)
1051 ret = sqlite3_prepare_v2(handle, "SELECT nodisplay FROM client WHERE pkgid = ?", -1, &stmt, NULL);
1052 if (ret != SQLITE_OK) {
1053 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1058 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1059 if (ret != SQLITE_OK) {
1060 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1065 ret = sqlite3_step(stmt);
1066 if (ret == SQLITE_ROW)
1067 ret = !!sqlite3_column_int(stmt, 0);
1072 sqlite3_reset(stmt);
1073 sqlite3_finalize(stmt);
1078 static inline char *get_lb_pkgname_by_appid(const char *appid)
1094 ret = sqlite3_prepare_v2(handle, "SELECT pkgid FROM pkgmap WHERE (appid = ? AND prime = 1) OR pkgid = ?", -1, &stmt, NULL);
1095 if (ret != SQLITE_OK) {
1096 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1101 ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT);
1102 if (ret != SQLITE_OK) {
1103 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1107 ret = sqlite3_bind_text(stmt, 2, appid, -1, SQLITE_TRANSIENT);
1108 if (ret != SQLITE_OK) {
1109 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1113 if (sqlite3_step(stmt) != SQLITE_ROW) {
1114 ErrPrint("Error: %s (has no record? - %s)\n", sqlite3_errmsg(handle), appid);
1118 tmp = (char *)sqlite3_column_text(stmt, 0);
1119 if (tmp && strlen(tmp)) {
1120 pkgid = strdup(tmp);
1122 ErrPrint("Heap: %s\n", strerror(errno));
1126 sqlite3_reset(stmt);
1127 sqlite3_finalize(stmt);
1132 EAPI int livebox_service_need_frame(const char *pkgid, int size_type)
1141 ErrPrint("Unable to open a DB\n");
1145 ret = sqlite3_prepare_v2(handle, "SELECT need_frame FROM box_size WHERE pkgid = ? AND size_type = ?", -1, &stmt, NULL);
1146 if (ret != SQLITE_OK) {
1147 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1154 lbid = livebox_service_pkgname(pkgid);
1156 ErrPrint("Invalid appid (%s)\n", pkgid);
1161 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
1163 if (ret != SQLITE_OK) {
1164 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1169 ret = sqlite3_bind_int(stmt, 2, size_type);
1170 if (ret != SQLITE_OK) {
1171 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1176 ret = sqlite3_step(stmt);
1177 if (ret == SQLITE_ROW) {
1178 ret = !!sqlite3_column_int(stmt, 0);
1181 ErrPrint("There is no such result\n");
1184 sqlite3_reset(stmt);
1185 sqlite3_finalize(stmt);
1190 EAPI int livebox_service_touch_effect(const char *pkgid, int size_type)
1199 ErrPrint("Unable to open a DB\n");
1203 ret = sqlite3_prepare_v2(handle, "SELECT touch_effect FROM box_size WHERE pkgid = ? AND size_type = ?", -1, &stmt, NULL);
1204 if (ret != SQLITE_OK) {
1205 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1212 * This function will validate the "pkgid"
1213 * call the exported API in the exported API is not recomended
1216 lbid = livebox_service_pkgname(pkgid);
1218 ErrPrint("Invalid appid (%s)\n", pkgid);
1223 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
1225 if (ret != SQLITE_OK) {
1226 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1231 ret = sqlite3_bind_int(stmt, 2, size_type);
1232 if (ret != SQLITE_OK) {
1233 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1238 ret = sqlite3_step(stmt);
1239 if (ret == SQLITE_ROW) {
1240 ret = !!sqlite3_column_int(stmt, 0);
1242 ret = 1; /*!< Default true: In this case the DB is corrupted. */
1243 ErrPrint("There is no result\n");
1247 sqlite3_reset(stmt);
1248 sqlite3_finalize(stmt);
1253 EAPI int livebox_service_mouse_event(const char *pkgid)
1264 ret = sqlite3_prepare_v2(handle, "SELECT mouse_event FROM client WHERE pkgid = ?", -1, &stmt, NULL);
1265 if (ret != SQLITE_OK) {
1266 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1271 lbid = livebox_service_pkgname(pkgid);
1273 ErrPrint("Failed to get lbid: %s\n", pkgid);
1278 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
1280 if (ret != SQLITE_OK) {
1281 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1286 ret = sqlite3_step(stmt);
1287 if (ret == SQLITE_ROW) {
1288 ret = !!sqlite3_column_int(stmt, 0);
1290 ret = 0; /*!< Default is false, In this case the DB is corrupted */
1291 ErrPrint("There is no result.\n");
1295 sqlite3_reset(stmt);
1296 sqlite3_finalize(stmt);
1301 EAPI char *livebox_service_preview(const char *pkgid, int size_type)
1306 char *preview = NULL;
1312 ret = sqlite3_prepare_v2(handle, "SELECT preview FROM box_size WHERE pkgid = ? AND size_type = ?", -1, &stmt, NULL);
1313 if (ret != SQLITE_OK) {
1314 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1319 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1320 if (ret != SQLITE_OK) {
1321 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1325 ret = sqlite3_bind_int(stmt, 2, size_type);
1326 if (ret != SQLITE_OK) {
1327 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1331 ret = sqlite3_step(stmt);
1332 if (ret == SQLITE_ROW) {
1334 tmp = (const char *)sqlite3_column_text(stmt, 0);
1335 if (tmp && strlen(tmp)) {
1336 preview = strdup(tmp);
1338 ErrPrint("Heap: %s\n", strerror(errno));
1343 sqlite3_reset(stmt);
1344 sqlite3_finalize(stmt);
1349 EAPI char *livebox_service_i18n_icon(const char *pkgid, const char *lang)
1358 language = strdup(lang);
1360 ErrPrint("Heap: %s\n", strerror(errno));
1364 language = cur_locale();
1375 ret = sqlite3_prepare_v2(handle, "SELECT icon FROM i18n WHERE pkgid = ? AND lang = ?", -1, &stmt, NULL);
1376 if (ret != SQLITE_OK) {
1377 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1383 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1384 if (ret != SQLITE_OK) {
1385 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1389 ret = sqlite3_bind_text(stmt, 2, language, -1, SQLITE_TRANSIENT);
1390 if (ret != SQLITE_OK) {
1391 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1395 ret = sqlite3_step(stmt);
1396 if (ret == SQLITE_ROW) {
1398 tmp = (const char *)sqlite3_column_text(stmt, 0);
1399 if (!tmp || !strlen(tmp)) {
1400 icon = get_default_icon(pkgid);
1404 ErrPrint("Heap: %s\n", strerror(errno));
1407 icon = get_default_icon(pkgid);
1411 sqlite3_reset(stmt);
1412 sqlite3_finalize(stmt);
1418 EAPI char *livebox_service_i18n_name(const char *pkgid, const char *lang)
1427 language = strdup(lang);
1429 ErrPrint("Error: %s\n", strerror(errno));
1433 language = cur_locale();
1444 ret = sqlite3_prepare_v2(handle, "SELECT name FROM i18n WHERE pkgid = ? AND lang = ?", -1, &stmt, NULL);
1445 if (ret != SQLITE_OK) {
1446 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1452 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1453 if (ret != SQLITE_OK) {
1454 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1458 ret = sqlite3_bind_text(stmt, 2, language, -1, SQLITE_TRANSIENT);
1459 if (ret != SQLITE_OK) {
1460 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1464 ret = sqlite3_step(stmt);
1465 if (ret == SQLITE_ROW) {
1467 tmp = (const char *)sqlite3_column_text(stmt, 0);
1468 if (!tmp || !strlen(tmp)) {
1469 name = get_default_name(pkgid);
1473 ErrPrint("Heap: %s\n", strerror(errno));
1476 name = get_default_name(pkgid);
1480 sqlite3_reset(stmt);
1481 sqlite3_finalize(stmt);
1487 EAPI int livebox_service_get_supported_sizes(const char *pkgid, int *cnt, int *w, int *h)
1494 if (!w || !h || !cnt || !pkgid)
1495 return LB_STATUS_ERROR_INVALID;
1499 return LB_STATUS_ERROR_IO;
1501 ret = sqlite3_prepare_v2(handle, "SELECT size_type FROM box_size WHERE pkgid = ? ORDER BY size_type ASC", -1, &stmt, NULL);
1502 if (ret != SQLITE_OK) {
1503 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1504 ret = LB_STATUS_ERROR_IO;
1508 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1509 if (ret != SQLITE_OK) {
1510 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1511 sqlite3_reset(stmt);
1512 sqlite3_finalize(stmt);
1513 ret = LB_STATUS_ERROR_IO;
1517 if (*cnt > NR_OF_SIZE_LIST)
1518 *cnt = NR_OF_SIZE_LIST;
1521 while (sqlite3_step(stmt) == SQLITE_ROW && ret < *cnt) {
1522 size = sqlite3_column_int(stmt, 0);
1523 ret += (convert_size_from_type(size, w + ret, h + ret) == 0);
1527 sqlite3_reset(stmt);
1528 sqlite3_finalize(stmt);
1535 EAPI char *livebox_service_libexec(const char *pkgid)
1552 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.libexec FROM pkgmap, provider WHERE pkgmap.pkgid = ? AND provider.pkgid = ?", -1, &stmt, NULL);
1553 if (ret != SQLITE_OK) {
1554 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1558 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1559 if (ret != SQLITE_OK) {
1560 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1561 sqlite3_finalize(stmt);
1565 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1566 if (ret != SQLITE_OK) {
1567 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1568 sqlite3_finalize(stmt);
1572 if (sqlite3_step(stmt) != SQLITE_ROW) {
1573 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1574 sqlite3_reset(stmt);
1575 sqlite3_finalize(stmt);
1577 libexec = util_conf_get_libexec(pkgid);
1578 DbgPrint("Fallback to conf checker: %s\n", libexec);
1582 appid = (char *)sqlite3_column_text(stmt, 0);
1583 if (!appid || !strlen(appid)) {
1584 ErrPrint("Invalid appid: %s\n", sqlite3_errmsg(handle));
1585 sqlite3_reset(stmt);
1586 sqlite3_finalize(stmt);
1590 path = (char *)sqlite3_column_text(stmt, 1);
1591 if (!path || !strlen(path)) {
1592 ErrPrint("Invalid libexec: %s\n", sqlite3_errmsg(handle));
1593 sqlite3_reset(stmt);
1594 sqlite3_finalize(stmt);
1598 libexec = strdup(path);
1600 ErrPrint("Heap: %s\n", strerror(errno));
1601 sqlite3_reset(stmt);
1602 sqlite3_finalize(stmt);
1606 DbgPrint("libexec: %s\n", libexec);
1608 sqlite3_reset(stmt);
1609 sqlite3_finalize(stmt);
1615 EAPI char *livebox_service_pkgname(const char *appid)
1618 pkgmgr_appinfo_h handle;
1625 lb_pkgname = get_lb_pkgname_by_appid(appid);
1631 * Try to get the package id using given appid
1633 ret = pkgmgr_appinfo_get_appinfo(appid, &handle);
1634 if (ret != PKGMGR_R_OK) {
1635 ErrPrint("Failed to get appinfo\n");
1639 ret = pkgmgr_appinfo_get_pkgname(handle, &new_appid);
1640 if (ret != PKGMGR_R_OK) {
1641 pkgmgr_appinfo_destroy_appinfo(handle);
1642 ErrPrint("Failed to get pkgname for (%s)\n", appid);
1646 lb_pkgname = get_lb_pkgname_by_appid(new_appid);
1647 pkgmgr_appinfo_destroy_appinfo(handle);
1649 if (!lb_pkgname && util_validate_livebox_package(appid) == 0)
1650 return strdup(appid);
1655 EAPI char *livebox_service_provider_name(const char *lbid)
1661 char *str = SAMSUNG_PREFIX;
1666 while (str[idx] && lbid[idx] && lbid[idx] == str[idx]) {
1668 if (seq < 2 && lbid[idx] == '.') {
1674 if (!str[idx] && lbid[idx]) {
1676 return strdup(lbid);
1677 } else if (seq < 2) {
1679 if (lbid[idx] == '.') {
1681 } else if (!lbid[idx]) {
1682 ErrPrint("Invalid lbid: %s\n", lbid);
1694 ret = strdup(lbid + stage);
1696 ErrPrint("Error: %s\n", strerror(errno));
1703 EAPI int livebox_service_is_enabled(const char *lbid)
1712 pkgname = livebox_service_appid(lbid);
1716 ret = ail_get_appinfo(pkgname, &ai);
1717 if (ret != AIL_ERROR_OK) {
1722 if (ail_appinfo_get_bool(ai, AIL_PROP_X_SLP_ENABLED_BOOL, &enabled) != AIL_ERROR_OK)
1725 ail_destroy_appinfo(ai);
1727 return enabled == true;
1731 EAPI int livebox_service_is_primary(const char *lbid)
1744 ret = sqlite3_prepare_v2(handle, "SELECT prime FROM pkgmap WHERE pkgid = ?", -1, &stmt, NULL);
1745 if (ret != SQLITE_OK) {
1746 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1751 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
1752 if (ret != SQLITE_OK) {
1753 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1757 ret = sqlite3_step(stmt);
1758 if (ret != SQLITE_ROW) {
1759 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1763 ret = sqlite3_column_int(stmt, 0);
1766 sqlite3_reset(stmt);
1767 sqlite3_finalize(stmt);
1773 * appid == Package ID
1774 * pkgid == Livebox ID
1776 EAPI char *livebox_service_appid(const char *pkgname)
1782 int is_prime __attribute__((__unused__));
1793 ret = sqlite3_prepare_v2(handle, "SELECT appid, prime FROM pkgmap WHERE pkgid = ? OR appid = ?", -1, &stmt, NULL);
1794 if (ret != SQLITE_OK) {
1795 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1799 ret = sqlite3_bind_text(stmt, 1, pkgname, -1, SQLITE_TRANSIENT);
1800 if (ret != SQLITE_OK) {
1801 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1802 sqlite3_reset(stmt);
1803 sqlite3_finalize(stmt);
1807 ret = sqlite3_bind_text(stmt, 2, pkgname, -1, SQLITE_TRANSIENT);
1808 if (ret != SQLITE_OK) {
1809 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1810 sqlite3_reset(stmt);
1811 sqlite3_finalize(stmt);
1815 ret = sqlite3_step(stmt);
1816 if (ret != SQLITE_ROW) {
1817 pkgmgr_appinfo_h pkg_handle;
1820 ErrPrint("Has no record?: %s\n", sqlite3_errmsg(handle));
1821 sqlite3_reset(stmt);
1822 sqlite3_finalize(stmt);
1824 ret = pkgmgr_appinfo_get_appinfo(pkgname, &pkg_handle);
1825 if (ret != PKGMGR_R_OK) {
1826 ErrPrint("Failed to get appinfo: %s\n", pkgname);
1830 ret = pkgmgr_appinfo_get_pkgname(pkg_handle, &new_appid);
1831 if (ret != PKGMGR_R_OK) {
1832 ErrPrint("Failed to get pkgname for (%s)\n", appid);
1833 pkgmgr_appinfo_destroy_appinfo(pkg_handle);
1837 appid = strdup(new_appid);
1839 ErrPrint("Heap: %s\n", strerror(errno));
1841 pkgmgr_appinfo_destroy_appinfo(pkg_handle);
1845 tmp = (char *)sqlite3_column_text(stmt, 0);
1846 if (!tmp || !strlen(tmp)) {
1847 ErrPrint("APPID is NIL\n");
1848 sqlite3_reset(stmt);
1849 sqlite3_finalize(stmt);
1853 appid = strdup(tmp);
1855 ErrPrint("Heap: %s\n", strerror(errno));
1856 sqlite3_reset(stmt);
1857 sqlite3_finalize(stmt);
1861 is_prime = sqlite3_column_int(stmt, 1);
1863 sqlite3_reset(stmt);
1864 sqlite3_finalize(stmt);
1870 EAPI char *livebox_service_lb_script_path(const char *pkgid)
1887 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.box_src FROM provider, pkgmap WHERE pkgmap.pkgid = ? AND provider.pkgid = ?", -1, &stmt, NULL);
1888 if (ret != SQLITE_OK) {
1889 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1893 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1894 if (ret != SQLITE_OK) {
1895 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1896 sqlite3_finalize(stmt);
1900 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1901 if (ret != SQLITE_OK) {
1902 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1903 sqlite3_finalize(stmt);
1907 ret = sqlite3_step(stmt);
1908 if (ret != SQLITE_ROW) {
1909 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1910 sqlite3_reset(stmt);
1911 sqlite3_finalize(stmt);
1915 appid = (char *)sqlite3_column_text(stmt, 0);
1916 if (!appid || !strlen(appid)) {
1917 ErrPrint("Invalid appid : %s\n", sqlite3_errmsg(handle));
1918 sqlite3_reset(stmt);
1919 sqlite3_finalize(stmt);
1923 lb_src = (char *)sqlite3_column_text(stmt, 1);
1924 if (!lb_src || !strlen(lb_src)) {
1925 ErrPrint("No records for lb src : %s\n", sqlite3_errmsg(handle));
1926 sqlite3_reset(stmt);
1927 sqlite3_finalize(stmt);
1931 path = strdup(lb_src);
1933 ErrPrint("Heap: %s\n", strerror(errno));
1934 sqlite3_reset(stmt);
1935 sqlite3_finalize(stmt);
1939 DbgPrint("LB Src: %s\n", path);
1941 sqlite3_reset(stmt);
1942 sqlite3_finalize(stmt);
1948 EAPI char *livebox_service_lb_script_group(const char *pkgid)
1964 ret = sqlite3_prepare_v2(handle, "SELECT box_group FROM provider WHERE pkgid = ?", -1, &stmt, NULL);
1965 if (ret != SQLITE_OK) {
1966 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1970 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1971 if (ret != SQLITE_OK) {
1972 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1973 sqlite3_finalize(stmt);
1977 ret = sqlite3_step(stmt);
1978 if (ret != SQLITE_ROW) {
1979 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1980 sqlite3_reset(stmt);
1981 sqlite3_finalize(stmt);
1985 tmp = (char *)sqlite3_column_text(stmt, 0);
1986 if (tmp && strlen(tmp)) {
1987 group = strdup(tmp);
1989 ErrPrint("Heap: %s\n", strerror(errno));
1992 sqlite3_reset(stmt);
1993 sqlite3_finalize(stmt);
1999 EAPI char *livebox_service_pd_script_path(const char *pkgid)
2016 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.pd_src FROM provider, pkgmap WHERE provider.pkgid = ? AND pkgmap.pkgid = ?", -1, &stmt, NULL);
2017 if (ret != SQLITE_OK) {
2018 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2022 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
2023 if (ret != SQLITE_OK) {
2024 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2025 sqlite3_finalize(stmt);
2029 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
2030 if (ret != SQLITE_OK) {
2031 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2032 sqlite3_finalize(stmt);
2036 ret = sqlite3_step(stmt);
2037 if (ret != SQLITE_ROW) {
2038 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2039 sqlite3_reset(stmt);
2040 sqlite3_finalize(stmt);
2044 appid = (char *)sqlite3_column_text(stmt, 0);
2045 if (!appid || !strlen(appid)) {
2046 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2047 sqlite3_reset(stmt);
2048 sqlite3_finalize(stmt);
2052 pd_src = (char *)sqlite3_column_text(stmt, 1);
2053 if (!pd_src || !strlen(pd_src)) {
2054 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2055 sqlite3_reset(stmt);
2056 sqlite3_finalize(stmt);
2060 path = strdup(pd_src);
2062 ErrPrint("Heap: %s\n", strerror(errno));
2063 sqlite3_reset(stmt);
2064 sqlite3_finalize(stmt);
2068 DbgPrint("PD Src: %s\n", path);
2069 sqlite3_reset(stmt);
2070 sqlite3_finalize(stmt);
2076 EAPI char *livebox_service_pd_script_group(const char *pkgid)
2092 ret = sqlite3_prepare_v2(handle, "SELECT pd_group FROM provider WHERE pkgid = ?", -1, &stmt, NULL);
2093 if (ret != SQLITE_OK) {
2094 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2098 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
2099 if (ret != SQLITE_OK) {
2100 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2101 sqlite3_finalize(stmt);
2105 ret = sqlite3_step(stmt);
2106 if (ret != SQLITE_ROW) {
2107 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2108 sqlite3_reset(stmt);
2109 sqlite3_finalize(stmt);
2113 tmp = (char *)sqlite3_column_text(stmt, 0);
2114 if (tmp && strlen(tmp)) {
2115 group = strdup(tmp);
2117 ErrPrint("Heap: %s\n", strerror(errno));
2119 sqlite3_reset(stmt);
2120 sqlite3_finalize(stmt);
2126 EAPI int livebox_service_enumerate_cluster_list(int (*cb)(const char *cluster, void *data), void *data)
2130 const char *cluster;
2135 return LB_STATUS_ERROR_INVALID;
2139 return LB_STATUS_ERROR_IO;
2142 ret = sqlite3_prepare_v2(handle, "SELECT DISTINCT cluster FROM groupinfo", -1, &stmt, NULL);
2143 if (ret != SQLITE_OK) {
2144 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2145 cnt = LB_STATUS_ERROR_IO;
2149 while (sqlite3_step(stmt) == SQLITE_ROW) {
2150 cluster = (const char *)sqlite3_column_text(stmt, 0);
2151 if (!cluster || !strlen(cluster))
2154 if (cb(cluster, data) < 0)
2160 sqlite3_reset(stmt);
2161 sqlite3_finalize(stmt);
2167 EAPI int livebox_service_enumerate_category_list(const char *cluster, int (*cb)(const char *cluster, const char *category, void *data), void *data)
2171 const char *category;
2175 if (!cluster || !cb)
2176 return LB_STATUS_ERROR_INVALID;
2180 return LB_STATUS_ERROR_IO;
2182 ret = sqlite3_prepare_v2(handle, "SELECT DISTINCT category FROM groupinfo WHERE cluster = ?", -1, &stmt, NULL);
2183 if (ret != SQLITE_OK) {
2184 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2185 cnt = LB_STATUS_ERROR_IO;
2190 while (sqlite3_step(stmt) == SQLITE_ROW) {
2191 category = (const char *)sqlite3_column_text(stmt, 0);
2192 if (!category || !strlen(category))
2195 if (cb(cluster, category, data) < 0)
2201 sqlite3_reset(stmt);
2202 sqlite3_finalize(stmt);
2208 EAPI int livebox_service_init(void)
2210 if (s_info.handle) {
2211 DbgPrint("Already initialized\n");
2212 s_info.init_count++;
2216 s_info.handle = open_db();
2217 if (s_info.handle) {
2218 s_info.init_count++;
2222 return LB_STATUS_ERROR_IO;
2225 EAPI int livebox_service_fini(void)
2227 if (!s_info.handle || s_info.init_count <= 0) {
2228 ErrPrint("Service is not initialized\n");
2229 return LB_STATUS_ERROR_IO;
2232 s_info.init_count--;
2233 if (s_info.init_count > 0) {
2234 DbgPrint("Init count %d\n", s_info.init_count);
2238 db_util_close(s_info.handle);
2239 s_info.handle = NULL;
2243 EAPI int livebox_service_get_size(int type, int *width, int *height)
2254 return convert_size_from_type(type, width, height);
2257 EAPI int livebox_service_size_type(int width, int height)
2261 if (update_resolution() < 0)
2262 ErrPrint("Failed to update the size list\n");
2264 for (idx = 0; idx < NR_OF_SIZE_LIST; idx++) {
2265 if (SIZE_LIST[idx].w == width && SIZE_LIST[idx].h == height)
2271 return LB_SIZE_TYPE_1x1;
2273 return LB_SIZE_TYPE_2x1;
2275 return LB_SIZE_TYPE_2x2;
2277 return LB_SIZE_TYPE_4x1;
2279 return LB_SIZE_TYPE_4x2;
2281 return LB_SIZE_TYPE_4x3;
2283 return LB_SIZE_TYPE_4x4;
2285 return LB_SIZE_TYPE_4x5;
2287 return LB_SIZE_TYPE_4x6;
2289 return LB_SIZE_TYPE_EASY_1x1;
2291 return LB_SIZE_TYPE_EASY_3x1;
2293 return LB_SIZE_TYPE_EASY_3x3;
2295 return LB_SIZE_TYPE_0x0;
2300 return LB_SIZE_TYPE_UNKNOWN;