summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorseungha.son <seungha.son@samsung.com>2017-02-10 11:45:07 +0900
committerseungha.son <seungha.son@samsung.com>2017-02-13 09:52:06 +0900
commit6876496d509e132111e843a0daf8ed9df901a922 (patch)
treec26017d9a659cf69f60ee535b4fcbd740fd60df1
parentb97fe420192994b46c5bf35bdae005ffc185de73 (diff)
downloadshortcut-accepted/tizen_3.0_ivi.tar.gz
shortcut-accepted/tizen_3.0_ivi.tar.bz2
shortcut-accepted/tizen_3.0_ivi.zip
- Currently, It is a structure in which the caller can not get a proper return value when there is a request such as shortcut add or remove. - The caller generates a request-id for each shortcut, passes the id to data-provider-master and passes the return vallue to caller using the id in the data-provider-master daemon. - related patch : https://review.tizen.org/gerrit/#/c/114091/ Signed-off-by: seungha.son <seungha.son@samsung.com> Change-Id: I30791a7a1309df8d9473a373e785bdc9ceb1f62a
-rwxr-xr-xlib/src/shortcut_internal.c54
-rwxr-xr-xlib/src/shortcut_manager.c33
2 files changed, 74 insertions, 13 deletions
diff --git a/lib/src/shortcut_internal.c b/lib/src/shortcut_internal.c
index 2194ab9..430b7db 100755
--- a/lib/src/shortcut_internal.c
+++ b/lib/src/shortcut_internal.c
@@ -57,9 +57,28 @@ typedef struct _shortcut_remove_cb_info {
static shortcut_request_cb_info _request_callback_info;
static shortcut_remove_cb_info _remove_callback_info;
+static void _shortcut_send_return(int ret_val, const char *request_id)
+{
+ int ret;
+ GDBusMessage *reply = NULL;
+
+ ret = _dbus_init();
+ if (ret != SHORTCUT_ERROR_NONE) {
+ SHORTCUT_ERR("Can't init dbus %d", ret);
+ return;
+ }
+
+ _send_sync_shortcut(g_variant_new("(is)", ret_val, request_id),
+ &reply,
+ "send_return_value");
+ if (reply)
+ g_object_unref(reply);
+}
+
/* LCOV_EXCL_START */
static void _add_shortcut_notify(GVariant *parameters)
{
+ int ret = SHORTCUT_ERROR_NOT_SUPPORTED;
const char *appid;
const char *name;
int type;
@@ -67,20 +86,24 @@ static void _add_shortcut_notify(GVariant *parameters)
const char *icon;
int allow_duplicate;
int sender_pid;
+ const char *request_id;
- g_variant_get(parameters, "(i&s&si&s&si)", &sender_pid, &appid, &name, &type, &content, &icon, &allow_duplicate);
+ g_variant_get(parameters, "(&si&s&si&s&si)", &request_id, &sender_pid, &appid, &name, &type, &content, &icon, &allow_duplicate);
SHORTCUT_DBG("_add_shortcut_notify sender pid : [%d] appid : [%s]", sender_pid, appid);
if (_request_callback_info.request_cb != NULL)
- _request_callback_info.request_cb(appid, name, type, content, icon, sender_pid, -1.0f, allow_duplicate, _request_callback_info.data);
+ 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);
+
}
/* LCOV_EXCL_STOP */
/* LCOV_EXCL_START */
static void _add_shortcut_widget_notify(GVariant *parameters)
{
+ int ret = SHORTCUT_ERROR_NOT_SUPPORTED;
const char *appid;
const char *name;
int type;
@@ -89,30 +112,35 @@ static void _add_shortcut_widget_notify(GVariant *parameters)
int allow_duplicate;
int sender_pid;
double period;
+ const char *request_id;
- g_variant_get(parameters, "(i&s&si&s&sdi)", &sender_pid, &appid, &name, &type, &content, &icon, &period, &allow_duplicate);
+ g_variant_get(parameters, "(&si&s&si&s&sdi)", &request_id, &sender_pid, &appid, &name, &type, &content, &icon, &period, &allow_duplicate);
SHORTCUT_DBG("_add_shortcut_widget_notify sender pid : [%d] appid : [%s]", sender_pid, appid);
if (_request_callback_info.request_cb != NULL)
- _request_callback_info.request_cb(appid, name, type, content, icon, sender_pid, period, allow_duplicate, _request_callback_info.data);
+ 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 */
static void _remove_shortcut_notify(GVariant *parameters)
{
+ int ret = SHORTCUT_ERROR_NOT_SUPPORTED;
const char *appid;
const char *name;
int sender_pid;
+ const char *request_id;
- g_variant_get(parameters, "(i&s&s)", &sender_pid, &appid, &name);
+ g_variant_get(parameters, "(&si&s&s)", &request_id, &sender_pid, &appid, &name);
SHORTCUT_DBG("_remove_shortcut_notify sender pid : [%d] appid : [%s]", sender_pid, appid);
if (_remove_callback_info.remove_cb != NULL)
- _remove_callback_info.remove_cb(appid, name, sender_pid, _remove_callback_info.data);
+ 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);
}
/* LCOV_EXCL_START */
@@ -296,6 +324,7 @@ int _send_sync_shortcut(GVariant *body, GDBusMessage **reply, char *cmd)
return ret;
/* LCOV_EXCL_STOP */
}
+
SHORTCUT_DBG("_send_sync_shortcut done !!");
return SHORTCUT_ERROR_NONE;
}
@@ -314,9 +343,10 @@ static void _send_message_with_reply_sync_cb(GDBusConnection *connection,
GAsyncResult *res,
gpointer user_data)
{
- int result = SHORTCUT_ERROR_NONE;
+ int result;
GError *err = NULL;
GDBusMessage *reply = NULL;
+ GVariant *body;
struct result_cb_item *cb_item = (struct result_cb_item *)user_data;
if (cb_item == NULL) {
@@ -339,8 +369,9 @@ static void _send_message_with_reply_sync_cb(GDBusConnection *connection,
}
result = SHORTCUT_ERROR_COMM;
/* LCOV_EXCL_STOP */
+ }
- } else if (g_dbus_message_to_gerror(reply, &err)) {
+ if (g_dbus_message_to_gerror(reply, &err)) {
/* LCOV_EXCL_START */
if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
result = SHORTCUT_ERROR_PERMISSION_DENIED;
@@ -350,12 +381,15 @@ static void _send_message_with_reply_sync_cb(GDBusConnection *connection,
SHORTCUT_ERR("_send_message_with_reply_sync_cb error %s err code: %d", err->message, result);
g_error_free(err);
/* LCOV_EXCL_STOP */
+ } else {
+ body = g_dbus_message_get_body(reply);
+ g_variant_get(body, "(i)", &result);
}
if (cb_item->result_internal_cb)
- result = cb_item->result_internal_cb(result, getpid(), cb_item->data); /* LCOV_EXCL_LINE */
+ cb_item->result_internal_cb(result, getpid(), cb_item->data); /* LCOV_EXCL_LINE */
else if (cb_item->result_cb)
- result = cb_item->result_cb(result, cb_item->data);
+ cb_item->result_cb(result, cb_item->data);
if (reply)
g_object_unref(reply);
diff --git a/lib/src/shortcut_manager.c b/lib/src/shortcut_manager.c
index dcb164c..04975ee 100755
--- a/lib/src/shortcut_manager.c
+++ b/lib/src/shortcut_manager.c
@@ -20,6 +20,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
+#include <time.h>
#include <aul.h>
#include <dlog.h>
@@ -33,6 +34,7 @@
#include "shortcut_internal.h"
#define SHORTCUT_IS_WIDGET_SIZE(size) (!!((size) & WIDGET_SIZE_DEFAULT))
+#define REQUEST_ID_LEN 40
EAPI int shortcut_set_request_cb(shortcut_request_cb request_cb, void *data)
{
@@ -132,6 +134,19 @@ EAPI void shortcut_unset_remove_cb(void)
_unset_remove_cb();
}
+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_t result_cb, void *data)
{
@@ -139,6 +154,7 @@ EAPI int shortcut_add_to_home(const char *name, shortcut_type type, const char *
char *appid;
int ret;
GVariant *body;
+ char *request_id = NULL;
if (ADD_TO_HOME_IS_DYNAMICBOX(type)) {
/* LCOV_EXCL_START */
@@ -191,7 +207,8 @@ EAPI int shortcut_add_to_home(const char *name, shortcut_type type, const char *
if (!icon)
icon = "";
- body = g_variant_new("(ississi)", getpid(), appid, name, type, uri, icon, allow_duplicate);
+ request_id = _make_request_id();
+ 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) {
@@ -205,6 +222,8 @@ EAPI int shortcut_add_to_home(const char *name, shortcut_type type, const char *
free(appid);
if (body)
g_variant_unref(body);
+ if (request_id)
+ free(request_id);
return ret;
}
@@ -216,6 +235,7 @@ EAPI int shortcut_add_to_home_widget(const char *name, shortcut_widget_size_e si
char *appid;
int ret;
GVariant *body;
+ char *request_id = NULL;
if (name == NULL) {
SHORTCUT_ERR("AppID is null\n");
@@ -264,7 +284,8 @@ EAPI int shortcut_add_to_home_widget(const char *name, shortcut_widget_size_e si
item->result_internal_cb = NULL;
item->data = data;
- body = g_variant_new("(ississdi)", getpid(), widget_id, name, size, NULL, icon, period, allow_duplicate);
+ request_id = _make_request_id();
+ 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) {
@@ -278,6 +299,8 @@ EAPI int shortcut_add_to_home_widget(const char *name, shortcut_widget_size_e si
free(appid);
if (body)
g_variant_unref(body);
+ if (request_id)
+ free(request_id);
return ret;
}
@@ -288,6 +311,7 @@ EAPI int shortcut_remove_from_home(const char *name, result_cb_t result_cb, void
char *appid;
int ret;
GVariant *body;
+ char *request_id = NULL;
if (name == NULL) {
SHORTCUT_ERR("name is NULL.");
@@ -329,7 +353,8 @@ EAPI int shortcut_remove_from_home(const char *name, result_cb_t result_cb, void
item->result_internal_cb = NULL;
item->data = user_data;
- body = g_variant_new("(iss)", getpid(), appid, name);
+ request_id = _make_request_id();
+ body = g_variant_new("(siss)", request_id, getpid(), appid, name);
ret = _send_async_shortcut(body, item, "remove_shortcut");
if (ret != SHORTCUT_ERROR_NONE) {
@@ -343,6 +368,8 @@ EAPI int shortcut_remove_from_home(const char *name, result_cb_t result_cb, void
free(appid);
if (body)
g_variant_unref(body);
+ if (request_id)
+ free(request_id);
return ret;
}