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 int pkgmgr_get_applist(const char *pkgid, const char *lbid, void (*cb)(const char *lbid, const char *appid, void *data), void *data)
612 struct pkgmgr_cbdata cbdata;
613 pkgmgrinfo_pkginfo_h handle;
616 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
618 ErrPrint("Unable to get pkginfo: %s\n", pkgid);
624 cbdata.cbdata = data;
626 ret = pkgmgrinfo_appinfo_get_list(handle, PM_UI_APP, pkgmgr_cb, &cbdata);
628 ErrPrint("Failed to get applist\n");
630 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
634 EAPI int livebox_service_get_applist(const char *lbid, void (*cb)(const char *lbid, const char *appid, void *data), void *data)
643 return LB_STATUS_ERROR_INVALID;
647 return LB_STATUS_ERROR_IO;
649 ret = sqlite3_prepare_v2(handle, "SELECT appid FROM pkgmap WHERE (pkgid = ?) or (appid = ?)", -1, &stmt, NULL);
650 if (ret != SQLITE_OK) {
651 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
652 ret = LB_STATUS_ERROR_IO;
656 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
657 if (ret != SQLITE_OK) {
658 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
659 ret = LB_STATUS_ERROR_IO;
663 ret = sqlite3_bind_text(stmt, 2, lbid, -1, SQLITE_TRANSIENT);
664 if (ret != SQLITE_OK) {
665 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
666 ret = LB_STATUS_ERROR_IO;
670 if (sqlite3_step(stmt) != SQLITE_ROW) {
671 ret = LB_STATUS_ERROR_INVALID;
673 sqlite3_finalize(stmt);
677 tmp = (const char *)sqlite3_column_text(stmt, 0);
678 if (!tmp || !strlen(tmp)) {
679 ErrPrint("Invalid package name (%s)\n", lbid);
680 ret = LB_STATUS_ERROR_INVALID;
682 sqlite3_finalize(stmt);
688 ErrPrint("Error: %s\n", strerror(errno));
689 ret = LB_STATUS_ERROR_MEMORY;
691 sqlite3_finalize(stmt);
696 sqlite3_finalize(stmt);
698 ret = pkgmgr_get_applist(pkgid, lbid, cb, data);
706 EAPI int livebox_service_get_supported_size_types(const char *pkgid, int *cnt, int *types)
713 if (!types || !cnt || !pkgid)
714 return LB_STATUS_ERROR_INVALID;
718 return LB_STATUS_ERROR_IO;
720 ret = sqlite3_prepare_v2(handle, "SELECT size_type FROM box_size WHERE pkgid = ? ORDER BY size_type ASC", -1, &stmt, NULL);
721 if (ret != SQLITE_OK) {
722 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
723 ret = LB_STATUS_ERROR_IO;
727 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
728 if (ret != SQLITE_OK) {
729 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
731 sqlite3_finalize(stmt);
732 ret = LB_STATUS_ERROR_IO;
736 if (*cnt > NR_OF_SIZE_LIST)
737 *cnt = NR_OF_SIZE_LIST;
740 while (sqlite3_step(stmt) == SQLITE_ROW && ret < *cnt) {
741 size = sqlite3_column_int(stmt, 0);
748 sqlite3_finalize(stmt);
755 static inline char *cur_locale(void)
758 language = vconf_get_str(VCONFKEY_LANGSET);
775 language = strdup("en-us");
777 ErrPrint("Heap: %s\n", strerror(errno));
783 static inline char *get_default_name(const char *pkgid)
794 ret = sqlite3_prepare_v2(handle, "SELECT name FROM client WHERE pkgid = ?", -1, &stmt, NULL);
795 if (ret != SQLITE_OK) {
796 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
801 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
802 if (ret != SQLITE_OK) {
803 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
807 ret = sqlite3_step(stmt);
808 if (ret == SQLITE_ROW) {
811 tmp = (const char *)sqlite3_column_text(stmt, 0);
812 if (tmp && strlen(tmp)) {
815 ErrPrint("Heap: %s\n", strerror(errno));
821 sqlite3_finalize(stmt);
826 static inline char *get_default_icon(const char *pkgid)
837 ret = sqlite3_prepare_v2(handle, "SELECT icon FROM client WHERE pkgid = ?", -1, &stmt, NULL);
838 if (ret != SQLITE_OK) {
839 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
844 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
845 if (ret != SQLITE_OK) {
846 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
850 ret = sqlite3_step(stmt);
851 if (ret == SQLITE_ROW) {
854 tmp = (const char *)sqlite3_column_text(stmt, 0);
855 if (tmp && strlen(tmp)) {
858 ErrPrint("Heap: %s\n", strerror(errno));
864 sqlite3_finalize(stmt);
869 EAPI char *livebox_service_content(const char *pkgid)
873 char *content = NULL;
880 ret = sqlite3_prepare_v2(handle, "SELECT content FROM client WHERE pkgid = ?", -1, &stmt, NULL);
881 if (ret != SQLITE_OK) {
882 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
887 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
888 if (ret != SQLITE_OK) {
889 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
893 ret = sqlite3_step(stmt);
894 if (ret == SQLITE_ROW) {
897 tmp = (const char *)sqlite3_column_text(stmt, 0);
898 if (tmp && strlen(tmp)) {
899 content = strdup(tmp);
901 ErrPrint("Heap: %s\n", strerror(errno));
907 sqlite3_finalize(stmt);
912 EAPI char *livebox_service_setup_appid(const char *lbid)
923 ret = sqlite3_prepare_v2(handle, "SELECT setup FROM client WHERE pkgid = ?", -1, &stmt, NULL);
924 if (ret != SQLITE_OK) {
925 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
931 ret = sqlite3_bind_text(stmt, 1, lbid, -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))
947 ErrPrint("Error: %s\n", strerror(errno));
952 sqlite3_finalize(stmt);
957 EAPI int livebox_service_nodisplay(const char *pkgid)
967 ret = sqlite3_prepare_v2(handle, "SELECT nodisplay 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));
981 ret = sqlite3_step(stmt);
982 if (ret == SQLITE_ROW)
983 ret = !!sqlite3_column_int(stmt, 0);
989 sqlite3_finalize(stmt);
994 static inline char *get_lb_pkgname_by_appid(const char *appid)
1010 ret = sqlite3_prepare_v2(handle, "SELECT pkgid FROM pkgmap WHERE (appid = ? AND prime = 1) OR pkgid = ?", -1, &stmt, NULL);
1011 if (ret != SQLITE_OK) {
1012 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1017 ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT);
1018 if (ret != SQLITE_OK) {
1019 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1023 ret = sqlite3_bind_text(stmt, 2, appid, -1, SQLITE_TRANSIENT);
1024 if (ret != SQLITE_OK) {
1025 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1029 if (sqlite3_step(stmt) != SQLITE_ROW) {
1030 ErrPrint("Error: %s (has no record? - %s)\n", sqlite3_errmsg(handle), appid);
1034 tmp = (char *)sqlite3_column_text(stmt, 0);
1035 if (tmp && strlen(tmp)) {
1036 pkgid = strdup(tmp);
1038 ErrPrint("Heap: %s\n", strerror(errno));
1042 sqlite3_reset(stmt);
1043 sqlite3_finalize(stmt);
1048 EAPI int livebox_service_need_frame(const char *pkgid, int size_type)
1057 ErrPrint("Unable to open a DB\n");
1061 ret = sqlite3_prepare_v2(handle, "SELECT need_frame FROM box_size WHERE pkgid = ? AND size_type = ?", -1, &stmt, NULL);
1062 if (ret != SQLITE_OK) {
1063 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1070 lbid = livebox_service_pkgname(pkgid);
1072 ErrPrint("Invalid appid (%s)\n", pkgid);
1077 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
1079 if (ret != SQLITE_OK) {
1080 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1085 ret = sqlite3_bind_int(stmt, 2, size_type);
1086 if (ret != SQLITE_OK) {
1087 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1092 ret = sqlite3_step(stmt);
1093 if (ret == SQLITE_ROW) {
1094 ret = !!sqlite3_column_int(stmt, 0);
1097 ErrPrint("There is no such result\n");
1100 sqlite3_reset(stmt);
1101 sqlite3_finalize(stmt);
1106 EAPI int livebox_service_touch_effect(const char *pkgid, int size_type)
1115 ErrPrint("Unable to open a DB\n");
1119 ret = sqlite3_prepare_v2(handle, "SELECT touch_effect FROM box_size WHERE pkgid = ? AND size_type = ?", -1, &stmt, NULL);
1120 if (ret != SQLITE_OK) {
1121 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1128 * This function will validate the "pkgid"
1129 * call the exported API in the exported API is not recomended
1132 lbid = livebox_service_pkgname(pkgid);
1134 ErrPrint("Invalid appid (%s)\n", pkgid);
1139 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
1141 if (ret != SQLITE_OK) {
1142 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1147 ret = sqlite3_bind_int(stmt, 2, size_type);
1148 if (ret != SQLITE_OK) {
1149 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1154 ret = sqlite3_step(stmt);
1155 if (ret == SQLITE_ROW) {
1156 ret = !!sqlite3_column_int(stmt, 0);
1158 ret = 1; /*!< Default true: In this case the DB is corrupted. */
1159 ErrPrint("There is no result\n");
1163 sqlite3_reset(stmt);
1164 sqlite3_finalize(stmt);
1169 EAPI int livebox_service_mouse_event(const char *pkgid)
1180 ret = sqlite3_prepare_v2(handle, "SELECT mouse_event FROM client WHERE pkgid = ?", -1, &stmt, NULL);
1181 if (ret != SQLITE_OK) {
1182 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1187 lbid = livebox_service_pkgname(pkgid);
1189 ErrPrint("Failed to get lbid: %s\n", pkgid);
1194 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
1196 if (ret != SQLITE_OK) {
1197 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1202 ret = sqlite3_step(stmt);
1203 if (ret == SQLITE_ROW) {
1204 ret = !!sqlite3_column_int(stmt, 0);
1206 ret = 0; /*!< Default is false, In this case the DB is corrupted */
1207 ErrPrint("There is no result.\n");
1211 sqlite3_reset(stmt);
1212 sqlite3_finalize(stmt);
1217 EAPI char *livebox_service_preview(const char *pkgid, int size_type)
1222 char *preview = NULL;
1228 ret = sqlite3_prepare_v2(handle, "SELECT preview FROM box_size WHERE pkgid = ? AND size_type = ?", -1, &stmt, NULL);
1229 if (ret != SQLITE_OK) {
1230 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1235 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1236 if (ret != SQLITE_OK) {
1237 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1241 ret = sqlite3_bind_int(stmt, 2, size_type);
1242 if (ret != SQLITE_OK) {
1243 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1247 ret = sqlite3_step(stmt);
1248 if (ret == SQLITE_ROW) {
1250 tmp = (const char *)sqlite3_column_text(stmt, 0);
1251 if (tmp && strlen(tmp)) {
1252 preview = strdup(tmp);
1254 ErrPrint("Heap: %s\n", strerror(errno));
1259 sqlite3_reset(stmt);
1260 sqlite3_finalize(stmt);
1265 EAPI char *livebox_service_i18n_icon(const char *pkgid, const char *lang)
1274 language = strdup(lang);
1276 ErrPrint("Heap: %s\n", strerror(errno));
1280 language = cur_locale();
1291 ret = sqlite3_prepare_v2(handle, "SELECT icon FROM i18n WHERE pkgid = ? AND lang = ?", -1, &stmt, NULL);
1292 if (ret != SQLITE_OK) {
1293 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1299 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1300 if (ret != SQLITE_OK) {
1301 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1305 ret = sqlite3_bind_text(stmt, 2, language, -1, SQLITE_TRANSIENT);
1306 if (ret != SQLITE_OK) {
1307 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1311 ret = sqlite3_step(stmt);
1312 if (ret == SQLITE_ROW) {
1314 tmp = (const char *)sqlite3_column_text(stmt, 0);
1315 if (!tmp || !strlen(tmp)) {
1316 icon = get_default_icon(pkgid);
1320 ErrPrint("Heap: %s\n", strerror(errno));
1323 icon = get_default_icon(pkgid);
1327 sqlite3_reset(stmt);
1328 sqlite3_finalize(stmt);
1334 EAPI char *livebox_service_i18n_name(const char *pkgid, const char *lang)
1343 language = strdup(lang);
1345 ErrPrint("Error: %s\n", strerror(errno));
1349 language = cur_locale();
1360 ret = sqlite3_prepare_v2(handle, "SELECT name FROM i18n WHERE pkgid = ? AND lang = ?", -1, &stmt, NULL);
1361 if (ret != SQLITE_OK) {
1362 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1368 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1369 if (ret != SQLITE_OK) {
1370 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1374 ret = sqlite3_bind_text(stmt, 2, language, -1, SQLITE_TRANSIENT);
1375 if (ret != SQLITE_OK) {
1376 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1380 ret = sqlite3_step(stmt);
1381 if (ret == SQLITE_ROW) {
1383 tmp = (const char *)sqlite3_column_text(stmt, 0);
1384 if (!tmp || !strlen(tmp)) {
1385 name = get_default_name(pkgid);
1389 ErrPrint("Heap: %s\n", strerror(errno));
1392 name = get_default_name(pkgid);
1396 sqlite3_reset(stmt);
1397 sqlite3_finalize(stmt);
1403 EAPI int livebox_service_get_supported_sizes(const char *pkgid, int *cnt, int *w, int *h)
1410 if (!w || !h || !cnt || !pkgid)
1411 return LB_STATUS_ERROR_INVALID;
1415 return LB_STATUS_ERROR_IO;
1417 ret = sqlite3_prepare_v2(handle, "SELECT size_type FROM box_size WHERE pkgid = ? ORDER BY size_type ASC", -1, &stmt, NULL);
1418 if (ret != SQLITE_OK) {
1419 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1420 ret = LB_STATUS_ERROR_IO;
1424 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1425 if (ret != SQLITE_OK) {
1426 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1427 sqlite3_reset(stmt);
1428 sqlite3_finalize(stmt);
1429 ret = LB_STATUS_ERROR_IO;
1433 if (*cnt > NR_OF_SIZE_LIST)
1434 *cnt = NR_OF_SIZE_LIST;
1437 while (sqlite3_step(stmt) == SQLITE_ROW && ret < *cnt) {
1438 size = sqlite3_column_int(stmt, 0);
1439 ret += (convert_size_from_type(size, w + ret, h + ret) == 0);
1443 sqlite3_reset(stmt);
1444 sqlite3_finalize(stmt);
1451 EAPI char *livebox_service_libexec(const char *pkgid)
1468 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.libexec FROM pkgmap, provider WHERE pkgmap.pkgid = ? AND provider.pkgid = ?", -1, &stmt, NULL);
1469 if (ret != SQLITE_OK) {
1470 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1474 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1475 if (ret != SQLITE_OK) {
1476 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1477 sqlite3_finalize(stmt);
1481 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1482 if (ret != SQLITE_OK) {
1483 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1484 sqlite3_finalize(stmt);
1488 if (sqlite3_step(stmt) != SQLITE_ROW) {
1489 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1490 sqlite3_reset(stmt);
1491 sqlite3_finalize(stmt);
1493 libexec = util_conf_get_libexec(pkgid);
1494 DbgPrint("Fallback to conf checker: %s\n", libexec);
1498 appid = (char *)sqlite3_column_text(stmt, 0);
1499 if (!appid || !strlen(appid)) {
1500 ErrPrint("Invalid appid: %s\n", sqlite3_errmsg(handle));
1501 sqlite3_reset(stmt);
1502 sqlite3_finalize(stmt);
1506 path = (char *)sqlite3_column_text(stmt, 1);
1507 if (!path || !strlen(path)) {
1508 ErrPrint("Invalid libexec: %s\n", sqlite3_errmsg(handle));
1509 sqlite3_reset(stmt);
1510 sqlite3_finalize(stmt);
1514 libexec = strdup(path);
1516 ErrPrint("Heap: %s\n", strerror(errno));
1517 sqlite3_reset(stmt);
1518 sqlite3_finalize(stmt);
1522 DbgPrint("libexec: %s\n", libexec);
1524 sqlite3_reset(stmt);
1525 sqlite3_finalize(stmt);
1531 EAPI char *livebox_service_pkgname(const char *appid)
1534 pkgmgr_appinfo_h handle;
1541 lb_pkgname = get_lb_pkgname_by_appid(appid);
1547 * Try to get the package id using given appid
1549 ret = pkgmgr_appinfo_get_appinfo(appid, &handle);
1550 if (ret != PKGMGR_R_OK) {
1551 ErrPrint("Failed to get appinfo\n");
1555 ret = pkgmgr_appinfo_get_pkgname(handle, &new_appid);
1556 if (ret != PKGMGR_R_OK) {
1557 pkgmgr_appinfo_destroy_appinfo(handle);
1558 ErrPrint("Failed to get pkgname for (%s)\n", appid);
1562 lb_pkgname = get_lb_pkgname_by_appid(new_appid);
1563 pkgmgr_appinfo_destroy_appinfo(handle);
1565 if (!lb_pkgname && util_validate_livebox_package(appid) == 0)
1566 return strdup(appid);
1571 EAPI char *livebox_service_provider_name(const char *lbid)
1577 char *str = SAMSUNG_PREFIX;
1582 while (str[idx] && lbid[idx] && lbid[idx] == str[idx]) {
1584 if (seq < 2 && lbid[idx] == '.') {
1590 if (!str[idx] && lbid[idx]) {
1592 return strdup(lbid);
1593 } else if (seq < 2) {
1595 if (lbid[idx] == '.') {
1597 } else if (!lbid[idx]) {
1598 ErrPrint("Invalid lbid: %s\n", lbid);
1610 ret = strdup(lbid + stage);
1612 ErrPrint("Error: %s\n", strerror(errno));
1619 EAPI int livebox_service_is_enabled(const char *lbid)
1628 pkgname = livebox_service_appid(lbid);
1632 ret = ail_get_appinfo(pkgname, &ai);
1633 if (ret != AIL_ERROR_OK) {
1638 if (ail_appinfo_get_bool(ai, AIL_PROP_X_SLP_ENABLED_BOOL, &enabled) != AIL_ERROR_OK)
1641 ail_destroy_appinfo(ai);
1643 return enabled == true;
1647 EAPI int livebox_service_is_primary(const char *lbid)
1660 ret = sqlite3_prepare_v2(handle, "SELECT prime FROM pkgmap WHERE pkgid = ?", -1, &stmt, NULL);
1661 if (ret != SQLITE_OK) {
1662 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1667 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
1668 if (ret != SQLITE_OK) {
1669 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1673 ret = sqlite3_step(stmt);
1674 if (ret != SQLITE_ROW) {
1675 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1679 ret = sqlite3_column_int(stmt, 0);
1682 sqlite3_reset(stmt);
1683 sqlite3_finalize(stmt);
1689 * appid == Package ID
1690 * pkgid == Livebox ID
1692 EAPI char *livebox_service_appid(const char *pkgname)
1698 int is_prime __attribute__((__unused__));
1709 ret = sqlite3_prepare_v2(handle, "SELECT appid, prime FROM pkgmap WHERE pkgid = ? OR appid = ?", -1, &stmt, NULL);
1710 if (ret != SQLITE_OK) {
1711 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1715 ret = sqlite3_bind_text(stmt, 1, pkgname, -1, SQLITE_TRANSIENT);
1716 if (ret != SQLITE_OK) {
1717 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1718 sqlite3_reset(stmt);
1719 sqlite3_finalize(stmt);
1723 ret = sqlite3_bind_text(stmt, 2, pkgname, -1, SQLITE_TRANSIENT);
1724 if (ret != SQLITE_OK) {
1725 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1726 sqlite3_reset(stmt);
1727 sqlite3_finalize(stmt);
1731 ret = sqlite3_step(stmt);
1732 if (ret != SQLITE_ROW) {
1733 pkgmgr_appinfo_h pkg_handle;
1736 ErrPrint("Has no record?: %s\n", sqlite3_errmsg(handle));
1737 sqlite3_reset(stmt);
1738 sqlite3_finalize(stmt);
1740 ret = pkgmgr_appinfo_get_appinfo(pkgname, &pkg_handle);
1741 if (ret != PKGMGR_R_OK) {
1742 ErrPrint("Failed to get appinfo: %s\n", pkgname);
1746 ret = pkgmgr_appinfo_get_pkgname(pkg_handle, &new_appid);
1747 if (ret != PKGMGR_R_OK) {
1748 ErrPrint("Failed to get pkgname for (%s)\n", appid);
1749 pkgmgr_appinfo_destroy_appinfo(pkg_handle);
1753 appid = strdup(new_appid);
1755 ErrPrint("Heap: %s\n", strerror(errno));
1757 pkgmgr_appinfo_destroy_appinfo(pkg_handle);
1761 tmp = (char *)sqlite3_column_text(stmt, 0);
1762 if (!tmp || !strlen(tmp)) {
1763 ErrPrint("APPID is NIL\n");
1764 sqlite3_reset(stmt);
1765 sqlite3_finalize(stmt);
1769 appid = strdup(tmp);
1771 ErrPrint("Heap: %s\n", strerror(errno));
1772 sqlite3_reset(stmt);
1773 sqlite3_finalize(stmt);
1777 is_prime = sqlite3_column_int(stmt, 1);
1779 sqlite3_reset(stmt);
1780 sqlite3_finalize(stmt);
1786 EAPI char *livebox_service_lb_script_path(const char *pkgid)
1803 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.box_src FROM provider, pkgmap WHERE pkgmap.pkgid = ? AND provider.pkgid = ?", -1, &stmt, NULL);
1804 if (ret != SQLITE_OK) {
1805 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1809 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1810 if (ret != SQLITE_OK) {
1811 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1812 sqlite3_finalize(stmt);
1816 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1817 if (ret != SQLITE_OK) {
1818 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1819 sqlite3_finalize(stmt);
1823 ret = sqlite3_step(stmt);
1824 if (ret != SQLITE_ROW) {
1825 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1826 sqlite3_reset(stmt);
1827 sqlite3_finalize(stmt);
1831 appid = (char *)sqlite3_column_text(stmt, 0);
1832 if (!appid || !strlen(appid)) {
1833 ErrPrint("Invalid appid : %s\n", sqlite3_errmsg(handle));
1834 sqlite3_reset(stmt);
1835 sqlite3_finalize(stmt);
1839 lb_src = (char *)sqlite3_column_text(stmt, 1);
1840 if (!lb_src || !strlen(lb_src)) {
1841 ErrPrint("No records for lb src : %s\n", sqlite3_errmsg(handle));
1842 sqlite3_reset(stmt);
1843 sqlite3_finalize(stmt);
1847 path = strdup(lb_src);
1849 ErrPrint("Heap: %s\n", strerror(errno));
1850 sqlite3_reset(stmt);
1851 sqlite3_finalize(stmt);
1855 DbgPrint("LB Src: %s\n", path);
1857 sqlite3_reset(stmt);
1858 sqlite3_finalize(stmt);
1864 EAPI char *livebox_service_lb_script_group(const char *pkgid)
1880 ret = sqlite3_prepare_v2(handle, "SELECT box_group FROM provider WHERE pkgid = ?", -1, &stmt, NULL);
1881 if (ret != SQLITE_OK) {
1882 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1886 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1887 if (ret != SQLITE_OK) {
1888 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1889 sqlite3_finalize(stmt);
1893 ret = sqlite3_step(stmt);
1894 if (ret != SQLITE_ROW) {
1895 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1896 sqlite3_reset(stmt);
1897 sqlite3_finalize(stmt);
1901 tmp = (char *)sqlite3_column_text(stmt, 0);
1902 if (tmp && strlen(tmp)) {
1903 group = strdup(tmp);
1905 ErrPrint("Heap: %s\n", strerror(errno));
1908 sqlite3_reset(stmt);
1909 sqlite3_finalize(stmt);
1915 EAPI char *livebox_service_pd_script_path(const char *pkgid)
1932 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.pd_src FROM provider, pkgmap WHERE provider.pkgid = ? AND pkgmap.pkgid = ?", -1, &stmt, NULL);
1933 if (ret != SQLITE_OK) {
1934 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1938 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1939 if (ret != SQLITE_OK) {
1940 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1941 sqlite3_finalize(stmt);
1945 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1946 if (ret != SQLITE_OK) {
1947 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1948 sqlite3_finalize(stmt);
1952 ret = sqlite3_step(stmt);
1953 if (ret != SQLITE_ROW) {
1954 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1955 sqlite3_reset(stmt);
1956 sqlite3_finalize(stmt);
1960 appid = (char *)sqlite3_column_text(stmt, 0);
1961 if (!appid || !strlen(appid)) {
1962 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1963 sqlite3_reset(stmt);
1964 sqlite3_finalize(stmt);
1968 pd_src = (char *)sqlite3_column_text(stmt, 1);
1969 if (!pd_src || !strlen(pd_src)) {
1970 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1971 sqlite3_reset(stmt);
1972 sqlite3_finalize(stmt);
1976 path = strdup(pd_src);
1978 ErrPrint("Heap: %s\n", strerror(errno));
1979 sqlite3_reset(stmt);
1980 sqlite3_finalize(stmt);
1984 DbgPrint("PD Src: %s\n", path);
1985 sqlite3_reset(stmt);
1986 sqlite3_finalize(stmt);
1992 EAPI char *livebox_service_pd_script_group(const char *pkgid)
2008 ret = sqlite3_prepare_v2(handle, "SELECT pd_group FROM provider WHERE pkgid = ?", -1, &stmt, NULL);
2009 if (ret != SQLITE_OK) {
2010 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2014 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
2015 if (ret != SQLITE_OK) {
2016 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2017 sqlite3_finalize(stmt);
2021 ret = sqlite3_step(stmt);
2022 if (ret != SQLITE_ROW) {
2023 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2024 sqlite3_reset(stmt);
2025 sqlite3_finalize(stmt);
2029 tmp = (char *)sqlite3_column_text(stmt, 0);
2030 if (tmp && strlen(tmp)) {
2031 group = strdup(tmp);
2033 ErrPrint("Heap: %s\n", strerror(errno));
2035 sqlite3_reset(stmt);
2036 sqlite3_finalize(stmt);
2042 EAPI int livebox_service_enumerate_cluster_list(int (*cb)(const char *cluster, void *data), void *data)
2046 const char *cluster;
2051 return LB_STATUS_ERROR_INVALID;
2055 return LB_STATUS_ERROR_IO;
2058 ret = sqlite3_prepare_v2(handle, "SELECT DISTINCT cluster FROM groupinfo", -1, &stmt, NULL);
2059 if (ret != SQLITE_OK) {
2060 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2061 cnt = LB_STATUS_ERROR_IO;
2065 while (sqlite3_step(stmt) == SQLITE_ROW) {
2066 cluster = (const char *)sqlite3_column_text(stmt, 0);
2067 if (!cluster || !strlen(cluster))
2070 if (cb(cluster, data) < 0)
2076 sqlite3_reset(stmt);
2077 sqlite3_finalize(stmt);
2083 EAPI int livebox_service_enumerate_category_list(const char *cluster, int (*cb)(const char *cluster, const char *category, void *data), void *data)
2087 const char *category;
2091 if (!cluster || !cb)
2092 return LB_STATUS_ERROR_INVALID;
2096 return LB_STATUS_ERROR_IO;
2098 ret = sqlite3_prepare_v2(handle, "SELECT DISTINCT category FROM groupinfo WHERE cluster = ?", -1, &stmt, NULL);
2099 if (ret != SQLITE_OK) {
2100 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2101 cnt = LB_STATUS_ERROR_IO;
2106 while (sqlite3_step(stmt) == SQLITE_ROW) {
2107 category = (const char *)sqlite3_column_text(stmt, 0);
2108 if (!category || !strlen(category))
2111 if (cb(cluster, category, data) < 0)
2117 sqlite3_reset(stmt);
2118 sqlite3_finalize(stmt);
2124 EAPI int livebox_service_init(void)
2126 if (s_info.handle) {
2127 DbgPrint("Already initialized\n");
2128 s_info.init_count++;
2132 s_info.handle = open_db();
2133 if (s_info.handle) {
2134 s_info.init_count++;
2138 return LB_STATUS_ERROR_IO;
2141 EAPI int livebox_service_fini(void)
2143 if (!s_info.handle || s_info.init_count <= 0) {
2144 ErrPrint("Service is not initialized\n");
2145 return LB_STATUS_ERROR_IO;
2148 s_info.init_count--;
2149 if (s_info.init_count > 0) {
2150 DbgPrint("Init count %d\n", s_info.init_count);
2154 db_util_close(s_info.handle);
2155 s_info.handle = NULL;
2159 EAPI int livebox_service_get_size(int type, int *width, int *height)
2170 return convert_size_from_type(type, width, height);
2173 EAPI int livebox_service_size_type(int width, int height)
2177 if (update_resolution() < 0)
2178 ErrPrint("Failed to update the size list\n");
2180 for (idx = 0; idx < NR_OF_SIZE_LIST; idx++) {
2181 if (SIZE_LIST[idx].w == width && SIZE_LIST[idx].h == height)
2187 return LB_SIZE_TYPE_1x1;
2189 return LB_SIZE_TYPE_2x1;
2191 return LB_SIZE_TYPE_2x2;
2193 return LB_SIZE_TYPE_4x1;
2195 return LB_SIZE_TYPE_4x2;
2197 return LB_SIZE_TYPE_4x3;
2199 return LB_SIZE_TYPE_4x4;
2201 return LB_SIZE_TYPE_4x5;
2203 return LB_SIZE_TYPE_4x6;
2205 return LB_SIZE_TYPE_EASY_1x1;
2207 return LB_SIZE_TYPE_EASY_3x1;
2209 return LB_SIZE_TYPE_EASY_3x3;
2211 return LB_SIZE_TYPE_0x0;
2216 return LB_SIZE_TYPE_UNKNOWN;