summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHyunho Kang <hhstark.kang@samsung.com>2016-01-22 11:50:45 +0900
committerHyunho Kang <hhstark.kang@samsung.com>2016-02-29 19:52:49 +0900
commit5c19ca93cb9303170f2ea93b122fd08e4e805ce6 (patch)
tree9ef65eed439fd719d6dee841e39be64d5c7c3540
parent661d6e334db995552335c4db8aeb085a656aee1f (diff)
downloadshortcut-5c19ca93cb9303170f2ea93b122fd08e4e805ce6.tar.gz
shortcut-5c19ca93cb9303170f2ea93b122fd08e4e805ce6.tar.bz2
shortcut-5c19ca93cb9303170f2ea93b122fd08e4e805ce6.zip
Using gdbus for IPC instead of com-core packagetizen_3.0_dbus
Change-Id: I2213aa72050e6aa183b2ae4768c4ec0b19cd6601 Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com> Signed-off-by: jusung son <jusung07.son@samsung.com>
-rwxr-xr-xlib/CMakeLists.txt3
-rwxr-xr-xlib/include/shortcut.h4
-rw-r--r--lib/include/shortcut_db.h28
-rwxr-xr-xlib/include/shortcut_private.h3
-rwxr-xr-xlib/src/shortcut_db.c280
-rwxr-xr-xlib/src/shortcut_manager.c906
-rwxr-xr-xpackaging/libshortcut.spec2
-rwxr-xr-xpkgmgr_shortcut/src/service_register.c13
8 files changed, 688 insertions, 551 deletions
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index dffc802..2cb3dee 100755
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -16,7 +16,6 @@ pkg_check_modules(svc_pkgs REQUIRED
libxml-2.0
glib-2.0
db-util
- com-core
vconf
capi-base-common
aul
@@ -36,6 +35,7 @@ ADD_DEFINITIONS("-DDB_PATH=\"${DB_PATH}\"")
ADD_LIBRARY(${PROJECT_NAME} SHARED
src/shortcut_manager.c
+ src/shortcut_db.c
)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${svc_pkgs_LDFLAGS})
@@ -46,6 +46,7 @@ SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_NAME}
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR})
INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/include/shortcut.h DESTINATION include/${PROJECT_NAME})
INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/include/shortcut_private.h DESTINATION include/${PROJECT_NAME})
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/include/shortcut_db.h DESTINATION include/${PROJECT_NAME})
INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/include/shortcut_manager.h DESTINATION include/${PROJECT_NAME})
INSTALL(FILES ${CMAKE_BINARY_DIR}/lib/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/LICENSE DESTINATION /usr/share/license RENAME "lib${PROJECT_NAME}")
diff --git a/lib/include/shortcut.h b/lib/include/shortcut.h
index 7d35a35..aad37b9 100755
--- a/lib/include/shortcut.h
+++ b/lib/include/shortcut.h
@@ -20,6 +20,7 @@
#include <tizen.h>
#include <shortcut_manager.h>
+#include <glib.h>
#ifdef __cplusplus
extern "C" {
@@ -85,6 +86,9 @@ enum shortcut_internal_type {
DYNAMICBOX_TYPE_UNKNOWN = 0x1FFF0000, /**< Error */
};
+#define SHORTCUT_ERROR (shortcut_error_quark ())
+GQuark shortcut_error_quark(void);
+
/**
* @brief Definition for a macro to check type.
diff --git a/lib/include/shortcut_db.h b/lib/include/shortcut_db.h
new file mode 100644
index 0000000..4c51f7d
--- /dev/null
+++ b/lib/include/shortcut_db.h
@@ -0,0 +1,28 @@
+
+#ifndef __SHORTCUT_DB_H__
+#define __SHORTCUT_DB_H__
+
+
+#include <sqlite3.h>
+#include <shortcut.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct shortcut_info {
+ char *package_name;
+ char *icon;
+ char *name;
+ char *extra_key;
+ char *extra_data;
+} shortcut_info_s;
+
+extern int shortcut_db_get_list(const char *package_name, GList **shortcut_list);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SHORTCUT_DB_H__ */ \ No newline at end of file
diff --git a/lib/include/shortcut_private.h b/lib/include/shortcut_private.h
index 260668c..2654d2c 100755
--- a/lib/include/shortcut_private.h
+++ b/lib/include/shortcut_private.h
@@ -29,9 +29,6 @@ extern FILE *__file_log_fp;
#define EAPI __attribute__((visibility("default")))
#endif
-#if !defined(VCONFKEY_MASTER_STARTED)
-#define VCONFKEY_MASTER_STARTED "memory/data-provider-master/started"
-#endif
#define DEFAULT_ICON_LAYOUT ""
#define DEFAULT_ICON_GROUP ""
diff --git a/lib/src/shortcut_db.c b/lib/src/shortcut_db.c
new file mode 100755
index 0000000..4385cc4
--- /dev/null
+++ b/lib/src/shortcut_db.c
@@ -0,0 +1,280 @@
+#include <dlog.h>
+#include <glib.h>
+#include <db-util.h>
+#include <shortcut_private.h>
+#include <shortcut_db.h>
+#include <vconf.h>
+#include <vconf-keys.h>
+
+
+
+static sqlite3 * _open_db(void)
+{
+ int ret;
+ const char *dbfile = DB_PATH;
+ sqlite3 *db = NULL;
+
+ ret = db_util_open(dbfile, &db, 0);
+ if (ret != SQLITE_OK) {
+ DbgPrint("Failed to open a %s\n", dbfile);
+ return NULL;
+ }
+
+ return db;
+}
+
+static int _close_db(sqlite3 ** db)
+{
+ int ret = 0;
+
+ if (db == NULL || *db == NULL)
+ return SHORTCUT_ERROR_INVALID_PARAMETER;
+
+ ret = db_util_close(*db);
+ if (ret != SQLITE_OK) {
+ DbgPrint("DB close error(%d)", ret);
+ return SHORTCUT_ERROR_IO_ERROR;
+ }
+
+ *db = NULL;
+
+ return SHORTCUT_ERROR_NONE;
+}
+
+
+/*!
+ * \note this function will returns allocated(heap) string
+ */
+static inline int _get_i18n_name(sqlite3 *handle, const char *lang, int id, char **name, char **icon)
+{
+ sqlite3_stmt *stmt;
+ static const char *query = "SELECT name, icon FROM shortcut_name WHERE id = ? AND lang = ? COLLATE NOCASE";
+ const unsigned char *_name;
+ const unsigned char *_icon;
+ int ret = 0;
+ int status;
+
+ status = sqlite3_prepare_v2(handle, query, -1, &stmt, NULL);
+ if (status != SQLITE_OK) {
+ ErrPrint("Failed to prepare stmt: %s\n", sqlite3_errmsg(handle));
+ return -EFAULT;
+ }
+
+ status = sqlite3_bind_int(stmt, 1, id);
+ if (status != SQLITE_OK) {
+ ErrPrint("Failed to bind id: %s\n", sqlite3_errmsg(handle));
+ ret = -EFAULT;
+ goto out;
+ }
+
+ status = sqlite3_bind_text(stmt, 2, lang, -1, SQLITE_TRANSIENT);
+ if (status != SQLITE_OK) {
+ ErrPrint("Failed to bind lang: %s\n", sqlite3_errmsg(handle));
+ ret = -EFAULT;
+ goto out;
+ }
+
+ DbgPrint("id: %d, lang: %s\n", id, lang);
+ if (SQLITE_ROW != sqlite3_step(stmt)) {
+ ErrPrint("Failed to do step: %s\n", sqlite3_errmsg(handle));
+ ret = -ENOENT;
+ goto out;
+ }
+
+ _name = sqlite3_column_text(stmt, 0);
+ if (name) {
+ if (_name && strlen((const char *)_name)) {
+ *name = strdup((const char *)_name);
+ if (!*name) {
+ ErrPrint("strdup: %d\n", errno);
+ ret = -ENOMEM;
+ goto out;
+ }
+ } else {
+ *name = NULL;
+ }
+ }
+
+ _icon = sqlite3_column_text(stmt, 1);
+ if (icon) {
+ if (_icon && strlen((const char *)_icon)) {
+ *icon = strdup((const char *)_icon);
+ if (!*icon) {
+ ErrPrint("strdup: %d\n", errno);
+ ret = -ENOMEM;
+ if (name && *name)
+ free(*name);
+
+ goto out;
+ }
+ } else {
+ *icon = NULL;
+ }
+ }
+
+out:
+ sqlite3_reset(stmt);
+ sqlite3_clear_bindings(stmt);
+ sqlite3_finalize(stmt);
+ return ret;
+}
+
+static inline char *_cur_locale(void)
+{
+ char *language;
+ char *ptr;
+
+ language = vconf_get_str(VCONFKEY_LANGSET);
+ if (language) {
+ ptr = language;
+ while (*ptr) {
+ if (*ptr == '.') {
+ *ptr = '\0';
+ break;
+ }
+
+ if (*ptr == '_')
+ *ptr = '-';
+
+ ptr++;
+ }
+ } else {
+ language = strdup("en-us");
+ if (!language)
+ ErrPrint("Heap: %d\n", errno);
+ }
+
+ return language;
+}
+
+EAPI int shortcut_db_get_list(const char *package_name, GList **shortcut_list)
+{
+ sqlite3_stmt *stmt;
+ sqlite3 *handle = NULL;
+ const char *query;
+ const unsigned char *name;
+ char *i18n_name = NULL;
+ char *i18n_icon = NULL;
+ const unsigned char *extra_data;
+ const unsigned char *extra_key;
+ const unsigned char *icon;
+ shortcut_info_s *shortcut;
+ int id;
+ int ret;
+ int cnt;
+ char *language;
+
+ handle = _open_db();
+ if (!handle) {
+ ErrPrint("Failed to open a DB\n");
+ return SHORTCUT_ERROR_IO_ERROR;
+ }
+
+ language = _cur_locale();
+ if (!language) {
+ ErrPrint("Locale is not valid\n");
+ _close_db(&handle);
+ return SHORTCUT_ERROR_FAULT;
+ }
+
+ if (package_name) {
+ query = "SELECT id, appid, name, extra_key, extra_data, icon FROM shortcut_service WHERE appid = ?";
+ ret = sqlite3_prepare_v2(handle, query, -1, &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ ErrPrint("prepare: %s\n", sqlite3_errmsg(handle));
+ free(language);
+ _close_db(&handle);
+ return SHORTCUT_ERROR_IO_ERROR;
+ }
+
+ ret = sqlite3_bind_text(stmt, 1, package_name, -1, SQLITE_TRANSIENT);
+ if (ret != SQLITE_OK) {
+ ErrPrint("bind text: %s\n", sqlite3_errmsg(handle));
+ sqlite3_finalize(stmt);
+ free(language);
+ _close_db(&handle);
+ return SHORTCUT_ERROR_IO_ERROR;
+ }
+ } else {
+ query = "SELECT id, appid, name, extra_key, extra_data, icon FROM shortcut_service";
+ ret = sqlite3_prepare_v2(handle, query, -1, &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ ErrPrint("prepare: %s\n", sqlite3_errmsg(handle));
+ free(language);
+ _close_db(&handle);
+ return SHORTCUT_ERROR_IO_ERROR;
+ }
+ }
+
+ cnt = 0;
+ *shortcut_list = NULL;
+ while (SQLITE_ROW == sqlite3_step(stmt)) {
+ id = sqlite3_column_int(stmt, 0);
+
+ package_name = (const char *)sqlite3_column_text(stmt, 1);
+ if (!package_name) {
+ LOGE("Failed to get package name\n");
+ continue;
+ }
+
+ name = sqlite3_column_text(stmt, 2);
+ if (!name) {
+ LOGE("Failed to get name\n");
+ continue;
+ }
+
+ extra_key = sqlite3_column_text(stmt, 3);
+ if (!extra_key) {
+ LOGE("Failed to get service\n");
+ continue;
+ }
+
+ extra_data = sqlite3_column_text(stmt, 4);
+ if (!extra_data) {
+ LOGE("Failed to get service\n");
+ continue;
+ }
+
+ icon = sqlite3_column_text(stmt, 5);
+ if (!icon) {
+ LOGE("Failed to get icon\n");
+ continue;
+ }
+
+ /*!
+ * \todo
+ * Implement the "GET LOCALE" code
+ */
+ /* if (get_i18n_name(language, id, &i18n_name, &i18n_icon) < 0) { */
+ /* Okay, we can't manage this. just use the fallback string */
+ /* } */
+ _get_i18n_name(handle, language, id, &i18n_name, &i18n_icon);
+
+ cnt++;
+ shortcut = (shortcut_info_s *)calloc(sizeof(shortcut_info_s), 1);
+ if (shortcut == NULL) {
+ free(i18n_name);
+ break;
+ }
+ shortcut->package_name = strdup(package_name);
+ shortcut->icon = strdup((i18n_icon != NULL ? i18n_icon : (char *)icon));
+ shortcut->name = strdup((i18n_name != NULL ? i18n_name : (char *)name));
+ shortcut->extra_key = strdup((char *)extra_key);
+ shortcut->extra_data = strdup((char *)extra_key);
+ *shortcut_list = g_list_append(*shortcut_list, shortcut);
+
+ free(i18n_name);
+ i18n_name = NULL;
+
+ free(i18n_icon);
+ i18n_icon = NULL;
+ }
+
+ sqlite3_reset(stmt);
+ sqlite3_clear_bindings(stmt);
+ sqlite3_finalize(stmt);
+ free(language);
+ _close_db(&handle);
+
+ return cnt;
+}
diff --git a/lib/src/shortcut_manager.c b/lib/src/shortcut_manager.c
index 2b35089..7cc6426 100755
--- a/lib/src/shortcut_manager.c
+++ b/lib/src/shortcut_manager.c
@@ -14,257 +14,185 @@
* limitations under the License.
*
*/
-
+#include <gio/gio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <libgen.h>
#include <aul.h>
#include <dlog.h>
#include <glib.h>
#include <db-util.h>
-#include <vconf.h>
-#include <vconf-keys.h>
-
-#include <packet.h>
-#include <com-core.h>
-#include <com-core_packet.h>
#include "shortcut.h"
#include "shortcut_private.h"
+#include "shortcut_db.h"
#include "shortcut_manager.h"
#define SHORTCUT_PKGNAME_LEN 512
-
#define SHORTCUT_IS_WIDGET_SIZE(size) (!!((size) & WIDGET_SIZE_DEFAULT))
-#define SHORTCUT_IS_EASY_MODE_WIDGET_SIZE(size) (!!((size) & WIDGET_SIZE_EASY_DEFAULT))
-
-int errno;
-
-static inline int make_connection(void);
-
-static struct info {
- const char *dbfile;
- sqlite3 *handle;
- int server_fd;
- int client_fd;
- const char *socket_file;
- struct {
- int (*request_cb)(const char *appid, const char *name, int type, const char *content, const char *icon, pid_t pid, double period, int allow_duplicate, void *data);
- void *data;
- } server_cb;
- int initialized;
- int db_opened;
- guint timer_id;
-} s_info = {
- .server_fd = -1,
- .client_fd = -1,
- .socket_file = "/tmp/.shortcut.service",
- .dbfile = DB_PATH,
- .handle = NULL,
- .initialized = 0,
- .db_opened = 0,
- .timer_id = 0,
-};
-
-static struct packet *add_shortcut_handler(pid_t pid, int handle, const struct packet *packet)
-{
- const char *appid;
- const char *name;
- int type;
- const char *content;
- const char *icon;
- int allow_duplicate;
- int ret = SHORTCUT_ERROR_NONE;
- int sender_pid;
- if (!packet)
- return NULL;
+#define PROVIDER_BUS_NAME "org.tizen.data_provider_service"
+#define PROVIDER_OBJECT_PATH "/org/tizen/data_provider_service"
+#define PROVIDER_SHORTCUT_INTERFACE_NAME "org.tizen.data_provider_shortcut_service"
- if (packet_get(packet, "ississi", &sender_pid, &appid, &name, &type, &content, &icon, &allow_duplicate) != 7) {
- ErrPrint("Invalid packet\n");
- return NULL;
- }
+#define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
+#define DBUS_PATH_DBUS "/org/freedesktop/DBus"
+#define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
- DbgPrint("appid[%s], name[%s], type[0x%x], content[%s], icon[%s] allow_duplicate[%d]\n", appid, name, type, content, icon, allow_duplicate);
+static GDBusConnection *_gdbus_conn = NULL;
+static int monitor_id = 0;
+static int provider_monitor_id = 0;
- if (s_info.server_cb.request_cb)
- ret = s_info.server_cb.request_cb(appid, name, type, content, icon, sender_pid, -1.0f, allow_duplicate, s_info.server_cb.data);
- else
- ret = SHORTCUT_ERROR_NOT_SUPPORTED;
+static const GDBusErrorEntry dbus_error_entries[] =
+{
+ {SHORTCUT_ERROR_INVALID_PARAMETER, "org.freedesktop.Shortcut.Error.INVALID_PARAMETER"},
+ {SHORTCUT_ERROR_OUT_OF_MEMORY, "org.freedesktop.Shortcut.Error.OUT_OF_MEMORY"},
+ {SHORTCUT_ERROR_IO_ERROR, "org.freedesktop.Shortcut.Error.IO_ERROR"},
+ {SHORTCUT_ERROR_PERMISSION_DENIED, "org.freedesktop.Shortcut.Error.PERMISSION_DENIED"},
+ {SHORTCUT_ERROR_NOT_SUPPORTED, "org.freedesktop.Shortcut.Error.NOT_SUPPORTED"},
+ {SHORTCUT_ERROR_RESOURCE_BUSY, "org.freedesktop.Shortcut.Error.RESOURCE_BUSY"},
+ {SHORTCUT_ERROR_NO_SPACE, "org.freedesktop.Shortcut.Error.NO_SPACE"},
+ {SHORTCUT_ERROR_EXIST, "org.freedesktop.Shortcut.Error.EXIST"},
+ {SHORTCUT_ERROR_FAULT, "org.freedesktop.Shortcut.Error.FAULT"},
+ {SHORTCUT_ERROR_COMM, "org.freedesktop.Shortcut.Error.COMM"},
+};
- if (ret != SHORTCUT_ERROR_NONE)
- ErrPrint("ret [%d]\n", ret);
+struct result_cb_item {
+ result_internal_cb_t result_internal_cb;
+ result_cb_t result_cb;
+ void *data;
+};
- return packet_create_reply(packet, "i", ret);
-}
+typedef struct _shortcut_cb_info {
+ int (*request_cb)(const char *appid, const char *name, int type, const char *content, const char *icon, pid_t pid, double period, int allow_duplicate, void *data);
+ void *data;
+} shortcut_cb_info;
+static shortcut_cb_info _callback_info;
+static int _dbus_init();
+static char *_shortcut_get_pkgname_by_pid(void);
+EXPORT_API GQuark shortcut_error_quark (void)
+{
+ static volatile gsize quark_volatile = 0;
+ g_dbus_error_register_error_domain ("shortcut-error-quark",
+ &quark_volatile,
+ dbus_error_entries,
+ G_N_ELEMENTS(dbus_error_entries));
+ return (GQuark) quark_volatile;
+}
-static struct packet *add_shortcut_widget_handler(pid_t pid, int handle, const struct packet *packet)
+static void _add_shortcut_notify(GVariant *parameters)
{
- const char *widget_id;
+ const char *appid;
const char *name;
int type;
const char *content;
const char *icon;
- double period;
int allow_duplicate;
- int ret = SHORTCUT_ERROR_NONE;
int sender_pid;
- if (!packet)
- return NULL;
-
- if (packet_get(packet, "ississdi", &sender_pid, &widget_id, &name, &type, &content, &icon, &period, &allow_duplicate) != 8) {
- ErrPrint("Invalid packet\n");
- return NULL;
- }
-
- DbgPrint("widget_id[%s], name[%s], type[0x%x], content[%s], icon[%s], period[%lf], allow_duplicate[%d]\n", widget_id, name, type, content, icon, period, allow_duplicate);
-
- if (s_info.server_cb.request_cb)
- ret = s_info.server_cb.request_cb(widget_id, name, type, content, icon, sender_pid, period, allow_duplicate, s_info.server_cb.data);
- else
- ret = 0;
-
- if (ret != SHORTCUT_ERROR_NONE)
- ErrPrint("ret [%d]\n", ret);
-
- return packet_create_reply(packet, "i", ret);
+ g_variant_get(parameters, "(i&s&si&s&si)", &sender_pid, &appid, &name, &type, &content, &icon, &allow_duplicate);
+ DbgPrint("_add_shortcut_notify sender_pid: %d ", sender_pid);
+ _callback_info.request_cb(appid, name, type, content, icon, sender_pid, -1.0f, allow_duplicate, _callback_info.data);
}
-int shortcut_is_master_ready(void)
+static void _add_shortcut_widget_notify(GVariant *parameters)
{
- int ret = -1, is_master_started = 0;
-
- ret = vconf_get_bool(VCONFKEY_MASTER_STARTED, &is_master_started);
- if (ret == 0 && is_master_started == 1) {
- ErrPrint("the master has been started");
- } else {
- is_master_started = 0;
- ErrPrint("the master has been stopped");
- }
+ const char *appid;
+ const char *name;
+ int type;
+ const char *content;
+ const char *icon;
+ int allow_duplicate;
+ int sender_pid;
+ double period;
- return is_master_started;
+ g_variant_get(parameters, "(i&s&si&s&sdi)", &sender_pid, &appid, &name, &type, &content, &icon, &period, &allow_duplicate);
+ _callback_info.request_cb(appid, name, type, content, icon, sender_pid, period, allow_duplicate, _callback_info.data);
}
-static void master_started_cb(keynode_t *node, void *user_data)
+static void _handle_shortcut_notify(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
{
- int state = 0;
-
- if (vconf_get_bool(VCONFKEY_MASTER_STARTED, &state) < 0)
- ErrPrint("Unable to get \"%s\"\n", VCONFKEY_MASTER_STARTED);
-
- if (state == 1 && make_connection() == SHORTCUT_ERROR_NONE)
- (void)vconf_ignore_key_changed(VCONFKEY_MASTER_STARTED, master_started_cb);
+ DbgPrint("signal_name: %s", signal_name);
+ if (g_strcmp0(signal_name, "add_shortcut_notify") == 0)
+ _add_shortcut_notify(parameters);
+ else if (g_strcmp0(signal_name, "add_shortcut_widget_notify") == 0)
+ _add_shortcut_widget_notify(parameters);
}
-static gboolean timeout_cb(void *data)
+static int _dbus_init(void)
{
- int ret;
-
- ret = vconf_notify_key_changed(VCONFKEY_MASTER_STARTED, master_started_cb, NULL);
- if (ret < 0)
- ErrPrint("Failed to add vconf for service state [%d]\n", ret);
- else
- DbgPrint("vconf is registered\n");
-
- master_started_cb(NULL, NULL);
-
- s_info.timer_id = 0;
- return FALSE;
-}
+ GError *error = NULL;
+ if (_gdbus_conn == NULL) {
+ _gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
-
-static int disconnected_cb(int handle, void *data)
-{
- if (s_info.client_fd == handle) {
- s_info.client_fd = SHORTCUT_ERROR_INVALID_PARAMETER;
- return 0;
- }
-
- if (s_info.server_fd == handle) {
- if (!s_info.timer_id) {
- s_info.server_fd = SHORTCUT_ERROR_INVALID_PARAMETER;
- s_info.timer_id = g_timeout_add(1000, timeout_cb, NULL);
- if (!s_info.timer_id)
- ErrPrint("Unable to add timer\n");
+ if (_gdbus_conn == NULL) {
+ if (error != NULL) {
+ ErrPrint("Failed to get dbus [%s]", error->message);
+ g_error_free(error);
+ }
+ return SHORTCUT_ERROR_IO_ERROR;
}
- return 0;
+ shortcut_error_quark();
}
- return 0;
+ return SHORTCUT_ERROR_NONE;
}
-static inline int make_connection(void)
+static int _dbus_signal_init()
{
- int ret;
- struct packet *packet;
- static struct method service_table[] = {
- {
- .cmd = "add_shortcut",
- .handler = add_shortcut_handler,
- },
- {
- .cmd = "add_shortcut_widget",
- .handler = add_shortcut_widget_handler,
- },
- };
-
- if (s_info.initialized == 0) {
- s_info.initialized = 1;
- com_core_add_event_callback(CONNECTOR_DISCONNECTED, disconnected_cb, NULL);
- }
-
- s_info.server_fd = com_core_packet_client_init(s_info.socket_file, 0, service_table);
- if (s_info.server_fd < 0) {
- ErrPrint("Failed to make a connection to the master\n");
- return SHORTCUT_ERROR_COMM;
- }
-
- packet = packet_create_noack("service_register", "");
- if (!packet) {
- ErrPrint("Failed to build a packet\n");
- return SHORTCUT_ERROR_FAULT;
- }
+ int ret = SHORTCUT_ERROR_NONE;
+ int id;
- ret = com_core_packet_send_only(s_info.server_fd, packet);
- DbgPrint("Service register sent: %d\n", ret);
- packet_destroy(packet);
- if (ret != 0) {
- com_core_packet_client_fini(s_info.server_fd);
- s_info.server_fd = -1;
- ret = SHORTCUT_ERROR_COMM;
- } else {
- ret = SHORTCUT_ERROR_NONE;
+ if (monitor_id == 0) {
+ DbgPrint("get dbus connection success");
+ id = g_dbus_connection_signal_subscribe(
+ _gdbus_conn,
+ PROVIDER_BUS_NAME,
+ PROVIDER_SHORTCUT_INTERFACE_NAME, /* interface */
+ NULL, /* member */
+ PROVIDER_OBJECT_PATH, /* path */
+ NULL, /* arg0 */
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ _handle_shortcut_notify,
+ NULL,
+ NULL);
+
+ DbgPrint("subscribe id : %d", id);
+ if (id == 0) {
+ ret = SHORTCUT_ERROR_IO_ERROR;
+ ErrPrint("Failed to _register_noti_dbus_interface");
+ } else {
+ monitor_id = id;
+ }
}
- DbgPrint("Server FD: %d\n", s_info.server_fd);
return ret;
}
-
-
static char *_shortcut_get_pkgname_by_pid(void)
{
char pkgname[SHORTCUT_PKGNAME_LEN + 1] = { 0, };
- int pid = 0, ret = 0;
+ char buf[SHORTCUT_PKGNAME_LEN + 1] = { 0, };
+ int pid, ret;
int fd;
- char *dup_pkgname;
+ char *dup_pkgname;
pid = getpid();
ret = aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname));
if (ret != 0) {
- char buf[SHORTCUT_PKGNAME_LEN + 1] = { 0, };
-
snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
fd = open(buf, O_RDONLY);
@@ -295,124 +223,227 @@ static char *_shortcut_get_pkgname_by_pid(void)
return dup_pkgname;
}
+/*
+ * implement user request
+ */
+static int _send_sync_shortcut(GVariant *body, GDBusMessage **reply, char *cmd)
+{
+ GError *err = NULL;
+ GDBusMessage *msg ;
+ int ret = SHORTCUT_ERROR_NONE;
+ msg = g_dbus_message_new_method_call(
+ PROVIDER_BUS_NAME,
+ PROVIDER_OBJECT_PATH,
+ PROVIDER_SHORTCUT_INTERFACE_NAME,
+ cmd);
+ if (!msg) {
+ ErrPrint("Can't allocate new method call");
+ if (body)
+ g_variant_unref(body);
+ return SHORTCUT_ERROR_OUT_OF_MEMORY;
+ }
-EAPI int shortcut_set_request_cb(shortcut_request_cb request_cb, void *data)
-{
- if (request_cb == NULL)
- return SHORTCUT_ERROR_INVALID_PARAMETER;
+ if (body != NULL)
+ g_dbus_message_set_body(msg, body);
- s_info.server_cb.request_cb = request_cb;
- s_info.server_cb.data = data;
+ *reply = g_dbus_connection_send_message_with_reply_sync(
+ _gdbus_conn,
+ msg,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL,
+ &err);
- if (s_info.server_fd < 0) {
- int ret;
+ g_object_unref(msg);
- ret = vconf_notify_key_changed(VCONFKEY_MASTER_STARTED, master_started_cb, NULL);
- if (ret < 0) {
- ErrPrint("Failed to add vconf for service state [%d]\n", ret);
- return SHORTCUT_ERROR_COMM;
- } else {
- DbgPrint("vconf is registered\n");
+ if (!*reply) {
+ if (err != NULL) {
+ ErrPrint("No reply. error = %s", err->message);
+ g_error_free(err);
}
-
- master_started_cb(NULL, NULL);
+ return SHORTCUT_ERROR_COMM;
}
+ if (g_dbus_message_to_gerror(*reply, &err)) {
+ ret = err->code;
+ ErrPrint("_send_sync_shortcut error %s", err->message);
+ g_error_free(err);
+ return ret;
+ }
+ DbgPrint("_send_sync_shortcut done !!");
return SHORTCUT_ERROR_NONE;
}
+static int _send_service_register()
+{
+ GDBusMessage *reply = NULL;
+ int result;
-struct result_cb_item {
- result_internal_cb_t result_internal_cb;
- result_cb_t result_cb;
- void *data;
-};
+ result = _send_sync_shortcut(NULL, &reply, "shortcut_service_register");
+ ErrPrint("_send_service_register done");
+ return result;
+}
-static int shortcut_send_cb(pid_t pid, int handle, const struct packet *packet, void *data)
+static void _send_message_with_reply_sync_cb(GDBusConnection *connection,
+ GAsyncResult *res,
+ gpointer user_data)
{
- struct result_cb_item *item = data;
- int ret;
+ int result = SHORTCUT_ERROR_NONE;
+ GError *err = NULL;
+ GDBusMessage *reply = NULL;
+ struct result_cb_item *cb_item = (struct result_cb_item *)user_data;
- if (!packet) {
- ErrPrint("Packet is not valid\n");
- ret = SHORTCUT_ERROR_FAULT;
- } else if (packet_get(packet, "i", &ret) != 1) {
- ErrPrint("Packet is not valid\n");
- ret = SHORTCUT_ERROR_INVALID_PARAMETER;
+ if (cb_item == NULL) {
+ ErrPrint("Failed to get a callback item");
+ return;
}
- if (ret != SHORTCUT_ERROR_NONE) {
- DbgPrint("Packet reply [%d]\n", ret);
- if (ret == SHORTCUT_ERROR_PERMISSION_DENIED)
- ret = SHORTCUT_ERROR_NONE;
+ reply = g_dbus_connection_send_message_with_reply_finish(
+ connection,
+ res,
+ &err);
+
+ if (!reply) {
+ if (err != NULL) {
+ ErrPrint("No reply. error = %s", err->message);
+ g_error_free(err);
+ }
+ result = SHORTCUT_ERROR_COMM;
+
+ } else if (g_dbus_message_to_gerror(reply, &err)) {
+ result = err->code;
+ g_error_free(err);
+ ErrPrint("_send_async_noti error %s", err->message);
}
- if (item->result_internal_cb)
- ret = item->result_internal_cb(ret, pid, item->data);
- else if (item->result_cb)
- ret = item->result_cb(ret, item->data);
- else
- ret = SHORTCUT_ERROR_NONE;
+ if (cb_item->result_internal_cb)
+ result = cb_item->result_internal_cb(result, getpid(), cb_item->data);
+ else if (cb_item->result_cb)
+ result = cb_item->result_cb(result, cb_item->data);
- free(item);
- return ret;
-}
+ if (reply)
+ g_object_unref(reply);
+ free(cb_item);
+}
-EAPI int add_to_home_shortcut(const char *appid, const char *name, int type, const char *content, const char *icon, int allow_duplicate, result_internal_cb_t result_cb, void *data)
+static int _send_async_noti(GVariant *body, struct result_cb_item *cb_item, char *cmd)
{
- /*Deprecated API */
+ GDBusMessage *msg;
+ msg = g_dbus_message_new_method_call(
+ PROVIDER_BUS_NAME,
+ PROVIDER_OBJECT_PATH,
+ PROVIDER_SHORTCUT_INTERFACE_NAME,
+ cmd);
+ if (!msg) {
+ ErrPrint("Can't allocate new method call");
+ return SHORTCUT_ERROR_OUT_OF_MEMORY;
+ }
+
+ if (body != NULL)
+ g_dbus_message_set_body(msg, body);
+
+ g_dbus_connection_send_message_with_reply(
+ _gdbus_conn,
+ msg,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL,
+ (GAsyncReadyCallback)_send_message_with_reply_sync_cb,
+ cb_item);
+
+ g_object_unref(msg);
+
+ DbgPrint("_send_async_noti done !!");
return SHORTCUT_ERROR_NONE;
}
-EAPI int add_to_home_dynamicbox(const char *appid, const char *name, int type, const char *content, const char *icon, double period, int allow_duplicate, result_internal_cb_t result_cb, void *data)
+static void _on_name_appeared(GDBusConnection *connection,
+ const gchar *name,
+ const gchar *name_owner,
+ gpointer user_data)
{
- /*Deprecated API */
- return SHORTCUT_ERROR_NONE;
+ DbgPrint("name appeared : %s", name);
+ _send_service_register();
}
+static void _on_name_vanished(GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ DbgPrint("name vanished : %s", name);
+}
+
+EAPI int shortcut_set_request_cb(shortcut_request_cb request_cb, void *data)
+{
+ int ret = _dbus_init();
+
+ if (ret != SHORTCUT_ERROR_NONE) {
+ ErrPrint("Can't init dbus %d", ret);
+ return ret;
+ }
+
+ ret = _dbus_signal_init();
+ if (ret != SHORTCUT_ERROR_NONE) {
+ ErrPrint("Can't init dbus_signal %d", ret);
+ return ret;
+ }
+
+ ret = _send_service_register();
+ if (ret != SHORTCUT_ERROR_NONE) {
+ ErrPrint("Can't init ipc_monitor_register %d", ret);
+ return ret;
+ }
+
+ if (request_cb == NULL)
+ return SHORTCUT_ERROR_INVALID_PARAMETER;
+
+ if (provider_monitor_id == 0) {
+ provider_monitor_id = g_bus_watch_name_on_connection(
+ _gdbus_conn,
+ PROVIDER_BUS_NAME,
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ _on_name_appeared,
+ _on_name_vanished,
+ NULL,
+ NULL);
+
+ if (provider_monitor_id == 0) {
+ ErrPrint("watch on name fail");
+ return SHORTCUT_ERROR_IO_ERROR;
+ }
+ }
+
+ _callback_info.request_cb = request_cb;
+ _callback_info.data = data;
+ return SHORTCUT_ERROR_NONE;
+}
-EAPI int shortcut_add_to_home(const char *name, shortcut_type type, const char *uri, const char *icon, int allow_duplicate, result_cb_t result_cb, void *data)
+EAPI int shortcut_add_to_home(const char *name, shortcut_type type, const char *uri,
+ const char *icon, int allow_duplicate, result_cb_t result_cb, void *data)
{
- struct packet *packet;
struct result_cb_item *item;
- char *appid = NULL;
+ char *appid;
int ret;
- static struct method service_table[] = {
- {
- .cmd = NULL,
- .handler = NULL,
- },
- };
+ GVariant *body;
if (ADD_TO_HOME_IS_DYNAMICBOX(type)) {
ErrPrint("Invalid type used for adding a shortcut\n");
return SHORTCUT_ERROR_INVALID_PARAMETER;
}
- appid = _shortcut_get_pkgname_by_pid();
-
- if (!s_info.initialized) {
- s_info.initialized = 1;
- com_core_add_event_callback(CONNECTOR_DISCONNECTED, disconnected_cb, NULL);
- }
-
- if (s_info.client_fd < 0) {
- s_info.client_fd = com_core_packet_client_init(s_info.socket_file, 0, service_table);
- if (s_info.client_fd < 0) {
- if (appid)
- free(appid);
-
- if (shortcut_is_master_ready() == 1)
- return SHORTCUT_ERROR_PERMISSION_DENIED;
- else
- return SHORTCUT_ERROR_COMM;
- }
+ ret = _dbus_init();
+ if (ret != SHORTCUT_ERROR_NONE) {
+ ErrPrint("Can't init dbus %d", ret);
+ return ret;
}
- item = malloc(sizeof(*item));
+ appid = _shortcut_get_pkgname_by_pid();
+ item = malloc(sizeof(struct result_cb_item));
if (!item) {
if (appid)
free(appid);
@@ -434,347 +465,132 @@ EAPI int shortcut_add_to_home(const char *name, shortcut_type type, const char *
if (!icon)
icon = "";
-
- packet = packet_create("add_shortcut", "ississi", getpid(), appid, name, type, uri, icon, allow_duplicate);
- if (!packet) {
- ErrPrint("Failed to build a packet\n");
- if (appid)
- free(appid);
-
- if (item)
- free(item);
-
- return SHORTCUT_ERROR_FAULT;
+ body = g_variant_new("(ississi)", getpid(), appid, name, type, uri, icon, allow_duplicate);
+ ret = _send_async_noti(body, item, "add_shortcut");
+ if (ret != SHORTCUT_ERROR_NONE) {
+ free(item);
+ item = NULL;
}
- ret = com_core_packet_async_send(s_info.client_fd, packet, 0.0f, shortcut_send_cb, item);
- packet_destroy(packet);
- if (ret < 0) {
- if (item)
- free(item);
-
- com_core_packet_client_fini(s_info.client_fd);
- s_info.client_fd = SHORTCUT_ERROR_INVALID_PARAMETER;
- return SHORTCUT_ERROR_COMM;
- }
+ if (appid)
+ free(appid);
+ if (body)
+ g_variant_unref(body);
- return SHORTCUT_ERROR_NONE;
+ return ret;
}
-
-EAPI int shortcut_add_to_home_widget(const char *name, shortcut_widget_size_e size, const char *widget_id, const char *icon, double period, int allow_duplicate, result_cb_t result_cb, void *data)
+EAPI int shortcut_add_to_home_widget(const char *name, shortcut_widget_size_e size, const char *widget_id,
+ const char *icon, double period, int allow_duplicate, result_cb_t result_cb, void *data)
{
- struct packet *packet;
struct result_cb_item *item;
- char *appid = NULL;
+ char *appid;
int ret;
- int err = SHORTCUT_ERROR_NONE;
- static struct method service_table[] = {
- {
- .cmd = NULL,
- .handler = NULL,
- },
- };
+ GVariant *body;
if (name == NULL) {
ErrPrint("AppID is null\n");
- err = SHORTCUT_ERROR_INVALID_PARAMETER;
- goto out;
+ return SHORTCUT_ERROR_INVALID_PARAMETER;
}
if (!SHORTCUT_IS_WIDGET_SIZE(size)) {
ErrPrint("Invalid type used for adding a widget\n");
- err = SHORTCUT_ERROR_INVALID_PARAMETER;
- goto out;
- }
-
- appid = _shortcut_get_pkgname_by_pid();
-
- if (!s_info.initialized) {
- s_info.initialized = 1;
- com_core_add_event_callback(CONNECTOR_DISCONNECTED, disconnected_cb, NULL);
+ return SHORTCUT_ERROR_INVALID_PARAMETER;
}
- if (s_info.client_fd < 0) {
- s_info.client_fd = com_core_packet_client_init(s_info.socket_file, 0, service_table);
- if (s_info.client_fd < 0) {
- err = SHORTCUT_ERROR_COMM;
- goto out;
- }
+ ret = _dbus_init();
+ if (ret != SHORTCUT_ERROR_NONE) {
+ ErrPrint("Can't init dbus %d", ret);
+ return ret;
}
- item = malloc(sizeof(*item));
+ appid = _shortcut_get_pkgname_by_pid();
+ item = malloc(sizeof(struct result_cb_item));
if (!item) {
+ if (appid)
+ free(appid);
+
ErrPrint("Heap: %d\n", errno);
- err = SHORTCUT_ERROR_OUT_OF_MEMORY;
- goto out;
+ return SHORTCUT_ERROR_OUT_OF_MEMORY;
}
- item->result_internal_cb = NULL;
item->result_cb = result_cb;
+ item->result_internal_cb = NULL;
item->data = data;
- packet = packet_create("add_shortcut_widget", "ississdi", getpid(), widget_id, name, size, NULL, icon, period, allow_duplicate);
- if (!packet) {
- ErrPrint("Failed to build a packet\n");
- free(item);
- err = SHORTCUT_ERROR_FAULT;
- goto out;
- }
+ body = g_variant_new("(ississdi)", getpid(), widget_id, name, size, NULL, icon, period, allow_duplicate);
+ ret = _send_async_noti(body, item, "add_shortcut_widget");
- ret = com_core_packet_async_send(s_info.client_fd, packet, 0.0f, shortcut_send_cb, item);
- if (ret < 0) {
- packet_destroy(packet);
+ if (ret != SHORTCUT_ERROR_NONE) {
free(item);
- com_core_packet_client_fini(s_info.client_fd);
- s_info.client_fd = SHORTCUT_ERROR_INVALID_PARAMETER;
- err = SHORTCUT_ERROR_COMM;
- goto out;
+ item = NULL;
}
-out:
+
if (appid)
free(appid);
+ if (body)
+ g_variant_unref(body);
- return err;
+ return ret;
}
-static inline int open_db(void)
+EAPI int add_to_home_shortcut(const char *appid, const char *name, int type, const char *content,
+ const char *icon, int allow_duplicate, result_internal_cb_t result_cb, void *data)
{
- int ret;
-
- ret = db_util_open(s_info.dbfile, &s_info.handle, DB_UTIL_REGISTER_HOOK_METHOD);
- if (ret != SQLITE_OK) {
- DbgPrint("Failed to open a %s\n", s_info.dbfile);
- return SHORTCUT_ERROR_IO_ERROR;
- }
-
+ /*Deprecated API */
return SHORTCUT_ERROR_NONE;
}
-/*!
- * \note this function will returns allocated(heap) string
- */
-static inline int get_i18n_name(const char *lang, int id, char **name, char **icon)
+EAPI int add_to_home_dynamicbox(const char *appid, const char *name, int type, const char *content, const char *icon, double period, int allow_duplicate, result_internal_cb_t result_cb, void *data)
{
- sqlite3_stmt *stmt;
- static const char *query = "SELECT name, icon FROM shortcut_name WHERE id = ? AND lang = ? COLLATE NOCASE";
- const unsigned char *_name;
- const unsigned char *_icon;
- int ret = 0;
- int status;
-
- status = sqlite3_prepare_v2(s_info.handle, query, -1, &stmt, NULL);
- if (status != SQLITE_OK) {
- ErrPrint("Failed to prepare stmt: %s\n", sqlite3_errmsg(s_info.handle));
- return -EFAULT;
- }
-
- status = sqlite3_bind_int(stmt, 1, id);
- if (status != SQLITE_OK) {
- ErrPrint("Failed to bind id: %s\n", sqlite3_errmsg(s_info.handle));
- ret = -EFAULT;
- goto out;
- }
-
- status = sqlite3_bind_text(stmt, 2, lang, -1, SQLITE_TRANSIENT);
- if (status != SQLITE_OK) {
- ErrPrint("Failed to bind lang: %s\n", sqlite3_errmsg(s_info.handle));
- ret = -EFAULT;
- goto out;
- }
-
- DbgPrint("id: %d, lang: %s\n", id, lang);
- if (SQLITE_ROW != sqlite3_step(stmt)) {
- ErrPrint("Failed to do step: %s\n", sqlite3_errmsg(s_info.handle));
- ret = -ENOENT;
- goto out;
- }
-
- _name = sqlite3_column_text(stmt, 0);
- if (name) {
- if (_name && strlen((const char *)_name)) {
- *name = strdup((const char *)_name);
- if (!*name) {
- ErrPrint("strdup: %d\n", errno);
- ret = -ENOMEM;
- goto out;
- }
- } else {
- *name = NULL;
- }
- }
-
- _icon = sqlite3_column_text(stmt, 1);
- if (icon) {
- if (_icon && strlen((const char *)_icon)) {
- *icon = strdup((const char *)_icon);
- if (!*icon) {
- ErrPrint("strdup: %d\n", errno);
- ret = -ENOMEM;
- if (name && *name)
- free(*name);
-
- goto out;
- }
- } else {
- *icon = NULL;
- }
- }
-
-out:
- sqlite3_reset(stmt);
- sqlite3_clear_bindings(stmt);
- sqlite3_finalize(stmt);
- return ret;
+ /*Deprecated API */
+ return SHORTCUT_ERROR_NONE;
}
-static inline char *cur_locale(void)
-{
- char *language;
- char *ptr;
-
- language = vconf_get_str(VCONFKEY_LANGSET);
- if (language) {
- ptr = language;
- while (*ptr) {
- if (*ptr == '.') {
- *ptr = '\0';
- break;
- }
-
- if (*ptr == '_')
- *ptr = '-';
-
- ptr++;
- }
- } else {
- language = strdup("en-us");
- if (!language)
- ErrPrint("Heap: %d\n", errno);
- }
-
- return language;
-}
EAPI int shortcut_get_list(const char *package_name, shortcut_list_cb list_cb, void *data)
{
- sqlite3_stmt *stmt;
- const char *query;
- const unsigned char *name;
- char *i18n_name = NULL;
- char *i18n_icon = NULL;
- const unsigned char *extra_data;
- const unsigned char *extra_key;
- const unsigned char *icon;
- int id;
- int ret;
- int cnt;
- char *language;
+ GDBusMessage *reply = NULL;
+ int result;
+ int count = 0;
+ GVariant *body;
+ GVariant *reply_body;
+ GVariant *iter_body;
+ GVariantIter *iter;
+ GVariantBuilder *b;
+ shortcut_info_s shortcut;
if (list_cb == NULL)
return SHORTCUT_ERROR_INVALID_PARAMETER;
- if (!s_info.db_opened)
- s_info.db_opened = (open_db() == 0);
-
- if (!s_info.db_opened) {
- ErrPrint("Failed to open a DB\n");
- return SHORTCUT_ERROR_IO_ERROR;
+ result = _dbus_init();
+ if (result != SHORTCUT_ERROR_NONE) {
+ ErrPrint("Can't init dbus %d", result);
+ return result;
}
- language = cur_locale();
- if (!language) {
- ErrPrint("Locale is not valid\n");
- return SHORTCUT_ERROR_FAULT;
- }
+ b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ if (package_name)
+ g_variant_builder_add(b, "{sv}", "package_name", g_variant_new_string(package_name));
+ body = g_variant_builder_end(b);
+ result = _send_sync_shortcut(g_variant_new("(v)", body), &reply, "get_list");
- if (package_name) {
- query = "SELECT id, appid, name, extra_key, extra_data, icon FROM shortcut_service WHERE appid = ?";
- ret = sqlite3_prepare_v2(s_info.handle, query, -1, &stmt, NULL);
- if (ret != SQLITE_OK) {
- ErrPrint("prepare: %s\n", sqlite3_errmsg(s_info.handle));
- free(language);
- return SHORTCUT_ERROR_IO_ERROR;
- }
+ if (result == SHORTCUT_ERROR_NONE) {
+ reply_body = g_dbus_message_get_body(reply);
+ g_variant_get(reply_body, "(ia(v))", &count, &iter);
- ret = sqlite3_bind_text(stmt, 1, package_name, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- ErrPrint("bind text: %s\n", sqlite3_errmsg(s_info.handle));
- sqlite3_finalize(stmt);
- free(language);
- return SHORTCUT_ERROR_IO_ERROR;
- }
- } else {
- query = "SELECT id, appid, name, extra_key, extra_data, icon FROM shortcut_service";
- ret = sqlite3_prepare_v2(s_info.handle, query, -1, &stmt, NULL);
- if (ret != SQLITE_OK) {
- ErrPrint("prepare: %s\n", sqlite3_errmsg(s_info.handle));
- free(language);
- return SHORTCUT_ERROR_IO_ERROR;
+ while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
+ g_variant_get(reply_body, "(&s&s&s&s&s)",
+ &shortcut.package_name, &shortcut.icon, &shortcut.name, &shortcut.extra_key, &shortcut.extra_data);
+ list_cb(shortcut.package_name, shortcut.icon, shortcut.name, shortcut.extra_key, shortcut.extra_data, data);
}
+ g_variant_iter_free(iter);
}
- cnt = 0;
- while (SQLITE_ROW == sqlite3_step(stmt)) {
- id = sqlite3_column_int(stmt, 0);
-
- package_name = (const char *)sqlite3_column_text(stmt, 1);
- if (!package_name) {
- LOGE("Failed to get package name\n");
- continue;
- }
-
- name = sqlite3_column_text(stmt, 2);
- if (!name) {
- LOGE("Failed to get name\n");
- continue;
- }
-
- extra_key = sqlite3_column_text(stmt, 3);
- if (!extra_key) {
- LOGE("Failed to get service\n");
- continue;
- }
-
- extra_data = sqlite3_column_text(stmt, 4);
- if (!extra_data) {
- LOGE("Failed to get service\n");
- continue;
- }
-
- icon = sqlite3_column_text(stmt, 5);
- if (!icon) {
- LOGE("Failed to get icon\n");
- continue;
- }
-
- /*!
- * \todo
- * Implement the "GET LOCALE" code
- */
- /* if (get_i18n_name(language, id, &i18n_name, &i18n_icon) < 0) { */
- /* Okay, we can't manage this. just use the fallback string */
- /* } */
- get_i18n_name(language, id, &i18n_name, &i18n_icon);
-
- cnt++;
- if (list_cb(package_name, (i18n_icon != NULL ? i18n_icon : (char *)icon), (i18n_name != NULL ? i18n_name : (char *)name), (char *)extra_key, (char *)extra_data, data) < 0) {
- free(i18n_name);
- break;
- }
-
- free(i18n_name);
- i18n_name = NULL;
-
- free(i18n_icon);
- i18n_icon = NULL;
- }
+ if(reply)
+ g_object_unref(reply);
- sqlite3_reset(stmt);
- sqlite3_clear_bindings(stmt);
- sqlite3_finalize(stmt);
- free(language);
- return cnt;
+ return count;
}
/* End of a file */
diff --git a/packaging/libshortcut.spec b/packaging/libshortcut.spec
index fd422fb..06a4687 100755
--- a/packaging/libshortcut.spec
+++ b/packaging/libshortcut.spec
@@ -15,7 +15,6 @@ BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(db-util)
BuildRequires: pkgconfig(sqlite3)
-BuildRequires: pkgconfig(com-core)
BuildRequires: pkgconfig(libxml-2.0)
BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(capi-base-common)
@@ -107,6 +106,7 @@ chsmack -a User::Home %{TZ_SYS_DB}/.shortcut_service.db-journal
%{_includedir}/shortcut/shortcut.h
%{_includedir}/shortcut/shortcut_private.h
%{_includedir}/shortcut/shortcut_manager.h
+%{_includedir}/shortcut/shortcut_db.h
%{_libdir}/pkgconfig/shortcut.pc
# End of a file
diff --git a/pkgmgr_shortcut/src/service_register.c b/pkgmgr_shortcut/src/service_register.c
index 2f20a50..cd0064e 100755
--- a/pkgmgr_shortcut/src/service_register.c
+++ b/pkgmgr_shortcut/src/service_register.c
@@ -365,6 +365,13 @@ static void do_upgrade_db_schema(void)
case -ENOSYS:
db_create_version();
/* Need to create version table */
+ if (set_version(1) < 0)
+ ErrPrint("Failed to set version\n");
+
+ /* Need to set version */
+ alter_shortcut_name();
+ alter_shortcut_service();
+ break;
case -ENOENT:
if (set_version(1) < 0)
ErrPrint("Failed to set version\n");
@@ -372,11 +379,15 @@ static void do_upgrade_db_schema(void)
/* Need to set version */
alter_shortcut_name();
alter_shortcut_service();
+ alter_shortcut_icon();
+ if (update_version(2) < 0)
+ ErrPrint("Failed to update version\n");
+ break;
case 1:
alter_shortcut_icon();
if (update_version(2) < 0)
ErrPrint("Failed to update version\n");
-
+ break;
case 2:
break;
default: