#include "shortcut_internal.h"
#define SHORTCUT_PKGNAME_LEN 512
+#define REQUEST_ID_LEN 40
+#define TIMEOUT 4000
#define PROVIDER_BUS_NAME "org.tizen.data_provider_service"
#define PROVIDER_OBJECT_PATH "/org/tizen/data_provider_service"
}
_send_sync_shortcut(g_variant_new("(is)", ret_val, request_id),
- &reply,
- "send_return_value");
+ &reply, "send_return_value");
if (reply)
g_object_unref(reply);
}
ret = _request_callback_info.request_cb(appid, name, type, content, icon, sender_pid, -1.0f, allow_duplicate, _request_callback_info.data);
else
SHORTCUT_DBG("request_cb is null.");
- _shortcut_send_return(ret, request_id);
+ _shortcut_send_return(ret, request_id);
}
/* LCOV_EXCL_STOP */
ret = _request_callback_info.request_cb(appid, name, type, content, icon, sender_pid, period, allow_duplicate, _request_callback_info.data);
else
SHORTCUT_DBG("request_cb is null.");
+
_shortcut_send_return(ret, request_id);
}
/* LCOV_EXCL_STOP */
ret = _remove_callback_info.remove_cb(appid, name, sender_pid, _remove_callback_info.data);
else
SHORTCUT_DBG("remove_cb is null.");
+
_shortcut_send_return(ret, request_id);
}
id = g_dbus_connection_signal_subscribe(
_gdbus_conn,
PROVIDER_BUS_NAME,
- PROVIDER_SHORTCUT_INTERFACE_NAME, /* interface */
- NULL, /* member */
- PROVIDER_OBJECT_PATH, /* path */
- NULL, /* arg0 */
+ PROVIDER_SHORTCUT_INTERFACE_NAME, /* interface */
+ NULL, /* member */
+ PROVIDER_OBJECT_PATH, /* path */
+ NULL, /* arg0 */
G_DBUS_SIGNAL_FLAGS_NONE,
_handle_shortcut_notify,
NULL,
_gdbus_conn,
msg,
G_DBUS_SEND_MESSAGE_FLAGS_NONE,
- -1,
+ TIMEOUT,
NULL,
NULL,
&err);
return SHORTCUT_ERROR_NONE;
}
+
+char *_make_request_id(void)
+{
+ static int id = 0;
+ char request_id[REQUEST_ID_LEN];
+
+ g_atomic_int_inc(&id);
+ snprintf(request_id, sizeof(request_id), "%d@%d", getpid(), id);
+
+ SHORTCUT_DBG("The request_id of shortcut is [%s]", request_id);
+
+ return strdup(request_id);
+}
+
+int _ready_to_send(char **appid, char **request_id)
+{
+ int ret;
+
+ ret = _dbus_init();
+ if (ret != SHORTCUT_ERROR_NONE) {
+ /* LCOV_EXCL_START */
+ SHORTCUT_ERR("Can't init dbus %d", ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = _check_privilege();
+ if (ret != SHORTCUT_ERROR_NONE)
+ return ret;
+
+ *appid = _shortcut_get_pkgname_by_pid();
+ if (*appid == NULL) {
+ /* LCOV_EXCL_START */
+ SHORTCUT_ERR("Can't get appid");
+ return SHORTCUT_ERROR_IO_ERROR;
+ /* LCOV_EXCL_STOP */
+ }
+
+ *request_id = _make_request_id();
+ if (*request_id == NULL) {
+ SHORTCUT_ERR("Can't get request_id");
+ free(*appid);
+ return SHORTCUT_ERROR_OUT_OF_MEMORY;
+ }
+
+ return SHORTCUT_ERROR_NONE;
+}
+
+EAPI int shortcut_add_to_home_sync(const char *name, shortcut_type type,
+ const char *uri, const char *icon, int allow_duplicate)
+{
+ int ret;
+ char *appid;
+ char *request_id = NULL;
+ GVariant *body;
+ GVariant *reply_body;
+ GDBusMessage *reply = NULL;
+
+ CHECK_SHORTCUT_FEATURE();
+
+ if (ADD_TO_HOME_IS_DYNAMICBOX(type)) {
+ /* LCOV_EXCL_START */
+ SHORTCUT_ERR("Invalid type used for adding a shortcut\n");
+ return SHORTCUT_ERROR_INVALID_PARAMETER;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = _ready_to_send(&appid, &request_id);
+ if (ret != SHORTCUT_ERROR_NONE) {
+ /* LCOV_EXCL_START */
+ SHORTCUT_ERR("ready to send error [%d]", ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+
+ if (!name)
+ name = "";
+
+ if (!uri)
+ uri = "";
+
+ if (!icon)
+ icon = "";
+
+ body = g_variant_new("(sississi)", request_id, getpid(), appid, name,
+ type, uri, icon, allow_duplicate);
+
+ ret = _send_sync_shortcut(body, &reply, "add_shortcut");
+ if (ret == SHORTCUT_ERROR_NONE) {
+ reply_body = g_dbus_message_get_body(reply);
+ g_variant_get(reply_body, "(i)", &ret);
+ }
+
+ if (appid)
+ free(appid);
+ if (body)
+ g_variant_unref(body);
+ if (request_id)
+ free(request_id);
+ if (reply)
+ g_object_unref(reply);
+
+ SHORTCUT_DBG("result[%d]", ret);
+
+ return ret;
+}
+
+EAPI int shortcut_add_to_home_widget_sync(const char *name,
+ shortcut_widget_size_e size, const char *widget_id,
+ const char *icon, double period, int allow_duplicate)
+{
+ int ret;
+ char *appid;
+ char *request_id = NULL;
+ GVariant *body;
+ GVariant *reply_body;
+ GDBusMessage *reply = NULL;
+
+ CHECK_SHORTCUT_FEATURE();
+
+ if (name == NULL) {
+ SHORTCUT_ERR("AppID is null\n");
+ return SHORTCUT_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!SHORTCUT_IS_WIDGET_SIZE(size)) {
+ /* LCOV_EXCL_START */
+ SHORTCUT_ERR("Invalid type used for adding a widget\n");
+ return SHORTCUT_ERROR_INVALID_PARAMETER;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = _ready_to_send(&appid, &request_id);
+ if (ret != SHORTCUT_ERROR_NONE) {
+ /* LCOV_EXCL_START */
+ SHORTCUT_ERR("ready to send error [%d]", ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+
+ body = g_variant_new("(sississdi)", request_id, getpid(), widget_id,
+ name, size, NULL, icon, period, allow_duplicate);
+
+ ret = _send_sync_shortcut(body, &reply, "add_shortcut_widget");
+ if (ret == SHORTCUT_ERROR_NONE) {
+ reply_body = g_dbus_message_get_body(reply);
+ g_variant_get(reply_body, "(i)", &ret);
+ }
+
+ if (appid)
+ free(appid);
+ if (body)
+ g_variant_unref(body);
+ if (request_id)
+ free(request_id);
+ if (reply)
+ g_object_unref(reply);
+
+ SHORTCUT_DBG("result[%d]", ret);
+
+ return ret;
+}
+
+EAPI int shortcut_remove_from_home_sync(const char *name)
+{
+ int ret;
+ char *appid;
+ char *request_id = NULL;
+ GVariant *body;
+ GVariant *reply_body;
+ GDBusMessage *reply = NULL;
+
+ CHECK_SHORTCUT_FEATURE();
+
+ if (name == NULL) {
+ SHORTCUT_ERR("name is NULL.");
+ return SHORTCUT_ERROR_INVALID_PARAMETER;
+ }
+
+ ret = _ready_to_send(&appid, &request_id);
+ if (ret != SHORTCUT_ERROR_NONE) {
+ /* LCOV_EXCL_START */
+ SHORTCUT_ERR("ready to send error [%d]", ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+
+ body = g_variant_new("(siss)", request_id, getpid(), appid, name);
+
+ ret = _send_sync_shortcut(body, &reply, "remove_shortcut");
+ if (ret == SHORTCUT_ERROR_NONE) {
+ reply_body = g_dbus_message_get_body(reply);
+ g_variant_get(reply_body, "(i)", &ret);
+ }
+
+ if (appid)
+ free(appid);
+ if (body)
+ g_variant_unref(body);
+ if (request_id)
+ free(request_id);
+ if (reply)
+ g_object_unref(reply);
+
+ SHORTCUT_DBG("result[%d]", ret);
+
+ return ret;
+}
#include "shortcut_manager.h"
#include "shortcut_internal.h"
-#define SHORTCUT_IS_WIDGET_SIZE(size) (!!((size) & WIDGET_SIZE_DEFAULT))
-#define REQUEST_ID_LEN 40
-
static int __shortcut_init_ipc_process()
{
int ret;
set_last_result(SHORTCUT_ERROR_NONE);
}
-static char *_make_request_id()
-{
- static int id = 0;
- char request_id[REQUEST_ID_LEN] = { 0, };
-
- g_atomic_int_inc(&id);
- snprintf(request_id, sizeof(request_id), "%d@%d", getpid(), id);
-
- SHORTCUT_DBG("The request_id of shortcut is [%s]", request_id);
-
- return strdup(request_id);
-}
-
-EAPI int shortcut_add_to_home(const char *name, shortcut_type type, const char *uri,
- const char *icon, int allow_duplicate, result_cb 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 cb, void *data)
{
struct result_cb_item *item;
char *appid;
/* LCOV_EXCL_STOP */
}
- ret = _dbus_init();
+ ret = _ready_to_send(&appid, &request_id);
if (ret != SHORTCUT_ERROR_NONE) {
/* LCOV_EXCL_START */
- SHORTCUT_ERR("Can't init dbus %d", ret);
+ SHORTCUT_ERR("ready to send error [%d]", ret);
return ret;
/* LCOV_EXCL_STOP */
}
- ret = _check_privilege();
- if (ret != SHORTCUT_ERROR_NONE)
- return ret;
-
- appid = _shortcut_get_pkgname_by_pid();
- if (appid == NULL) {
- /* LCOV_EXCL_START */
- SHORTCUT_ERR("Can't get appid");
- return SHORTCUT_ERROR_IO_ERROR;
- /* LCOV_EXCL_STOP */
- }
-
item = malloc(sizeof(struct result_cb_item));
if (!item) {
/* LCOV_EXCL_START */
if (!icon)
icon = "";
- request_id = _make_request_id();
- body = g_variant_new("(sississi)", request_id, getpid(), appid, name, type, uri, icon, allow_duplicate);
+ body = g_variant_new("(sississi)", request_id, getpid(), appid, name,
+ type, uri, icon, allow_duplicate);
ret = _send_async_shortcut(body, item, "add_shortcut");
if (ret != 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 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 cb, void *data)
{
struct result_cb_item *item;
char *appid;
/* LCOV_EXCL_STOP */
}
- ret = _dbus_init();
+ ret = _ready_to_send(&appid, &request_id);
if (ret != SHORTCUT_ERROR_NONE) {
/* LCOV_EXCL_START */
- SHORTCUT_ERR("Can't init dbus %d", ret);
+ SHORTCUT_ERR("ready to send error [%d]", ret);
return ret;
/* LCOV_EXCL_STOP */
}
- ret = _check_privilege();
- if (ret != SHORTCUT_ERROR_NONE)
- return ret;
-
- appid = _shortcut_get_pkgname_by_pid();
- if (appid == NULL) {
- /* LCOV_EXCL_START */
- SHORTCUT_ERR("Can't get appid");
- return SHORTCUT_ERROR_IO_ERROR;
- /* LCOV_EXCL_STOP */
- }
-
item = malloc(sizeof(struct result_cb_item));
if (!item) {
/* LCOV_EXCL_START */
item->result_internal_cb = NULL;
item->data = data;
- request_id = _make_request_id();
- body = g_variant_new("(sississdi)", request_id, getpid(), widget_id, name, size, NULL, icon, period, allow_duplicate);
+ body = g_variant_new("(sississdi)", request_id, getpid(), widget_id,
+ name, size, NULL, icon, period, allow_duplicate);
+
ret = _send_async_shortcut(body, item, "add_shortcut_widget");
if (ret != SHORTCUT_ERROR_NONE) {
return SHORTCUT_ERROR_INVALID_PARAMETER;
}
- ret = _dbus_init();
+ ret = _ready_to_send(&appid, &request_id);
if (ret != SHORTCUT_ERROR_NONE) {
/* LCOV_EXCL_START */
- SHORTCUT_ERR("Can't init dbus %d", ret);
+ SHORTCUT_ERR("ready to send error [%d]", ret);
return ret;
/* LCOV_EXCL_STOP */
}
- ret = _check_privilege();
- if (ret != SHORTCUT_ERROR_NONE)
- return ret;
-
- appid = _shortcut_get_pkgname_by_pid();
- if (appid == NULL) {
- /* LCOV_EXCL_START */
- SHORTCUT_ERR("Can't get appid");
- return SHORTCUT_ERROR_IO_ERROR;
- /* LCOV_EXCL_STOP */
- }
-
item = malloc(sizeof(struct result_cb_item));
if (!item) {
/* LCOV_EXCL_START */
item->result_internal_cb = NULL;
item->data = user_data;
- request_id = _make_request_id();
body = g_variant_new("(siss)", request_id, getpid(), appid, name);
ret = _send_async_shortcut(body, item, "remove_shortcut");